feat(wren): add cross-dialect type translation to type_mapping#2410
Conversation
Add translate_type() and translate_types() helpers plus utils `translate-type`/`translate-types` CLI commands that parse a SQL type string in a source dialect and re-render it in a target dialect (e.g. postgres int8 -> bigquery INT64, postgres character varying(255) -> clickhouse Nullable(String)). This complements the existing parse_type/parse_types normalization for schema-mirroring and cross-engine modeling workflows where a column's type must be expressed in a different engine's spelling. Parsing failures fall back to the original string, matching parse_type's behavior. Built on sqlglot only (no connector drivers), so the new tests run in the lightweight unit CI job.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughAdds cross-dialect SQL type translation helpers, two CLI commands for single and batch translation, and tests covering translation behavior, fallback, stdin/file input, and error handling. ChangesSQL Type Translation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@core/wren/src/wren/utils_cli.py`:
- Around line 103-114: The input parsing in the CLI path around the
`Path.read_text`, `json.loads`, and `json.load` flow only handles
`json.JSONDecodeError`, so file read and encoding failures from `--input` can
still surface as tracebacks. Update the `utils_cli` parsing block to catch
`OSError` and `UnicodeDecodeError` alongside the existing JSON decode handling,
and route them through the same `typer.echo(..., err=True)` plus `typer.Exit(1)`
behavior used for missing files and invalid JSON.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 44c354b1-2779-46d7-af18-a20cceb1753a
📒 Files selected for processing (3)
core/wren/src/wren/type_mapping.pycore/wren/src/wren/utils_cli.pycore/wren/tests/unit/test_type_mapping.py
translate-types and parse-types now catch file read/decode failures and exit(1) cleanly instead of leaking a traceback, matching the existing not-found and invalid-JSON handling. Adds regression tests.
|
Good catch — fixed in |
|
The one actionable finding (catch |
What & why
wren.type_mappingalready gives usparse_type()/parse_types()to normalize a raw DB type string into sqlglot's canonical form for a single dialect. A common adjacent need in cross-engine modeling (mirroring a Postgres schema into BigQuery, generating MDL for a different target engine, etc.) is to translate a type from one engine's spelling into another's.This PR adds that as a small, focused companion:
translate_type(type_str, source_dialect, target_dialect)— parse in source dialect, render in target dialect.translate_types(columns, source_dialect, target_dialect, *, type_field="raw_type")— batch variant mirroringparse_types(non-mutating, adds atypekey).wren utils translate-typeandwren utils translate-typesCLI commands, matching the existingparse-type/parse-typesUX (single via flags, batch via stdin/--inputJSON).Examples:
int8INT64character varying(255)Nullable(String)INT64BIGINTDECIMAL(10,2)DECIMAL(10, 2)Parse failures fall back to the original string, matching
parse_type's existing contract.Implementation notes
unit testsCI job (nopytest.importorskipguard needed).parse_*paths.Tests
Added to
tests/unit/test_type_mapping.py:translate_typecases (cross-dialect, identity-normalization, unknown-type fallback, empty passthrough)translate_typesbatch tests (adds field, no mutation, custom field, empty list)translate-type/translate-typesLocal run (
core/wren, sqlglot 30.12.0):Summary by CodeRabbit