Skip to content

Commit dbc8af1

Browse files
authored
profiles parquet encoding: fix profile column count (#3420)
1 parent 3509421 commit dbc8af1

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

pkg/phlaredb/schemas/v1/profiles.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,9 @@ func deconstructMemoryProfile(imp InMemoryProfile, row parquet.Row) parquet.Row
503503
col++
504504
return col
505505
}
506-
totalCols = 8 + (7 * len(imp.Samples.StacktraceIDs)) + len(imp.Comments)
506+
totalCols = profileColumnCount(imp)
507507
)
508+
508509
if cap(row) < totalCols {
509510
row = make(parquet.Row, 0, totalCols)
510511
}
@@ -614,6 +615,17 @@ func deconstructMemoryProfile(imp InMemoryProfile, row parquet.Row) parquet.Row
614615
return row
615616
}
616617

618+
func profileColumnCount(imp InMemoryProfile) int {
619+
var totalCols = 10 + (7 * len(imp.Samples.StacktraceIDs)) + len(imp.Comments)
620+
if len(imp.Comments) == 0 {
621+
totalCols++
622+
}
623+
if len(imp.Samples.StacktraceIDs) == 0 {
624+
totalCols += 7
625+
}
626+
return totalCols
627+
}
628+
617629
func NewMergeProfilesRowReader(rowGroups []parquet.RowReader) parquet.RowReader {
618630
if len(rowGroups) == 0 {
619631
return phlareparquet.EmptyRowReader

pkg/phlaredb/schemas/v1/profiles_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,41 @@ func Test_SamplesRange(t *testing.T) {
542542
})
543543
}
544544
}
545+
546+
func TestColumnCount(t *testing.T) {
547+
profiles := []InMemoryProfile{{
548+
SeriesIndex: 1,
549+
TimeNanos: 2,
550+
Samples: Samples{
551+
StacktraceIDs: []uint32{1, 2, 3},
552+
Values: []uint64{1, 2, 3},
553+
},
554+
},
555+
{
556+
SeriesIndex: 1,
557+
TimeNanos: 2,
558+
Samples: Samples{
559+
StacktraceIDs: []uint32{1, 2, 3},
560+
Values: []uint64{1, 2, 3},
561+
Spans: []uint64{1, 2, 3},
562+
},
563+
},
564+
{
565+
SeriesIndex: 1,
566+
TimeNanos: 2,
567+
Samples: Samples{
568+
StacktraceIDs: []uint32{1, 2, 3},
569+
Values: []uint64{1, 2, 3},
570+
Spans: []uint64{1, 2, 3},
571+
},
572+
Comments: []int64{1, 2, 3},
573+
}}
574+
for _, profile := range profiles {
575+
count := profileColumnCount(profile)
576+
577+
row := deconstructMemoryProfile(profile, nil)
578+
assert.Equal(t, len(row), count)
579+
assert.Equal(t, cap(row), count)
580+
}
581+
582+
}

0 commit comments

Comments
 (0)