Skip to content

Conversation

@aminghadersohi
Copy link
Contributor

Summary

Adds a time_grain parameter to XYChartConfig that allows LLM clients to specify temporal granularity when creating time-series charts via the MCP service.

Changes:

  • Added time_grain field to XYChartConfig schema with support for common granularities (second, minute, hour, day, week, month, quarter, year)
  • Updated map_xy_config() to include time_grain_sqla in form_data when specified
  • Added 6 unit tests for the new functionality

Problem

When creating time-series charts through the MCP generate_chart tool, charts with temporal x-axis columns would aggregate all data together instead of grouping by the desired time period. This made it impossible for LLM clients to create charts showing monthly/weekly/daily breakdowns.

Solution

Added an optional time_grain parameter that maps to Superset's time_grain_sqla form_data field, allowing proper temporal grouping.

Example usage:

config = XYChartConfig(
    chart_type="xy",
    x=ColumnRef(name="order_date"),
    y=[ColumnRef(name="revenue", aggregate="SUM")],
    kind="bar",
    time_grain="P1M",  # Monthly breakdown
)

BEFORE/AFTER

BEFORE: Time-series charts aggregated all data into a single point
AFTER: Time-series charts can show data grouped by the specified time grain (day, week, month, etc.)

TESTING INSTRUCTIONS

  1. Run the new unit tests:
pytest tests/unit_tests/mcp_service/chart/test_chart_utils.py -v -k time_grain
  1. Test via MCP client by creating a chart with time_grain parameter

ADDITIONAL INFORMATION

  • Has unit tests
  • No breaking changes

🤖 Generated with Claude Code

Adds a `time_grain` parameter to XYChartConfig that allows LLM clients
to specify temporal granularity (second, minute, hour, day, week, month,
quarter, year) when creating time-series charts via the MCP service.

This fixes an issue where charts with temporal x-axis columns would
aggregate all data together instead of grouping by the desired time
period (e.g., monthly breakdown).

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@codeant-ai-for-open-source
Copy link
Contributor

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Jan 15, 2026

Code Review Agent Run #d257c0

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: a3cd03e..a3cd03e
    • superset/mcp_service/chart/chart_utils.py
    • superset/mcp_service/chart/schemas.py
    • tests/unit_tests/mcp_service/chart/test_chart_utils.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot bot added the change:backend Requires changing the backend label Jan 15, 2026
@netlify
Copy link

netlify bot commented Jan 15, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit a3cd03e
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6969742a34b8f2000847ae8f
😎 Deploy Preview https://deploy-preview-37182--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codeant-ai-for-open-source
Copy link
Contributor

CodeAnt AI finished reviewing your PR.

@codecov
Copy link

codecov bot commented Jan 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.83%. Comparing base (82d74d1) to head (7c0ab8a).
⚠️ Report is 12 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #37182       +/-   ##
===========================================
+ Coverage        0   67.83%   +67.83%     
===========================================
  Files           0      642      +642     
  Lines           0    48088    +48088     
  Branches        0     5262     +5262     
===========================================
+ Hits            0    32622    +32622     
- Misses          0    14179    +14179     
- Partials        0     1287     +1287     
Flag Coverage Δ
hive 42.84% <ø> (?)
mysql 65.86% <ø> (?)
postgres 65.91% <ø> (?)
presto 46.41% <ø> (?)
python 67.80% <ø> (?)
sqlite 65.62% <ø> (?)
unit 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bito-code-review
Copy link
Contributor

Based on the PR diff, the time_grain field and its type are newly added to the XYChartConfig class in schemas.py. The changes don't show this type defined elsewhere in the modified files.

Addresses review feedback to reuse the existing TimeGrain StrEnum
from superset/constants.py instead of defining an inline Literal type.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@pull-request-size pull-request-size bot added size/M and removed size/L labels Jan 16, 2026
@codeant-ai-for-open-source
Copy link
Contributor

CodeAnt AI is running Incremental review


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@aminghadersohi
Copy link
Contributor Author

Thanks for the feedback @mistercrunch! I've updated the PR to use TimeGrain from superset/constants.py instead of the inline Literal type.

Changes:

  • Imported TimeGrain from superset.constants
  • Updated time_grain: TimeGrain | None to use the existing StrEnum

All tests pass and pre-commit checks are green.

@codeant-ai-for-open-source
Copy link
Contributor

CodeAnt AI Incremental review completed.

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Jan 16, 2026

Code Review Agent Run #71ee3e

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: a3cd03e..7c0ab8a
    • superset/mcp_service/chart/chart_utils.py
    • superset/mcp_service/chart/schemas.py
    • tests/unit_tests/mcp_service/chart/test_chart_utils.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants