Skip to content

fix: normalize type aliases and add promotion rules for schema evolution#82

Open
zfarrell wants to merge 3 commits intomainfrom
fix/type-normalization-promotion
Open

fix: normalize type aliases and add promotion rules for schema evolution#82
zfarrell wants to merge 3 commits intomainfrom
fix/type-normalization-promotion

Conversation

@zfarrell
Copy link
Contributor

@zfarrell zfarrell commented Mar 1, 2026

Summary

  • Add normalize_ducklake_type() to convert type aliases to canonical forms (e.g., "int" -> "int32", "text" -> "varchar")
  • Add is_promotable() with safe type widening rules: integer widening, float widening, int-to-float64, timestamp-to-timestamptz, decimal precision widening
  • Add types_compatible() that checks alias equivalence and promotion for schema evolution
  • Replace strict string equality in schema evolution check with types_compatible() so that e.g. a table with "int" columns can accept "int32" data without error

Test plan

  • Unit tests for normalize_ducklake_type() across all alias families (int, bigint, string, float, double, bool, smallint, tinyint)
  • Unit tests for is_promotable() covering signed/unsigned widening, float widening, int-to-float, timestamp promotion, decimal widening, and rejection of narrowing/incompatible types
  • Unit tests for types_compatible() covering alias equivalence, case insensitivity, promotion, and incompatible types
  • cargo test passes

zfarrell and others added 3 commits February 26, 2026 20:19
- Add normalize_ducklake_type() for canonical type resolution (int/integer/INT all -> int32)
- Add is_promotable() for safe type widening (int->bigint, float->double, timestamp->timestamptz)
- Add types_compatible() combining normalization + promotion for schema evolution checks
- Replace exact string equality with types_compatible() in schema evolution

Found during Feb 2026 security review

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous check (tp >= fp && ts >= fs) allowed promotions like
decimal(10,2) → decimal(12,8) where the integer part shrinks from
8 to 4 digits, potentially causing overflow. Now checks that both
integer digits (precision - scale) and fractional digits don't shrink.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant