-
Notifications
You must be signed in to change notification settings - Fork 114
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
Implement predicate type conversion. #204
Conversation
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.
I think the overall approach looks sane -- could you point out the part that worries you @Dragomir-Ivanov?
@smyrman My initial concern is:
I do like however the way whole operator validation step is separate from other steps, and can be opted-out if needed. |
Why is |
It looks like it validates that the operator is allowed? Can't that be done as part of the normal Validate? |
I am not sure I understand. You want |
I think your proposal was separate interface Also I will try to remove |
@smyrman Are we calling interface functions, and struct functions |
no. I mean why does the Predicate and Expression need a new method: // ValidateOperator TODO
func (e Predicate) ValidateOperator(validator schema.Validator) (Expression, error) {
return nil, validateOperatorExpressions(e, validator)
}
// Expression is a query or query component that can be matched against a payload.
type Expression interface {
Match(payload map[string]interface{}) bool
Validate(validator schema.Validator) error
ValidateOperator(validator schema.Validator) (Expression, error)
String() string
} How does
yes, that was my proposal (to add it as a new interface for the schema package). |
The concept, in my mind, is the same regarding of language.
Or, as they say all methods are functions, not all functions are methods. |
Hi @smyrman @rs , here is my design proposal for this PR. Lets define 2 new interfaces that can be implemented by
In order to accomplish the above, I needed to refactor a little bit passed arguments of some functions involved in predicate parsing. I will not go into much details here, because code will explain better. |
Looks good to me. |
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.
I think the design looks good overall. I think Prepare
on schema needs a better name, otherwise some small comments and advice here and there. God work.
@smyrman Committed with your suggestions. Didn't implemented Integer field with Float compare value. Lets leave that for later, when we clean things up. There will be patches for all |
Think this approach looks good @Dragomir-Ivanov 👍 Looking forward to the result :-) I think it's fair not to add |
Thanks @smyrman , can you take quick look on the questions above? |
Tried to answer the ones for unresolved (closed) conversations - Let me know if there are any more questions I have missed.
Do you mean for the type switch? Yes, I suppose so... I don't like adding struct pointers to slices (memory gets scattered), but it's fine. We already do slices of pointers for e.g. resource.Items. When I do an overhaul in #77 (eventually) I can have another look at the query design to see if there is anything we can/should do differently there as well. |
I actually made a couple of code comments above on the last commit, since I am not sure how to best Go approach. |
Can't see any comments in neither Changed Files nor the last commit itself -- sure they are not with state pending? If they are you need to "submit a review" for me to see them. |
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.
Sorry @smyrman, didn't used review functionality before. I thought these are regular code comments. Will not happen again.
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.
Looks quite good.
schema/query/predicate_validator.go
Outdated
return fmt.Errorf("%s: invalid query expression `%#v': %v", field, v, err) | ||
} | ||
} | ||
} |
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.
looks like indenting error -- If there is a way ti enable gofmt
or goimports
in your editor, it should fix this automatically on save.
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.
I am using VSCode, with the Golang plugin, so I have these enabled. Don't know what happened.
PS! Can you please add a note to the "breaking changes" section of the README with a link to this PR? Breaking changes is defined as anything that changes the public interface in a way that would cause old code to no longer compile. |
Before we do the final merge, please also do a final rebase and squah and write a nice commit message :-) |
@smyrman This is what I recall for the breaking changes part. Do you recall something else?
|
@smyrman Pushed the squashed rebase. When you merge it, I will do additional PRs to fix the DB drivers. EDIT: It seems that SQLite3 and Google Data Store drivers are rotten. They complain about missing |
Yes. Third-party drivers seam out of date. |
Sorry for comming with even more comments now... I sort of look at this in between other things and haven't been able to really spot everything in my first pass through. Thanks a lot for your great work! |
No problem Sindre, I am learning a lot of things during these passes, so let it be as many as needed :) |
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.
LGTM -- @rs, you want to have a final look to see if you can spot something?
@Dragomir-Ivanov can you squash the last fixup commits as well? If there are no more comments, I think this is good for merging and we can deal with any fallout if there is anything we haven't spotted yet. |
Checks query parameters if applicable to concrete schema resource types. Doesn't not check type constrains. Checks sub-resource query parameters. Adds suport for custom comparable types, and support for `rest-layer-mem`.
@smyrman Done. |
Helps with querying for
schema.Time
and others. It also skips validation forschema.*
types during predicate phase of query.This is just a preview PR, I will fix the tests, when implementation is accepted.