Skip to content

Commit

Permalink
fix issue with field names ending space
Browse files Browse the repository at this point in the history
  • Loading branch information
scottlepp committed Feb 23, 2024
1 parent 3968853 commit e1ec15b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions duck/data/parquet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ func ToParquet(frames []*data.Frame, chunk int) (map[string]string, error) {
// need to return multiple frames instead
for _, f := range frames {
for _, fld := range f.Fields {
lbls := fld.Labels.String()
fld.Name = fmt.Sprintf("%s %s", fld.Name, lbls)
if len(fld.Labels) > 0 {
lbls := fld.Labels.String()
fld.Name = fmt.Sprintf("%s %s", fld.Name, lbls)
}
}
}

Expand Down
13 changes: 10 additions & 3 deletions duck/duckdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,34 @@ func TestLabels(t *testing.T) {
func TestLabelsMultiFrame(t *testing.T) {
db := NewInMemoryDB()

tt := "2024-02-23 09:01:54"
dd, err := dateparse.ParseAny(tt)
assert.Nil(t, err)

var timeValues = []time.Time{dd}

f := new(float64)
*f = 12345

var values = []*float64{f}
labels := map[string]string{
"server": "A",
}
frame := data.NewFrame("foo", data.NewField("value", labels, values))
frame := data.NewFrame("foo", data.NewField("timestamp", nil, timeValues), data.NewField("value", labels, values))
frame.RefID = "foo"

var values2 = []*float64{f}
labels2 := map[string]string{
"server": "B",
}
frame2 := data.NewFrame("foo", data.NewField("value", labels2, values2))
frame2 := data.NewFrame("foo", data.NewField("timestamp", nil, timeValues), data.NewField("value", labels2, values2))
frame2.RefID = "foo"

frames := []*data.Frame{frame, frame2}

// TODO - ordering is broken!
model := &data.Frame{}
_, err := db.QueryFramesInto("foo", "select * from foo", frames, model)
_, err = db.QueryFramesInto("foo", "select * from foo order by 'timestamp'", frames, model)
assert.Nil(t, err)

assert.Equal(t, 2, model.Rows())
Expand Down

0 comments on commit e1ec15b

Please sign in to comment.