Skip to content

Conversation

@rusackas
Copy link
Member

SUMMARY

When importing example datasets, this PR automatically transpiles virtual dataset SQL to the target database dialect using SQLGlot. This ensures that virtual datasets exported from one database type (e.g., PostgreSQL) can be loaded into a different database type (e.g., MySQL, DuckDB, SQLite).

Problem: Virtual datasets contain raw SQL that is dialect-specific. If someone exports a dashboard with virtual datasets from PostgreSQL (using syntax like DATE_TRUNC, :: casting, etc.) and someone else tries to load it with MySQL or SQLite, the SQL would fail.

Solution: Leverage Superset's existing transpile_to_dialect() function (which uses SQLGlot) to automatically convert the SQL to the target database's dialect during import.

Changes:

  • Add transpile_virtual_dataset_sql() helper function in superset/commands/importers/v1/examples.py
  • Integrate transpilation into ImportExamplesCommand._import() before dataset import
  • Gracefully fall back to original SQL if transpilation fails (logs a warning)
  • Add 7 comprehensive unit tests

This builds on the work from #36538 which modernized example data loading with Parquet and YAML configs.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A - Backend change only

TESTING INSTRUCTIONS

  1. Export a dashboard with virtual datasets from a PostgreSQL-backed Superset instance
  2. Configure a different database engine (e.g., DuckDB, MySQL) as the examples database
  3. Run superset load-examples
  4. Verify that virtual datasets are created with SQL transpiled to the target dialect

Unit tests:

pytest tests/unit_tests/commands/importers/v1/examples_test.py -v

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

When importing example datasets, automatically transpile virtual dataset
SQL to the target database dialect using SQLGlot. This ensures that
virtual datasets exported from one database type (e.g., PostgreSQL) can
be loaded into a different database type (e.g., MySQL, DuckDB, SQLite).

- Add transpile_virtual_dataset_sql() helper function
- Integrate transpilation into ImportExamplesCommand._import()
- Fall back gracefully to original SQL if transpilation fails
- Add comprehensive unit tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@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

@dosubot dosubot bot added the data:connect Namespace | Anything related to db connections / integrations label Jan 21, 2026
@codeant-ai-for-open-source
Copy link
Contributor

Sequence Diagram

When importing example datasets, the importer automatically transpiles a dataset's SQL to the target database dialect (via SQLGlot) before creating the dataset, ensuring cross-dialect compatibility. The diagram shows the main success path added in this PR.

sequenceDiagram
    participant Importer as ImportExamplesCommand
    participant DB as Database (ORM)
    participant Transpiler as transpile_to_dialect (SQLGlot)
    participant DatasetService as import_dataset

    Importer->>Importer: Iterate dataset config (has SQL)
    Importer->>DB: Query Database by database_id
    DB-->>Importer: Database (with engine)
    Importer->>Transpiler: transpile_to_dialect(sql, target_engine)
    Transpiler-->>Importer: transpiled_sql
    Importer->>DatasetService: import_dataset(config with transpiled SQL)
    DatasetService-->>Importer: created dataset
Loading

Generated by CodeAnt AI

@apache apache deleted a comment from codeant-ai-for-open-source bot Jan 21, 2026
@apache apache deleted a comment from bito-code-review bot Jan 21, 2026
Address review feedback:
1. transpile_to_dialect now accepts source_engine parameter to properly
   parse SQL from specific dialects (not just generic SQL)
2. Export stores source_db_engine in dataset YAML for virtual datasets
3. Import uses source_db_engine when transpiling to target dialect
4. Added comprehensive tests for PostgreSQL -> MySQL/DuckDB/ClickHouse/SQLite

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@netlify
Copy link

netlify bot commented Jan 21, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 119b45f
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69713ed0e060e30008679292
😎 Deploy Preview https://deploy-preview-37311--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.

Copy link
Contributor

@bito-code-review bito-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #aebbb4

Actionable Suggestions - 1
  • tests/unit_tests/sql/transpile_to_dialect_test.py - 1
    • Parametrize decorator expects tuple not string · Line 351-352
Review Details
  • Files reviewed - 6 · Commit Range: 119b45f..0cd1b48
    • superset/commands/dashboard/export_example.py
    • superset/commands/importers/v1/examples.py
    • superset/datasets/schemas.py
    • superset/sql/parse.py
    • tests/unit_tests/commands/importers/v1/examples_test.py
    • tests/unit_tests/sql/transpile_to_dialect_test.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
@rusackas
Copy link
Member Author

Bot and human suggestions applied :D

Co-authored-by: bito-code-review[bot] <188872107+bito-code-review[bot]@users.noreply.github.com>
@bito-code-review
Copy link
Contributor

bito-code-review bot commented Jan 22, 2026

Code Review Agent Run #9274c1

Actionable Suggestions - 0
Review Details
  • Files reviewed - 6 · Commit Range: 0cd1b48..eae1da1
    • superset/commands/dashboard/export_example.py
    • superset/commands/importers/v1/examples.py
    • superset/datasets/schemas.py
    • superset/sql/parse.py
    • tests/unit_tests/commands/importers/v1/examples_test.py
    • tests/unit_tests/sql/transpile_to_dialect_test.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas rusackas merged commit 87bbd54 into master Jan 22, 2026
61 checks passed
@rusackas rusackas deleted the feat/transpile-virtual-datasets-on-import branch January 22, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:connect Namespace | Anything related to db connections / integrations size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants