Skip to content

Commit

Permalink
set frame type (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottlepp authored Sep 19, 2024
1 parent 5059f0c commit 69ee396
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions duck/duckdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ func resultsToFrame(name string, res string, f *sdk.Frame, frames []*sdk.Frame)
f.Meta = resultsFrame.Meta
f.RefID = resultsFrame.RefID

kind := f.TimeSeriesSchema().Type
if kind == sdk.TimeSeriesTypeLong {
fillMode := &sdk.FillMissing{Mode: sdk.FillModeNull}
frame, err := sdk.LongToWide(f, fillMode)
if err != nil {
logger.Warn("could not convert frame long to wide", "error", err)
return nil
}
f.Fields = frame.Fields
f.Meta = frame.Meta
}

// TODO - appending to field names for now
// applyLabels(*resultsFrame, frames)

Expand Down
32 changes: 32 additions & 0 deletions duck/duckdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,38 @@ func TestTimestamps(t *testing.T) {
assert.Contains(t, txt, "Type: []*time.Time")
}

func TestTimeSeries(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)

groupField := data.NewField("group", nil, []string{"A"})
valueField := data.NewField("value", nil, []*float64{new(float64)})

frame := data.NewFrame("foo", timeField, groupField, 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 69ee396

Please sign in to comment.