From 10c7e916cbc9414c0a3ee8b740f2ed52f1bc303a Mon Sep 17 00:00:00 2001 From: "docmerlin (j. Emrys Landivar)" Date: Thu, 20 Aug 2020 06:53:19 -0500 Subject: [PATCH] fix: missing outputs when the first batched row has null clumns --- edge/messages.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/edge/messages.go b/edge/messages.go index 71e6beacb..cf35ec5b3 100644 --- a/edge/messages.go +++ b/edge/messages.go @@ -681,16 +681,33 @@ func (bb *bufferedBatchMessage) ToRow() (row *models.Row) { return } row.Columns = []string{"time"} - p := bb.points[0] - for f := range p.Fields() { + + tagNames := make(map[string]struct{}) + fieldNames := make(map[string]struct{}) + // we have to walk all the points to get the columns. + for _, p := range bb.points { + for f := range p.Fields() { + fieldNames[f] = struct{}{} + } + + // Append tags that are not on the batch + for t := range p.Tags() { + if _, ok := bb.begin.Tags()[t]; !ok { + tagNames[t] = struct{}{} + } + } + } + for f := range fieldNames { row.Columns = append(row.Columns, f) } + // Append tags that are not on the batch - for t := range p.Tags() { + for t := range tagNames { if _, ok := bb.begin.Tags()[t]; !ok { row.Columns = append(row.Columns, t) } } + // Sort all columns but leave time as first sort.Strings(row.Columns[1:]) row.Values = make([][]interface{}, len(bb.points))