wsamyak-cars24 opened a new issue, #38189:
URL: https://github.com/apache/superset/issues/38189

   ### Bug description
   
   ### Superset version
   
   6.0.0
   
   ### Additional environment info
   
   - **Database engine:** StarRocks
   ---
   
   ### Bug description
   
   Superset's SQL parser reformats queries before execution. During this 
process, 
   inline `--` comments are converted to `/* */` block comments and 
repositioned — 
   and when a query contains a `/*+ SET_VAR(...) */` optimizer hint, the 
converted 
   comment gets **injected inside the hint block**, producing invalid SQL 
syntax.
   
   This causes a hard syntax error in StarRocks (and likely any engine that 
uses 
   the `/*+ ... */` hint convention, such as MySQL or TiDB).
   
   ---
   
   ### How to reproduce
   
   1. Connect Superset to a **StarRocks** database.
   2. Open SQL Lab and run the following query:
   ```sql
   SELECT /*+ SET_VAR(query_timeout = 3000) */ col1, col2
   FROM my_table
   LIMIT 100
   
   -- increase timeout for large scans
   ```
   
   3. Click **Run**.
   
   ---
   
   ### Expected behavior
   
   The query should execute as written. The `--` comment is cosmetic and should 
   not affect the optimizer hint syntax. Expected SQL sent to StarRocks:
   ```sql
   SELECT /*+ SET_VAR(query_timeout = 3000) */ col1, col2
   FROM my_table
   LIMIT 100
   /* increase timeout for large scans */
   ```
   
   Or with the comment stripped/moved safely outside the hint block.
   
   ---
   
   ### Actual behavior
   
   Superset's SQL reformatter moves the `--` comment and injects it **inside** 
the 
   optimizer hint block. The actual SQL sent to StarRocks becomes:
   ```sql
   SELECT /*+ SET_VAR(query_timeout /* increase timeout for large scans */ = 
3000) */ col1, col2
   FROM my_table
   LIMIT 100
   ```
   
   StarRocks throws a syntax error because nested `/* */` inside `/*+ ... */` 
is 
   not valid:
   ```
   starrocks error: Getting syntax error at line 1, column 50. Detail message: 
Unexpected input '=', the most similar input is {a legal identifier}.
   ```
   
   ---
   
   ### Root cause (hypothesis)
   
   Superset passes SQL through `sqlglot` for parsing, pretty-printing, and 
   security checks (e.g. RLS injection, table extraction). During SQL 
   regeneration, `sqlglot`:
   
   1. Converts `--` inline comments to `/* */` block comment nodes.
   2. Re-attaches them to the nearest token — which in this case is **inside** 
      the optimizer hint block.
   
   Since Superset does not have a dedicated StarRocks dialect in `sqlglot`, the 
   hint is treated as a generic comment, and comment repositioning corrupts it.
   
   **Related:**
   - PR #30350 — "fix: don't reformat generated queries"  
   - Issue #29466 — SQL with inline `--` comments fails after reformatting  
   - Issue #4412 — trailing `--` comments leaking into subqueries
   
   ---
   
   ### Screenshots / logs
   
   <img width="1343" height="174" alt="Image" 
src="https://github.com/user-attachments/assets/72326783-1c69-44ec-a38c-1ed8487722a6";
 />
   
   ---
   
   ### Workaround
   
   Removing all `--` comments from queries that use `/*+ ... */` optimizer 
hints 
   prevents the issue. This is not a sustainable fix for production use.
   
   ---
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [x] I have checked Superset's logs for errors and included relevant 
details above.
   
   ---
   
   ### Screenshots/recordings
   
   _No response_
   
   ### Superset version
   
   6.0.0
   
   ### Python version
   
   3.11
   
   ### Node version
   
   Not applicable
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   _No response_
   
   ### Checklist
   
   - [ ] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [ ] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [ ] I have checked Superset's logs for errors and if I found a relevant 
Python stacktrace, I included it here as text in the "additional context" 
section.


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