aminghadersohi opened a new pull request, #37433:
URL: https://github.com/apache/superset/pull/37433
## Summary
When generating XY charts via MCP tools, columns like "year" stored as
BIGINT were incorrectly treated as temporal columns, causing DATE_TRUNC SQL
errors:
```
Error: function date_trunc(unknown, double precision) does not exist
LINE 2: DATE_TRUNC('DAY', year) AS year, ^
HINT: No function matches the given name and argument types.
```
This happens because Superset marks columns as `is_dttm=True` based on
column name heuristics (e.g., columns named "year", "month"), but if the actual
SQL type is BIGINT or INTEGER, DATE_TRUNC cannot be applied.
### Changes
- Add `is_column_truly_temporal()` helper to check actual SQL column type
(not just `is_dttm` flag)
- Add `TEMPORAL_SQL_TYPES` and `NUMERIC_NON_TEMPORAL_TYPES` constants for
type checking
- Add `configure_temporal_handling()` helper to reduce function complexity
- Update `map_xy_config()` to accept `dataset_id` and configure form_data
based on actual column type:
- **Temporal columns** (DATE, TIMESTAMP, etc.): Standard time series
handling with optional time_grain
- **Non-temporal columns** (BIGINT, INTEGER, etc.): Configure as
categorical with `x_axis_sort_series_type="name"` and disable time_grain
- Update all MCP chart tools to pass `dataset_id` for column type checking
## Testing Instructions
1. Create a dataset with a BIGINT column named "year" (e.g., values like
2010, 2011, 2012)
2. Use MCP `generate_explore_link` tool to create a bar chart with year on
x-axis
3. Verify the chart renders without DATE_TRUNC errors
4. Verify charts with proper TIMESTAMP columns still work with time_grain
## Additional Information
**Files changed:**
- `superset/mcp_service/chart/chart_utils.py` - Main logic changes
- `superset/mcp_service/chart/tool/generate_chart.py` - Pass dataset_id
- `superset/mcp_service/chart/tool/update_chart.py` - Pass dataset_id
- `superset/mcp_service/chart/tool/update_chart_preview.py` - Pass dataset_id
- `superset/mcp_service/explore/tool/generate_explore_link.py` - Pass
dataset_id
--
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]