Skip to content

Commit f0e52a0

Browse files
authored
Merge pull request #2067 from Chessing234/fix/convert-file-bigquery-dest
Allow convert_file destination_dialect=bigquery
2 parents c6d3b4e + a321148 commit f0e52a0

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/mimic_utils/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def main():
1717
file_parser.add_argument("source_file", help="Source file.")
1818
file_parser.add_argument("destination_file", help="Destination file.")
1919
file_parser.add_argument("--source_dialect", choices=["bigquery", "postgres", "duckdb"], default='bigquery', help="SQL dialect to transpile.")
20-
file_parser.add_argument("--destination_dialect", choices=["postgres", "duckdb"], default='postgres', help="SQL dialect to transpile.")
20+
file_parser.add_argument("--destination_dialect", choices=["bigquery", "postgres", "duckdb"], default='postgres', help="SQL dialect to transpile.")
2121
file_parser.set_defaults(func=transpile_file)
2222

2323
folder_parser = subparsers.add_parser('convert_folder', help='Transpile all SQL files in a folder.')

src/mimic_utils/transpile.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ def _strip_catalog(parsed: exp.Expression) -> None:
4747

4848
def transpile_query(query: str, source_dialect: str = "bigquery", destination_dialect: str = "postgres") -> str:
4949
"""Transpile a SQL string from ``source_dialect`` to ``destination_dialect``."""
50+
parsed = sqlglot.parse_one(query, read=source_dialect)
51+
52+
# Identity / BQ target: folder CLI already accepts bigquery; keep catalog.
53+
if destination_dialect == "bigquery":
54+
sql = parsed.sql(dialect="bigquery", pretty=True, comments=True)
55+
return _strip_timezone_types(sql)
56+
5057
if destination_dialect not in _DESTINATION_DIALECTS:
5158
raise ValueError(f"Unsupported destination dialect: {destination_dialect}")
5259

53-
parsed = sqlglot.parse_one(query, read=source_dialect)
5460
_strip_catalog(parsed)
5561

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

0 commit comments

Comments
 (0)