This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
forked from fraugster/parquet-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filereader_test.go
110 lines (101 loc) · 2.19 KB
/
filereader_test.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package goparquet
import (
"bytes"
"io"
"math/rand"
"testing"
"github.com/fraugster/parquet-go/parquetschema"
"github.com/stretchr/testify/require"
)
func buildTestStream(t *testing.T) []byte {
schema, err := parquetschema.ParseSchemaDefinition(`message msg {
required int64 a;
required int64 b;
optional group x {
required int64 c;
required int64 d;
}
required group y {
required int64 e;
}
}
`)
require.NoError(t, err)
buf := &bytes.Buffer{}
pw := NewFileWriter(buf, WithSchemaDefinition(schema))
for i := 0; i < 10000; i++ {
data := map[string]interface{}{
"a": rand.Int63(),
"b": rand.Int63(),
"x": map[string]interface{}{
"c": rand.Int63(),
"d": rand.Int63(),
},
"y": map[string]interface{}{
"e": rand.Int63(),
},
}
require.NoError(t, pw.AddData(data))
if i%100 == 0 {
require.NoError(t, pw.FlushRowGroup())
}
}
require.NoError(t, pw.Close())
return buf.Bytes()
}
func TestByteReaderSelected(t *testing.T) {
r := buildTestStream(t)
pr, err := NewFileReader(bytes.NewReader(r), "a")
require.NoError(t, err)
for {
data, err := pr.NextRow()
if err == io.EOF {
break
}
require.NoError(t, err)
require.Equal(t, 2, len(data))
_, ok := data["a"]
require.True(t, ok)
y, ok := data["y"]
require.True(t, ok)
require.Empty(t, y)
}
}
func TestByteReaderSelectedInner(t *testing.T) {
r := buildTestStream(t)
pr, err := NewFileReader(bytes.NewReader(r), "x.c")
require.NoError(t, err)
for {
data, err := pr.NextRow()
if err == io.EOF {
break
}
require.NoError(t, err)
require.Equal(t, 2, len(data))
x, ok := data["x"].(map[string]interface{})
require.True(t, ok)
require.Equal(t, 1, len(x))
y, ok := data["y"]
require.True(t, ok)
require.Empty(t, y)
}
}
func TestByteReaderSelectedInnerFull(t *testing.T) {
r := buildTestStream(t)
pr, err := NewFileReader(bytes.NewReader(r), "x")
require.NoError(t, err)
for {
data, err := pr.NextRow()
if err == io.EOF {
break
}
require.NoError(t, err)
require.Equal(t, 2, len(data))
x, ok := data["x"].(map[string]interface{})
require.True(t, ok)
require.Equal(t, 2, len(x))
y, ok := data["y"]
require.True(t, ok)
require.Empty(t, y)
}
}