Skip to content

Commit b41edc6

Browse files
authored
Define dynamic column as map[string]T (#632)
No special tag is need any field of type map[string]T where T is `int64|bool|float64|string` is a dynamic column. Example ``go type Sample struct { Labels map[string]string `frostdb:"labels,rle_dict,asc(1),null_first"` } ```
1 parent 37e11d0 commit b41edc6

10 files changed

+299
-348
lines changed

aggregate_test.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func TestAggregateInconsistentSchema(t *testing.T) {
3838
require.NoError(t, err)
3939

4040
samples := dynparquet.Samples{{
41-
Labels: []dynparquet.Label{
42-
{Name: "label1", Value: "value1"},
41+
Labels: map[string]string{
42+
"label1": "value1",
4343
},
4444
Stacktrace: []uuid.UUID{
4545
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
@@ -48,8 +48,8 @@ func TestAggregateInconsistentSchema(t *testing.T) {
4848
Timestamp: 1,
4949
Value: 1,
5050
}, {
51-
Labels: []dynparquet.Label{
52-
{Name: "label2", Value: "value2"},
51+
Labels: map[string]string{
52+
"label2": "value2",
5353
},
5454
Stacktrace: []uuid.UUID{
5555
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
@@ -58,8 +58,8 @@ func TestAggregateInconsistentSchema(t *testing.T) {
5858
Timestamp: 2,
5959
Value: 2,
6060
}, {
61-
Labels: []dynparquet.Label{
62-
{Name: "label2", Value: "value2"},
61+
Labels: map[string]string{
62+
"label2": "value2",
6363
},
6464
Stacktrace: []uuid.UUID{
6565
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
@@ -161,9 +161,9 @@ func TestAggregationProjection(t *testing.T) {
161161
require.NoError(t, err)
162162

163163
samples := dynparquet.Samples{{
164-
Labels: []dynparquet.Label{
165-
{Name: "label1", Value: "value1"},
166-
{Name: "label2", Value: "value2"},
164+
Labels: map[string]string{
165+
"label1": "value1",
166+
"label2": "value2",
167167
},
168168
Stacktrace: []uuid.UUID{
169169
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
@@ -172,10 +172,10 @@ func TestAggregationProjection(t *testing.T) {
172172
Timestamp: 1,
173173
Value: 1,
174174
}, {
175-
Labels: []dynparquet.Label{
176-
{Name: "label1", Value: "value2"},
177-
{Name: "label2", Value: "value2"},
178-
{Name: "label3", Value: "value3"},
175+
Labels: map[string]string{
176+
"label1": "value2",
177+
"label2": "value2",
178+
"label3": "value3",
179179
},
180180
Stacktrace: []uuid.UUID{
181181
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
@@ -184,10 +184,10 @@ func TestAggregationProjection(t *testing.T) {
184184
Timestamp: 2,
185185
Value: 2,
186186
}, {
187-
Labels: []dynparquet.Label{
188-
{Name: "label1", Value: "value3"},
189-
{Name: "label2", Value: "value2"},
190-
{Name: "label4", Value: "value4"},
187+
Labels: map[string]string{
188+
"label1": "value3",
189+
"label2": "value2",
190+
"label4": "value4",
191191
},
192192
Stacktrace: []uuid.UUID{
193193
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
@@ -354,9 +354,9 @@ func BenchmarkAggregation(b *testing.B) {
354354
samples := make(dynparquet.Samples, 0, 10_000)
355355
for i := 0; i < cap(samples); i++ {
356356
samples = append(samples, dynparquet.Sample{
357-
Labels: []dynparquet.Label{
358-
{Name: "label1", Value: "value1"},
359-
{Name: "label2", Value: "value" + strconv.Itoa(i%3)},
357+
Labels: map[string]string{
358+
"label1": "value1",
359+
"label2": "value" + strconv.Itoa(i%3),
360360
},
361361
Stacktrace: []uuid.UUID{
362362
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},

bench_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,9 @@ func NewTestSamples(num int) dynparquet.Samples {
421421
samples = append(samples,
422422
dynparquet.Sample{
423423
ExampleType: "cpu",
424-
Labels: []dynparquet.Label{{
425-
Name: "node",
426-
Value: "test3",
427-
}},
424+
Labels: map[string]string{
425+
"node": "test3",
426+
},
428427
Stacktrace: []uuid.UUID{
429428
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
430429
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2},

0 commit comments

Comments
 (0)