Skip to content

Enable Where clause to generate $filter query options for key predicates - #1762

Merged
mikepizzo merged 8 commits into
OData:masterfrom
KenitoInc:fix-851/where-clause
Aug 31, 2020
Merged

mikepizzo merged 8 commits into
OData:masterfrom
KenitoInc:fix-851/where-clause

Conversation

@KenitoInc

@KenitoInc KenitoInc commented May 5, 2020 •

Copy link
Copy Markdown
Contributor

Issues

This pull request fixes issue #851 .

Description

The Where clause generates a Uri with a $filter where we have a non-key predicate e.g
var books = dsc.Books.Where(b => b.Title == "B1"); creates the Uri below
https://serviceRoot/Books?$filter=Title eq 'B1'
In this case, if the Title is not found, the query will return an empty collection.

When we have a key in the predicate, the Where clause generates a Uri with a ByKey resource path e.g
var books = dsc.Books.Where(b => b.Id == 1); creates the Uri below
https://serviceRoot/Books(1)
In this case, if the Id is not found, the query will throw an exception.

By design Where should not throw an exception whenever the predicate does not match any value/element in the source collection.

Solution

Changing the current behavior will be a breaking change. So I have added a DataServiceContext.KeyComparisonGeneratesFilterQuery property which is false by default.
So if a customer want to ensure that a Uri with a $filter query option is generated for key predicates in the Where clause, they need to set the KeyComparisonGeneratesFilterQuery property as true

Container context = new Container(uri);
context.KeyComparisonGeneratesFilterQuery= true;

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

@odero odero added this to the 7.7.0 milestone May 6, 2020
@odero odero added the Ready for review Use this label if a pull request is ready to be reviewed label May 6, 2020

@odero odero left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Considering how long this issue has existed I'm wondering if it might be a breaking change for people who might rely on this behaviour?

@KenitoInc
KenitoInc force-pushed the fix-851/where-clause branch from 45c2c33 to f9d25d5 Compare May 11, 2020 13:28
@KanishManuja-MS

KanishManuja-MS commented May 19, 2020 •

Copy link
Copy Markdown
Contributor

@KenitoInc Can you please rebase the PR and get someone to approve it from the Nairobi team? #Closed

@KenitoInc KenitoInc removed this from the 7.7.0 milestone May 20, 2020
@KenitoInc

KenitoInc commented May 20, 2020 •

Copy link
Copy Markdown
Contributor Author

@KanishManuja-MS I need to redesign a small feature so as not to break exisiting functionality. In the meantime I have removed this PR from v7.7 milestone #Closed

@KenitoInc
KenitoInc force-pushed the fix-851/where-clause branch from f9d25d5 to bb159a3 Compare May 27, 2020 07:37
@KenitoInc
KenitoInc requested a review from odero June 2, 2020 07:44
@KenitoInc KenitoInc changed the title Where clause should generate $filter query options for both key and non-key predicates Enable Where clause to generate $filter query options for key predicates Jun 2, 2020
@KenitoInc
KenitoInc force-pushed the fix-851/where-clause branch from edfb389 to 5b52a5b Compare June 2, 2020 08:12
@odero odero added this to the v8.0 milestone Jun 2, 2020

@gathogojr gathogojr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. I'd argue that in the next major version we shouldn't make this optional. We should just make it generate the $filter expression

@KenitoInc
KenitoInc force-pushed the fix-851/where-clause branch from 96898ac to e137d26 Compare June 10, 2020 13:08
Comment thread src/Microsoft.OData.Client/DataServiceContext.cs
Comment thread src/Microsoft.OData.Client/ALinq/ResourceBinder.cs Outdated
Comment thread src/Microsoft.OData.Client/ALinq/ResourceBinder.cs Outdated
Comment thread src/Microsoft.OData.Client/ALinq/ResourceBinder.cs Outdated
Comment thread src/Microsoft.OData.Client/ALinq/ResourceBinder.cs Outdated
Comment thread src/Microsoft.OData.Client/ALinq/ResourceBinder.cs Outdated
Comment thread src/Microsoft.OData.Client/DataServiceContext.cs Outdated
Comment thread src/Microsoft.OData.Client/DataServiceContext.cs Outdated
@KenitoInc
KenitoInc force-pushed the fix-851/where-clause branch 2 times, most recently from 6c84b2f to dac85cd Compare June 22, 2020 08:40
Comment thread src/Microsoft.OData.Client/ALinq/ResourceBinder.cs Outdated
@KenitoInc
KenitoInc force-pushed the fix-851/where-clause branch from e45873b to d943421 Compare August 19, 2020 10:07
Comment thread src/Microsoft.OData.Client/ALinq/ResourceBinder.cs Outdated
@mikepizzo

mikepizzo commented Aug 24, 2020 •

Copy link
Copy Markdown
Contributor
            if (!input.UseFilterAsPredicate)

trying to understand how UseFilterAsPredicate relates to the new keyComparisonGeneratesFilterQuery. Do they do the same thing, but are set in different places? In what cases/why do we set UseFilterAsPredicate today? Would we have the same logic if line 278 was !input.UseFilterAsPredicate && !keyComparisonGeneratesFilterQuery, and removed the additional checks below? #Resolved


Refers to: src/Microsoft.OData.Client/ALinq/ResourceBinder.cs:278 in 8368f37. [](commit_id = 8368f37, deletion_comment = False)

@mikepizzo mikepizzo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🕐

@mikepizzo

mikepizzo commented Aug 27, 2020 •

Copy link
Copy Markdown
Contributor

@kennedy - See a couple comments. If we can get those resolved I'd love to merge. Also, please mark other comments as resolved as appropriate (i.e., in codeflow) to make it easier to track status of comments. Thanks! #Resolved

@KenitoInc

KenitoInc commented Aug 31, 2020 •

Copy link
Copy Markdown
Contributor Author
            if (!input.UseFilterAsPredicate)

trying to understand how UseFilterAsPredicate relates to the new keyComparisonGeneratesFilterQuery. Do they do the same thing, but are set in different places? In what cases/why do we set UseFilterAsPredicate today? Would we have the same logic if line 278 was !input.UseFilterAsPredicate && !keyComparisonGeneratesFilterQuery, and removed the additional checks below?

Refers to: src/Microsoft.OData.Client/ALinq/ResourceBinder.cs:278 in 8368f37. [](commit_id = 8368f37, deletion_comment = False)

@mikepizzo
UseFilterAsPredicate is used create a $filter query option when we have both key and non-key predicates in the expression.
However in scenarios where we have only a key predicate in the expression, we generate a Uri with a ByKey resource path. KeyComparisonGeneratesFilterQuery allows us to specify if we want a $filter or ByKey.

We can clean up the logic so as to work well with both. #Resolved

@KenitoInc
KenitoInc requested review from ElizabethOkerio, gathogojr, habbes, mikepizzo and odero and removed request for KanishManuja-MS August 31, 2020 14:10
@mikepizzo

mikepizzo commented Aug 31, 2020 •

Copy link
Copy Markdown
Contributor

Considering how long this issue has existed I'm wondering if it might be a breaking change for people who might rely on this behaviour?


In reply to: 406936949 [](ancestors = 406936949)

@mikepizzo mikepizzo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

@mikepizzo
mikepizzo merged commit d853504 into OData:master Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Use this label if a pull request is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants