Skip to content

Commit

Permalink
groupby debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jbguerraz committed Nov 24, 2020
1 parent 9c00981 commit 5c29e1b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
39 changes: 25 additions & 14 deletions builder/query/group_by.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type GroupBy struct {
PostAggregations []builder.PostAggregator `json:"postAggregations"`
Having builder.HavingSpec `json:"having"`
LimitSpec builder.LimitSpec `json:"limitSpec"`
SubtotalsSpec [][]string `json:"subtotalsSpec"`
SubtotalsSpec [][]string `json:"subtotalsSpec",omitempty`
}

func NewGroupBy() *GroupBy {
Expand Down Expand Up @@ -88,8 +88,8 @@ func (g *GroupBy) SetSubtotalsSpec(subtotalsSpec [][]string) *GroupBy {
}

func (g *GroupBy) UnmarshalJSON(data []byte) error {
var err error
var tmp struct {
Base
VirtualColumns []json.RawMessage `json:"virtualColumns"`
Filter json.RawMessage `json:"filter"`
Granularity json.RawMessage `json:"granularity"`
Expand All @@ -99,10 +99,9 @@ func (g *GroupBy) UnmarshalJSON(data []byte) error {
LimitSpec json.RawMessage `json:"limitSpec"`
SubtotalsSpec [][]string `json:"subtotalsSpec"`
}
if err := json.Unmarshal(data, &tmp); err != nil {
if err = json.Unmarshal(data, &tmp); err != nil {
return err
}
var err error
var v builder.VirtualColumn
vv := make([]builder.VirtualColumn, len(tmp.VirtualColumns))
for i := range tmp.VirtualColumns {
Expand All @@ -111,9 +110,12 @@ func (g *GroupBy) UnmarshalJSON(data []byte) error {
}
vv[i] = v
}
f, err := filter.Load(tmp.Filter)
if err != nil {
return err
var f builder.Filter
if tmp.Filter != nil {
f, err = filter.Load(tmp.Filter)
if err != nil {
return err
}
}
gr, err := granularity.Load(tmp.Granularity)
if err != nil {
Expand All @@ -135,15 +137,24 @@ func (g *GroupBy) UnmarshalJSON(data []byte) error {
}
pp[i] = p
}
h, err := havingspec.Load(tmp.Having)
if err != nil {
return err
var h builder.HavingSpec
if tmp.Having != nil {
h, err = havingspec.Load(tmp.Having)
if err != nil {
return err
}
}
l, err := limitspec.Load(tmp.LimitSpec)
if err != nil {
return err
var l builder.LimitSpec
if tmp.LimitSpec != nil {
l, err = limitspec.Load(tmp.LimitSpec)
if err != nil {
return err
}
}
if len(tmp.SubtotalsSpec) == 0 {
tmp.SubtotalsSpec = nil
}
g.Base = tmp.Base
g.Base.UnmarshalJSON(data)
g.VirtualColumns = vv
g.Filter = f
g.Granularity = gr
Expand Down
2 changes: 0 additions & 2 deletions builder/query/timeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"

"github.com/davecgh/go-spew/spew"
"github.com/grafadruid/go-druid/builder"
"github.com/grafadruid/go-druid/builder/aggregation"
"github.com/grafadruid/go-druid/builder/filter"
Expand Down Expand Up @@ -139,6 +138,5 @@ func (t *Timeseries) UnmarshalJSON(data []byte) error {
t.Aggregations = aa
t.PostAggregations = pp
t.Limit = tmp.Limit
spew.Dump(t)
return nil
}
7 changes: 6 additions & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ func main() {
d.Query().Execute(q, &results)
spew.Dump(results)

q, err = d.Query().Load([]byte("{\"aggregations\":[{\"fieldName\":\"sum_delta\",\"name\":\"delta\",\"type\":\"longSum\"}],\"context\":{\"plop\":\"plep\"},\"dataSource\":{\"name\":\"wikipedia\",\"type\":\"table\"},\"dimension\":{\"dimension\":\"regionName\",\"outputName\":\"region\",\"outputType\":\"STRING\",\"type\":\"default\"},\"filter\":{\"dimension\":\"countryName\",\"extractionFn\":null,\"type\":\"selector\",\"value\":\"France\"},\"granularity\":\"day\",\"intervals\":[\"2016-06-26T23:46:21.573Z/2016-06-27T16:03:59.999Z\"],\"metric\":{\"metric\":\"delta\",\"type\":\"numeric\"},\"postAggregations\":[],\"queryType\":\"topN\",\"threshold\":50,\"virtualColumns\":[]}"))
q, err = d.Query().Load([]byte("{\"aggregations\":[{\"fieldName\":\"sum_delta\",\"name\":\"delta\",\"type\":\"longSum\"}],\"context\":{\"plop\":\"plep\"},\"dataSource\":{\"name\":\"wikipedia\",\"type\":\"table\"},\"dimension\":{\"dimension\":\"regionName\",\"outputName\":\"region\",\"outputType\":\"STRING\",\"type\":\"default\"},\"filter\":{\"dimension\":\"countryName\",\"extractionFn\":null,\"type\":\"selector\",\"value\":\"France\"},\"granularity\":\"hour\",\"intervals\":[\"2016-06-26T23:46:21.573Z/2016-07-27T16:03:59.999Z\"],\"metric\":{\"metric\":\"delta\",\"type\":\"numeric\"},\"postAggregations\":[],\"queryType\":\"topN\",\"threshold\":50,\"virtualColumns\":[]}"))
spew.Dump(q, err)
d.Query().Execute(q, &results)
spew.Dump(results)

q, err = d.Query().Load([]byte("{\"aggregations\":[{\"fieldName\":\"sum_delta\",\"name\":\"delta\",\"type\":\"longSum\"}],\"context\":{\"plop\":\"plep\"},\"dataSource\":{\"name\":\"wikipedia\",\"type\":\"table\"},\"dimensions\":[{\"dimension\":\"countryName\",\"outputName\":\"country\",\"outputType\":\"STRING\",\"type\":\"default\"},{\"dimension\":\"regionName\",\"outputName\":\"region\",\"outputType\":\"STRING\",\"type\":\"default\"}],\"filter\":{\"dimension\":\"countryName\",\"extractionFn\":null,\"type\":\"selector\",\"value\":\"France\"},\"granularity\":\"minute\",\"intervals\":[\"2016-06-26T23:58:44.369Z/2016-06-27T21:02:53.165Z\"],\"postAggregations\":[],\"queryType\":\"groupBy\",\"subtotalsSpec\":[],\"virtualColumns\":[]}"))
spew.Dump(q, err)
d.Query().Execute(q, &results)
spew.Dump(results)
Expand Down

0 comments on commit 5c29e1b

Please sign in to comment.