From 09ba979354a7604eb2ad316a556f26bc525b2f92 Mon Sep 17 00:00:00 2001 From: Noah Treuhaft Date: Fri, 25 Sep 2026 11:57:13 -0400 Subject: [PATCH] runtime/sam/expr/function: remove HasError --- compiler/semantic/op.go | 13 +++++---- runtime/sam/expr/function/types.go | 45 ------------------------------ runtime/vam/expr/function/types.go | 4 +++ 3 files changed, 12 insertions(+), 50 deletions(-) delete mode 100644 runtime/sam/expr/function/types.go diff --git a/compiler/semantic/op.go b/compiler/semantic/op.go index 0181a6de3..63fc7460e 100644 --- a/compiler/semantic/op.go +++ b/compiler/semantic/op.go @@ -20,11 +20,12 @@ import ( "github.com/brimdata/super/pkg/plural" "github.com/brimdata/super/pkg/reglob" "github.com/brimdata/super/runtime/sam/expr" - samfunction "github.com/brimdata/super/runtime/sam/expr/function" "github.com/brimdata/super/runtime/vam/expr/function" + "github.com/brimdata/super/sbuf" "github.com/brimdata/super/sio" "github.com/brimdata/super/sio/anyio" "github.com/brimdata/super/sup" + "github.com/brimdata/super/vector" "github.com/segmentio/ksuid" ) @@ -196,7 +197,7 @@ func (t *translator) fromCTE(node ast.Node, c *ast.SQLCTE) (sem.Seq, relTable) { func (t *translator) fromFString(entity *ast.FromEval, args []ast.OpArg, seq sem.Seq) (sem.Seq, string) { expr, _ := t.fstringExpr(entity.Expr, t.checker.unknown) val, ok := t.maybeEval(expr) - if ok && !hasError(val) { + if ok && !t.hasError(val) { if bad := t.hasFromParent(entity, seq); bad != nil { return bad, "" } @@ -211,9 +212,11 @@ func (t *translator) fromFString(entity *ast.FromEval, args []ast.OpArg, seq sem }), "" } -func hasError(val super.Value) bool { - result := samfunction.HasError{}.Call([]super.Value{val}) - return result.AsBool() +func (t *translator) hasError(val super.Value) bool { + vec := sbuf.ValToVec(t.sctx, val) + vec = function.NewHasError(t.sctx).Call(vec) + val = vector.ValueAt(nil, vec, 0) + return val.AsBool() } func (t *translator) hasFromParent(loc ast.Node, seq sem.Seq) sem.Seq { diff --git a/runtime/sam/expr/function/types.go b/runtime/sam/expr/function/types.go deleted file mode 100644 index 5033ffcb1..000000000 --- a/runtime/sam/expr/function/types.go +++ /dev/null @@ -1,45 +0,0 @@ -package function - -import ( - "slices" - - "github.com/brimdata/super" - "github.com/brimdata/super/scode" -) - -type HasError struct{} - -func (h HasError) Call(args []super.Value) super.Value { - return super.NewBool(h.hasError(args[0].Type(), args[0].Bytes())) -} - -func (h HasError) hasError(t super.Type, b scode.Bytes) bool { - switch typ := super.TypeUnder(t).(type) { - case *super.TypeRecord: - it := b.Iter() - return slices.ContainsFunc(typ.Fields, func(f super.Field) bool { - return h.hasError(f.Type, it.Next()) - }) - case *super.TypeArray, *super.TypeSet: - inner := super.InnerType(typ) - for it := b.Iter(); !it.Done(); { - if h.hasError(inner, it.Next()) { - return true - } - } - return false - case *super.TypeMap: - for it := b.Iter(); !it.Done(); { - if h.hasError(typ.KeyType, it.Next()) || h.hasError(typ.ValType, it.Next()) { - return true - } - } - return false - case *super.TypeUnion: - return h.hasError(typ.Untag(b)) - case *super.TypeError: - return true - default: - return false - } -} diff --git a/runtime/vam/expr/function/types.go b/runtime/vam/expr/function/types.go index 2eb9699ce..2eef37e0c 100644 --- a/runtime/vam/expr/function/types.go +++ b/runtime/vam/expr/function/types.go @@ -12,6 +12,10 @@ type HasError struct { sctx *super.Context } +func NewHasError(sctx *super.Context) expr.Function { + return &HasError{sctx} +} + func (h HasError) Call(args ...vector.Any) vector.Any { return h.hasError(args[0]) }