-
Notifications
You must be signed in to change notification settings - Fork 693
Expand file tree
/
Copy pathcmd-convert-block.go
More file actions
62 lines (53 loc) · 1.13 KB
/
cmd-convert-block.go
File metadata and controls
62 lines (53 loc) · 1.13 KB
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
package main
import (
"fmt"
"os"
"github.com/grafana/tempo/tempodb/encoding/vparquet"
"github.com/parquet-go/parquet-go"
)
type convertParquet struct {
In string `arg:"" help:"The input parquet file to read from"`
Out string `arg:"" help:"The output parquet file to write to"`
}
func (cmd *convertParquet) Run() error {
// open In
fIn, err := os.Open(cmd.In)
if err != nil {
return err
}
s, err := fIn.Stat()
if err != nil {
return err
}
pf, err := parquet.OpenFile(fIn, s.Size())
if err != nil {
return err
}
// open Out
fOut, err := os.Create(cmd.Out)
if err != nil {
return err
}
sch := parquet.SchemaOf(new(vparquet.Trace))
writer := parquet.NewWriter(fOut, sch)
conversion, err := parquet.Convert(sch, pf.Schema())
if err != nil {
return err
}
// copy a rowgroup at a time
rgs := pf.RowGroups()
fmt.Println("Total Rowgroups: ", len(rgs))
for i, rg := range rgs {
fmt.Println("Converting ", i+1)
rg = parquet.ConvertRowGroup(rg, conversion)
_, err = writer.WriteRowGroup(rg)
if err != nil {
return err
}
err = writer.Flush()
if err != nil {
return err
}
}
return writer.Close()
}