feat(examples): Transpile virtual dataset SQL on import (#37311)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: bito-code-review[bot] <188872107+bito-code-review[bot]@users.noreply.github.com>
This commit is contained in:
Evan Rusackas
2026-01-22 09:50:05 -08:00
committed by GitHub
parent b630830841
commit 87bbd54d0a
6 changed files with 377 additions and 3 deletions

View File

@@ -1522,9 +1522,21 @@ def sanitize_clause(clause: str, engine: str) -> str:
raise QueryClauseValidationException(f"Invalid SQL clause: {clause}") from ex
def transpile_to_dialect(sql: str, target_engine: str) -> str:
def transpile_to_dialect(
sql: str,
target_engine: str,
source_engine: str | None = None,
) -> str:
"""
Transpile SQL from "generic SQL" to the target database dialect using SQLGlot.
Transpile SQL from one database dialect to another using SQLGlot.
Args:
sql: The SQL query to transpile
target_engine: The target database engine (e.g., "mysql", "postgresql")
source_engine: The source database engine. If None, uses generic SQL dialect.
Returns:
The transpiled SQL string
If the target engine is not in SQLGLOT_DIALECTS, returns the SQL as-is.
"""
@@ -1534,8 +1546,11 @@ def transpile_to_dialect(sql: str, target_engine: str) -> str:
if target_dialect is None:
return sql
# Get source dialect (default to generic if not specified)
source_dialect = SQLGLOT_DIALECTS.get(source_engine) if source_engine else Dialect
try:
parsed = sqlglot.parse_one(sql, dialect=Dialect)
parsed = sqlglot.parse_one(sql, dialect=source_dialect)
return Dialect.get_or_raise(target_dialect).generate(
parsed,
copy=True,