From 424471912e26d7f044a30743c95bcfbf6d952795 Mon Sep 17 00:00:00 2001 From: hongyu guo Date: Thu, 22 Feb 2024 19:17:47 +0800 Subject: [PATCH] [Feature] Support trino current_catalog and current_schema function (#41319) Signed-off-by: hongyu guo --- .../starrocks/connector/parser/trino/AstBuilder.java | 12 ++++++++++++ .../parser/trino/TrinoFunctionTransformTest.java | 9 +++++++++ 2 files changed, 21 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 aca036ee524e9..a826a7706a3f7 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 @@ -105,6 +105,8 @@ import io.trino.sql.tree.ComparisonExpression; import io.trino.sql.tree.CreateTableAsSelect; 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; @@ -1105,6 +1107,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), 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 dc04a8bf11bc5..d45c024c9f64b 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 @@ -425,4 +425,13 @@ public void testIsNullFunction() throws Exception { sql = "select isnotnull(1, 2)"; analyzeFail(sql, "isnotnull function must have 1 argument"); } + + @Test + public void testUtilityFunction() throws Exception { + String sql = "select current_catalog"; + assertPlanContains(sql, " : CATALOG()"); + + sql = "select current_schema"; + assertPlanContains(sql, " : 'test'"); + } }