Skip to content

Commit

Permalink
zio: change record column references to field (#4340)
Browse files Browse the repository at this point in the history
This is a follow-up to #4306, which renamed zed.Column to Field.
  • Loading branch information
nwt authored Jan 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b39b4bd commit da55f70
Showing 17 changed files with 170 additions and 179 deletions.
10 changes: 5 additions & 5 deletions zio/csvio/writer.go
Original file line number Diff line number Diff line change
@@ -56,8 +56,8 @@ func (w *Writer) Write(rec *zed.Value) error {
if w.first == nil {
w.first = zed.TypeRecordOf(rec.Type)
var hdr []string
for _, col := range rec.Fields() {
hdr = append(hdr, col.Name)
for _, f := range rec.Fields() {
hdr = append(hdr, f.Name)
}
if err := w.encoder.Write(hdr); err != nil {
return err
@@ -66,11 +66,11 @@ func (w *Writer) Write(rec *zed.Value) error {
return ErrNotDataFrame
}
w.strings = w.strings[:0]
cols := rec.Fields()
for i, it := 0, rec.Bytes.Iter(); i < len(cols) && !it.Done(); i++ {
fields := rec.Fields()
for i, it := 0, rec.Bytes.Iter(); i < len(fields) && !it.Done(); i++ {
var s string
if zb := it.Next(); zb != nil {
val := zed.NewValue(cols[i].Type, zb).Under()
val := zed.NewValue(fields[i].Type, zb).Under()
switch id := val.Type.ID(); {
case id == zed.IDBytes && len(val.Bytes) == 0:
// We want "" instead of "0x" for a zero-length value.
9 changes: 4 additions & 5 deletions zio/jsonio/builder.go
Original file line number Diff line number Diff line change
@@ -15,8 +15,7 @@ type builder struct {
items []item // Stack of items.

// These exist only to reduce memory allocations.
bytes []byte
columns []zed.Field
fields []zed.Field
itemptrs []*item
types []zed.Type
val zed.Value
@@ -124,12 +123,12 @@ func (b *builder) endRecord() {
}
itemptrs := b.itemptrs
for {
b.columns = b.columns[:0]
b.fields = b.fields[:0]
for _, item := range itemptrs {
b.columns = append(b.columns, zed.NewField(item.fieldName, item.typ))
b.fields = append(b.fields, zed.NewField(item.fieldName, item.typ))
}
var err error
container.typ, err = b.zctx.LookupTypeRecord(b.columns)
container.typ, err = b.zctx.LookupTypeRecord(b.fields)
if err == nil {
break
}
4 changes: 2 additions & 2 deletions zio/jsonio/marshal.go
Original file line number Diff line number Diff line change
@@ -66,8 +66,8 @@ func marshalAny(typ zed.Type, bytes zcode.Bytes) interface{} {
func marshalRecord(typ *zed.TypeRecord, bytes zcode.Bytes) interface{} {
it := bytes.Iter()
rec := record{}
for _, col := range typ.Fields {
rec = append(rec, field{col.Name, marshalAny(col.Type, it.Next())})
for _, f := range typ.Fields {
rec = append(rec, field{f.Name, marshalAny(f.Type, it.Next())})
}
return rec
}
4 changes: 2 additions & 2 deletions zio/parquetio/builder.go
Original file line number Diff line number Diff line change
@@ -75,8 +75,8 @@ func (b *builder) appendValue(typ zed.Type, v interface{}) {
}
case *zed.TypeRecord:
b.BeginContainer()
for _, c := range typ.Fields {
b.appendValue(c.Type, v[c.Name])
for _, f := range typ.Fields {
b.appendValue(f.Type, v[f.Name])
}
b.EndContainer()
default:
4 changes: 2 additions & 2 deletions zio/parquetio/reader.go
Original file line number Diff line number Diff line change
@@ -44,8 +44,8 @@ func (r *Reader) Read() (*zed.Value, error) {
return nil, err
}
r.builder.Truncate()
for _, c := range r.typ.Fields {
r.builder.appendValue(c.Type, data[c.Name])
for _, f := range r.typ.Fields {
r.builder.appendValue(f.Type, data[f.Name])
}
r.val = *zed.NewValue(r.typ, r.builder.Bytes())
return &r.val, nil
4 changes: 2 additions & 2 deletions zio/parquetio/schemadefinition.go
Original file line number Diff line number Diff line change
@@ -251,8 +251,8 @@ func newRecordColumnDefinition(name string, typ *zed.TypeRecord) (*parquetschema
return nil, ErrEmptyRecordType
}
var children []*parquetschema.ColumnDefinition
for _, c := range typ.Fields {
c, err := newColumnDefinition(c.Name, c.Type)
for _, f := range typ.Fields {
c, err := newColumnDefinition(f.Name, f.Type)
if err != nil {
return nil, err
}
8 changes: 4 additions & 4 deletions zio/tableio/writer.go
Original file line number Diff line number Diff line change
@@ -56,10 +56,10 @@ func (w *Writer) Write(r *zed.Value) error {
w.nline = 0
}
var out []string
for k, col := range r.Fields() {
for k, f := range r.Fields() {
var v string
value := r.DerefByColumn(k).MissingAsNull()
if col.Type == zed.TypeTime {
if f.Type == zed.TypeTime {
if !value.IsNull() {
v = zed.DecodeTime(value.Bytes).Time().Format(time.RFC3339Nano)
}
@@ -78,11 +78,11 @@ func (w *Writer) flush() error {
}

func (w *Writer) writeHeader(typ *zed.TypeRecord) {
for i, c := range typ.Fields {
for i, f := range typ.Fields {
if i > 0 {
w.table.Write([]byte{'\t'})
}
w.table.Write([]byte(c.Name))
w.table.Write([]byte(f.Name))
}
w.table.Write([]byte{'\n'})
}
4 changes: 2 additions & 2 deletions zio/textio/writer.go
Original file line number Diff line number Diff line change
@@ -41,10 +41,10 @@ func (w *Writer) writeRecord(rec *zed.Value) error {
return err
}
var out []string
for k, col := range zed.TypeRecordOf(rec.Type).Fields {
for k, f := range zed.TypeRecordOf(rec.Type).Fields {
var s string
value := rec.DerefByColumn(k).MissingAsNull()
if col.Type == zed.TypeTime {
if f.Type == zed.TypeTime {
if value.IsNull() {
s = "-"
} else {
30 changes: 15 additions & 15 deletions zio/zeekio/builder.go
Original file line number Diff line number Diff line change
@@ -24,12 +24,12 @@ type builder struct {
func (b *builder) build(typ *zed.TypeRecord, sourceFields []int, path []byte, data []byte) (*zed.Value, error) {
b.Truncate()
b.Grow(len(data))
columns := typ.Fields
fields := typ.Fields
if path != nil {
if columns[0].Name != "_path" {
return nil, errors.New("no _path in column 0")
if fields[0].Name != "_path" {
return nil, errors.New("no _path in field 0")
}
columns = columns[1:]
fields = fields[1:]
b.Append(path)
}
b.fields = b.fields[:0]
@@ -53,7 +53,7 @@ func (b *builder) build(typ *zed.TypeRecord, sourceFields []int, path []byte, da
for _, s := range sourceFields {
b.reorderedFields = append(b.reorderedFields, b.fields[s])
}
leftoverFields, err := b.appendColumns(columns, b.reorderedFields)
leftoverFields, err := b.appendFields(fields, b.reorderedFields)
if err != nil {
return nil, err
}
@@ -64,17 +64,17 @@ func (b *builder) build(typ *zed.TypeRecord, sourceFields []int, path []byte, da
return &b.val, nil
}

func (b *builder) appendColumns(columns []zed.Field, fields [][]byte) ([][]byte, error) {
func (b *builder) appendFields(fields []zed.Field, values [][]byte) ([][]byte, error) {
const setSeparator = ','
const emptyContainer = "(empty)"
for _, c := range columns {
if len(fields) == 0 {
for _, f := range fields {
if len(values) == 0 {
return nil, errors.New("too few values")
}
switch typ := c.Type.(type) {
switch typ := f.Type.(type) {
case *zed.TypeArray, *zed.TypeSet:
val := fields[0]
fields = fields[1:]
val := values[0]
values = values[1:]
if string(val) == "-" {
b.Append(nil)
continue
@@ -104,18 +104,18 @@ func (b *builder) appendColumns(columns []zed.Field, fields [][]byte) ([][]byte,
case *zed.TypeRecord:
b.BeginContainer()
var err error
if fields, err = b.appendColumns(typ.Fields, fields); err != nil {
if values, err = b.appendFields(typ.Fields, values); err != nil {
return nil, err
}
b.EndContainer()
default:
if err := b.appendPrimitive(c.Type, fields[0]); err != nil {
if err := b.appendPrimitive(f.Type, values[0]); err != nil {
return nil, err
}
fields = fields[1:]
values = values[1:]
}
}
return fields, nil
return values, nil
}

func (b *builder) appendPrimitive(typ zed.Type, val []byte) error {
4 changes: 2 additions & 2 deletions zio/zeekio/format.go
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ func formatRecord(t *zed.TypeRecord, zv zcode.Bytes) string {
separator := byte(',')
first := true
it := zv.Iter()
for _, col := range t.Fields {
for _, f := range t.Fields {
if first {
first = false
} else {
@@ -123,7 +123,7 @@ func formatRecord(t *zed.TypeRecord, zv zcode.Bytes) string {
if val := it.Next(); val == nil {
b.WriteByte('-')
} else {
b.WriteString(formatAny(zed.NewValue(col.Type, val), false))
b.WriteString(formatAny(zed.NewValue(f.Type, val), false))
}
}
return b.String()
Loading

0 comments on commit da55f70

Please sign in to comment.