Skip to content

Commit

Permalink
pkg/query: Remove GroupByMetadata column
Browse files Browse the repository at this point in the history
The UI doesn't need this data anymore.
  • Loading branch information
metalmatze committed Feb 13, 2025
1 parent 86e66e1 commit 0d5535f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 129 deletions.
57 changes: 0 additions & 57 deletions pkg/query/flamegraph_arrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ const (

FlamegraphFieldTimestamp = "timestamp"
FlamegraphFieldDuration = "duration"

FlamegraphFieldGroupByMetadata = "groupby_metadata"
)

func GenerateFlamegraphArrow(
Expand Down Expand Up @@ -868,7 +866,6 @@ type flamegraphBuilder struct {
builderLabelsExist *builder.OptBooleanBuilder
builderLabels []*builder.OptInt32Builder
builderLabelsDictUnifiers []array.DictionaryUnifier
builderGroupByMetadata *array.StructBuilder
builderChildren *builder.ListBuilder
builderChildrenValues *array.Uint32Builder
builderCumulative *builder.OptInt64Builder
Expand Down Expand Up @@ -926,10 +923,6 @@ func newFlamegraphBuilder(
groupBy []string,
) (*flamegraphBuilder, error) {
builderChildren := builder.NewListBuilder(pool, arrow.PrimitiveTypes.Uint32)
groupByMetadataStructFields := make([]arrow.Field, 0, len(groupBy))
for _, f := range groupBy {
groupByMetadataStructFields = append(groupByMetadataStructFields, arrow.Field{Name: f, Type: arrow.BinaryTypes.Binary})
}

fb := &flamegraphBuilder{
pool: pool,
Expand Down Expand Up @@ -969,9 +962,6 @@ func newFlamegraphBuilder(
builderCumulative: builder.NewOptInt64Builder(arrow.PrimitiveTypes.Int64),
builderFlat: builder.NewOptInt64Builder(arrow.PrimitiveTypes.Int64),
builderDiff: builder.NewOptInt64Builder(arrow.PrimitiveTypes.Int64),

groupByMetadataFields: groupByMetadataStructFields,
builderGroupByMetadata: array.NewStructBuilder(pool, arrow.StructOf(groupByMetadataStructFields...)),
}

fb.aggregationConfig = aggregationConfig{aggregateByLabels: map[string]struct{}{}}
Expand Down Expand Up @@ -1023,8 +1013,6 @@ func newFlamegraphBuilder(
fb.builderTimestamp.Append(0)
fb.builderDuration.Append(0)

fb.builderGroupByMetadata.AppendNull()

return fb, nil
}

Expand Down Expand Up @@ -1157,8 +1145,6 @@ func (fb *flamegraphBuilder) NewRecord() (arrow.Record, error) {
// Timestamp
{Name: FlamegraphFieldTimestamp, Type: arrow.PrimitiveTypes.Int64},
{Name: FlamegraphFieldDuration, Type: arrow.PrimitiveTypes.Int64},
// Metadata
{Name: FlamegraphFieldGroupByMetadata, Type: fb.builderGroupByMetadata.Type().(*arrow.StructType)},
}

numCols := len(fields)
Expand Down Expand Up @@ -1216,8 +1202,6 @@ func (fb *flamegraphBuilder) NewRecord() (arrow.Record, error) {
cleanupArrs = append(cleanupArrs, arrays[14])
arrays[15] = fb.trimmedDuration.NewArray()
cleanupArrs = append(cleanupArrs, arrays[15])
arrays[16] = fb.builderGroupByMetadata.NewArray()
cleanupArrs = append(cleanupArrs, arrays[16])

for i, field := range fb.builderLabelFields {
field.Type = fb.labels[i].DataType() // overwrite for variable length uint types
Expand Down Expand Up @@ -1261,8 +1245,6 @@ func (fb *flamegraphBuilder) Release() {
fb.builderFlat.Release()
fb.builderDiff.Release()

fb.builderGroupByMetadata.Release()

if fb.trimmedLocationLine != nil {
fb.trimmedLocationLine.Release()
}
Expand Down Expand Up @@ -1432,29 +1414,9 @@ func (fb *flamegraphBuilder) appendRow(
fb.builderDiff.AppendNull()
}

appendGroupByMetadata(fb, r, sampleRow)

return nil
}

func appendGroupByMetadata(fb *flamegraphBuilder, r *profile.RecordReader, sampleRow int) {
fb.builderGroupByMetadata.Append(true)
for i := 0; i < fb.builderGroupByMetadata.NumField(); i++ {
n := fb.groupByMetadataFields[i].Name
b := fb.builderGroupByMetadata.FieldBuilder(i).(*array.BinaryBuilder)
switch n {
case FlamegraphFieldTimestamp:
ts := r.Timestamp.Value(sampleRow)
b.Append([]byte(fmt.Sprint(ts)))
case FlamegraphFieldDuration:
duration := r.Duration.Value(sampleRow)
b.Append([]byte(fmt.Sprint(duration)))
default:
b.AppendNull()
}
}
}

func (fb *flamegraphBuilder) AppendLabelRow(
r *profile.RecordReader,
t *transpositions,
Expand Down Expand Up @@ -1608,7 +1570,6 @@ func (fb *flamegraphBuilder) trim(ctx context.Context, tracer trace.Tracer, thre
trimmedFlat := array.NewBuilder(fb.pool, trimmedFlatType)
trimmedDiffType := smallestSignedTypeFor(smallestDiffValue, largestDiffValue)
trimmedDiff := array.NewBuilder(fb.pool, trimmedDiffType)
trimmedGroupByMetadata := array.NewStructBuilder(fb.pool, fb.builderGroupByMetadata.Type().(*arrow.StructType))

trimmedTimestamps := builder.NewOptInt64Builder(arrow.PrimitiveTypes.Int64)
// TODO: We should use the smallest type for the duration.
Expand Down Expand Up @@ -1645,7 +1606,6 @@ func (fb *flamegraphBuilder) trim(ctx context.Context, tracer trace.Tracer, thre
trimmedCumulative.Reserve(row)
trimmedFlat.Reserve(row)
trimmedDiff.Reserve(row)
trimmedGroupByMetadata.Reserve(row)
trimmedTimestamps.Reserve(row)
trimmedDurations.Reserve(row)

Expand All @@ -1672,7 +1632,6 @@ func (fb *flamegraphBuilder) trim(ctx context.Context, tracer trace.Tracer, thre
appendDictionaryIndexInt32(fb.functionNameIndices, trimmedFunctionNameIndices, te.row)
appendDictionaryIndexInt32(fb.functionSystemNameIndices, trimmedFunctionSystemNameIndices, te.row)
appendDictionaryIndexInt32(fb.functionFilenameIndices, trimmedFunctionFilenameIndices, te.row)
copyStructBuilderValue(fb.builderGroupByMetadata, trimmedGroupByMetadata, te.row)
copyOptInt64BuilderValue(fb.builderTimestamp, trimmedTimestamps, te.row)
copyOptInt64BuilderValue(fb.builderDuration, trimmedDurations, te.row)
for i := range fb.labels {
Expand Down Expand Up @@ -1845,7 +1804,6 @@ func (fb *flamegraphBuilder) trim(ctx context.Context, tracer trace.Tracer, thre
fb.builderDiff,
fb.builderLocationLine,
fb.builderFunctionStartLine,
fb.builderGroupByMetadata,
)
fb.builderLabelsOnly = trimmedLabelsOnly
fb.builderLabelsExist = trimmedLabelsExist
Expand All @@ -1856,7 +1814,6 @@ func (fb *flamegraphBuilder) trim(ctx context.Context, tracer trace.Tracer, thre
fb.trimmedCumulative = trimmedCumulative
fb.trimmedFlat = trimmedFlat
fb.trimmedDiff = trimmedDiff
fb.builderGroupByMetadata = trimmedGroupByMetadata
fb.trimmedChildren = trimmedChildren
fb.trimmedTimestamp = trimmedTimestamps
fb.trimmedDuration = trimmedDurations
Expand Down Expand Up @@ -1947,20 +1904,6 @@ func appendDictionaryIndexInt32(dict *array.Int32, index *array.Int32Builder, ro
index.Append(dict.Value(row))
}

func copyStructBuilderValue(old, new *array.StructBuilder, row int) {
if old.IsNull(row) {
new.AppendNull()
return
}

new.Append(true)
for i := 0; i < old.NumField(); i++ {
old := old.FieldBuilder(i).(*array.BinaryBuilder)
new := new.FieldBuilder(i).(*array.BinaryBuilder)
new.Append(old.Value(row))
}
}

func isLocationRoot(beg, end, i int64, list *array.List) bool {
for j := end - 1; j >= beg; j-- {
if !list.ListValues().IsNull(int(j)) {
Expand Down
Loading

0 comments on commit 0d5535f

Please sign in to comment.