diff --git a/zio/csvio/writer.go b/zio/csvio/writer.go index 56a9a50c19..d708ec4169 100644 --- a/zio/csvio/writer.go +++ b/zio/csvio/writer.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "slices" "strings" "github.com/brimdata/zed" @@ -62,7 +63,7 @@ func (w *Writer) Write(rec *zed.Value) error { if err := w.encoder.Write(hdr); err != nil { return err } - } else if rec.Type != w.first { + } else if rec.Type != w.first && !fieldsEqual(rec.Fields(), w.first.Fields) { return ErrNotDataFrame } w.strings = w.strings[:0] @@ -96,3 +97,9 @@ func formatValue(typ zed.Type, bytes zcode.Bytes) string { } return zson.FormatValue(zed.NewValue(typ, bytes)) } + +func fieldsEqual(a, b []zed.Field) bool { + return slices.EqualFunc(a, b, func(a, b zed.Field) bool { + return a.Name == b.Name + }) +} diff --git a/zio/csvio/ztests/different-types.yaml b/zio/csvio/ztests/different-types.yaml new file mode 100644 index 0000000000..da59907576 --- /dev/null +++ b/zio/csvio/ztests/different-types.yaml @@ -0,0 +1,14 @@ +zed: '*' + +input: | + {a:0} + {a:"foo"} + {a:127.0.0.1} + +output-flags: -f csv + +output: | + a + 0 + foo + 127.0.0.1