codeant-ai-for-open-source[bot] commented on code in PR #43578:
URL: https://github.com/apache/superset/pull/43578#discussion_r3869318188


##########
superset/sql/parse.py:
##########
@@ -1427,11 +1450,17 @@ def set_limit_value(
         if not isinstance(self._parsed, exp.Query):
             return
 
-        if method == LimitMethod.FORCE_LIMIT:
+        # A ClickHouse `LIMIT ... BY` occupies the very `limit`/`offset` slot 
that
+        # `FORCE_LIMIT` overwrites, so forcing a row cap in place would drop 
the
+        # `BY` grouping and silently change what the query returns. The cap 
can't
+        # be appended alongside it either -- sqlglot rejects ClickHouse's 
native
+        # `LIMIT n BY x LIMIT m` with "Found multiple 'LIMIT' clauses" -- so it
+        # goes on a wrapping query instead, exactly as `WRAP_SQL` does.
+        if method == LimitMethod.FORCE_LIMIT and not self._has_limit_by():
             self._parsed.args["limit"] = exp.Limit(
                 expression=exp.Literal(this=str(limit), is_string=False)
             )
-        elif method == LimitMethod.WRAP_SQL:
+        elif method in {LimitMethod.FORCE_LIMIT, LimitMethod.WRAP_SQL}:
             self._parsed = exp.Select(

Review Comment:
   **Suggestion:** The wrapper moves ClickHouse-specific top-level query 
semantics into a subquery. For example, a grouped query using `WITH TOTALS` can 
lose its totals result because ClickHouse emits totals only for the top-level 
query, so applying `FORCE_LIMIT` changes the result beyond adding an overall 
row cap. Preserve such clauses at the outer level or avoid this rewrite for 
queries whose top-level modifiers are not subquery-safe. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ ClickHouse aggregate queries can lose `WITH TOTALS` output.
   - ⚠️ SQL Lab results differ from the submitted query.
   - ⚠️ Affected queries require both `LIMIT BY` and `WITH TOTALS`.
   ```
   </details>
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=e413bdb0878b468e816c90bc273b410e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=e413bdb0878b468e816c90bc273b410e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/sql/parse.py
   **Line:** 1464:1470
   **Comment:**
        *Logic Error: The wrapper moves ClickHouse-specific top-level query 
semantics into a subquery. For example, a grouped query using `WITH TOTALS` can 
lose its totals result because ClickHouse emits totals only for the top-level 
query, so applying `FORCE_LIMIT` changes the result beyond adding an overall 
row cap. Preserve such clauses at the outer level or avoid this rewrite for 
queries whose top-level modifiers are not subquery-safe.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43578&comment_hash=f8bb11fa64b173dc9b3fe8ee34b43a6a1fa669d34054ed1bed76b270a10a4eae&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43578&comment_hash=f8bb11fa64b173dc9b3fe8ee34b43a6a1fa669d34054ed1bed76b270a10a4eae&reaction=dislike'>👎</a>



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to