Skip to content

replace old shaper code with upcast#6634

Merged
mccanne merged 2 commits intomainfrom
no-shaper-2
Feb 17, 2026
Merged

replace old shaper code with upcast#6634
mccanne merged 2 commits intomainfrom
no-shaper-2

Conversation

@mccanne
Copy link
Collaborator

@mccanne mccanne commented Feb 17, 2026

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

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.
Comment on lines +150 to +153
case "upcast":
argmin = 2
argmax = 2
f = &upcast{sctx}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Put this after unflatten so these stay alphabetized.

sctx *super.Context
}

func NewCaster(sctx *super.Context) *cast {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
func NewCaster(sctx *super.Context) *cast {
func NewCaster(sctx *super.Context) Caster {

sctx *super.Context
}

func NewUpCaster(sctx *super.Context) *upcast {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
func NewUpCaster(sctx *super.Context) *upcast {
func NewUpcaster(sctx *super.Context) Caster {

Comment on lines +241 to +242
_, ok := super.TypeUnder(to.Type()).(*super.TypeOfType)
if !ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
_, ok := super.TypeUnder(to.Type()).(*super.TypeOfType)
if !ok {
if _, ok := super.TypeUnder(to.Type()).(*super.TypeOfType); !ok {

case *super.TypeNamed:
return u.toNamed(from, to)
default:
return u.sctx.WrapError("cannot upcast to "+sup.FormatType(to), from)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
return u.sctx.WrapError("cannot upcast to "+sup.FormatType(to), from)
return u.error(from, to)

return super.NewValue(to, b.Bytes().Body())
}

func (u *upcast) maybeRecordUpcast(from super.Value, to *super.TypeUnion) (super.Value, int, bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Comment on lines +85 to +87
if f.caster == nil {
f.typ = f.uberSchema.Type()
f.caster = function.NewUpCaster(f.sctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

@mccanne mccanne merged commit 4dbc2fe into main Feb 17, 2026
4 checks passed
@mccanne mccanne deleted the no-shaper-2 branch February 17, 2026 13:31
@nwt nwt mentioned this pull request Feb 24, 2026
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.

Primitive type foils fuse

2 participants