refactor: CastExpr queries CastRulesRegistry before operator methods (#17012)#17012
Open
natashasehgal wants to merge 2 commits intofacebookincubator:mainfrom
Open
refactor: CastExpr queries CastRulesRegistry before operator methods (#17012)#17012natashasehgal wants to merge 2 commits intofacebookincubator:mainfrom
natashasehgal wants to merge 2 commits intofacebookincubator:mainfrom
Conversation
|
@natashasehgal has exported this pull request. If you are a Meta employee, you can view the originating Diff in D99232107. |
✅ Deploy Preview for meta-velox canceled.
|
Build Impact AnalysisSelective Build Targets (building these covers all 495 affected)Total affected: 495/556 targets Affected targets (495)Directly changed (12)
Transitively affected (483)
Fast path • Graph from main@cf7d5a7b77016a3efc796f6c30cd5538ce7b91b6 |
… resolution (facebookincubator#17006) Summary: Registers `registerCastRules()` for all remaining Presto and SparkSQL custom types that have CastOperators, declaring their supported casts in the centralized CastRulesRegistry alongside `registerCustomType()`. Types registered (all explicit-only, no implicit coercions): - UUID: VARCHAR, VARBINARY ↔ UUID - BINGTILE: BIGINT ↔ BINGTILE - IPADDRESS: VARCHAR, VARBINARY, IPPREFIX ↔ IPADDRESS - IPPREFIX: VARCHAR, IPADDRESS ↔ IPPREFIX - BIGINT_ENUM: TINYINT/SMALLINT/INTEGER/BIGINT → BIGINT_ENUM, BIGINT_ENUM → BIGINT - VARCHAR_ENUM: VARCHAR ↔ VARCHAR_ENUM - P4HYPERLOGLOG: HYPERLOGLOG ↔ P4HYPERLOGLOG - JSON: primitive types only → JSON and JSON → primitives (container types handled by JsonCastOperator). JSON → TIMESTAMP is not supported in Presto. - TIMESTAMP_NTZ (SparkSQL): VARCHAR → TIMESTAMP_NTZ Also fixes a limitation in `CastRulesRegistry::castCostImpl` where the `size() == 0` guard prevented rule lookup for custom types that extend RowType. Specifically, IPPREFIX is implemented as `RowType(HUGEINT, TINYINT)` so `size() > 0`, which caused rule lookup to skip directly to the container recursion path — which then failed because the base type names differ (e.g., "VARCHAR" != "IPPREFIX"). Before this fix, `canCast(VARCHAR(), IPPREFIX())` returned false despite having a registered rule. The fix tries rule lookup by name first for all types, then falls through to container recursion only when no explicit rule exists. This is safe because container types (ARRAY, MAP, ROW) never have registered cast rules. Differential Revision: D99173066
…acebookincubator#17012) Summary: CastExpr::applyPeeled() now checks CastRulesRegistry::canCast() before falling back to the per-operator isSupportedFromType()/isSupportedToType() methods. This makes the registry the primary source of truth for cast validation, with operator methods as a fallback for types not yet fully migrated to the registry (e.g., JSON container types like ARRAY<X>→JSON that require recursive type checking). This is a no-op behavioral change: the registry answers match what operators would answer for all registered types. The fallback path ensures JSON container casts and any future types with complex validation continue to work. Differential Revision: D99232107
dfb1d25 to
73bbbd9
Compare
natashasehgal
added a commit
to natashasehgal/velox
that referenced
this pull request
Apr 2, 2026
…acebookincubator#17012) Summary: CastExpr::applyPeeled() now checks CastRulesRegistry::canCast() before falling back to the per-operator isSupportedFromType()/isSupportedToType() methods. This makes the registry the primary source of truth for cast validation, with operator methods as a fallback for types not yet fully migrated to the registry (e.g., JSON container types like ARRAY<X>→JSON that require recursive type checking). This is a no-op behavioral change: the registry answers match what operators would answer for all registered types. The fallback path ensures JSON container casts and any future types with complex validation continue to work. Differential Revision: D99232107
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
CastExpr::applyPeeled() now checks CastRulesRegistry::canCast() before falling back to the per-operator isSupportedFromType()/isSupportedToType() methods. This makes the registry the primary source of truth for cast validation, with operator methods as a fallback for types not yet fully migrated to the registry (e.g., JSON container types like ARRAY→JSON that require recursive type checking).
This is a no-op behavioral change: the registry answers match what operators would answer for all registered types. The fallback path ensures JSON container casts and any future types with complex validation continue to work.
Differential Revision: D99232107