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

caiconghui pushed a commit to branch presto_offset_limit
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 62e82d64eb035c1bfea2aadfbc34cb320df192ef
Author: caiconghui1 <caicongh...@jd.com>
AuthorDate: Mon Aug 12 14:54:09 2024 +0800

    [enhancment](limit) make offset be reserverd keyword to support 'offset 
integer limit integer' grammar to be compatible with presto
---
 .../src/main/antlr4/org/apache/doris/nereids/DorisParser.g4  |  2 +-
 fe/fe-core/src/main/cup/sql_parser.cup                       |  4 ++--
 regression-test/suites/nereids_syntax_p0/test_limit.groovy   | 12 ++++++++++++
 3 files changed, 15 insertions(+), 3 deletions(-)

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 659355c6597..6ae14ff264f 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
@@ -534,6 +534,7 @@ limitClause
     : (LIMIT limit=INTEGER_VALUE)
     | (LIMIT limit=INTEGER_VALUE OFFSET offset=INTEGER_VALUE)
     | (LIMIT offset=INTEGER_VALUE COMMA limit=INTEGER_VALUE)
+    | (OFFSET offset=INTEGER_VALUE LIMIT limit=INTEGER_VALUE)
     ;
 
 partitionClause
@@ -1259,7 +1260,6 @@ nonReserved
     | NON_NULLABLE
     | NULLS
     | OF
-    | OFFSET
     | ONLY
     | OPEN
     | OPTIMIZED
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup 
b/fe/fe-core/src/main/cup/sql_parser.cup
index 619f13e6278..4fa2282dca0 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -6804,6 +6804,8 @@ limit_clause ::=
   {: RESULT = new LimitElement(offset.longValue(), limit.longValue()); :}
   | KW_LIMIT INTEGER_LITERAL:limit KW_OFFSET INTEGER_LITERAL:offset
   {: RESULT = new LimitElement(offset.longValue(), limit.longValue()); :}
+  | KW_OFFSET INTEGER_LITERAL:offset KW_LIMIT INTEGER_LITERAL:limit
+  {: RESULT = new LimitElement(offset.longValue(), limit.longValue()); :}
   ;
 
 type ::=
@@ -8258,8 +8260,6 @@ keyword ::=
     {: RESULT = id; :}
     | KW_OF:id
     {: RESULT = id; :}
-    | KW_OFFSET:id
-    {: RESULT = id; :}
     | KW_ONLY:id
     {: RESULT = id; :}
     | KW_OPEN:id
diff --git a/regression-test/suites/nereids_syntax_p0/test_limit.groovy 
b/regression-test/suites/nereids_syntax_p0/test_limit.groovy
index 64e48195a17..ef9203ee28d 100644
--- a/regression-test/suites/nereids_syntax_p0/test_limit.groovy
+++ b/regression-test/suites/nereids_syntax_p0/test_limit.groovy
@@ -36,4 +36,16 @@ suite("test_limit") {
         sql "select * from test1 limit 2 offset 1"
         result([[1]])
     }
+
+    test {
+        sql "select * from test1 offset 1 limit 2"
+        result([[1]])
+    }
+
+    test {
+        sql "select * from test1 limit 1,2"
+        result([[1]])
+    }
+
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to