You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "betodealmeida (via GitHub)" <gi...@apache.org> on 2025/07/22 14:09:17 UTC

[PR] chore: improve sqlglot parsing [superset]

betodealmeida opened a new pull request, #34270:
URL: https://github.com/apache/superset/pull/34270

   <!---
   Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   <!--- Describe the change below, including rationale and design decisions -->
   
   Asked Claude Code to check `superset/sql/parse.py` for non-idiomatic uses of `sqlglot`, or places where the code could be optimized.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   
   100% unit test coverage.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] chore: improve sqlglot parsing [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #34270:
URL: https://github.com/apache/superset/pull/34270#discussion_r2222674994


##########
superset/sql/parse.py:
##########
@@ -626,27 +626,26 @@ def is_mutating(self) -> bool:
 
         :return: True if the statement mutates data.
         """
-        for node in self._parsed.walk():
-            if isinstance(
-                node,
-                (
-                    exp.Insert,
-                    exp.Update,
-                    exp.Delete,
-                    exp.Merge,
-                    exp.Create,
-                    exp.Drop,
-                    exp.TruncateTable,
-                    exp.Alter,
-                ),
-            ):
-                return True
+        mutating_nodes = (
+            exp.Insert,
+            exp.Update,
+            exp.Delete,
+            exp.Merge,
+            exp.Create,
+            exp.Drop,
+            exp.TruncateTable,
+            exp.Alter,
+        )
 
-            # depending on the dialect (Oracle, MS SQL) the `ALTER` is parsed as a
-            # command, not an expression
-            if isinstance(node, exp.Command) and node.name == "ALTER":
+        for node_type in mutating_nodes:
+            if self._parsed.find(node_type):
                 return True
 
+        # depending on the dialect (Oracle, MS SQL) the `ALTER` is parsed as a
+        # command, not an expression - check at root level
+        if isinstance(self._parsed, exp.Command) and self._parsed.name == "ALTER":
+            return True

Review Comment:
   ### Over-Inclusive ALTER Command Detection <sub>![category Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The code assumes that checking for 'ALTER' command name alone is sufficient to detect mutations, but some ALTER commands may be non-mutating operations like 'ALTER SESSION' or 'ALTER SYSTEM'.
   
   
   ###### Why this matters
   Treating all ALTER commands as mutating operations may incorrectly block legitimate read-only operations that use ALTER for session or system configurations.
   
   ###### Suggested change ∙ *Feature Preview*
   Add more specific checks for the ALTER command type:
   ```python
   if isinstance(self._parsed, exp.Command) and self._parsed.name == "ALTER":
       # Check for non-mutating ALTER commands
       if any(self._parsed.expression.name.upper().startswith(cmd) for cmd in ['SESSION', 'SYSTEM']):
           return False
       return True
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/4de782b2-8580-434a-9c38-75fa7aeeb387/upvote) [![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/4de782b2-8580-434a-9c38-75fa7aeeb387?what_not_true=true)  [![Not in Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/4de782b2-8580-434a-9c38-75fa7aeeb387?what_out_of_scope=true) [![Not in coding standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/4de782b2-8580-434a-9c38-75fa7aeeb387?what_not_in_standard=true) [![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/4de782b2-8580-434a-9c38-75fa7aeeb387)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:3d48fb6d-13c2-42c4-8e5c-908b720ac5bd -->
   
   
   [](3d48fb6d-13c2-42c4-8e5c-908b720ac5bd)



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] chore: improve sqlglot parsing [superset]

Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida merged PR #34270:
URL: https://github.com/apache/superset/pull/34270


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org