-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add IS_SUBSTRING operator for use in API resource filtering. #645
Conversation
This should allow substring matches on fields like names and labels and so on. Also bump the version of Mastermind/squirrel so we get the new 'like' operator for use when building the SQL query. Additionally, I also had to fix the generate_api.sh script which had a bug (it modified the wrong file permissions before), and add a dummy service to generate Swagger definitions for the Filter itself (this was a hack in the previous Makefile that I lost when we moved to Bazel).
/assign @rileyjbauer |
@@ -107,6 +110,14 @@ func (f *Filter) AddToSelect(sb squirrel.SelectBuilder) squirrel.SelectBuilder { | |||
sb = sb.Where(squirrel.Eq(f.in)) | |||
} | |||
|
|||
if len(f.substring) > 0 { | |||
like := make(squirrel.Like) | |||
for k, v := range f.substring { |
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.
why is this loop 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.
To prepend/append the %
character to the string being matched.
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.
Maybe go is just strange... are you looping over each letter? there can't be more than one substring in a filter, right?
Is there no better way to access the key/value in substring?
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.
Actually, I'm looping over the map named substring, which holds key/values for substring matches in the filter. So
for k, v := range f.substring
means loop over the map f.substring, and let k be the map key and v be the map value.
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.
do you mind add more comments explaining it?
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.
Ah, I see... so the squirrel operations take a map, and the other operations are already formatted correctly, but LIKE has its special syntax.
Out of curiosity, if a filter has multiple substring predicates, are those combined into a single f.substring
map?
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.
Added more comments.
/lgtm |
@@ -115,4 +119,6 @@ message Filter { | |||
repeated Predicate predicates = 1; | |||
} | |||
|
|||
|
|||
service DummyFilterService { |
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.
do we need this?
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.
Yes, otherwise we don't get the swagger definitions being generated for Filter message. Added clarifying comments
case *api.Predicate_StringValue: | ||
return nil | ||
default: | ||
return fmt.Errorf("cannot use non string value type %T with operator %v", p.Op, t) |
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 don't think we should return fmt.errorf, as we dissused before.
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.
same applies to other places
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.
Done.
@@ -4,6 +4,8 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ | |||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | |||
github.com/Masterminds/squirrel v0.0.0-20170825200431-a6b93000bd21 h1:7+Xpo0TxPIBqSHVktrR1VYU2LSNTrJ3B79nVzE74nPA= | |||
github.com/Masterminds/squirrel v0.0.0-20170825200431-a6b93000bd21/go.mod h1:xnKTFzjGUiZtiOagBsfnvomW+nJg2usB1ZpordQWqNM= | |||
github.com/Masterminds/squirrel v0.0.0-20190107164353-fa735ea14f09 h1:enWVS77aJkLWVIUExiqF6A8eWTVzCXUKUvkST3/wyKI= |
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.
are changes in go.sum needed? if version update is needed, should old version entry be removed?
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 didn't touch this file. This is updated by Go itself when one does go get <library>@<version>
. There are multiple such instances of duplicates in this file. See also golang/go#28456
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: IronPan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
1 similar comment
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: IronPan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm |
…ubeflow#645) * Management cluster is a cluster running Cloud Config connector which can be used to create GCP resources. * This PR checks in the config for cluster kf-ci-management. We also setup a namespace to administer resources in project kubeflow-ci-deployment Fix kubeflow#644
This should allow substring matches on fields like names and labels and
so on.
Also bump the version of Mastermind/squirrel so we get the new 'like'
operator for use when building the SQL query.
Additionally, I also had to fix the generate_api.sh script which had a
bug (it modified the wrong file permissions before), and add a dummy
service to generate Swagger definitions for the Filter itself (this was
a hack in the previous Makefile that I lost when we moved to Bazel).
This change is