Skip to content

Commit 57e1275

Browse files
authored
Merge pull request #3849 from parca-dev/transfer-empty-correctly
pkg/query: Transfer empty values from empty dictionaries correctly
2 parents 7b7a5d9 + 320d9b7 commit 57e1275

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

pkg/query/columnquery.go

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,25 @@ func filterRecord(
354354
w.MappingStart.Append(r.MappingStart.Value(j))
355355
w.MappingLimit.Append(r.MappingLimit.Value(j))
356356
w.MappingOffset.Append(r.MappingOffset.Value(j))
357-
if r.MappingFileDict.Len() == 0 {
358-
w.MappingFile.AppendNull()
357+
358+
mappingFile := r.MappingFileDict.Value(int(r.MappingFileIndices.Value(j)))
359+
if len(mappingFile) > 0 {
360+
if err := w.MappingFile.Append(mappingFile); err != nil {
361+
return nil, 0, 0, fmt.Errorf("append mapping file: %w", err)
362+
}
359363
} else {
360-
if err := w.MappingFile.Append(r.MappingFileDict.Value(int(r.MappingFileIndices.Value(j)))); err != nil {
364+
if err := w.MappingFile.Append([]byte{}); err != nil {
361365
return nil, 0, 0, fmt.Errorf("append mapping file: %w", err)
362366
}
363367
}
364-
if r.MappingBuildIDDict.Len() == 0 {
365-
w.MappingBuildID.AppendNull()
368+
369+
mappingBuildID := r.MappingBuildIDDict.Value(int(r.MappingBuildIDIndices.Value(j)))
370+
if len(mappingBuildID) > 0 {
371+
if err := w.MappingBuildID.Append(mappingBuildID); err != nil {
372+
return nil, 0, 0, fmt.Errorf("append mapping build id: %w", err)
373+
}
366374
} else {
367-
if err := w.MappingBuildID.Append(r.MappingBuildIDDict.Value(int(r.MappingBuildIDIndices.Value(j)))); err != nil {
375+
if err := w.MappingBuildID.Append([]byte{}); err != nil {
368376
return nil, 0, 0, fmt.Errorf("append mapping build id: %w", err)
369377
}
370378
}
@@ -384,35 +392,40 @@ func filterRecord(
384392
w.Line.Append(true)
385393
w.LineNumber.Append(r.LineNumber.Value(k))
386394

387-
if r.LineFunctionNameIndices.IsValid(k) {
388-
if r.LineFunctionNameDict.Len() == 0 {
389-
w.FunctionName.AppendNull()
390-
} else {
391-
if err := w.FunctionName.Append(r.LineFunctionNameDict.Value(int(r.LineFunctionNameIndices.Value(k)))); err != nil {
392-
return nil, 0, 0, fmt.Errorf("append function name: %w", err)
393-
}
395+
functionName := r.LineFunctionNameDict.Value(int(r.LineFunctionNameIndices.Value(k)))
396+
if len(functionName) > 0 {
397+
if err := w.FunctionName.Append(functionName); err != nil {
398+
return nil, 0, 0, fmt.Errorf("append function name: %w", err)
399+
}
400+
} else {
401+
if err := w.FunctionName.Append(functionName); err != nil {
402+
return nil, 0, 0, fmt.Errorf("append function name: %w", err)
403+
}
404+
}
405+
406+
functionSystemName := r.LineFunctionSystemNameDict.Value(int(r.LineFunctionSystemNameIndices.Value(k)))
407+
if len(functionSystemName) > 0 {
408+
if err := w.FunctionSystemName.Append(functionSystemName); err != nil {
409+
return nil, 0, 0, fmt.Errorf("append function system name: %w", err)
394410
}
395-
if r.LineFunctionSystemNameDict.Len() == 0 {
396-
w.FunctionSystemName.AppendNull()
397-
} else {
398-
if err := w.FunctionSystemName.Append(r.LineFunctionSystemNameDict.Value(int(r.LineFunctionSystemNameIndices.Value(k)))); err != nil {
399-
return nil, 0, 0, fmt.Errorf("append function system name: %w", err)
400-
}
411+
} else {
412+
if err := w.FunctionSystemName.Append([]byte{}); err != nil {
413+
return nil, 0, 0, fmt.Errorf("append function system name: %w", err)
401414
}
402-
if r.LineFunctionFilenameDict.Len() == 0 {
403-
w.FunctionFilename.AppendNull()
404-
} else {
405-
if err := w.FunctionFilename.Append(r.LineFunctionFilenameDict.Value(int(r.LineFunctionFilenameIndices.Value(k)))); err != nil {
406-
return nil, 0, 0, fmt.Errorf("append function filename: %w", err)
407-
}
415+
}
416+
417+
functionFilename := r.LineFunctionFilenameDict.Value(int(r.LineFunctionFilenameIndices.Value(k)))
418+
if len(functionFilename) > 0 {
419+
if err := w.FunctionFilename.Append(functionFilename); err != nil {
420+
return nil, 0, 0, fmt.Errorf("append function filename: %w", err)
408421
}
409-
w.FunctionStartLine.Append(r.LineFunctionStartLine.Value(k))
410422
} else {
411-
w.FunctionName.AppendNull()
412-
w.FunctionSystemName.AppendNull()
413-
w.FunctionFilename.AppendNull()
414-
w.FunctionStartLine.AppendNull()
423+
if err := w.FunctionFilename.Append([]byte{}); err != nil {
424+
return nil, 0, 0, fmt.Errorf("append function filename: %w", err)
425+
}
415426
}
427+
428+
w.FunctionStartLine.Append(r.LineFunctionStartLine.Value(k))
416429
}
417430
continue
418431
}

0 commit comments

Comments
 (0)