Skip to content

Conversation

@richardfogaca
Copy link
Contributor

@richardfogaca richardfogaca commented Dec 4, 2025

SUMMARY

Adds dynamic currency detection for chart formatting. When a metric's currency is set to "Auto-detect", Superset queries the dataset's designated currency code column to determine the appropriate currency symbol.

How it works:

  • Dataset owners configure a currency_code_column (e.g., a column containing "USD", "EUR", "GBP")
  • When building a chart, users select "Auto-detect" in the currency format dropdown
  • Backend detects the currency from filtered data:
    • Single currency → formats with that currency symbol
    • Mixed currencies → falls back to neutral numeric formatting

Key changes:

Backend:

  • Added currency_code_column field to SqlaTable model with DB migration
  • Added detect_currency() utility that queries distinct currencies from filtered data
  • Integrated currency detection into both QueryContext API and legacy viz API
  • Returns detected_currency in API response for frontend consumption

Frontend:

  • Added "Auto-detect" option to CurrencyControl (only shown when dataset has currency_code_column)
  • Updated chart plugins to handle AUTO currency resolution: Timeseries, MixedTimeseries, BigNumber variants, Table, PivotTable, Heatmap, Sunburst, Treemap, Pie, Funnel, Gauge
  • Refactored DatasourceEditor: moved main_dttm_col from inline radio buttons to a new "Default Column Settings" section alongside currency_code_column

Example data:

  • Added international_sales example dataset demonstrating multi-currency transactions across regions

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A - Requires screenshot of:

  • Currency code column
Screenshot 2025-12-01 at 20 29 36
  • Currency control dropdown with "Auto-detect" option + Chart displaying auto-detected currency formatting
Screenshot 2025-12-01 at 20 19 54 (1)

TESTING INSTRUCTIONS

  1. Open the international_sales dataset and set "Currency code column" to currency_code
  2. Create a new chart (e.g., Big Number Total) using this dataset
  3. Select a numeric metric (e.g., revenue)
  4. In the "Number Format" section, set currency to "Auto-detect"
  5. Apply filters to show single-currency data (e.g., filter by country = USA)
  6. Verify the chart displays USD formatting
  7. Change filter to show mixed currencies (e.g., all countries)
  8. Verify the chart falls back to neutral number formatting

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-193)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

CodeAnt-AI Description

Auto-detect currency from dataset and per-row for chart formatting

What Changed

  • Charts can use "Auto-detect" currency: when a dataset defines a currency code column, selecting Auto-detect formats values with the dataset’s currency (or a per-row currency for tables/pivot tables) instead of a fixed symbol.
  • Table and PivotTable now perform per-cell currency detection when Auto-detect is selected and the currency column is included in query results; mixed-currency rows fall back to neutral numeric formatting.
  • The backend returns a detected_currency value for chart queries; other chart types (timeseries, big number, pie, heatmap, treemap, gauge, etc.) use this dataset-level detection as a fallback when per-row data is not available.
  • Currency selector in controls shows an "Auto-detect" option only when the current dataset has a configured currency code column and moves that option to the top of the list.
  • Dataset editor exposes a "Default Column Settings" area to pick the currency code column (string columns only) and stores it on datasets; a DB migration and example dataset demonstrating multi-currency data were added.
  • Currency formatting behavior: AUTO mode now uses row context when available, then backend-detected currency, and finally neutral formatting for mixed or missing currencies; numerous tests added to cover these cases.

Impact

✅ Clearer currency symbols in charts when dataset provides a currency column
✅ Fewer mixed-currency formatting errors (mixed rows now show neutral numbers)
✅ Auto-detect option only appears when it will work for the selected dataset

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

… cell-level detection (table, pivot_table_v2)
@eschutho eschutho added 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR and removed 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR 🎪 🛑 showtime-trigger-stop Destroy ephemeral environment and clean up AWS resources 🎪 🔒 showtime-blocked 🎪 f0165e5 📅 2025-12-08T18-06 Environment f0165e5 created at 2025-12-08T18-06 🎪 f0165e5 ⌛ 48h Environment f0165e5 expires after 48h 🎪 f0165e5 🤡 geido Environment f0165e5 requested by geido 🎪 f0165e5 🚦 running Environment f0165e5 status: running 🎪 f0165e5 🌐 44.255.20.214:8080 Environment f0165e5 URL: http://44.255.20.214:8080 (click to visit) labels Dec 9, 2025
@github-actions github-actions bot added 🎪 5b992bb 🚦 building Environment 5b992bb status: building 🎪 5b992bb 📅 2025-12-09T01-28 Environment 5b992bb created at 2025-12-09T01-28 🎪 5b992bb ⌛ 48h Environment 5b992bb expires after 48h 🎪 5b992bb 🤡 eschutho Environment 5b992bb requested by eschutho and removed 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR labels Dec 9, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

🎪 Showtime is building environment on GHA for 5b992bb

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

🎪 Showtime is building environment on GHA for 5b992bb

@github-actions github-actions bot added 🎪 5b992bb 🚦 deploying Environment 5b992bb status: deploying 🎪 5b992bb 🚦 failed Environment 5b992bb status: failed 🎪 5b992bb 🚦 running Environment 5b992bb status: running 🎪 🎯 5b992bb Active environment pointer - 5b992bb is receiving traffic 🎪 5b992bb 🌐 35.162.7.251:8080 Environment 5b992bb URL: http://35.162.7.251:8080 (click to visit) and removed 🎪 5b992bb 🚦 building Environment 5b992bb status: building 🎪 5b992bb 🚦 deploying Environment 5b992bb status: deploying 🎪 5b992bb 🚦 failed Environment 5b992bb status: failed 🎪 5b992bb 🚦 running Environment 5b992bb status: running 🎪 🎯 5b992bb Active environment pointer - 5b992bb is receiving traffic labels Dec 9, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

🎪 Showtime deployed environment on GHA for 5b992bb

Environment: http://35.162.7.251:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

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

Labels

api Related to the REST API change:backend Requires changing the backend change:frontend Requires changing the frontend packages plugins risk:db-migration PRs that require a DB migration size/XXL size:XXL This PR changes 1000+ lines, ignoring generated files 🎪 5b992bb 🤡 eschutho Environment 5b992bb requested by eschutho 🎪 5b992bb 🚦 running Environment 5b992bb status: running 🎪 5b992bb 🌐 35.162.7.251:8080 Environment 5b992bb URL: http://35.162.7.251:8080 (click to visit) 🎪 5b992bb ⌛ 48h Environment 5b992bb expires after 48h 🎪 5b992bb 📅 2025-12-09T01-28 Environment 5b992bb created at 2025-12-09T01-28

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants