Skip to content

Commit

Permalink
Rename ColumnOfField to IndexOfField on TypeRecord & Value (#4687)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwt authored Jun 29, 2023
1 parent fab1082 commit 2423608
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion complex.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (t *TypeRecord) ID() int {
return t.id
}

func (t *TypeRecord) ColumnOfField(field string) (int, bool) {
func (t *TypeRecord) IndexOfField(field string) (int, bool) {
v, ok := t.LUT[field]
return v, ok
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/expr/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (d *DotExpr) fieldIndex(typ *zed.TypeRecord) (int, bool) {
} else if i < 0 {
return 0, false
}
i, ok := typ.ColumnOfField(d.field)
i, ok := typ.IndexOfField(d.field)
if ok {
d.fieldIndices[id] = i + 1
} else {
Expand Down
2 changes: 1 addition & 1 deletion runtime/expr/function/unflatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (u *Unflatten) parseElem(inner zed.Type, vb zcode.Bytes) (field.Path, zed.T
if typ == nil || len(typ.Fields) != 2 {
return nil, nil, nil, nil
}
nkey, ok := typ.ColumnOfField("key")
nkey, ok := typ.IndexOfField("key")
if !ok {
return nil, nil, nil, nil
}
Expand Down
8 changes: 4 additions & 4 deletions runtime/expr/renamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ func NewRenamer(zctx *zed.Context, srcs, dsts field.List) *Renamer {
}

func (r *Renamer) dstType(typ *zed.TypeRecord, src, dst field.Path) (*zed.TypeRecord, error) {
c, ok := typ.ColumnOfField(src[0])
i, ok := typ.IndexOfField(src[0])
if !ok {
return typ, nil
}
var innerType zed.Type
if len(src) > 1 {
recType, ok := typ.Fields[c].Type.(*zed.TypeRecord)
recType, ok := typ.Fields[i].Type.(*zed.TypeRecord)
if !ok {
return typ, nil
}
Expand All @@ -43,10 +43,10 @@ func (r *Renamer) dstType(typ *zed.TypeRecord, src, dst field.Path) (*zed.TypeRe
}
innerType = typ
} else {
innerType = typ.Fields[c].Type
innerType = typ.Fields[i].Type
}
fields := slices.Clone(typ.Fields)
fields[c] = zed.NewField(dst[0], innerType)
fields[i] = zed.NewField(dst[0], innerType)
typ, err := r.zctx.LookupTypeRecord(fields)
if err != nil {
var dferr *zed.DuplicateFieldError
Expand Down
2 changes: 1 addition & 1 deletion runtime/expr/shaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ Switch:
func newRecordStep(zctx *zed.Context, in *zed.TypeRecord, out zed.Type) (step, error) {
var children []step
for _, outField := range zed.TypeRecordOf(out).Fields {
ind, ok := in.ColumnOfField(outField.Name)
ind, ok := in.IndexOfField(outField.Name)
if !ok {
children = append(children, step{op: null, toType: outField.Type})
continue
Expand Down
8 changes: 4 additions & 4 deletions runtime/vcache/projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func findCuts(o *Object, names []string) ([]*cut, error) {
fields := Under(o.vectors[k]).(Record)
var actuals []string
for _, name := range names {
if _, ok := recType.ColumnOfField(name); !ok {
if _, ok := recType.IndexOfField(name); !ok {
continue
}
actuals = append(actuals, name)
Expand Down Expand Up @@ -101,11 +101,11 @@ func newCut(zctx *zed.Context, typ *zed.TypeRecord, fields []Vector, actuals []s
iters := make([]iterator, len(actuals))
outFields := make([]zed.Field, len(actuals))
for k, name := range actuals {
col, _ := typ.ColumnOfField(name)
outFields[k] = typ.Fields[col]
i, _ := typ.IndexOfField(name)
outFields[k] = typ.Fields[i]
which := k
group.Go(func() error {
it, err := fields[col].NewIter(reader)
it, err := fields[i].NewIter(reader)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ func (v *Value) DerefByColumn(col int) *Value {
return v
}

func (v *Value) ColumnOfField(field string) (int, bool) {
func (v *Value) IndexOfField(field string) (int, bool) {
if typ := TypeRecordOf(v.Type); typ != nil {
return typ.ColumnOfField(field)
return typ.IndexOfField(field)
}
return 0, false
}
Expand All @@ -380,11 +380,11 @@ func (v *Value) Deref(field string) *Value {
if v == nil {
return nil
}
col, ok := v.ColumnOfField(field)
i, ok := v.IndexOfField(field)
if !ok {
return nil
}
return v.DerefByColumn(col)
return v.DerefByColumn(i)
}

func (v *Value) DerefPath(path field.Path) *Value {
Expand Down

0 comments on commit 2423608

Please sign in to comment.