Skip to content

Commit

Permalink
datasource > query circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jbguerraz committed Oct 21, 2020
1 parent d0ed1a8 commit 4995687
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 60 deletions.
5 changes: 5 additions & 0 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ func main() {
fmt.Println("{\"version\": \"" + status.Version + "\"}")
q, err := d.Query().Load([]byte("{\"queryType\":\"scan\",\"dataSource\":{\"type\":\"table\",\"name\":\"wikipedia\"},\"intervals\":[\"1980-06-12T22:30:00.000Z/2020-01-26T23:00:00.000Z\"],\"virtualColumns\":[{\"type\":\"expression\",\"name\":\"v0\",\"expression\":\"'France'\",\"outputType\":\"STRING\"}],\"resultFormat\":\"compactedList\",\"batchSize\":20480,\"limit\":1,\"order\":\"none\",\"filter\":{\"type\":\"selector\",\"dimension\":\"countryName\",\"value\":\"France\",\"extractionFn\":null},\"columns\":[\"__time\",\"channel\",\"cityName\",\"comment\",\"count\",\"countryIsoCode\",\"diffUrl\",\"flags\",\"isAnonymous\",\"isMinor\",\"isNew\",\"isRobot\",\"isUnpatrolled\",\"metroCode\",\"namespace\",\"page\",\"regionIsoCode\",\"regionName\",\"sum_added\",\"sum_commentLength\",\"sum_deleted\",\"sum_delta\",\"sum_deltaBucket\",\"user\",\"v0\"],\"legacy\":false,\"context\":{\"sqlOuterLimit\":100,\"sqlQueryId\":\"b12ac7bb-7cc5-4873-b19d-1cd95264e01b\"},\"descending\":false,\"granularity\":{\"type\":\"all\"}}"))
spew.Dump(q)
q, err = d.Query().Load([]byte("{\"batchSize\":20480,\"columns\":[\"__time\",\"channel\",\"cityName\",\"comment\",\"count\",\"countryIsoCode\",\"diffUrl\",\"flags\",\"isAnonymous\",\"isMinor\",\"isNew\",\"isRobot\",\"isUnpatrolled\",\"metroCode\",\"namespace\",\"page\",\"regionIsoCode\",\"regionName\",\"sum_added\",\"sum_commentLength\",\"sum_deleted\",\"sum_delta\",\"sum_deltaBucket\",\"user\"],\"dataSource\":{\"name\":\"wikipedia\",\"type\":\"table\"},\"filter\":{\"dimension\":\"countryName\",\"extractionFn\":{\"locale\":\"\",\"type\":\"lower\"},\"type\":\"selector\",\"value\":\"france\"},\"intervals\":[\"1980-01-26T23:00:00.000Z/2020-01-26T23:00:00.000Z\"],\"limit\":10,\"order\":\"descending\",\"queryType\":\"scan\", \"resultFormat\":\"compactedList\"}"))
spew.Dump(q)
q, err = d.Query().Load([]byte("{\"batchSize\":20480,\"columns\":[\"__time\",\"channel\",\"cityName\",\"comment\",\"count\",\"countryIsoCode\",\"diffUrl\",\"flags\",\"isAnonymous\",\"isMinor\",\"isNew\",\"isRobot\",\"isUnpatrolled\",\"metroCode\",\"namespace\",\"page\",\"regionIsoCode\",\"regionName\",\"sum_added\",\"sum_commentLength\",\"sum_deleted\",\"sum_delta\",\"sum_deltaBucket\",\"user\"],\"dataSource\":{\"type\":\"query\",\"query\":{\"queryType\":\"scan\",\"dataSource\":{\"type\":\"table\",\"name\":\"A\"},\"columns\":[\"AT\"],\"intervals\":[\"1980-01-26T23:00:00.000Z/2020-01-26T23:00:00.000Z\"]}},\"filter\":{\"dimension\":\"countryName\",\"extractionFn\":{\"locale\":\"\",\"type\":\"lower\"},\"type\":\"selector\",\"value\":\"france\"},\"intervals\":[\"1980-01-26T23:00:00.000Z/2020-01-26T23:00:00.000Z\"],\"limit\":10,\"order\":\"descending\",\"queryType\":\"scan\"}"))
spew.Dump(q, err)
//var results []map[string]interface{}
//d.Query().Execute(q, &results)
//spew.Dump(results)
//var j []byte
//j, err = json.Marshal(results[0])
//if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions query/aggregation/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Base struct {
Type string `json:"type"`
Typ string `json:"type"`
Name string `json:"name"`
}

Expand All @@ -17,7 +17,7 @@ func NewBase() *Base {
}

func (b *Base) SetType(typ string) *Base {
b.Type = typ
b.Typ = typ
return b
}

Expand All @@ -26,6 +26,10 @@ func (b *Base) SetName(name string) *Base {
return b
}

func (b *Base) Type() query.ComponentType {
return b.Typ
}

func Load(data []byte) (query.Aggregator, error) {
var t struct {
Typ string `json:"type"`
Expand Down
8 changes: 6 additions & 2 deletions query/datasource/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Base struct {
Type string `json:"type"`
Typ string `json:"type"`
}

func NewBase() *Base {
Expand All @@ -16,10 +16,14 @@ func NewBase() *Base {
}

func (b *Base) SetType(typ string) *Base {
b.Type = typ
b.Typ = typ
return b
}

func (b *Base) Type() query.ComponentType {
return b.Typ
}

func Load(data []byte) (query.DataSource, error) {
var t struct {
Typ string `json:"type"`
Expand Down
37 changes: 20 additions & 17 deletions query/datasource/query.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package datasource

import (
"encoding/json"

"github.com/grafadruid/go-druid/query"
//base "github.com/grafadruid/go-druid/query/query"
)

type Query struct {
Base
Query query.Query
Query query.Query `json:"-"`
}

func NewQuery() *Query {
Expand All @@ -19,19 +22,19 @@ func (q *Query) SetQuery(query query.Query) {
q.Query = query
}

//func (q *Query) UnmarshalJSON(data []byte) error {
//var tmp struct {
//Base
//Query json.RawMessage `json:"query"`
//}
//if err := json.Unmarshal(data, &tmp); err != nil {
//return err
//}
//qry, err := queries.Load(tmp.Query)
//if err != nil {
//return err
//}
//q.Base = tmp.Base
//q.Query = qry
//return nil
//}
func (q *Query) UnmarshalJSONWithQueryLoader(data []byte, loader func(data []byte) (query.Query, error)) error {
var tmp struct {
Base
Query json.RawMessage `json:"query"`
}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
qry, err := loader(tmp.Query)
if err != nil {
return err
}
q.Base = tmp.Base
q.Query = qry
return nil
}
8 changes: 6 additions & 2 deletions query/dimension/dimension.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type Base struct {
Type string `json:"type"`
Typ string `json:"type"`
Dimension string `json:"dimension"`
OutputName string `json:"outputName"`
OutputType types.OutputType `json:"outputType,omitempty"`
Expand All @@ -20,7 +20,7 @@ func NewBase() *Base {
}

func (b *Base) SetType(typ string) *Base {
b.Type = typ
b.Typ = typ
return b
}

Expand All @@ -39,6 +39,10 @@ func (b *Base) SetOutputType(outputType types.OutputType) *Base {
return b
}

func (b *Base) Type() query.ComponentType {
return b.Typ
}

func Load(data []byte) (query.Dimension, error) {
var t struct {
Typ string `json:"type"`
Expand Down
8 changes: 6 additions & 2 deletions query/extractionfn/extraction_fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Base struct {
Type string `json:"type"`
Typ string `json:"type"`
}

func NewBase() *Base {
Expand All @@ -16,10 +16,14 @@ func NewBase() *Base {
}

func (b *Base) SetType(typ string) *Base {
b.Type = typ
b.Typ = typ
return b
}

func (b *Base) Type() query.ComponentType {
return b.Typ
}

func Load(data []byte) (query.ExtractionFn, error) {
var t struct {
Typ string `json:"type"`
Expand Down
8 changes: 6 additions & 2 deletions query/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Base struct {
Type string `json:"type"`
Typ string `json:"type"`
}

func NewBase() *Base {
Expand All @@ -17,10 +17,14 @@ func NewBase() *Base {
}

func (b *Base) SetType(typ string) *Base {
b.Type = typ
b.Typ = typ
return b
}

func (b *Base) Type() query.ComponentType {
return b.Typ
}

func Load(data []byte) (query.Filter, error) {
var t struct {
Typ string `json:"type"`
Expand Down
8 changes: 6 additions & 2 deletions query/granularity/granularity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Base struct {
Type string `json:"type"`
Typ string `json:"type"`
}

func NewBase() *Base {
Expand All @@ -16,10 +16,14 @@ func NewBase() *Base {
}

func (b *Base) SetType(typ string) *Base {
b.Type = typ
b.Typ = typ
return b
}

func (b *Base) Type() query.ComponentType {
return b.Typ
}

func Load(data []byte) (query.Granularity, error) {
var t struct {
Typ string `json:"type"`
Expand Down
6 changes: 6 additions & 0 deletions query/granularity/simple.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package granularity

import "github.com/grafadruid/go-druid/query"

type Simple string

const (
Expand All @@ -17,6 +19,10 @@ const (
Year = "year"
)

func (s *Simple) Type() query.ComponentType {
return "simple"
}

func NewSimple() *Simple {
var s Simple
return &s
Expand Down
8 changes: 6 additions & 2 deletions query/havingspec/having_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Base struct {
Type string `json:"type"`
Typ string `json:"type"`
}

func NewBase() *Base {
Expand All @@ -16,10 +16,14 @@ func NewBase() *Base {
}

func (b *Base) SetType(typ string) *Base {
b.Type = typ
b.Typ = typ
return b
}

func (b *Base) Type() query.ComponentType {
return b.Typ
}

func Load(data []byte) (query.Dimension, error) {
var t struct {
Typ string `json:"type"`
Expand Down
8 changes: 6 additions & 2 deletions query/limitspec/limit_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Base struct {
Type string
Typ string
}

func NewBase() *Base {
Expand All @@ -16,10 +16,14 @@ func NewBase() *Base {
}

func (b *Base) SetType(typ string) *Base {
b.Type = typ
b.Typ = typ
return b
}

func (b *Base) Type() query.ComponentType {
return b.Typ
}

func Load(data []byte) (query.Dimension, error) {
var t struct {
Typ string `json:"type"`
Expand Down
8 changes: 6 additions & 2 deletions query/postaggregation/post_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Base struct {
Type string `json:"type"`
Typ string `json:"type"`
Name string `json:"name"`
}

Expand All @@ -18,7 +18,7 @@ func NewBase() *Base {
}

func (b *Base) SetType(typ string) *Base {
b.Type = typ
b.Typ = typ
return b
}

Expand All @@ -27,6 +27,10 @@ func (b *Base) SetName(name string) *Base {
return b
}

func (b *Base) Type() query.ComponentType {
return b.Typ
}

func Load(data []byte) (query.PostAggregator, error) {
var t struct {
Typ string `json:"type"`
Expand Down
Loading

0 comments on commit 4995687

Please sign in to comment.