From 4ca650f306dcc3e87e83a351fb40f4b442d2ea73 Mon Sep 17 00:00:00 2001 From: zy-kkk Date: Thu, 21 Sep 2023 08:45:27 +0800 Subject: [PATCH] [improvement](jdbc catalog) Adjust function replacement order and add new function support (#24685) --- .../jdbc/JdbcFunctionPushDownRule.java | 8 +++++--- .../jdbc/test_clickhouse_jdbc_catalog.out | Bin 2782 -> 2801 bytes .../jdbc/test_clickhouse_jdbc_catalog.groovy | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/external/jdbc/JdbcFunctionPushDownRule.java b/fe/fe-core/src/main/java/org/apache/doris/planner/external/jdbc/JdbcFunctionPushDownRule.java index d1a44cb700..35d069c12c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/external/jdbc/JdbcFunctionPushDownRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/external/jdbc/JdbcFunctionPushDownRule.java @@ -45,6 +45,7 @@ public class JdbcFunctionPushDownRule { static { CLICKHOUSE_SUPPORTED_FUNCTIONS.add("from_unixtime"); + CLICKHOUSE_SUPPORTED_FUNCTIONS.add("unix_timestamp"); } private static boolean isMySQLFunctionUnsupported(String functionName) { @@ -70,6 +71,7 @@ public class JdbcFunctionPushDownRule { static { REPLACE_CLICKHOUSE_FUNCTIONS.put("from_unixtime", "FROM_UNIXTIME"); + REPLACE_CLICKHOUSE_FUNCTIONS.put("unix_timestamp", "toUnixTimestamp"); } private static boolean isReplaceClickHouseFunctions(String functionName) { @@ -105,14 +107,14 @@ public class JdbcFunctionPushDownRule { Preconditions.checkArgument(!func.isEmpty(), "function can not be empty"); - func = replaceFunctionNameIfNecessary(func, replaceFunction, functionCallExpr, tableType); - - if (!func.isEmpty() && checkFunction.test(func)) { + if (checkFunction.test(func)) { String errMsg = "Unsupported function: " + func + " in expr: " + expr.toMySql() + " in JDBC Table Type: " + tableType; LOG.warn(errMsg); errors.add(errMsg); } + + replaceFunctionNameIfNecessary(func, replaceFunction, functionCallExpr, tableType); } List children = expr.getChildren(); diff --git a/regression-test/data/external_table_p0/jdbc/test_clickhouse_jdbc_catalog.out b/regression-test/data/external_table_p0/jdbc/test_clickhouse_jdbc_catalog.out index 05372e3f0af9d16c6158e62adee6b887b2a13358..d6591a4828d6ecbf3fccc182ec3cc90519e7ee71 100644 GIT binary patch delta 27 icmca7`cZVlJuYEgT?NIo(!AvOg3{s)BL!VuE-nC%%m~W> delta 7 Ocmew;dQWu2JuUzboCA^o diff --git a/regression-test/suites/external_table_p0/jdbc/test_clickhouse_jdbc_catalog.groovy b/regression-test/suites/external_table_p0/jdbc/test_clickhouse_jdbc_catalog.groovy index b01f200574..8fb0f32399 100644 --- a/regression-test/suites/external_table_p0/jdbc/test_clickhouse_jdbc_catalog.groovy +++ b/regression-test/suites/external_table_p0/jdbc/test_clickhouse_jdbc_catalog.groovy @@ -75,7 +75,12 @@ suite("test_clickhouse_jdbc_catalog", "p0,external,clickhouse,external_docker,ex } explain { sql("select * from ts where nvl(ts,null) >= '2022-01-01';") - contains """QUERY: SELECT "id", "ts" FROM "doris_test"."ts"""" + contains """QUERY: SELECT "id", "ts" FROM "doris_test"."ts""" + } + order_qt_func_push2 """select * from ts where ts <= unix_timestamp(from_unixtime(ts,'yyyyMMdd'));""" + explain { + sql("select * from ts where ts <= unix_timestamp(from_unixtime(ts,'yyyy-MM-dd'));") + contains """QUERY: SELECT "id", "ts" FROM "doris_test"."ts" WHERE (ts <= toUnixTimestamp(FROM_UNIXTIME(ts, '%Y-%m-%d')))""" } sql """ drop catalog if exists ${catalog_name} """