msyavuz opened a new pull request, #35553: URL: https://github.com/apache/superset/pull/35553
## Summary Fixes column names with spaces breaking chart x-axis rendering in MSSQL and SQLite databases. **Problem:** - Column names containing spaces (e.g., "Test Column") were causing SQL parsing errors when used on chart x-axis - Error: `SELECT Test AS column AS "Test column"` - invalid double AS clause - Issue introduced in #35482 where `_process_select_expression` incorrectly parsed "Test column" as "Test AS column" - Affected MSSQL and SQLite databases which don't force column alias quoting by default **Root Cause:** 1. Column name "Test column" sent as sqlExpression 2. `_process_select_expression` prefixes with "SELECT" → "SELECT Test column" 3. SQL parser interprets unquoted spaces as implicit alias → "Test AS column" 4. `make_sqla_column_compatible` adds another AS → "Test AS column AS [Test column]" ## Changes ### Core Fixes - **Fix `_process_select_expression`**: Quote column names with spaces before SQL parsing to prevent misinterpretation - **Add `force_column_alias_quotes = True`** to MSSQL and SQLite engine specs for proper alias quoting - **Enhance column processing methods** to distinguish between column names with spaces vs SQL expressions ### Files Modified - `superset/models/helpers.py` - Fixed _process_select_expression method - `superset/db_engine_specs/mssql.py` - Added force_column_alias_quotes - `superset/db_engine_specs/sqlite.py` - Added force_column_alias_quotes - `superset/connectors/sqla/models.py` - Enhanced adhoc_column_to_sqla and TableColumn methods - Added comprehensive tests ## Test Plan - [x] Unit tests pass for column name handling with spaces - [x] MSSQL engine spec properly quotes column aliases - [x] SQLite engine spec properly quotes column aliases - [x] Complex SQL expressions still work with literal_column() - [x] Simple column names without spaces use existing efficient path - [x] Pre-commit checks pass **Manual Testing:** 1. Create dataset with column containing spaces (e.g., "Test Column") 2. Create bar chart with spaced column name on x-axis 3. Verify chart renders without SQL parsing errors 4. Test with both MSSQL and SQLite databases ## Before/After **Before (Broken SQL):** ```sql SELECT Test AS column AS "Test column", COUNT(*) AS "count" ``` **After (Fixed SQL):** ```sql SELECT "Test column" AS "Test column", COUNT(*) AS "count" -- SQLite SELECT [Test column] AS [Test column], COUNT(*) AS "count" -- MSSQL ``` Closes #35493 🤖 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]
