-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Changes from 17 commits
481e38a
6d123ea
6d11d52
7f4d4ad
5b663d9
02e1d71
2a89234
c072cd1
c558a84
7ac8ca2
47b64af
909d42a
dcf3d72
5201ffa
e50a8b5
37f3d35
00cf3e2
a5b32c6
6cb6624
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,9 @@ public class SelectExpression : Expression | |
private readonly List<ProjectionExpression> _projection = new List<ProjectionExpression>(); | ||
private readonly List<OrderingExpression> _orderings = new List<OrderingExpression>(); | ||
|
||
private IProperty _partitionKeyProperty; | ||
private Expression _paritionKeyValueExpression; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
|
@@ -130,6 +133,45 @@ public SelectExpression( | |
public virtual Expression GetMappedProjection([NotNull] ProjectionMember projectionMember) | ||
=> _projectionMapping[projectionMember]; | ||
|
||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public virtual void SetPartitionKeyProperty([NotNull]IProperty partitionKeyProperty, [NotNull]Expression expression) | ||
{ | ||
_partitionKeyProperty = partitionKeyProperty; | ||
_paritionKeyValueExpression = expression; | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public virtual string GetPartitionKey([NotNull]IReadOnlyDictionary<string, object> parameterValues) | ||
{ | ||
return _partitionKeyProperty != null && _paritionKeyValueExpression is ConstantExpression constantExpression | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _partitionKeyProperty is guaranteed not-null. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only if set by If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
? GetString(_partitionKeyProperty, constantExpression.Value) | ||
: _partitionKeyProperty != null | ||
&& _paritionKeyValueExpression is ParameterExpression parameterExpression | ||
&& parameterValues.TryGetValue(parameterExpression.Name, out var value) | ||
? GetString(_partitionKeyProperty, value) | ||
: null; | ||
|
||
static string GetString(IProperty property, object value) | ||
{ | ||
var converter = property.GetTypeMapping().Converter; | ||
|
||
return converter is null | ||
? (string)value | ||
: (string)converter.ConvertToProvider(value); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
|
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.
This is unnecessarily complicated. I will update it when merging.
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.
Agree. Thanks for helping out.
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.
... also cleaned it up a bit in new latest commit.