From 52d29fa9f665d70f8755b878ac5c9c60b5f36d72 Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Tue, 5 Nov 2024 23:55:30 +0800 Subject: [PATCH 01/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../com/starrocks/connector/parser/trino/AstBuilder.java | 5 +++++ .../parser/trino/TrinoFunctionTransformTest.java | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java index 3bb6e8e3a7e35..daa0e1456dc12 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java @@ -999,6 +999,11 @@ protected ParseNode visitCoalesceExpression(CoalesceExpression node, ParseTreeCo @Override protected ParseNode visitExtract(Extract node, ParseTreeContext context) { String fieldString = node.getField().toString(); + if (fieldString.equalsIgnoreCase("dow")) { + fieldString = "dayofweek_iso"; + } else if (fieldString.equalsIgnoreCase("week")) { + fieldString = "week_iso"; + } return new FunctionCallExpr(fieldString, new FunctionParams(Lists.newArrayList((Expr) visit(node.getExpression(), context)))); } diff --git a/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java b/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java index c6e134eea03a3..f9f8a6a096229 100644 --- a/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java @@ -339,6 +339,15 @@ public void testJsonFnTransform() throws Exception { assertPlanContains(sql, "CAST(json_query(parse_json('{\"a\": {\"b\": 1}}'), '$.a.b') AS VARCHAR)"); } + @Test + public void testExtractFnTransform() throws Exception { + String sql = "SELECT extract(dow FROM TIMESTAMP '2022-10-20 05:10:00')"; + assertPlanContains(sql, "dayofweek_iso('2022-10-20 05:10:00')"); + sql = "SELECT week(dow FROM TIMESTAMP '2022-10-20 05:10:00')"; + assertPlanContains(sql, "week_iso('2022-10-20 05:10:00')"); + } + + @Test public void testBitFnTransform() throws Exception { String sql = "select bitwise_and(19,25)"; From 9c3515fcffe6ea4f7b62472103f3045438c354b0 Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Fri, 8 Nov 2024 16:33:29 +0800 Subject: [PATCH 02/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../connector/parser/trino/TrinoFunctionTransformTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java b/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java index f9f8a6a096229..ee441fdc95ffc 100644 --- a/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java @@ -343,7 +343,7 @@ public void testJsonFnTransform() throws Exception { public void testExtractFnTransform() throws Exception { String sql = "SELECT extract(dow FROM TIMESTAMP '2022-10-20 05:10:00')"; assertPlanContains(sql, "dayofweek_iso('2022-10-20 05:10:00')"); - sql = "SELECT week(dow FROM TIMESTAMP '2022-10-20 05:10:00')"; + sql = "SELECT extract(dow FROM TIMESTAMP '2022-10-20 05:10:00')"; assertPlanContains(sql, "week_iso('2022-10-20 05:10:00')"); } From 134f856dada162a31a9315ac5578745757594be9 Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Sat, 9 Nov 2024 07:15:03 +0800 Subject: [PATCH 03/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../connector/parser/trino/TrinoFunctionTransformTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java b/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java index ee441fdc95ffc..f54f63b24caa5 100644 --- a/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoFunctionTransformTest.java @@ -343,7 +343,7 @@ public void testJsonFnTransform() throws Exception { public void testExtractFnTransform() throws Exception { String sql = "SELECT extract(dow FROM TIMESTAMP '2022-10-20 05:10:00')"; assertPlanContains(sql, "dayofweek_iso('2022-10-20 05:10:00')"); - sql = "SELECT extract(dow FROM TIMESTAMP '2022-10-20 05:10:00')"; + sql = "SELECT extract(week FROM TIMESTAMP '2022-10-20 05:10:00')"; assertPlanContains(sql, "week_iso('2022-10-20 05:10:00')"); } From 21f42c094519c0abeff42fbeed8fe4e14b7c09ec Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Tue, 12 Nov 2024 13:22:23 +0800 Subject: [PATCH 04/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../starrocks/connector/parser/trino/AstBuilder.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java index daa0e1456dc12..a415f85b73232 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java @@ -998,14 +998,9 @@ protected ParseNode visitCoalesceExpression(CoalesceExpression node, ParseTreeCo @Override protected ParseNode visitExtract(Extract node, ParseTreeContext context) { - String fieldString = node.getField().toString(); - if (fieldString.equalsIgnoreCase("dow")) { - fieldString = "dayofweek_iso"; - } else if (fieldString.equalsIgnoreCase("week")) { - fieldString = "week_iso"; - } - return new FunctionCallExpr(fieldString, - new FunctionParams(Lists.newArrayList((Expr) visit(node.getExpression(), context)))); + String fieldString = node.getField().toString().toLowerCase(); + return Trino2SRFunctionCallTransformer.convert(fieldString, + Lists.newArrayList((Expr) visit(node.getExpression(), context))); } @Override From ec30a0c1ff892716dff528ce4daab4dd20b9a71e Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Thu, 14 Nov 2024 13:14:47 +0800 Subject: [PATCH 05/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../connector/parser/trino/Trino2SRFunctionCallTransformer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java index 87f11a2cf0cde..a51e342a6e0e1 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java @@ -232,6 +232,8 @@ private static void registerDateFunctionTransformer() { // last_day_of_month(x) -> last_day(x,'month') registerFunctionTransformer("last_day_of_month", 1, new FunctionCallExpr("last_day", List.of(new PlaceholderExpr(1, Expr.class), new StringLiteral("month")))); + // year -> year + registerFunctionTransformer("year", 1, "year" ,List.of(Expr.class)); } private static void registerStringFunctionTransformer() { From d647ea995ec404035d4320445bd3cae2b1f2a1bb Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Thu, 14 Nov 2024 14:00:35 +0800 Subject: [PATCH 06/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../connector/parser/trino/Trino2SRFunctionCallTransformer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java index a51e342a6e0e1..8dd2dbb321546 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java @@ -233,7 +233,7 @@ private static void registerDateFunctionTransformer() { registerFunctionTransformer("last_day_of_month", 1, new FunctionCallExpr("last_day", List.of(new PlaceholderExpr(1, Expr.class), new StringLiteral("month")))); // year -> year - registerFunctionTransformer("year", 1, "year" ,List.of(Expr.class)); + registerFunctionTransformer("year", 1, "year", List.of(Expr.class)); } private static void registerStringFunctionTransformer() { From 6f054136325bfd7148cdb0407c829bd27582a110 Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Thu, 14 Nov 2024 19:35:59 +0800 Subject: [PATCH 07/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../com/starrocks/connector/parser/trino/AstBuilder.java | 5 ++++- .../parser/trino/Trino2SRFunctionCallTransformer.java | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java index a415f85b73232..2a2a50adf22d0 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/AstBuilder.java @@ -192,6 +192,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; @@ -999,8 +1000,10 @@ protected ParseNode visitCoalesceExpression(CoalesceExpression node, ParseTreeCo @Override protected ParseNode visitExtract(Extract node, ParseTreeContext context) { String fieldString = node.getField().toString().toLowerCase(); - return Trino2SRFunctionCallTransformer.convert(fieldString, + Expr expr = Trino2SRFunctionCallTransformer.convert(fieldString, Lists.newArrayList((Expr) visit(node.getExpression(), context))); + return Objects.requireNonNullElseGet(expr, () -> new FunctionCallExpr(fieldString, + new FunctionParams(Lists.newArrayList((Expr) visit(node.getExpression(), context))))); } @Override diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java index 8dd2dbb321546..8e81d2f3cef65 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java @@ -232,8 +232,12 @@ private static void registerDateFunctionTransformer() { // last_day_of_month(x) -> last_day(x,'month') registerFunctionTransformer("last_day_of_month", 1, new FunctionCallExpr("last_day", List.of(new PlaceholderExpr(1, Expr.class), new StringLiteral("month")))); - // year -> year - registerFunctionTransformer("year", 1, "year", List.of(Expr.class)); + + // year_of_week -> weekofyear + registerFunctionTransformer("year_of_week", 1, "weekofyear", List.of(Expr.class)); + + // yow -> year_of_week + registerFunctionTransformer("yow", 1, "weekofyear", List.of(Expr.class)); } private static void registerStringFunctionTransformer() { From 686079041e2ddb0c3ac35ebaec2153f59fca0b73 Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Thu, 14 Nov 2024 20:29:40 +0800 Subject: [PATCH 08/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../connector/parser/trino/Trino2SRFunctionCallTransformer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java index 8e81d2f3cef65..bc4b434c43e37 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java @@ -235,7 +235,6 @@ private static void registerDateFunctionTransformer() { // year_of_week -> weekofyear registerFunctionTransformer("year_of_week", 1, "weekofyear", List.of(Expr.class)); - // yow -> year_of_week registerFunctionTransformer("yow", 1, "weekofyear", List.of(Expr.class)); } From 9c4a3abf76ed900c62c9000ef7a642466bdb8e47 Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Thu, 14 Nov 2024 21:52:56 +0800 Subject: [PATCH 09/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../connector/parser/trino/Trino2SRFunctionCallTransformer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java index bc4b434c43e37..8e81d2f3cef65 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java @@ -235,6 +235,7 @@ private static void registerDateFunctionTransformer() { // year_of_week -> weekofyear registerFunctionTransformer("year_of_week", 1, "weekofyear", List.of(Expr.class)); + // yow -> year_of_week registerFunctionTransformer("yow", 1, "weekofyear", List.of(Expr.class)); } From 331891bc8dbc322dd5c0e484f215a9735a99b52e Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Fri, 15 Nov 2024 00:14:03 +0800 Subject: [PATCH 10/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../connector/parser/trino/Trino2SRFunctionCallTransformer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java index 8e81d2f3cef65..bc4b434c43e37 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java @@ -235,7 +235,6 @@ private static void registerDateFunctionTransformer() { // year_of_week -> weekofyear registerFunctionTransformer("year_of_week", 1, "weekofyear", List.of(Expr.class)); - // yow -> year_of_week registerFunctionTransformer("yow", 1, "weekofyear", List.of(Expr.class)); } From 0b91e73e3ffab9f792031e4d09b3a8dcaa3a81fa Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Fri, 15 Nov 2024 19:21:37 +0800 Subject: [PATCH 11/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../parser/trino/Trino2SRFunctionCallTransformer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java index bc4b434c43e37..f8039e73eb2b9 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java @@ -234,9 +234,9 @@ private static void registerDateFunctionTransformer() { List.of(new PlaceholderExpr(1, Expr.class), new StringLiteral("month")))); // year_of_week -> weekofyear - registerFunctionTransformer("year_of_week", 1, "weekofyear", List.of(Expr.class)); + registerFunctionTransformer("year_of_week", 1, "week_iso", List.of(Expr.class)); // yow -> year_of_week - registerFunctionTransformer("yow", 1, "weekofyear", List.of(Expr.class)); + registerFunctionTransformer("yow", 1, "week_iso", List.of(Expr.class)); } private static void registerStringFunctionTransformer() { From 83e318feb4d6870752d02964105b0eac0aab0420 Mon Sep 17 00:00:00 2001 From: "zhiminr.ren" <1240388654@qq.com> Date: Fri, 15 Nov 2024 19:25:42 +0800 Subject: [PATCH 12/12] Trino dialect, the extract function supports dow and week parameters Signed-off-by: zhiminr.ren <1240388654@qq.com> --- .../parser/trino/Trino2SRFunctionCallTransformer.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java index f8039e73eb2b9..87f11a2cf0cde 100644 --- a/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java +++ b/fe/fe-core/src/main/java/com/starrocks/connector/parser/trino/Trino2SRFunctionCallTransformer.java @@ -232,11 +232,6 @@ private static void registerDateFunctionTransformer() { // last_day_of_month(x) -> last_day(x,'month') registerFunctionTransformer("last_day_of_month", 1, new FunctionCallExpr("last_day", List.of(new PlaceholderExpr(1, Expr.class), new StringLiteral("month")))); - - // year_of_week -> weekofyear - registerFunctionTransformer("year_of_week", 1, "week_iso", List.of(Expr.class)); - // yow -> year_of_week - registerFunctionTransformer("yow", 1, "week_iso", List.of(Expr.class)); } private static void registerStringFunctionTransformer() {