Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions runtime/vam/expr/arith.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ func (a *Arith) Eval(val vector.Any) vector.Any {
func (a *Arith) eval(vecs ...vector.Any) (out vector.Any) {
lhs := enumToIndex(vector.Under(vecs[0]))
rhs := enumToIndex(vector.Under(vecs[1]))
if k := vector.KindOf(lhs); k == vector.KindNull || k == vector.KindError {
if k := lhs.Kind(); k == vector.KindNull || k == vector.KindError {
return lhs
}
if k := vector.KindOf(rhs); k == vector.KindNull || k == vector.KindError {
if k := rhs.Kind(); k == vector.KindNull || k == vector.KindError {
return rhs
}
lhs, rhs, errVal := coerceVals(a.sctx, lhs, rhs)
if errVal != nil {
return errVal
}
kind := vector.KindOf(lhs)
if kind != vector.KindOf(rhs) {
kind := lhs.Kind()
if kind != rhs.Kind() {
panic(fmt.Sprintf("vector kind mismatch after coerce (%#v and %#v)", lhs, rhs))
}
if kind == vector.KindFloat && a.opCode == vector.ArithMod {
Expand Down
4 changes: 2 additions & 2 deletions runtime/vam/expr/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (c *Compare) eval(vecs ...vector.Any) vector.Any {
return vector.NewConst(super.False, vecs[0].Len(), nulls)
}
//XXX need to handle overflow (see sam)
kind := vector.KindOf(lhs)
if kind != vector.KindOf(rhs) {
kind := lhs.Kind()
if kind != rhs.Kind() {
panic("vector kind mismatch after coerce")
}
switch kind {
Expand Down
2 changes: 1 addition & 1 deletion runtime/vam/expr/function/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ type Log struct {
func (l *Log) Call(args ...vector.Any) vector.Any {
arg := vector.Under(args[0])
if !super.IsNumber(arg.Type().ID()) {
if vector.KindOf(arg) == vector.KindError {
if arg.Kind() == vector.KindError {
return arg
}
return vector.NewWrappedError(l.sctx, "log: not a number", arg)
Expand Down
2 changes: 1 addition & 1 deletion runtime/vam/expr/function/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Concat struct {
func (c *Concat) Call(args ...vector.Any) vector.Any {
args = underAll(args)
for _, arg := range args {
switch vector.KindOf(arg) {
switch arg.Kind() {
case vector.KindError:
return arg
case vector.KindString:
Expand Down
2 changes: 1 addition & 1 deletion runtime/vam/expr/function/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type IsErr struct{}

func (IsErr) Call(args ...vector.Any) vector.Any {
vec := vector.Under(args[0])
if vector.KindOf(vec) != vector.KindError {
if vec.Kind() != vector.KindError {
return vector.NewConst(super.False, vec.Len(), bitvec.Zero)
}
nulls := vector.NullsOf(vec)
Expand Down
2 changes: 1 addition & 1 deletion runtime/vam/expr/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (i *Index) eval(args ...vector.Any) vector.Any {
this := args[0]
container := vector.Under(i.container.Eval(this))
index := vector.Under(i.index.Eval(this))
switch vector.KindOf(container) {
switch container.Kind() {
case vector.KindArray, vector.KindSet:
return indexArrayOrSet(i.sctx, container, index, i.base1)
case vector.KindRecord:
Expand Down
3 changes: 2 additions & 1 deletion runtime/vam/expr/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ func orError(err, vec vector.Any) vector.Any {
func evalBool(sctx *super.Context, fn func(...vector.Any) vector.Any, vecs ...vector.Any) vector.Any {
return vector.Apply(false, func(vecs ...vector.Any) vector.Any {
for i, vec := range vecs {
if vec := vector.Under(vec); vec.Type() == super.TypeBool || vector.KindOf(vec) == vector.KindError {
vec := vector.Under(vec)
if k := vec.Kind(); k == vector.KindBool || k == vector.KindError {
vecs[i] = vec
} else {
vecs[i] = vector.NewWrappedError(sctx, "not type bool", vec)
Expand Down
2 changes: 1 addition & 1 deletion runtime/vam/expr/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewSearch(s string, val super.Value, e Evaluator) Evaluator {
}
eq := NewCompare(super.NewContext() /* XXX */, "==", nil, nil)
vectorPred := func(vec vector.Any) vector.Any {
if net.IsValid() && vector.KindOf(vec) == vector.KindIP {
if net.IsValid() && vec.Kind() == vector.KindIP {
out := vector.NewFalse(vec.Len())
for i := range vec.Len() {
if ip, null := vector.IPValue(vec, i); !null && net.Contains(ip) {
Expand Down
4 changes: 2 additions & 2 deletions runtime/vam/expr/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *sliceExpr) eval(vecs ...vector.Any) vector.Any {
return vector.NewStringError(s.sctx, "slice index is not a number", to.Len())
}
}
switch vector.KindOf(container) {
switch container.Kind() {
case vector.KindArray, vector.KindSet:
return s.evalArrayOrSlice(container, from, to, s.base1)
case vector.KindBytes, vector.KindString:
Expand Down Expand Up @@ -116,7 +116,7 @@ func (s *sliceExpr) evalArrayOrSlice(vec, fromVec, toVec vector.Any, base1 bool)
}
var out vector.Any
inner = vector.Pick(inner, innerIndex)
if vector.KindOf(vec) == vector.KindArray {
if vec.Kind() == vector.KindArray {
out = vector.NewArray(vec.Type().(*super.TypeArray), newOffsets, inner, nullsOut)
} else {
out = vector.NewSet(vec.Type().(*super.TypeSet), newOffsets, inner, nullsOut)
Expand Down
1 change: 1 addition & 0 deletions vector/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type Any interface {
Type() super.Type
Kind() Kind
Len() uint32
Serialize(*scode.Builder, uint32)
}
Expand Down
4 changes: 4 additions & 0 deletions vector/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func NewArray(typ *super.TypeArray, offsets []uint32, values Any, nulls bitvec.B
return &Array{Typ: typ, Offsets: offsets, Values: values, Nulls: nulls}
}

func (*Array) Kind() Kind {
return KindArray
}

func (a *Array) Type() super.Type {
return a.Typ
}
Expand Down
4 changes: 4 additions & 0 deletions vector/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func NewTrue(length uint32) *Bool {
return NewBool(bitvec.NewTrue(length), bitvec.Zero)
}

func (*Bool) Kind() Kind {
return KindBool
}

func (b *Bool) Type() super.Type {
return super.TypeBool
}
Expand Down
4 changes: 4 additions & 0 deletions vector/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (b *Bytes) Append(v []byte) {
b.table.Append(v)
}

func (*Bytes) Kind() Kind {
return KindBytes
}

func (b *Bytes) Type() super.Type {
return super.TypeBytes
}
Expand Down
29 changes: 29 additions & 0 deletions vector/const.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vector

import (
"fmt"

"github.com/brimdata/super"
"github.com/brimdata/super/runtime/sam/expr/coerce"
"github.com/brimdata/super/scode"
Expand All @@ -22,6 +24,33 @@ func NewConst(val super.Value, len uint32, nulls bitvec.Bits) *Const {
return &Const{val: val, len: len, Nulls: nulls}
}

func (c *Const) Kind() Kind {
// c.val must be a primitive.
switch id := c.val.Type().ID(); {
case super.IsUnsigned(id):
return KindUint
case super.IsSigned(id):
return KindInt
case super.IsFloat(id):
return KindFloat
case id == super.IDBool:
return KindBool
case id == super.IDBytes:
return KindBytes
case id == super.IDString:
return KindString
case id == super.IDIP:
return KindIP
case id == super.IDNet:
return KindNet
case id == super.IDType:
return KindType
case id == super.IDNull:
return KindNull
}
panic(fmt.Sprintf("%#v\n", super.TypeUnder(c.val.Type())))
}

func (c *Const) Type() super.Type {
return c.val.Type()
}
Expand Down
4 changes: 4 additions & 0 deletions vector/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func NewDynamic(tags []uint32, values []Any) *Dynamic {
return &Dynamic{Tags: tags, Values: values}
}

func (*Dynamic) Kind() Kind {
return KindInvalid
}

func (*Dynamic) Type() super.Type {
panic("can't call Type() on a vector.Dynamic")
}
Expand Down
2 changes: 2 additions & 0 deletions vector/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ func NewEnum(typ *super.TypeEnum, vals []uint64, nulls bitvec.Bits) *Enum {
}
}

func (*Enum) Kind() Kind { return KindEnum }

func (e *Enum) Type() super.Type { return e.Typ }
4 changes: 4 additions & 0 deletions vector/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func NewError(typ *super.TypeError, vals Any, nulls bitvec.Bits) *Error {
return &Error{Typ: typ, Vals: vals, Nulls: nulls}
}

func (*Error) Kind() Kind {
return KindError
}

func (e *Error) Type() super.Type {
return e.Typ
}
Expand Down
4 changes: 4 additions & 0 deletions vector/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (f *Float) Append(v float64) {
f.Values = append(f.Values, v)
}

func (*Float) Kind() Kind {
return KindFloat
}

func (f *Float) Type() super.Type {
return f.Typ
}
Expand Down
4 changes: 4 additions & 0 deletions vector/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func (i *Int) Append(v int64) {
i.Values = append(i.Values, v)
}

func (*Int) Kind() Kind {
return KindInt
}

func (i *Int) Type() super.Type {
return i.Typ
}
Expand Down
4 changes: 4 additions & 0 deletions vector/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func NewIP(values []netip.Addr, nulls bitvec.Bits) *IP {
return &IP{Values: values, Nulls: nulls}
}

func (*IP) Kind() Kind {
return KindIP
}

func (i *IP) Type() super.Type {
return super.TypeIP
}
Expand Down
78 changes: 3 additions & 75 deletions vector/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package vector

import (
"fmt"

"github.com/brimdata/super"
)

type Kind int
Expand All @@ -25,6 +23,9 @@ const (
KindSet = 12
KindMap = 13
KindRecord = 14
KindBool = 15
KindUnion = 16
KindEnum = 17
)

const (
Expand All @@ -34,47 +35,6 @@ const (
FormConst = 3
)

//XXX might not need Kind...

func KindOf(v Any) Kind {
switch v := v.(type) {
case *Array:
return KindArray
case *Int:
return KindInt
case *Uint:
return KindUint
case *Float:
return KindFloat
case *Bytes:
return KindBytes
case *String:
return KindString
case *Error:
return KindError
case *IP:
return KindIP
case *Net:
return KindNet
case *TypeValue:
return KindType
case *Map:
return KindMap
case *Record:
return KindRecord
case *Set:
return KindSet
case *Dict:
return KindOf(v.Any)
case *View:
return KindOf(v.Any)
case *Const:
return KindOfType(v.Value().Type())
default:
return KindInvalid
}
}

func KindFromString(v string) Kind {
switch v {
case "Int":
Expand Down Expand Up @@ -102,38 +62,6 @@ func KindFromString(v string) Kind {
}
}

func KindOfType(typ super.Type) Kind {
switch super.TypeUnder(typ).(type) {
case *super.TypeOfInt16, *super.TypeOfInt32, *super.TypeOfInt64, *super.TypeOfDuration, *super.TypeOfTime:
return KindInt
case *super.TypeOfUint16, *super.TypeOfUint32, *super.TypeOfUint64:
return KindUint
case *super.TypeOfFloat16, *super.TypeOfFloat32, *super.TypeOfFloat64:
return KindFloat
case *super.TypeOfString:
return KindString
case *super.TypeOfBytes:
return KindBytes
case *super.TypeOfIP:
return KindIP
case *super.TypeOfNet:
return KindNet
case *super.TypeOfType:
return KindType
case *super.TypeOfNull:
return KindNull
case *super.TypeArray:
return KindArray
case *super.TypeSet:
return KindSet
case *super.TypeMap:
return KindMap
case *super.TypeRecord:
return KindRecord
}
return KindInvalid
}

func FormOf(v Any) (Form, bool) {
switch v.(type) {
case *Int, *Uint, *Float, *Bytes, *String, *TypeValue: //XXX IP, Net
Expand Down
4 changes: 4 additions & 0 deletions vector/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func NewMap(typ *super.TypeMap, offsets []uint32, keys Any, values Any, nulls bi
return &Map{Typ: typ, Offsets: offsets, Keys: keys, Values: values, Nulls: nulls}
}

func (*Map) Kind() Kind {
return KindMap
}

func (m *Map) Type() super.Type {
return m.Typ
}
Expand Down
4 changes: 4 additions & 0 deletions vector/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func NewNet(values []netip.Prefix, nulls bitvec.Bits) *Net {
return &Net{Values: values, Nulls: nulls}
}

func (*Net) Kind() Kind {
return KindNet
}

func (n *Net) Type() super.Type {
return super.TypeNet
}
Expand Down
4 changes: 4 additions & 0 deletions vector/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func NewRecord(typ *super.TypeRecord, fields []Any, length uint32, nulls bitvec.
return &Record{Typ: typ, Fields: fields, len: length, Nulls: nulls}
}

func (*Record) Kind() Kind {
return KindRecord
}

func (r *Record) Type() super.Type {
return r.Typ
}
Expand Down
Loading