From 0e2d829293d74b39f0ac83f4baf793c63b02c5e1 Mon Sep 17 00:00:00 2001 From: niu niu Date: Sun, 5 Nov 2023 10:43:56 +0800 Subject: [PATCH] Support oracle wm_concat function parse --- .../main/antlr4/imports/oracle/BaseRule.g4 | 6 +- .../src/main/antlr4/imports/oracle/Keyword.g4 | 4 + .../statement/OracleStatementVisitor.java | 11 ++ .../src/main/resources/case/dml/select.xml | 142 ++++++++++++++++++ .../resources/sql/supported/dml/select.xml | 4 + 5 files changed, 166 insertions(+), 1 deletion(-) diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 index de4c407488839..d18cb9e3b86aa 100644 --- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 +++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 @@ -783,7 +783,11 @@ leadLagInfo specialFunction : castFunction | charFunction | extractFunction | formatFunction | firstOrLastValueFunction | trimFunction | featureFunction - | setFunction | translateFunction | cursorFunction | toDateFunction | approxRank + | setFunction | translateFunction | cursorFunction | toDateFunction | approxRank | wmConcatFunction + ; + +wmConcatFunction + : WM_CONCAT LP_ expr RP_ overClause? ; approxRank diff --git a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4 b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4 index 37d228e1e22b6..0580c89348a4a 100644 --- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4 +++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/Keyword.g4 @@ -835,3 +835,7 @@ ANYDATASET AUTONOMOUS_TRANSACTION : A U T O N O M O U S UL_ T R A N S A C T I O N ; + +WM_CONCAT + : W M UL_ C O N C A T + ; diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java index 915d2a392c1de..7b375b5e28a4a 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java @@ -85,6 +85,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TypeNameContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.UnreservedWordContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ViewNameContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.WmConcatFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.XmlAggFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.XmlCdataFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.XmlColattvalFunctionContext; @@ -710,6 +711,13 @@ public final ASTNode visitAggregationFunction(final AggregationFunctionContext c : createAggregationFunctionSegment(ctx, aggregationType); } + @Override + public ASTNode visitWmConcatFunction(final WmConcatFunctionContext ctx) { + FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.WM_CONCAT().getText(), getOriginalText(ctx)); + result.getParameters().add((ExpressionSegment) visit(ctx.expr())); + return result; + } + private FunctionSegment createAggregationFunctionSegment(final AggregationFunctionContext ctx, final String aggregationType) { FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), aggregationType, getOriginalText(ctx)); result.getParameters().addAll(getExpressions(ctx.expr())); @@ -982,6 +990,9 @@ public final ASTNode visitSpecialFunction(final SpecialFunctionContext ctx) { if (null != ctx.approxRank()) { return visit(ctx.approxRank()); } + if (null != ctx.wmConcatFunction()) { + return visit(ctx.wmConcatFunction()); + } throw new IllegalStateException( "SpecialFunctionContext must have castFunction, charFunction, extractFunction, formatFunction, firstOrLastValueFunction, trimFunction, toDateFunction, approxCount" + " or featureFunction."); diff --git a/test/it/parser/src/main/resources/case/dml/select.xml b/test/it/parser/src/main/resources/case/dml/select.xml index 9dd07a52faf19..8a497f44e3cbc 100644 --- a/test/it/parser/src/main/resources/case/dml/select.xml +++ b/test/it/parser/src/main/resources/case/dml/select.xml @@ -7032,4 +7032,146 @@ literal-stop-index="32"/> + + + + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select.xml b/test/it/parser/src/main/resources/sql/supported/dml/select.xml index 47d15ee9abf1b..00db43c5587ca 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/select.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/select.xml @@ -213,4 +213,8 @@ + + + +