Skip to content
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

Fix builder.Intervals marshal and filter.Interval #68

Merged
merged 15 commits into from
Jun 20, 2022

Conversation

cosmic-chichu
Copy link
Contributor

@cosmic-chichu cosmic-chichu commented Jun 16, 2022

Currently, builder.Intervals supports only complex interval types during Load. But when marshaled it produces a simple interval. This behavior violates the expected idempotent behavior of marshaling and un-marshaling.

Steps to reproduce:

interval := NewInterval().SetInterval(start,end)
intervals := NewIntervals().SetIntervals([]*Interval{interval})
f, err := json.Marshal(interval)
fmt.Println(string(f))

Actual Output: ["2022-06-16T08:28:53.33441Z/2022-06-16T15:28:53.33441Z"]
Expected Output: {"type":"intervals","intervals":["2022-06-16T08:28:53.33441Z/2022-06-16T15:28:53.33441Z"]}

Note: This change ensures the intervals are always processed(input/output) as a well-defined struct.

This also relates to #17 and #18 and provides a fix

Filters have a different struct defined for interval which only requires intervals of type []*intervals.Interval.

@cosmic-chichu
Copy link
Contributor Author

@jbguerraz @vigith Load intervals was not compliant to the full spec causing problems in chaining go-druid clients.
Scenario:
A - web application
P - Proxy
D - Druid

A (go-druid builder query marshaled ) -> Proxy (tries to load json but fails) -> Druid.

Please don't mind the older commits, I lost my local copy. We can squash these.

@vigith
Copy link
Collaborator

vigith commented Jun 17, 2022

does this fix #18 ?

@cosmic-chichu
Copy link
Contributor Author

does this fix #18 ?

Thank you for the pointer! I fixed the filter's Interval type. It only cares about the interval of type []*intervals.Interval from builder.Intervals. The type is explicitly/statically set here

I verified the query output with multiple filters works:

"queryType":"scan","dataSource":{"type":"table","name":"wikipedia"},"intervals":{"type":"intervals","intervals":["2022-06-16T08:28:53.33441Z/2022-06-16T15:28:53.33441Z"]},"limit":10,"filter":{"type":"or","fields":[{"type":"selector","dimension":"countryName","value":"France"},{"type":"interval","dimension":"__time","intervals":["2022-06-16T08:28:53.33441Z/2022-06-16T15:28:53.33441Z","2022-06-12T08:28:53.33441Z/2022-06-12T15:28:53.33441Z"]}]}}

@cosmic-chichu cosmic-chichu changed the title Fix builder.Intervals marshal Fix builder.Intervals marshal and filter.Interval Jun 17, 2022
Copy link
Collaborator

@vigith vigith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test where we marshal, unmarshal and then marshal and make sure it matches the input we started with?

@vigith vigith requested a review from jbguerraz June 17, 2022 16:59
@cosmic-chichu cosmic-chichu requested a review from vigith June 17, 2022 17:57
vigith
vigith previously approved these changes Jun 17, 2022
builder/intervals/intervals_test.go Outdated Show resolved Hide resolved
@jbguerraz jbguerraz merged commit 9ab16a4 into grafadruid:master Jun 20, 2022
@jbguerraz
Copy link
Contributor

thank you @cosmic-chichu !!! 🎆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants