Skip to content

Commit

Permalink
add meta for wide time series (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottlepp authored Sep 19, 2024
1 parent 69ee396 commit 7c8f8ea
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions duck/duckdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ func resultsToFrame(name string, res string, f *sdk.Frame, frames []*sdk.Frame)
}
f.Fields = frame.Fields
f.Meta = frame.Meta
return nil
}

if kind == sdk.TimeSeriesTypeWide {
if f.Meta == nil {
f.Meta = &sdk.FrameMeta{}
}
f.Meta.Type = sdk.FrameTypeTimeSeriesWide
}

// TODO - appending to field names for now
Expand Down
30 changes: 30 additions & 0 deletions duck/duckdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,36 @@ func TestTimeSeries(t *testing.T) {
assert.Contains(t, txt, "Type: []time.Time")
}

func TestTimeSeriesWide(t *testing.T) {
db := NewInMemoryDB()

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

var values = []time.Time{dd}
timeField := data.NewField("time", nil, values)
valueField := data.NewField("value", nil, []*float64{new(float64)})

frame := data.NewFrame("foo", timeField, valueField)
frame.RefID = "foo"

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

model := &data.Frame{}
err = db.QueryFramesInto("foo", "select * from foo", frames, model)
assert.Nil(t, err)

assert.Equal(t, data.FrameTypeTimeSeriesWide, model.Meta.Type)

assert.Equal(t, 1, model.Rows())
txt, err := model.StringTable(-1, -1)
assert.Nil(t, err)

fmt.Printf("GOT: %s", txt)
assert.Contains(t, txt, "Type: []*time.Time")
}

func TestLabels(t *testing.T) {
db := NewInMemoryDB()

Expand Down

0 comments on commit 7c8f8ea

Please sign in to comment.