-
Notifications
You must be signed in to change notification settings - Fork 67
/
command.go
76 lines (68 loc) · 1.74 KB
/
command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package copy
import (
"errors"
"flag"
"github.com/brimdata/zed"
"github.com/brimdata/zed/cli/outputflags"
"github.com/brimdata/zed/cmd/zed/dev/vector"
"github.com/brimdata/zed/cmd/zed/root"
"github.com/brimdata/zed/pkg/charm"
"github.com/brimdata/zed/pkg/storage"
"github.com/brimdata/zed/runtime/vam"
"github.com/brimdata/zed/runtime/vcache"
"github.com/brimdata/zed/zbuf"
)
var Copy = &charm.Spec{
Name: "copy",
Usage: "copy [flags] path",
Short: "read a VNG file and copy to the output through the vector cache",
Long: `
The copy command reads VNG vectors from
a VNG storage objects (local files or s3 objects) and outputs
the reconstructed ZNG row data by exercising the vector cache.
This command is most useful for testing the VNG vector cache.
`,
New: newCommand,
}
func init() {
vector.Cmd.Add(Copy)
}
type Command struct {
*root.Command
outputFlags outputflags.Flags
}
func newCommand(parent charm.Command, f *flag.FlagSet) (charm.Command, error) {
c := &Command{Command: parent.(*root.Command)}
c.outputFlags.SetFlags(f)
return c, nil
}
func (c *Command) Run(args []string) error {
ctx, cleanup, err := c.Init(&c.outputFlags)
if err != nil {
return err
}
defer cleanup()
if len(args) != 1 {
return errors.New("VNG read: must be run with a single path argument")
}
uri, err := storage.ParseURI(args[0])
if err != nil {
return err
}
local := storage.NewLocalEngine()
object, err := vcache.NewObject(ctx, local, uri)
if err != nil {
return err
}
defer object.Close()
writer, err := c.outputFlags.Open(ctx, local)
if err != nil {
return err
}
puller := vam.NewProjection(zed.NewContext(), object, nil)
if err := zbuf.CopyPuller(writer, puller); err != nil {
writer.Close()
return err
}
return writer.Close()
}