xiedeyantu commented on code in PR #5113:
URL: https://github.com/apache/calcite/pull/5113#discussion_r3620472474


##########
core/src/main/java/org/apache/calcite/sql/SqlDialect.java:
##########
@@ -1081,37 +1081,49 @@ protected static void unparseFetchUsingAnsi(SqlWriter 
writer, @Nullable SqlNode
           writer.startList(SqlWriter.FrameTypeEnum.FETCH);
       writer.keyword("FETCH");
       writer.keyword("NEXT");
-      if (fetch instanceof SqlLiteral
-          || fetch instanceof SqlDynamicParam) {
-        fetch.unparse(writer, -1, -1);
-      } else {
-        final SqlWriter.Frame expressionFrame = writer.startList("(", ")");
-        if (fetch instanceof SqlCall) {
-          writer.getDialect().unparseCall(writer, (SqlCall) fetch, 0, 0);
-        } else {
-          fetch.unparse(writer, 0, 0);
-        }
-        writer.endList(expressionFrame);
-      }
+      unparseOffsetFetchExpression(writer, fetch);
       writer.keyword("ROWS");
       writer.keyword("ONLY");
       writer.endList(fetchFrame);
     }
   }
 
+  private static void unparseOffsetExpression(SqlWriter writer, SqlNode 
offset) {
+    if (offset instanceof SqlCall) {
+      writer.getDialect().unparseCall(writer, (SqlCall) offset, 0, 0);
+    } else {
+      offset.unparse(writer, 0, 0);
+    }
+  }
+
+  private static void unparseOffsetFetchExpression(SqlWriter writer, SqlNode 
node) {

Review Comment:
   Could `unparseOffsetExpression` and `unparseOffsetFetchExpression` be 
consolidated into a single method? Or perhaps `unparseFetchUsingAnsi` could be 
refactored? It seems like there is a lot of similar logic involved.



##########
core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java:
##########
@@ -10739,14 +10758,12 @@ void testGroupExpressionEquivalenceParams() {
   @Test void testNegativeFetchOffsetLimit() {
     sql("select name from dept limit ^-^1")
         .fails("(?s).*Encountered \"-\".*");
-    sql("select name from dept offset ^-^1")
-        .fails("(?s).*Encountered \"-\".*");
+    sql("select name from dept offset -1").ok();
     sql("select name from dept fetch next ^-^1 rows only")
         .fails("(?s).*Encountered \"-\".*");
     sql("select name from dept order by name limit ^-^1")
         .fails("(?s).*Encountered \"-\".*");
-    sql("select name from dept order by name offset ^-^1")
-        .fails("(?s).*Encountered \"-\".*");
+    sql("select name from dept order by name offset -1").ok();

Review Comment:
   Why did this test pass?



##########
core/src/test/resources/sql/offset.iq:
##########
@@ -0,0 +1,186 @@
+# offset.iq
+#
+# 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.
+#
+
+!use post
+!set outputformat mysql

Review Comment:
   You might need to add all the test cases here to the link so that the 
reviewer can easily view them, like this: 
https://onecompiler.com/postgresql/44veytn3y



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to