This is an automated email from the ASF dual-hosted git repository. starocean999 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 035bc7e278e [Enhancement](nereids)Support show global function (#50034) 035bc7e278e is described below commit 035bc7e278ed09f21b7c4a2355fddd6f6c5e48f6 Author: lsy3993 <110876560+lsy3...@users.noreply.github.com> AuthorDate: Thu Apr 17 15:03:30 2025 +0800 [Enhancement](nereids)Support show global function (#50034) Related PR: #49893 --- .../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +- .../doris/nereids/parser/LogicalPlanBuilder.java | 12 +++ .../apache/doris/nereids/trees/plans/PlanType.java | 1 + .../trees/plans/commands/ShowFunctionsCommand.java | 12 +++ .../commands/ShowGlobalFunctionsCommandTest.java | 97 ++++++++++++++++++++++ .../show/test_nereids_show_global_functions.groovy | 43 ++++++++++ 6 files changed, 166 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index d2c3dbbf36f..d80f9561f20 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -293,6 +293,7 @@ supportedShowStatement | SHOW DELETE ((FROM | IN) database=multipartIdentifier)? #showDelete | SHOW FULL? BUILTIN? FUNCTIONS ((FROM | IN) database=multipartIdentifier)? (LIKE STRING_LITERAL)? #showFunctions + | SHOW GLOBAL FULL? FUNCTIONS (LIKE STRING_LITERAL)? #showGlobalFunctions | SHOW ALL? GRANTS #showGrants | SHOW GRANTS FOR userIdentify #showGrantsForUser | SHOW SYNC JOB ((FROM | IN) database=multipartIdentifier)? #showSyncJob @@ -423,7 +424,6 @@ unsupportedShowStatement wildWhere? sortClause? limitClause? #showPartitions | SHOW RESOURCES wildWhere? sortClause? limitClause? #showResources | SHOW WORKLOAD GROUPS wildWhere? #showWorkloadGroups - | SHOW GLOBAL FULL? FUNCTIONS wildWhere? #showGlobalFunctions | SHOW TYPECAST ((FROM | IN) database=multipartIdentifier)? #showTypeCast | SHOW (KEY | KEYS | INDEX | INDEXES) (FROM |IN) tableName=multipartIdentifier diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index 65f6ce755f4..3b2d4999e1f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -330,6 +330,7 @@ import org.apache.doris.nereids.DorisParser.ShowEncryptKeysContext; import org.apache.doris.nereids.DorisParser.ShowEventsContext; import org.apache.doris.nereids.DorisParser.ShowFrontendsContext; import org.apache.doris.nereids.DorisParser.ShowFunctionsContext; +import org.apache.doris.nereids.DorisParser.ShowGlobalFunctionsContext; import org.apache.doris.nereids.DorisParser.ShowGrantsContext; import org.apache.doris.nereids.DorisParser.ShowGrantsForUserContext; import org.apache.doris.nereids.DorisParser.ShowLastInsertContext; @@ -5403,6 +5404,17 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { return new ShowFunctionsCommand(dbName, isBuiltin, isVerbose, wild); } + @Override + public LogicalPlan visitShowGlobalFunctions(ShowGlobalFunctionsContext ctx) { + boolean isVerbose = ctx.FULL() != null; + + String wild = null; + if (ctx.STRING_LITERAL() != null) { + wild = stripQuotes(ctx.STRING_LITERAL().getText()); + } + return new ShowFunctionsCommand(isVerbose, wild, true); + } + @Override public LogicalPlan visitShowCreateDatabase(ShowCreateDatabaseContext ctx) { List<String> nameParts = visitMultipartIdentifier(ctx.name); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java index 3bfe92a2b72..9d406d9f757 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java @@ -250,6 +250,7 @@ public enum PlanType { SHOW_DATA_TYPES_COMMAND, SHOW_FRONTENDS_COMMAND, SHOW_FUNCTIONS_COMMAND, + SHOW_GLOBAL_FUNCTIONS_COMMAND, SHOW_GRANTS_COMMAND, SHOW_INDEX_STATS_COMMAND, SHOW_LAST_INSERT_COMMAND, diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowFunctionsCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowFunctionsCommand.java index d5c003052df..f9913fc5ada 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowFunctionsCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowFunctionsCommand.java @@ -83,6 +83,18 @@ public class ShowFunctionsCommand extends ShowCommand { this.likeCondition = likeCondition; } + /** + * constructor for global functions + */ + public ShowFunctionsCommand(boolean isVerbose, String likeCondition, boolean isGlobal) { + super(PlanType.SHOW_GLOBAL_FUNCTIONS_COMMAND); + this.isVerbose = isVerbose; + this.likeCondition = likeCondition; + if (isGlobal) { + this.type = SetType.GLOBAL; + } + } + /*** * get Info by nereids. * To make the code in nereids more concise, all irrelevant information here will use an empty string. diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowGlobalFunctionsCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowGlobalFunctionsCommandTest.java new file mode 100644 index 00000000000..fefa2e02578 --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowGlobalFunctionsCommandTest.java @@ -0,0 +1,97 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.trees.plans.commands; + +import org.apache.doris.common.AnalysisException; +import org.apache.doris.utframe.TestWithFeService; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +public class ShowGlobalFunctionsCommandTest extends TestWithFeService { + @Override + protected void runBeforeAll() throws Exception { + createDatabase("test"); + connectContext.setDatabase("test"); + createFunction( + "CREATE GLOBAL ALIAS FUNCTION test.test_for_create_function(bigint) " + + "WITH PARAMETER(id) AS CONCAT(LEFT(id,3),'****',RIGHT(id,4));"); + } + + @Test + void testGetFunctions() throws AnalysisException { + // test for not global + ShowFunctionsCommand sf = new ShowFunctionsCommand(false, null, false); + ShowFunctionsCommand finalSf = sf; + Assertions.assertThrows(AnalysisException.class, () -> finalSf.getFunctions(connectContext)); + + // test for verbose + connectContext.setDatabase("test"); + sf = new ShowFunctionsCommand(true, null, true); + List<String> re1 = sf.getFunctions(connectContext); + Assertions.assertEquals(1, re1.size()); + Assertions.assertEquals("test_for_create_function", re1.get(0)); + + // test for no verbose + sf = new ShowFunctionsCommand(false, null, true); + List<String> re2 = sf.getFunctions(connectContext); + Assertions.assertEquals(1, re2.size()); + Assertions.assertEquals("test_for_create_function", re2.get(0)); + + // test for like condition + sf = new ShowFunctionsCommand(false, "test_for_create%", true); + List<String> re3 = sf.getFunctions(connectContext); + Assertions.assertEquals(1, re3.size()); + Assertions.assertEquals("test_for_create_function", re3.get(0)); + } + + @Test + void testGetResultRowSetByFunctions() throws AnalysisException { + connectContext.setDatabase("test"); + // test for verbose + ShowFunctionsCommand sf = new ShowFunctionsCommand(true, null, true); + List<String> func3 = sf.getFunctions(connectContext); + List<List<String>> re3 = sf.getResultRowSetByFunctions(func3); + Assertions.assertEquals(1, re3.size()); + Assertions.assertEquals("", re3.get(0).get(1)); + Assertions.assertEquals("", re3.get(0).get(2)); + Assertions.assertEquals("", re3.get(0).get(3)); + Assertions.assertEquals("", re3.get(0).get(4)); + + // test for not verbose + sf = new ShowFunctionsCommand(false, null, true); + List<String> func4 = sf.getFunctions(connectContext); + List<List<String>> re4 = sf.getResultRowSetByFunctions(func4); + Assertions.assertEquals(1, re4.get(0).size()); + Assertions.assertEquals("test_for_create_function", re4.get(0).get(0)); + + // test for like condition + String where = "test_for_create_function%"; + sf = new ShowFunctionsCommand(true, where, true); + List<String> func5 = sf.getFunctions(connectContext); + List<List<String>> re5 = sf.getResultRowSetByFunctions(func5); + Assertions.assertEquals(5, re5.get(0).size()); + Assertions.assertEquals("test_for_create_function", re5.get(0).get(0)); + Assertions.assertEquals("", re5.get(0).get(1)); + Assertions.assertEquals("", re5.get(0).get(2)); + Assertions.assertEquals("", re5.get(0).get(3)); + Assertions.assertEquals("", re5.get(0).get(4)); + } +} diff --git a/regression-test/suites/nereids_p0/show/test_nereids_show_global_functions.groovy b/regression-test/suites/nereids_p0/show/test_nereids_show_global_functions.groovy new file mode 100644 index 00000000000..4f14bcfc5cf --- /dev/null +++ b/regression-test/suites/nereids_p0/show/test_nereids_show_global_functions.groovy @@ -0,0 +1,43 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_nereids_show_global_functions") { + String dbName = "show_functions_db" + String functionName = "global_xyz" + + sql "CREATE DATABASE IF NOT EXISTS ${dbName}" + sql """CREATE global ALIAS FUNCTION ${functionName}(INT) WITH PARAMETER(id) AS CONCAT(LEFT(id, 3), '****', RIGHT(id, 4));""" + + checkNereidsExecute("use ${dbName}; show global functions;") + checkNereidsExecute("use ${dbName}; show global full functions;") + checkNereidsExecute("use ${dbName}; show global functions like 'global_%';") + checkNereidsExecute("use ${dbName}; show global full functions like 'global_%';") + + def res = sql """use ${dbName}; show global functions like 'global_%';""" + assertTrue(res.size() == 1) + def res1 = sql """use ${dbName}; show global full functions like 'global_%';""" + assertTrue(res1.size() == 1) + // in nereids, each column of 'show full functions' is empty string, except Signature. + def res3 = sql """use ${dbName}; show global full functions like '${functionName}%';""" + assertTrue(res3.size() == 1) + assertEquals(res3.get(0).get(0), functionName) + assertEquals(res3.get(0).get(1), "") + assertEquals(res3.get(0).get(2), "") + assertEquals(res3.get(0).get(3), "") + assertEquals(res3.get(0).get(4), "") + sql """DROP GLOBAL FUNCTION ${functionName}(INT)""" +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org