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..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; @@ -998,9 +999,11 @@ protected ParseNode visitCoalesceExpression(CoalesceExpression node, ParseTreeCo @Override protected ParseNode visitExtract(Extract node, ParseTreeContext context) { - String fieldString = node.getField().toString(); - return new FunctionCallExpr(fieldString, - new FunctionParams(Lists.newArrayList((Expr) visit(node.getExpression(), context)))); + String fieldString = node.getField().toString().toLowerCase(); + 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 87f11a2cf0cde..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 @@ -232,6 +232,11 @@ 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, "weekofyear", List.of(Expr.class)); + // yow -> year_of_week + registerFunctionTransformer("yow", 1, "weekofyear", List.of(Expr.class)); } private static void registerStringFunctionTransformer() { 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..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 @@ -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 extract(week 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)";