diff --git a/builder/filter/bound.go b/builder/filter/bound.go index ae3c98f..1569954 100644 --- a/builder/filter/bound.go +++ b/builder/filter/bound.go @@ -61,6 +61,7 @@ func (b *Bound) SetOrdering(ordering types.StringComparator) *Bound { } func (b *Bound) UnmarshalJSON(data []byte) error { + var err error var tmp struct { Base Dimension string `json:"dimension"` @@ -71,12 +72,15 @@ func (b *Bound) UnmarshalJSON(data []byte) error { ExtractionFn json.RawMessage `json:"extractionFn"` Ordering types.StringComparator `json:"ordering"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } - e, err := extractionfn.Load(tmp.ExtractionFn) - if err != nil { - return err + var e builder.ExtractionFn + if tmp.ExtractionFn != nil { + e, err = extractionfn.Load(tmp.ExtractionFn) + if err != nil { + return err + } } b.Base = tmp.Base b.Dimension = tmp.Dimension diff --git a/builder/filter/column_comparison.go b/builder/filter/column_comparison.go index 70cda41..e472cbb 100644 --- a/builder/filter/column_comparison.go +++ b/builder/filter/column_comparison.go @@ -24,14 +24,14 @@ func (c *ColumnComparison) SetDimensions(dimensions []builder.Dimension) *Column } func (c *ColumnComparison) UnmarshalJSON(data []byte) error { + var err error var tmp struct { Base Dimensions []json.RawMessage `json:"dimensions"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } - var err error var d builder.Dimension dd := make([]builder.Dimension, len(tmp.Dimensions)) for i := range tmp.Dimensions { diff --git a/builder/filter/extraction.go b/builder/filter/extraction.go index 85d593d..d6eaf00 100644 --- a/builder/filter/extraction.go +++ b/builder/filter/extraction.go @@ -36,18 +36,22 @@ func (e *Extraction) SetExtractionFn(extractionFn builder.ExtractionFn) *Extract } func (e *Extraction) UnmarshalJSON(data []byte) error { + var err error var tmp struct { Base Dimension string `json:"dimension"` Value string `json:"value"` ExtractionFn json.RawMessage `json:"extractionFn"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } - ex, err := extractionfn.Load(tmp.ExtractionFn) - if err != nil { - return err + var ex builder.ExtractionFn + if tmp.ExtractionFn != nil { + ex, err = extractionfn.Load(tmp.ExtractionFn) + if err != nil { + return err + } } e.Base = tmp.Base e.Dimension = tmp.Dimension diff --git a/builder/filter/in.go b/builder/filter/in.go index f9a6fd0..86090e3 100644 --- a/builder/filter/in.go +++ b/builder/filter/in.go @@ -42,6 +42,7 @@ func (i *In) SetFilterTuning(filterTuning *FilterTuning) *In { } func (i *In) UnmarshalJSON(data []byte) error { + var err error var tmp struct { Base Dimension string `json:"dimension"` @@ -49,12 +50,15 @@ func (i *In) UnmarshalJSON(data []byte) error { ExtractionFn json.RawMessage `json:"extractionFn"` FilterTuning *FilterTuning `json:"filterTuning"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } - e, err := extractionfn.Load(tmp.ExtractionFn) - if err != nil { - return err + var e builder.ExtractionFn + if tmp.ExtractionFn != nil { + e, err = extractionfn.Load(tmp.ExtractionFn) + if err != nil { + return err + } } i.Base = tmp.Base i.Dimension = tmp.Dimension diff --git a/builder/filter/interval.go b/builder/filter/interval.go index 3522673..e2a6a9d 100644 --- a/builder/filter/interval.go +++ b/builder/filter/interval.go @@ -43,6 +43,7 @@ func (i *Interval) SetFilterTuning(filterTuning *FilterTuning) *Interval { } func (i *Interval) UnmarshalJSON(data []byte) error { + var err error var tmp struct { Base Dimension string `json:"dimension"` @@ -50,12 +51,15 @@ func (i *Interval) UnmarshalJSON(data []byte) error { ExtractionFn json.RawMessage `json:"extractionFn"` FilterTuning *FilterTuning `json:"filterTuning"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } - e, err := extractionfn.Load(tmp.ExtractionFn) - if err != nil { - return err + var e builder.ExtractionFn + if tmp.ExtractionFn != nil { + e, err = extractionfn.Load(tmp.ExtractionFn) + if err != nil { + return err + } } i.Base = tmp.Base i.Dimension = tmp.Dimension diff --git a/builder/filter/javascript.go b/builder/filter/javascript.go index 4eacb17..4b8b219 100644 --- a/builder/filter/javascript.go +++ b/builder/filter/javascript.go @@ -42,6 +42,7 @@ func (j *Javascript) SetFilterTuning(filterTuning *FilterTuning) *Javascript { } func (j *Javascript) UnmarshalJSON(data []byte) error { + var err error var tmp struct { Base Dimension string `json:"dimension"` @@ -49,12 +50,15 @@ func (j *Javascript) UnmarshalJSON(data []byte) error { ExtractionFn json.RawMessage `json:"extractionFn"` FilterTuning *FilterTuning `json:"filterTuning"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } - e, err := extractionfn.Load(tmp.ExtractionFn) - if err != nil { - return err + var e builder.ExtractionFn + if tmp.ExtractionFn != nil { + e, err = extractionfn.Load(tmp.ExtractionFn) + if err != nil { + return err + } } j.Base = tmp.Base j.Dimension = tmp.Dimension diff --git a/builder/filter/like.go b/builder/filter/like.go index d6c8ee9..4b4da2a 100644 --- a/builder/filter/like.go +++ b/builder/filter/like.go @@ -48,6 +48,7 @@ func (l *Like) SetFilterTuning(filterTuning *FilterTuning) *Like { } func (l *Like) UnmarshalJSON(data []byte) error { + var err error var tmp struct { Base Dimension string `json:"dimension"` @@ -56,12 +57,15 @@ func (l *Like) UnmarshalJSON(data []byte) error { ExtractionFn json.RawMessage `json:"extractionFn"` FilterTuning *FilterTuning `json:"filterTuning"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } - e, err := extractionfn.Load(tmp.ExtractionFn) - if err != nil { - return err + var e builder.ExtractionFn + if tmp.ExtractionFn != nil { + e, err = extractionfn.Load(tmp.ExtractionFn) + if err != nil { + return err + } } l.Base = tmp.Base l.Dimension = tmp.Dimension diff --git a/builder/filter/regex.go b/builder/filter/regex.go index 229a2a2..2c66a53 100644 --- a/builder/filter/regex.go +++ b/builder/filter/regex.go @@ -42,6 +42,7 @@ func (r *Regex) SetFilterTuning(filterTuning *FilterTuning) *Regex { } func (r *Regex) UnmarshalJSON(data []byte) error { + var err error var tmp struct { Base Dimension string `json:"dimension"` @@ -49,12 +50,15 @@ func (r *Regex) UnmarshalJSON(data []byte) error { ExtractionFn json.RawMessage `json:"extractionFn"` FilterTuning *FilterTuning `json:"filterTuning"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } - e, err := extractionfn.Load(tmp.ExtractionFn) - if err != nil { - return err + var e builder.ExtractionFn + if tmp.ExtractionFn != nil { + e, err = extractionfn.Load(tmp.ExtractionFn) + if err != nil { + return err + } } r.Base = tmp.Base r.Dimension = tmp.Dimension diff --git a/builder/filter/search.go b/builder/filter/search.go index 199bc05..a400bd0 100644 --- a/builder/filter/search.go +++ b/builder/filter/search.go @@ -42,6 +42,7 @@ func (s *Search) SetFilterTuning(filterTuning *FilterTuning) *Search { } func (s *Search) UnmarshalJSON(data []byte) error { + var err error var tmp struct { Base Dimension string `json:"dimension"` @@ -49,12 +50,15 @@ func (s *Search) UnmarshalJSON(data []byte) error { ExtractionFn json.RawMessage `json:"extractionFn"` FilterTuning *FilterTuning `json:"filterTuning"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } - e, err := extractionfn.Load(tmp.ExtractionFn) - if err != nil { - return err + var e builder.ExtractionFn + if tmp.ExtractionFn != nil { + e, err = extractionfn.Load(tmp.ExtractionFn) + if err != nil { + return err + } } s.Base = tmp.Base s.Dimension = tmp.Dimension diff --git a/builder/filter/selector.go b/builder/filter/selector.go index dd84809..a46eb34 100644 --- a/builder/filter/selector.go +++ b/builder/filter/selector.go @@ -42,6 +42,7 @@ func (s *Selector) SetFilterTuning(filterTuning *FilterTuning) *Selector { } func (s *Selector) UnmarshalJSON(data []byte) error { + var err error var tmp struct { Base Dimension string `json:"dimension"` @@ -49,12 +50,15 @@ func (s *Selector) UnmarshalJSON(data []byte) error { ExtractionFn json.RawMessage `json:"extractionFn"` FilterTuning *FilterTuning `json:"filterTuning"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } - e, err := extractionfn.Load(tmp.ExtractionFn) - if err != nil { - return err + var e builder.ExtractionFn + if tmp.ExtractionFn != nil { + e, err = extractionfn.Load(tmp.ExtractionFn) + if err != nil { + return err + } } s.Base = tmp.Base s.Dimension = tmp.Dimension diff --git a/builder/query/scan.go b/builder/query/scan.go index 94323b9..eda2a54 100644 --- a/builder/query/scan.go +++ b/builder/query/scan.go @@ -20,7 +20,7 @@ const ( type Scan struct { Base VirtualColumns []builder.VirtualColumn `json:"virtualColumns"` - ResultFormat string `json:"resultFormat"` + ResultFormat string `json:"resultFormat,omitempty"` BatchSize int64 `json:"batchSize"` Limit int64 `json:"limit"` Order Order `json:"order"` @@ -102,7 +102,7 @@ func (s *Scan) UnmarshalJSON(data []byte) error { Columns []string `json:"columns"` Legacy bool `json:"legacy"` } - if err := json.Unmarshal(data, &tmp); err != nil { + if err = json.Unmarshal(data, &tmp); err != nil { return err } var v builder.VirtualColumn diff --git a/examples/main.go b/examples/main.go index ed81d2b..f2ed478 100644 --- a/examples/main.go +++ b/examples/main.go @@ -25,6 +25,11 @@ func main() { d.Query().Execute(q, &results) spew.Dump(results) + 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\",\"v0\"],\"context\":{\"plopa\":\"plep\"},\"dataSource\":{\"name\":\"wikipedia\",\"type\":\"table\"},\"filter\":{\"dimension\":\"countryName\",\"type\":\"selector\",\"value\":\"France\"},\"intervals\":[\"2016-06-27T01:55:25.000Z/2016-06-27T10:07:01.000Z\"],\"limit\":10,\"order\":\"none\",\"queryType\":\"scan\",\"virtualColumns\":[{\"expression\":\"'France'\",\"name\":\"v0\",\"outputType\":\"STRING\",\"type\":\"expression\"}]}")) + spew.Dump(q) + d.Query().Execute(q, &results) + spew.Dump(results) + 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) d.Query().Execute(q, &results)