-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow dimension and datasource values to be string #61
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package intervals | |
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
|
||
"github.com/grafadruid/go-druid/builder" | ||
) | ||
|
@@ -25,17 +24,19 @@ func Load(data []byte) (builder.Intervals, error) { | |
if string(data) == "null" { | ||
return i, nil | ||
} | ||
var t struct { | ||
Typ builder.ComponentType `json:"type,omitempty"` | ||
} | ||
if err := json.Unmarshal(data, &t); err != nil { | ||
// "intervals" in the spec is just an string array | ||
var intv []string | ||
if err := json.Unmarshal(data, &intv); err != nil { | ||
return nil, err | ||
} | ||
switch t.Typ { | ||
case "intervals": | ||
i = NewIntervals() | ||
default: | ||
return nil, errors.New("unsupported intervals type") | ||
// Now cast the only array item into an actual "interval" | ||
interval := Interval(intv[0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no guarantee that we have an item, it could be Also, does the spec say it's only one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately the Druid documentation for the query spec is... not very specific (from what I've seen).
However some other documentation shows that multiple time ranges are acceptable.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this is a good point, the code should be able to handle multiple intervals. |
||
// create our "intervals" object with "Typ" | ||
i = &Intervals{ | ||
Base: Base{ | ||
Typ: "intervals", | ||
}, | ||
Intervals: []*Interval{&interval}, | ||
} | ||
return i, json.Unmarshal(data, &i) | ||
return i, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
(*Base)
shouldn't be required in this context, as it's already a concrete type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remove the
(*Base)
type assertion, the compiler complains.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/facepalm
My bad, I didn't realize
d
already existed, I read it asd := &Base{}
. Keep it as is.