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

Cosmos: Detect partition key filters in queries #20690

Merged

Conversation

1iveowl
Copy link
Contributor

@1iveowl 1iveowl commented Apr 20, 2020

Suggestion for how to implement a partition key query detection filter.

Please see #20350

@smitpatel
Copy link
Member

Larger question,
if we are using partitionKey in query, do we still need filter on partitionKey in SQL? or can we eleminate it?

@AndriySvyryd
Copy link
Member

if we are using partitionKey in query, do we still need filter on partitionKey in SQL? or can we eleminate it?

No, we should remove it.

@dotnet dotnet deleted a comment from smitpatel Apr 21, 2020
1iveowl and others added 4 commits April 23, 2020 13:20
…ries

# Conflicts:
#	src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs
#	src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitorBase.cs
#	src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.ReadItemQueryingEnumerable.cs
#	test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs
/// </summary>
public virtual string GetPartitionKey([NotNull]IReadOnlyDictionary<string, object> parameterValues)
{
return _partitionKeyProperty != null && _paritionKeyValueExpression is ConstantExpression constantExpression
Copy link
Member

Choose a reason for hiding this comment

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

_partitionKeyProperty is guaranteed not-null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only if set by SetPartitionKeyProperty(..).

If SetPartitionKeyProperty is never called it would be null, right?

Copy link
Member

Choose a reason for hiding this comment

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

If _partitionKeyProperty is null you can return early

@@ -1012,6 +1029,156 @@ protected override ShapedQueryExpression TranslateWhere(ShapedQueryExpression so
}

return null;

static (Expression predicateExpression, IProperty partitionKeyProperty, Expression partitionKeyValueExpression)
Copy link
Member

Choose a reason for hiding this comment

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

This is unnecessarily complicated. I will update it when merging.

Copy link
Contributor Author

@1iveowl 1iveowl Apr 25, 2020

Choose a reason for hiding this comment

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

This is unnecessarily complicated. I will update it when merging.

Agree. Thanks for helping out.

Copy link
Contributor Author

@1iveowl 1iveowl Apr 25, 2020

Choose a reason for hiding this comment

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

... also cleaned it up a bit in new latest commit.

@smitpatel
Copy link
Member

@AndriySvyryd - Can you sign-off on this one? I will do cleanup and merge.

1iveowl and others added 2 commits April 26, 2020 14:34
…ingExpressionVisitor.cs

Co-Authored-By: Andriy Svyryd <AndriySvyryd@users.noreply.github.com>
@smitpatel smitpatel merged commit 7defe35 into dotnet:master Apr 27, 2020
@AndriySvyryd
Copy link
Member

@1iveowl Thanks for another contribution!

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