This is an automated email from the ASF dual-hosted git repository. chengzhang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push: new 318e17edcce Support MySQL INSERT with GEOMCOLLECTION function parse (#34654) 318e17edcce is described below commit 318e17edcce1c0e2321a24dc2dd4c7dc0a3e0f31 Author: Zhengqiang Duan <duanzhengqi...@apache.org> AuthorDate: Thu Feb 13 11:45:11 2025 +0800 Support MySQL INSERT with GEOMCOLLECTION function parse (#34654) --- RELEASE-NOTES.md | 1 + .../src/main/antlr4/imports/mysql/BaseRule.g4 | 10 +++++++++- .../visitor/statement/MySQLStatementVisitor.java | 22 ++++++++++++++++++++- .../parser/src/main/resources/case/dml/insert.xml | 23 ++++++++++++++++++++++ .../main/resources/sql/supported/dml/insert.xml | 2 +- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 4eedfc17986..81fe14d6cd7 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -13,6 +13,7 @@ 1. SQL Binder: Support case when then else segment bind - [#34600](https://github.com/apache/shardingsphere/pull/34600) 1. SQL Parser: Support MySQL SELECT CAST AS YEAR statement parse - [#34638](https://github.com/apache/shardingsphere/pull/34638) 1. SQL Parser: Support MySQL SELECT MAX(ALL expr) statement parse - [#34639](https://github.com/apache/shardingsphere/pull/34639) +1. SQL Parser: Support MySQL INSERT with GEOMCOLLECTION function parse - [#34654](https://github.com/apache/shardingsphere/pull/34654) ### Bug Fixes diff --git a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4 b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4 index f5536f8514c..a8904dda3f7 100644 --- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4 +++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4 @@ -979,7 +979,7 @@ columnRefList ; functionCall - : aggregationFunction | specialFunction | jsonFunction | regularFunction | udfFunction + : aggregationFunction | specialFunction | jsonFunction | regularFunction | udfFunction | specialAnalysisFunction ; udfFunction @@ -1218,6 +1218,14 @@ regularFunctionName | CURRENT_DATE | CURRENT_TIME | UTC_TIMESTAMP | identifier ; +specialAnalysisFunction + : geomCollectionFunction + ; + +geomCollectionFunction + : GEOMCOLLECTION LP_ expr (COMMA_ expr)* RP_ + ; + matchExpression : MATCH (columnRefList | LP_ columnRefList RP_ ) AGAINST LP_ expr matchSearchModifier? RP_ ; diff --git a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java index ef1526926d0..97acc56b503 100644 --- a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java +++ b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/MySQLStatementVisitor.java @@ -64,6 +64,7 @@ import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FieldsC import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FromClauseContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FunctionCallContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FunctionNameContext; +import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.GeomCollectionFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.GroupByClauseContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.GroupConcatFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.HavingClauseContext; @@ -120,6 +121,7 @@ import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SetAssi import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShorthandRegularFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SimpleExprContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SingleTableClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SpecialAnalysisFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SpecialFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.StringLiteralsContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.String_Context; @@ -899,7 +901,10 @@ public abstract class MySQLStatementVisitor extends MySQLStatementBaseVisitor<AS if (null != ctx.udfFunction()) { return visit(ctx.udfFunction()); } - throw new IllegalStateException("FunctionCallContext must have aggregationFunction, regularFunction, specialFunction, jsonFunction or udfFunction."); + if (null != ctx.specialAnalysisFunction()) { + return visit(ctx.specialAnalysisFunction()); + } + throw new IllegalStateException("FunctionCallContext must have aggregationFunction, regularFunction, specialFunction, jsonFunction, udfFunction or specialAnalysisFunction."); } @Override @@ -913,6 +918,21 @@ public abstract class MySQLStatementVisitor extends MySQLStatementBaseVisitor<AS return result; } + @Override + public ASTNode visitSpecialAnalysisFunction(final SpecialAnalysisFunctionContext ctx) { + return null != ctx.geomCollectionFunction() ? visit(ctx.geomCollectionFunction()) + : new ExpressionProjectionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), getOriginalText(ctx)); + } + + @Override + public ASTNode visitGeomCollectionFunction(final GeomCollectionFunctionContext ctx) { + FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.GEOMCOLLECTION().getText(), getOriginalText(ctx)); + for (ExprContext each : ctx.expr()) { + result.getParameters().add((ExpressionSegment) visit(each)); + } + return result; + } + @Override public final ASTNode visitAggregationFunction(final AggregationFunctionContext ctx) { String aggregationType = ctx.aggregationFunctionName().getText(); diff --git a/test/it/parser/src/main/resources/case/dml/insert.xml b/test/it/parser/src/main/resources/case/dml/insert.xml index 7f10b171b83..15c5b983210 100644 --- a/test/it/parser/src/main/resources/case/dml/insert.xml +++ b/test/it/parser/src/main/resources/case/dml/insert.xml @@ -4320,4 +4320,27 @@ </projections> </returning> </insert> + + <insert sql-case-id="insert_with_geom_collection_function"> + <table name="t1" start-index="12" stop-index="13" /> + <columns start-index="14" stop-index="14" /> + <values> + <value> + <assignment-value> + <function function-name="GEOMCOLLECTION" text="GEOMCOLLECTION(POINT(0, 0))" start-index="23" stop-index="49"> + <parameter> + <function function-name="POINT" text="POINT(0, 0)" start-index="38" stop-index="48"> + <parameter> + <literal-expression value="0" start-index="44" stop-index="44" /> + </parameter> + <parameter> + <literal-expression value="0" start-index="47" stop-index="47" /> + </parameter> + </function> + </parameter> + </function> + </assignment-value> + </value> + </values> + </insert> </sql-parser-test-cases> diff --git a/test/it/parser/src/main/resources/sql/supported/dml/insert.xml b/test/it/parser/src/main/resources/sql/supported/dml/insert.xml index 1ac4e963992..7eba88217f3 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/insert.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/insert.xml @@ -154,5 +154,5 @@ <sql-case id="insert_with_aes_encrypt" value="INSERT INTO t_order_item(item_id,encrypt) VALUES (1,AES_ENCRYPT('text','key_str'))" db-types="MySQL" /> <sql-case id="insert_on_duplicate_key_update_with_values" value="INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);" db-types="MySQL" /> <sql-case id="insert_returning_expressions" value="INSERT INTO t2 (id) VALUES (2),(3) RETURNING id,t&t" db-types="MySQL,Firebird" /> - + <sql-case id="insert_with_geom_collection_function" value="INSERT INTO t1 VALUES (GEOMCOLLECTION(POINT(0, 0)))" db-types="MySQL" /> </sql-cases>