Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mimic_utils/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def main():
file_parser.add_argument("source_file", help="Source file.")
file_parser.add_argument("destination_file", help="Destination file.")
file_parser.add_argument("--source_dialect", choices=["bigquery", "postgres", "duckdb"], default='bigquery', help="SQL dialect to transpile.")
file_parser.add_argument("--destination_dialect", choices=["postgres", "duckdb"], default='postgres', help="SQL dialect to transpile.")
file_parser.add_argument("--destination_dialect", choices=["bigquery", "postgres", "duckdb"], default='postgres', help="SQL dialect to transpile.")
file_parser.set_defaults(func=transpile_file)

folder_parser = subparsers.add_parser('convert_folder', help='Transpile all SQL files in a folder.')
Expand Down
8 changes: 7 additions & 1 deletion src/mimic_utils/transpile.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ def _strip_catalog(parsed: exp.Expression) -> None:

def transpile_query(query: str, source_dialect: str = "bigquery", destination_dialect: str = "postgres") -> str:
"""Transpile a SQL string from ``source_dialect`` to ``destination_dialect``."""
parsed = sqlglot.parse_one(query, read=source_dialect)

# Identity / BQ target: folder CLI already accepts bigquery; keep catalog.
if destination_dialect == "bigquery":
sql = parsed.sql(dialect="bigquery", pretty=True, comments=True)
return _strip_timezone_types(sql)

if destination_dialect not in _DESTINATION_DIALECTS:
raise ValueError(f"Unsupported destination dialect: {destination_dialect}")

parsed = sqlglot.parse_one(query, read=source_dialect)
_strip_catalog(parsed)

# DuckDB does not accept the default /* ... */ block comment style, so we
Expand Down
Loading