-
Notifications
You must be signed in to change notification settings - Fork 1
/
parquet_test.go
112 lines (103 loc) · 2.64 KB
/
parquet_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
111
112
package arrow3
import (
"bytes"
"context"
"os"
"testing"
"github.com/apache/arrow/go/v17/arrow/memory"
commonv1 "go.opentelemetry.io/proto/otlp/common/v1"
metricsv1 "go.opentelemetry.io/proto/otlp/metrics/v1"
"google.golang.org/protobuf/encoding/protojson"
)
func TestRead(t *testing.T) {
msg := &metricsv1.MetricsData{}
b := build(msg.ProtoReflect())
b.build(memory.DefaultAllocator)
b.append(msg.ProtoReflect())
msg.ResourceMetrics = []*metricsv1.ResourceMetrics{
{ScopeMetrics: []*metricsv1.ScopeMetrics{
{Metrics: []*metricsv1.Metric{
{Name: "check", Data: &metricsv1.Metric_Gauge{
Gauge: &metricsv1.Gauge{
DataPoints: []*metricsv1.NumberDataPoint{
{TimeUnixNano: 16, Value: &metricsv1.NumberDataPoint_AsInt{
AsInt: 18,
},
Attributes: []*commonv1.KeyValue{
{Key: "key", Value: &commonv1.AnyValue{
Value: &commonv1.AnyValue_StringValue{
StringValue: "value",
},
}},
},
},
},
},
}},
}},
}},
}
b.append(msg.ProtoReflect())
var o bytes.Buffer
err := b.WriteParquet(&o)
if err != nil {
t.Fatal(err)
}
matchBytes(t, "testdata/otel_metrics_data.parquet", o.Bytes())
f, err := os.Open("testdata/otel_metrics_data.parquet")
if err != nil {
t.Fatal(err)
}
defer f.Close()
r, err := b.Read(context.Background(), f, nil)
if err != nil {
t.Fatal(err)
}
data, err := r.MarshalJSON()
if err != nil {
t.Fatal(err)
}
match(t, "testdata/otel_metrics_data_parquet_read.json", string(data))
rd := unmarshal[*metricsv1.MetricsData](b.root, r, []int{1})
data, err = protojson.Marshal(rd[0])
if err != nil {
t.Fatal(err)
}
match(t, "testdata/otel_metrics_data_parquet_read_decoded.json", string(data))
}
func TestWriteMultiple(t *testing.T) {
msg := &metricsv1.MetricsData{}
b := build(msg.ProtoReflect())
b.build(memory.DefaultAllocator)
b.append(msg.ProtoReflect())
msg.ResourceMetrics = []*metricsv1.ResourceMetrics{
{ScopeMetrics: []*metricsv1.ScopeMetrics{
{Metrics: []*metricsv1.Metric{
{Name: "check", Data: &metricsv1.Metric_Gauge{
Gauge: &metricsv1.Gauge{
DataPoints: []*metricsv1.NumberDataPoint{
{TimeUnixNano: 16, Value: &metricsv1.NumberDataPoint_AsInt{
AsInt: 18,
},
Attributes: []*commonv1.KeyValue{
{Key: "key", Value: &commonv1.AnyValue{
Value: &commonv1.AnyValue_StringValue{
StringValue: "value",
},
}},
},
},
},
},
}},
}},
}},
}
b.append(msg.ProtoReflect())
var o bytes.Buffer
r := b.NewRecord()
err := b.WriteParquetRecords(&o, r, r)
if err != nil {
t.Fatal(err)
}
}