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

[PR] fix(sql): handle backtick-quoted identifiers with base dialect [superset]

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

   ### SUMMARY
   
   When using the "Other" database type (or unknown engines), SQL parsing would fail if the query contained backtick-quoted identifiers like `SELECT * FROM database.`6``.
   
   **Root Cause:** The base sqlglot dialect (`Dialects.DIALECT`) doesn't support backtick-quoted identifiers, but some databases (particularly MySQL-compatible ones like the sqlalchemy-mongobi connector mentioned in the issue) use backticks for quoting table/column names.
   
   **Solution:** This change adds a fallback mechanism in the `_parse` method: when parsing fails with the base dialect (or no dialect for unknown engines) and the SQL contains backticks, we retry parsing with the MySQL dialect which supports backticks natively.
   
   The fallback only triggers when:
   1. The initial parse fails
   2. The dialect is the base dialect OR None (unknown engine)
   3. The SQL contains backtick characters
   
   If the MySQL dialect also fails to parse the SQL, the original error is raised to maintain proper error messaging.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   **Before:** Queries with backtick-quoted identifiers fail with:
   ```
   sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 1, Col: 24.
   SELECT * FROM database.`6` LIMIT 100
   ```
   
   **After:** Queries parse successfully, allowing datasets to be created and SQL Lab queries to run.
   
   ### TESTING INSTRUCTIONS
   
   1. Create a database connection with the "Other" database type
   2. Try to create a dataset using SQL with backtick-quoted table names:
      - `SELECT * FROM database.`6``
      - `SELECT * FROM `my_table``
      - `SELECT `col1`, `col2` FROM `schema`.`table``
   3. Verify the queries parse successfully and datasets can be created
   4. Run the unit tests: `pytest tests/unit_tests/sql/parse_tests.py -k "backtick" -v`
   
   ### ADDITIONAL INFORMATION
   
   - [x] Has associated issue: Fixes #31853
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   🤖 Generated with [Claude Code](https://claude.ai/code)


-- 
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] fix(sql): handle backtick-quoted identifiers with base dialect [superset]

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


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