Skip to content
Closed
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
35 changes: 22 additions & 13 deletions go/arrow/ipc/cmd/arrow-cat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,24 @@ func processStream(w io.Writer, rin io.Reader) error {
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer mem.AssertSize(nil, 0)

r, err := ipc.NewReader(rin, ipc.WithAllocator(mem))
if err != nil {
return err
}
defer r.Release()

n := 0
for r.Next() {
n++
fmt.Fprintf(w, "record %d...\n", n)
rec := r.Record()
for i, col := range rec.Columns() {
fmt.Fprintf(w, " col[%d] %q: %v\n", i, rec.ColumnName(i), col)
for {
r, err := ipc.NewReader(rin, ipc.WithAllocator(mem))
if err != nil {
if errors.Cause(err) == io.EOF {
return nil
}
return err
}
defer r.Release()

n := 0
for r.Next() {
n++
fmt.Fprintf(w, "record %d...\n", n)
rec := r.Record()
for i, col := range rec.Columns() {
fmt.Fprintf(w, " col[%d] %q: %v\n", i, rec.ColumnName(i), col)
}
}
}
return nil
Expand Down Expand Up @@ -142,6 +147,9 @@ func processFile(w io.Writer, fname string) error {

r, err := ipc.NewFileReader(f, ipc.WithAllocator(mem))
if err != nil {
if errors.Cause(err) == io.EOF {
return nil
}
return err
}
defer r.Close()
Expand All @@ -159,6 +167,7 @@ func processFile(w io.Writer, fname string) error {
fmt.Fprintf(w, " col[%d] %q: %v\n", i, rec.ColumnName(i), col)
}
}

return nil
}

Expand Down
43 changes: 33 additions & 10 deletions go/arrow/ipc/cmd/arrow-ls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
package main // import "github.com/apache/arrow/go/arrow/ipc/cmd/arrow-ls"

import (
"bytes"
"flag"
"fmt"
"io"
Expand All @@ -63,6 +64,7 @@ import (
"github.com/apache/arrow/go/arrow"
"github.com/apache/arrow/go/arrow/ipc"
"github.com/apache/arrow/go/arrow/memory"
"github.com/pkg/errors"
)

func main() {
Expand All @@ -87,19 +89,24 @@ func processStream(w io.Writer, rin io.Reader) error {
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer mem.AssertSize(nil, 0)

r, err := ipc.NewReader(rin, ipc.WithAllocator(mem))
if err != nil {
return err
}
defer r.Release()
for {
r, err := ipc.NewReader(rin, ipc.WithAllocator(mem))
if err != nil {
if errors.Cause(err) == io.EOF {
return nil
}
return err
}
defer r.Release()

fmt.Fprintf(w, "schema:\n%v", displaySchema(r.Schema()))
fmt.Fprintf(w, "schema:\n%v", displaySchema(r.Schema()))

nrecs := 0
for r.Next() {
nrecs++
nrecs := 0
for r.Next() {
nrecs++
}
fmt.Fprintf(w, "records: %d\n", nrecs)
}
fmt.Fprintf(w, "records: %d\n", nrecs)
return nil
}

Expand All @@ -121,18 +128,34 @@ func processFile(w io.Writer, fname string) error {
}
defer f.Close()

hdr := make([]byte, len(ipc.Magic))
_, err = io.ReadFull(f, hdr)
if err != nil {
return errors.Errorf("could not read file header: %v", err)
}
f.Seek(0, io.SeekStart)

if !bytes.Equal(hdr, ipc.Magic) {
// try as a stream.
return processStream(w, f)
}

mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer mem.AssertSize(nil, 0)

r, err := ipc.NewFileReader(f, ipc.WithAllocator(mem))
if err != nil {
if errors.Cause(err) == io.EOF {
return nil
}
return err
}
defer r.Close()

fmt.Fprintf(w, "version: %v\n", r.Version())
fmt.Fprintf(w, "schema:\n%v", displaySchema(r.Schema()))
fmt.Fprintf(w, "records: %d\n", r.NumRecords())

return nil
}

Expand Down