Conversation
This commit removes the old shaper code and replaces it with a new function upcast with behavior somewhat different from a normal cast, requiring exact type matching (no coercion) and providing casting intended only for supertypes of the upcasted value. We adapted agg-fuse/op-fuse to use this new approach and to use the optional-fields-as-null approach of NewSchemaWithMissingFieldsAsNullable, which will be replaced with optional fields in the forthcoming optional-fields PR. Upcast tests will also be added in this PR.
nwt
approved these changes
Feb 17, 2026
Comment on lines
+150
to
+153
| case "upcast": | ||
| argmin = 2 | ||
| argmax = 2 | ||
| f = &upcast{sctx} |
Member
There was a problem hiding this comment.
Nit: Put this after unflatten so these stay alphabetized.
runtime/sam/expr/function/cast.go
Outdated
| sctx *super.Context | ||
| } | ||
|
|
||
| func NewCaster(sctx *super.Context) *cast { |
Member
There was a problem hiding this comment.
Nit:
Suggested change
| func NewCaster(sctx *super.Context) *cast { | |
| func NewCaster(sctx *super.Context) Caster { |
runtime/sam/expr/function/cast.go
Outdated
| sctx *super.Context | ||
| } | ||
|
|
||
| func NewUpCaster(sctx *super.Context) *upcast { |
Member
There was a problem hiding this comment.
Nit:
Suggested change
| func NewUpCaster(sctx *super.Context) *upcast { | |
| func NewUpcaster(sctx *super.Context) Caster { |
runtime/sam/expr/function/cast.go
Outdated
Comment on lines
+241
to
+242
| _, ok := super.TypeUnder(to.Type()).(*super.TypeOfType) | ||
| if !ok { |
Member
There was a problem hiding this comment.
Nit:
Suggested change
| _, ok := super.TypeUnder(to.Type()).(*super.TypeOfType) | |
| if !ok { | |
| if _, ok := super.TypeUnder(to.Type()).(*super.TypeOfType); !ok { |
runtime/sam/expr/function/cast.go
Outdated
| case *super.TypeNamed: | ||
| return u.toNamed(from, to) | ||
| default: | ||
| return u.sctx.WrapError("cannot upcast to "+sup.FormatType(to), from) |
Member
There was a problem hiding this comment.
Nit:
Suggested change
| return u.sctx.WrapError("cannot upcast to "+sup.FormatType(to), from) | |
| return u.error(from, to) |
runtime/sam/expr/function/cast.go
Outdated
| return super.NewValue(to, b.Bytes().Body()) | ||
| } | ||
|
|
||
| func (u *upcast) maybeRecordUpcast(from super.Value, to *super.TypeUnion) (super.Value, int, bool) { |
Member
There was a problem hiding this comment.
Nit:
Suggested change
| func (u *upcast) maybeRecordUpcast(from super.Value, to *super.TypeUnion) (super.Value, int, bool) { | |
| func (u *upcast) maybeUpcastRecord(from super.Value, to *super.TypeUnion) (super.Value, int, bool) { |
runtime/sam/op/fuse/fuser.go
Outdated
Comment on lines
+85
to
+87
| if f.caster == nil { | ||
| f.typ = f.uberSchema.Type() | ||
| f.caster = function.NewUpCaster(f.sctx) |
Member
There was a problem hiding this comment.
Nit: Would be a little clearer to initialize f.caster in NewFuser and just test f.typ here.
Suggested change
| if f.caster == nil { | |
| f.typ = f.uberSchema.Type() | |
| f.caster = function.NewUpCaster(f.sctx) | |
| if f.typ == nil { | |
| f.typ = f.uberSchema.Type() |
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.
This commit removes the old shaper code and replaces it with a new function upcast with behavior somewhat different from a normal cast, requiring exact type matching (no coercion) and providing casting intended only for supertypes of the upcasted value.
We adapted agg-fuse/op-fuse to use this new approach and to use the optional-fields-as-null approach of NewSchemaWithMissingFieldsAsNullable, which will be replaced with optional fields in the forthcoming optional-fields PR. Upcast tests will also be added in this PR.
Fixes #4525