Skip to content

Commit

Permalink
[improvement](jdbc catalog) Adjust function replacement order and add…
Browse files Browse the repository at this point in the history
… new function support (apache#24685)
  • Loading branch information
zy-kkk authored Sep 21, 2023
1 parent 5e82aeb commit 4ca650f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -70,6 +71,7 @@ private static boolean isReplaceMysqlFunctions(String functionName) {

static {
REPLACE_CLICKHOUSE_FUNCTIONS.put("from_unixtime", "FROM_UNIXTIME");
REPLACE_CLICKHOUSE_FUNCTIONS.put("unix_timestamp", "toUnixTimestamp");
}

private static boolean isReplaceClickHouseFunctions(String functionName) {
Expand Down Expand Up @@ -105,14 +107,14 @@ private static Expr processFunctionsRecursively(Expr expr, Predicate<String> che

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<Expr> children = expr.getChildren();
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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} """
Expand Down

0 comments on commit 4ca650f

Please sign in to comment.