tkalkirill commented on code in PR #13464:
URL: https://github.com/apache/ignite/pull/13464#discussion_r3781611406


##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java:
##########
@@ -267,10 +268,65 @@ private void validateTableModify(SqlNode table) {
     @Override protected void validateSelect(SqlSelect select, RelDataType 
targetRowType) {
         super.validateSelect(select, targetRowType);
 
-        validateFetchOffset(select.getFetch(), "fetch / limit");
+        validateFetch(select, "fetch / limit");
         validateFetchOffset(select.getOffset(), "offset");
     }
 
+    /** Validate fetch expression. */
+    // TODO: https://issues.apache.org/jira/browse/CALCITE-7592
+    //  Remove this method after upgrading to Calcite 1.43.
+    private void validateFetch(SqlSelect select, String clauseName) {
+        SqlNode fetch = select.getFetch();
+
+        if (fetch == null)
+            return;
+
+        if (SqlUtil.isNullLiteral(fetch, true))
+            throw newValidationError(fetch, 
IgniteResource.INSTANCE.illegalFetchLimit(clauseName));
+
+        validateFetchExpression(fetch, clauseName);
+        deriveDynamicParameterTypes(fetch);
+
+        RelDataType type = deriveType(getWhereScope(select), fetch);
+
+        if (type.getSqlTypeName().getFamily() != SqlTypeFamily.NUMERIC)
+            throw newValidationError(fetch, 
IgniteResource.INSTANCE.illegalFetchLimit(clauseName));
+
+        validateFetchOffset(fetch, clauseName);
+    }
+
+    /** Reject column references, aggregate functions, and window functions in 
a fetch expression. */
+    // TODO: https://issues.apache.org/jira/browse/CALCITE-7592
+    //  Remove this method after upgrading to Calcite 1.43.
+    private void validateFetchExpression(SqlNode node, String clauseName) {
+        if (node instanceof SqlIdentifier) {
+            if (makeNullaryCall((SqlIdentifier)node) == null)
+                throw newValidationError(node, 
IgniteResource.INSTANCE.illegalFetchLimit(clauseName));
+
+            return;
+        }
+
+        if (node instanceof SqlNodeList) {
+            for (SqlNode child : (SqlNodeList)node)
+                validateFetchExpression(child, clauseName);
+        }
+        else if (node instanceof SqlCall call) {
+            if (call.isA(SqlKind.QUERY))
+                throw newValidationError(call, 
IgniteResource.INSTANCE.illegalFetchLimit(clauseName));
+
+            if (call.getKind() == SqlKind.OVER)

Review Comment:
   I partially agree that covering every possible invalid expression and 
keeping all related errors consistent may be quite cumbersome. For now, I’ll 
remove these specific checks and rely on the general validation. If a concrete 
need arises, we can restore them together with focused tests.



-- 
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