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

Removed parentheses from filtering #256

Merged
merged 6 commits into from
Nov 8, 2019
Merged

Removed parentheses from filtering #256

merged 6 commits into from
Nov 8, 2019

Conversation

vbauzys
Copy link
Contributor

@vbauzys vbauzys commented Oct 24, 2019

Fix for https://github.com/terraform-providers/terraform-provider-vcd/issues/287

Parentheses isn't needed(accordig documentation used when need to create sophisticated filtering) and if we will need to use them later - we have to figure out how to escape them, as in different env behaves differently.

Building query docs: https://pubs.vmware.com/vcloud-api-1-5/wwhelp/wwhimpl/js/html/wwhelp.htm#href=api_prog/GUID-CDF04296-5EB5-47E1-9BEC-228837C584CE.html#1_22_9_1

Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
@vbauzys vbauzys self-assigned this Oct 24, 2019
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
@vbauzys vbauzys added the draft label Oct 30, 2019
@vbauzys vbauzys requested review from dataclouder, lvirbalas and Didainius and removed request for dataclouder and lvirbalas November 7, 2019 13:40
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
@vbauzys vbauzys removed the draft label Nov 7, 2019
Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

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

Looks to be dead simple.
I was just looking at a more recent version of the docs: https://code.vmware.com/docs/8072/vcloud-director-api-programming-guide/GUID-CDF04296-5EB5-47E1-9BEC-228837C584CE.html

Main concern from me, is the "grouping" (parenthesis) not used so that it matches both conditions (logical and) while without parenthesis would be logical or?

In such case a query with multiple fields may have different results or am I wrong?

This one would look for objects matching both conditions - name to be "name" and orgName to be "adminOrg.AdminOrg.Name":

"filter": fmt.Sprintf("(name==%s;orgName==%s)", url.QueryEscape(name), url.QueryEscape(adminOrg.AdminOrg.Name)),

While this one would look for objects whose name matches "name" or orgName matches "adminOrg.AdminOrg.Name"

"filter": fmt.Sprintf("name==%s;orgName==%s", url.QueryEscape(name), url.QueryEscape(adminOrg.AdminOrg.Name)),

Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

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

A few small changes required. LGTM otherwise

CHANGELOG.md Outdated
@@ -4,6 +4,9 @@
to allow understand if value was returned or not.
* Added method VApp.AddNewVMWithStorageProfile that adds a VM with custom storage profile.

BUGS FIXED:
* Removed parentheses from filtering which in some env wasn't treated correctly [#256] (https://github.com/vmware/go-vcloud-director/pull/256)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Removed parentheses from filtering which in some env wasn't treated correctly [#256] (https://github.com/vmware/go-vcloud-director/pull/256)
* Removed parentheses from filtering since they weren't treated correctly in some environment [#256] (https://github.com/vmware/go-vcloud-director/pull/256)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

govcd/api.go Outdated
@@ -122,7 +122,7 @@ func ContainsNotFound(err error) bool {
return err != nil && strings.Contains(err.Error(), ErrorEntityNotFound.Error())
}

// Function allow to pass complex values params which shouldn't be encoded like for queries. e.g. /query?filter=(name=foo)
// Function allow to pass complex values params which shouldn't be encoded like for queries. e.g. /query?filter=name=foo
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Function allow to pass complex values params which shouldn't be encoded like for queries. e.g. /query?filter=name=foo
// NewRequestWitNotEncodedParams allows passing complex values params that shouldn't be encoded like for queries. e.g. /query?filter=name=foo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update

@vbauzys
Copy link
Contributor Author

vbauzys commented Nov 8, 2019

Looks to be dead simple.
I was just looking at a more recent version of the docs: https://code.vmware.com/docs/8072/vcloud-director-api-programming-guide/GUID-CDF04296-5EB5-47E1-9BEC-228837C584CE.html

Main concern from me, is the "grouping" (parenthesis) not used so that it matches both conditions (logical and) while without parenthesis would be logical or?

In such case a query with multiple fields may have different results or am I wrong?

This one would look for objects matching both conditions - name to be "name" and orgName to be "adminOrg.AdminOrg.Name":

"filter": fmt.Sprintf("(name==%s;orgName==%s)", url.QueryEscape(name), url.QueryEscape(adminOrg.AdminOrg.Name)),

While this one would look for objects whose name matches "name" or orgName matches "adminOrg.AdminOrg.Name"

"filter": fmt.Sprintf("name==%s;orgName==%s", url.QueryEscape(name), url.QueryEscape(adminOrg.AdminOrg.Name)),

We can't 100% rely on latest docs as we working still with older versions.
Regarding question Logical OR and Logical AND is managed by separator , and ; .
E.g.

attribute1==value1,attribute2==value2 	
vs 
attribute1==value1;attribute2!=value2 	

Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
@dataclouder
Copy link
Contributor

Looks to be dead simple.
I was just looking at a more recent version of the docs: https://code.vmware.com/docs/8072/vcloud-director-api-programming-guide/GUID-CDF04296-5EB5-47E1-9BEC-228837C584CE.html

Main concern from me, is the "grouping" (parenthesis) not used so that it matches both conditions (logical and) while without parenthesis would be logical or?

In such case a query with multiple fields may have different results or am I wrong?

This one would look for objects matching both conditions - name to be "name" and orgName to be "adminOrg.AdminOrg.Name":

"filter": fmt.Sprintf("(name==%s;orgName==%s)", url.QueryEscape(name), url.QueryEscape(adminOrg.AdminOrg.Name)),

While this one would look for objects whose name matches "name" or orgName matches "adminOrg.AdminOrg.Name"

"filter": fmt.Sprintf("name==%s;orgName==%s", url.QueryEscape(name), url.QueryEscape(adminOrg.AdminOrg.Name)),

Parentheses are needed only if we have groups, or sub-expression.
For example, "(A=1;B=2),(A=2;B=3)" means (A == 1 AND B == 2) OR (A ==2 AND B == 3)

If we have only one set of parentheses, they should be superfluous, as we are grouping the only sub-expression in the condition.
(Notice that in your example the comma should not be followed by spaces)

@Didainius
Copy link
Collaborator

Parentheses are needed only if we have groups, or sub-expression.
For example, "(A=1;B=2),(A=2;B=3)" means (A == 1 AND B == 2) OR (A ==2 AND B == 3)

If we have only one set of parentheses, they should be superfluous, as we are grouping the only sub-expression in the condition.
(Notice that in your example the comma should not be followed by spaces)

Alright. I am sold :)

The example in website confused me initially having and everywhere:

(attribute1==value1;attribute2!=value2);(attribute3==value3;attribute4!=value4)...

Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

LGTM, but in the commit message, please explain why these parentheses were doing harm - I don't see a single note about that in this PR.

@vbauzys vbauzys merged commit 5cf7034 into vmware:master Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants