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