From e3b5028223d82e2432d037d56d2cee1315a6d7ab Mon Sep 17 00:00:00 2001 From: Mihai Budiu Date: Mon, 16 Oct 2023 13:45:03 -0700 Subject: [PATCH] [CALCITE-6030] DATE_PART is not handled by the RexToLixTranslator Signed-off-by: Mihai Budiu --- babel/src/test/java/org/apache/calcite/test/BabelTest.java | 7 +++++++ .../org/apache/calcite/adapter/enumerable/RexImpTable.java | 2 ++ 2 files changed, 9 insertions(+) diff --git a/babel/src/test/java/org/apache/calcite/test/BabelTest.java b/babel/src/test/java/org/apache/calcite/test/BabelTest.java index 42166a1d0d2..1feb2e6020f 100644 --- a/babel/src/test/java/org/apache/calcite/test/BabelTest.java +++ b/babel/src/test/java/org/apache/calcite/test/BabelTest.java @@ -232,6 +232,13 @@ private void checkInfixCast(Statement statement, String typeName, int sqlType) "EXPR$0=false\n"); } + /** Test case for + * [CALCITE-6030] DATE_PART is not handled by the RexToLixTranslator. */ + @Test void testDatePart() { + checkSqlResult("postgresql", "SELECT DATE_PART(second, TIME '10:10:10')", + "EXPR$0=10\n"); + } + /** Test case for * [CALCITE-5816] * Query with LEFT SEMI JOIN should not refer to RHS columns. */ diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java index 9d563077c81..b3a5565eb5d 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java @@ -169,6 +169,7 @@ import static org.apache.calcite.sql.fun.SqlLibraryOperators.DATETIME; import static org.apache.calcite.sql.fun.SqlLibraryOperators.DATETIME_TRUNC; import static org.apache.calcite.sql.fun.SqlLibraryOperators.DATE_FROM_UNIX_DATE; +import static org.apache.calcite.sql.fun.SqlLibraryOperators.DATE_PART; import static org.apache.calcite.sql.fun.SqlLibraryOperators.DATE_TRUNC; import static org.apache.calcite.sql.fun.SqlLibraryOperators.DAYNAME; import static org.apache.calcite.sql.fun.SqlLibraryOperators.DIFFERENCE; @@ -688,6 +689,7 @@ Builder populate2() { map.put(DATETIME_PLUS, new DatetimeArithmeticImplementor()); map.put(MINUS_DATE, new DatetimeArithmeticImplementor()); map.put(EXTRACT, new ExtractImplementor()); + map.put(DATE_PART, new ExtractImplementor()); map.put(FLOOR, new FloorImplementor(BuiltInMethod.FLOOR.method, BuiltInMethod.UNIX_TIMESTAMP_FLOOR.method,