You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/09/28 07:00:49 UTC

[shardingsphere] branch master updated: Support openGauss select offset, count statement parse and remove useless syntax in PostgreSQL grammar (#21232)

This is an automated email from the ASF dual-hosted git repository.

panjuan 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 a596551ee02 Support openGauss select offset, count statement parse and remove useless syntax in PostgreSQL grammar (#21232)
a596551ee02 is described below

commit a596551ee02c7e3ea86614e0568630beb1fba0cf
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Wed Sep 28 15:00:40 2022 +0800

    Support openGauss select offset, count statement parse and remove useless syntax in PostgreSQL grammar (#21232)
---
 .../main/antlr4/imports/opengauss/DMLStatement.g4  |  2 +-
 .../main/antlr4/imports/postgresql/DMLStatement.g4 |  1 -
 .../impl/PostgreSQLStatementSQLVisitor.java        |  5 ----
 ...> SQLNodeConverterEngineParameterizedTest.java} | 27 +++++++++++++++++++---
 .../main/resources/case/dml/select-pagination.xml  |  2 --
 .../sql/supported/dml/select-pagination.xml        |  2 +-
 6 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4
index 20ece25dfbf..21a0cddfa39 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4
@@ -227,7 +227,7 @@ valuesClause
 
 limitClause
     : LIMIT selectLimitValue
-    | LIMIT selectLimitValue COMMA_ selectOffsetValue
+    | LIMIT selectOffsetValue COMMA_ selectLimitValue 
     | FETCH firstOrNext selectFetchFirstValue rowOrRows ONLY
     | FETCH firstOrNext selectFetchFirstValue rowOrRows WITH TIES
     | FETCH firstOrNext rowOrRows ONLY
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
index 490e74fb51c..60fbc78726f 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
@@ -229,7 +229,6 @@ valuesClause
 
 limitClause
     : LIMIT selectLimitValue
-    | LIMIT selectLimitValue COMMA_ selectOffsetValue
     | FETCH firstOrNext selectFetchFirstValue rowOrRows ONLY
     | FETCH firstOrNext selectFetchFirstValue rowOrRows WITH TIES
     | FETCH firstOrNext rowOrRows ONLY
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
index fe34ab7b4e7..63bd3ed2b2c 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
@@ -1219,11 +1219,6 @@ public abstract class PostgreSQLStatementSQLVisitor extends PostgreSQLStatementP
     
     private LimitSegment createLimitSegmentWhenRowCountOrOffsetAbsent(final SelectLimitContext ctx) {
         if (null != ctx.limitClause()) {
-            if (null != ctx.limitClause().selectOffsetValue()) {
-                LimitValueSegment limit = (LimitValueSegment) visit(ctx.limitClause().selectLimitValue());
-                LimitValueSegment offset = (LimitValueSegment) visit(ctx.limitClause().selectOffsetValue());
-                return new LimitSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), offset, limit);
-            }
             LimitValueSegment limit = (LimitValueSegment) visit(ctx.limitClause().selectLimitValue());
             return new LimitSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), null, limit);
         }
diff --git a/shardingsphere-test/shardingsphere-optimize-test/src/test/java/org/apache/shardingsphere/infra/federation/converter/parameterized/engine/SQLNodeConvertEngineParameterizedTest.java b/shardingsphere-test/shardingsphere-optimize-test/src/test/java/org/apache/shardingsphere/infra/federation/converter/parameterized/engine/SQLNodeConverterEngineParameterizedTest.java
similarity index 84%
rename from shardingsphere-test/shardingsphere-optimize-test/src/test/java/org/apache/shardingsphere/infra/federation/converter/parameterized/engine/SQLNodeConvertEngineParameterizedTest.java
rename to shardingsphere-test/shardingsphere-optimize-test/src/test/java/org/apache/shardingsphere/infra/federation/converter/parameterized/engine/SQLNodeConverterEngineParameterizedTest.java
index 43ca9b1e866..5944dcb10bb 100644
--- a/shardingsphere-test/shardingsphere-optimize-test/src/test/java/org/apache/shardingsphere/infra/federation/converter/parameterized/engine/SQLNodeConvertEngineParameterizedTest.java
+++ b/shardingsphere-test/shardingsphere-optimize-test/src/test/java/org/apache/shardingsphere/infra/federation/converter/parameterized/engine/SQLNodeConverterEngineParameterizedTest.java
@@ -58,7 +58,7 @@ import static org.junit.Assert.assertTrue;
 
 @RunWith(Parameterized.class)
 @RequiredArgsConstructor
-public final class SQLNodeConvertEngineParameterizedTest {
+public final class SQLNodeConverterEngineParameterizedTest {
     
     private static final SQLCasesLoader SQL_CASES_LOADER = CasesRegistry.getInstance().getSqlCasesLoader();
     
@@ -68,6 +68,8 @@ public final class SQLNodeConvertEngineParameterizedTest {
     
     private static final Set<String> SUPPORTED_SQL_CASE_IDS = new HashSet<>();
     
+    // TODO remove SUPPORTED_SQL_CASE_IDS when all sql statement support convert to sql node
+    // CHECKSTYLE:OFF
     static {
         SUPPORTED_SQL_CASE_IDS.add("select_with_join_table_subquery");
         SUPPORTED_SQL_CASE_IDS.add("select_with_projection_subquery");
@@ -76,8 +78,6 @@ public final class SQLNodeConvertEngineParameterizedTest {
         SUPPORTED_SQL_CASE_IDS.add("select_with_exist_subquery_condition");
         SUPPORTED_SQL_CASE_IDS.add("select_with_not_exist_subquery_condition");
         SUPPORTED_SQL_CASE_IDS.add("select_with_simple_table");
-        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_limit_offset_and_row_count");
-        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_limit_row_count");
         SUPPORTED_SQL_CASE_IDS.add("select_group_by_with_limit");
         SUPPORTED_SQL_CASE_IDS.add("select_left_outer_join_related_with_alias");
         SUPPORTED_SQL_CASE_IDS.add("select_right_outer_join_related_with_alias");
@@ -108,7 +108,28 @@ public final class SQLNodeConvertEngineParameterizedTest {
         SUPPORTED_SQL_CASE_IDS.add("select_cast_function");
         SUPPORTED_SQL_CASE_IDS.add("select_position");
         SUPPORTED_SQL_CASE_IDS.add("select_mod_function");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_offset");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_row_count");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_top");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_top_percent_with_ties");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_row_number");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_limit_with_back_quotes");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_limit_and_offset_keyword");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_offset_and_limit");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_offset_and_limit_all");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_top_for_greater_than");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_top_percent_with_ties_for_greater_than");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_top_for_greater_than_and_equal");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_top_percent_with_ties_for_greater_than_and_equal");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_row_number_for_greater_than");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_row_number_for_greater_than_and_equal");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_row_number_not_at_end");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_fetch_first_with_row_number");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_offset_fetch");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_limit_offset_and_row_count");
+        SUPPORTED_SQL_CASE_IDS.add("select_pagination_with_limit_row_count");
     }
+    // CHECKSTYLE:ON
     
     private final String sqlCaseId;
     
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-pagination.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-pagination.xml
index e65cd79f24e..24b300722b6 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-pagination.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-pagination.xml
@@ -68,7 +68,6 @@
                 <owner name="i" start-index="7" stop-index="7" />
             </shorthand-projection>
         </projections>
-        <!-- TODO parameters-count should be 4, because the last parameter is in offset -->
         <where start-index="99" stop-index="154" literal-stop-index="155">
             <expr>
                 <binary-operation-expression start-index="105" stop-index="154" literal-stop-index="155">
@@ -750,7 +749,6 @@
                 <owner name="i" start-index="7" stop-index="7" />
             </shorthand-projection>
         </projections>
-        <!-- TODO parameters-count should be 4, because the last parameter is in offset -->
         <where start-index="99" stop-index="154" literal-stop-index="155">
             <expr>
                 <binary-operation-expression start-index="105" stop-index="154" literal-stop-index="155">
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select-pagination.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select-pagination.xml
index 8e8184a27e2..e5e08b9f561 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select-pagination.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dml/select-pagination.xml
@@ -35,6 +35,6 @@
     <sql-case id="select_pagination_with_row_number_not_at_end" value="SELECT * FROM t_order WHERE ROWNUM &lt;= ? ORDER BY order_id" db-types="Oracle" />
     <sql-case id="select_pagination_with_fetch_first_with_row_number" value="SELECT * FROM t_order ORDER BY order_id FETCH FIRST 5 ROWS ONLY" db-types="Oracle" />
     <sql-case id="select_pagination_with_offset_fetch" value="SELECT * FROM t_order ORDER BY order_id OFFSET 0 ROW FETCH NEXT ? ROWS ONLY" db-types="SQLServer" />
-    <sql-case id="select_pagination_with_limit_offset_and_row_count" value="SELECT order_id, user_id FROM t_order LIMIT 1, 2" db-types="MySQL" />
+    <sql-case id="select_pagination_with_limit_offset_and_row_count" value="SELECT order_id, user_id FROM t_order LIMIT 1, 2" db-types="MySQL,openGauss" />
     <sql-case id="select_pagination_with_limit_row_count" value="SELECT order_id, user_id FROM t_order LIMIT 2" db-types="MySQL" />
 </sql-cases>