Skip to content

Commit

Permalink
[Feature] Support trino current_catalog and current_schema function (…
Browse files Browse the repository at this point in the history
…backport #41319) (#41518)

Signed-off-by: hongyu guo <[email protected]>
Co-authored-by: hongyu guo <[email protected]>
  • Loading branch information
Youngwb and macroguo-ghy authored Feb 23, 2024
1 parent 195031c commit d36860b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
import io.trino.sql.tree.CoalesceExpression;
import io.trino.sql.tree.ComparisonExpression;
import io.trino.sql.tree.Cube;
import io.trino.sql.tree.CurrentCatalog;
import io.trino.sql.tree.CurrentSchema;
import io.trino.sql.tree.CurrentTime;
import io.trino.sql.tree.CurrentUser;
import io.trino.sql.tree.DataType;
Expand Down Expand Up @@ -1091,6 +1093,16 @@ protected ParseNode visitCurrentTime(CurrentTime node, ParseTreeContext context)
return new FunctionCallExpr(node.getFunction().getName(), new ArrayList<>());
}

@Override
protected ParseNode visitCurrentCatalog(CurrentCatalog node, ParseTreeContext context) {
return new InformationFunction(FunctionSet.CATALOG.toUpperCase());
}

@Override
protected ParseNode visitCurrentSchema(CurrentSchema node, ParseTreeContext context) {
return new InformationFunction(FunctionSet.SCHEMA.toUpperCase());
}

@Override
protected ParseNode visitSearchedCaseExpression(SearchedCaseExpression node, ParseTreeContext context) {
return new CaseExpr(null, visit(node.getWhenClauses(), context, CaseWhenClause.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,13 @@ public void testIsNullFunction() throws Exception {
sql = "select isnotnull(null)";
assertPlanContains(sql, "<slot 2> : FALSE");
}

@Test
public void testUtilityFunction() throws Exception {
String sql = "select current_catalog";
assertPlanContains(sql, "<slot 2> : CATALOG()");

sql = "select current_schema";
assertPlanContains(sql, "<slot 2> : SCHEMA()");
}
}

0 comments on commit d36860b

Please sign in to comment.