Skip to content

Commit

Permalink
Trino dialect, the extract function supports dow and week parameters
Browse files Browse the repository at this point in the history
Signed-off-by: zhiminr.ren <[email protected]>
  • Loading branch information
renzhimin7 committed Nov 8, 2024
1 parent aeff4a3 commit 52d29fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
}
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 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)";
Expand Down

0 comments on commit 52d29fa

Please sign in to comment.