Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Trino dialect, the extract function supports dow and week parameters #52651

Merged
merged 12 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand Down
Loading