-
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
Set operation support (except navigation/include) #16127
Conversation
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.
Need a lot more testing on combination of shapes which are not same in SelectExpression.
Also non-entity projections combined.
src/EFCore.Relational/Query/Pipeline/RelationalQueryableMethodTranslatingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/Pipeline/RelationalQueryableMethodTranslatingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
src/EFCore/Query/Pipeline/QueryableMethodTranslatingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.cs
Outdated
Show resolved
Hide resolved
@smitpatel @maumar here's a new version in a much more advanced state. Various projections and hierarchy edge cases are now working, take a look at the tests. Some notes on siblings/hierarchy:
Some other notes:
|
src/EFCore.Relational/Query/Pipeline/RelationalQueryableMethodTranslatingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/Pipeline/SqlExpressions/SelectExpression.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/Pipeline/SqlExpressions/SelectExpression.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/Pipeline/SqlExpressions/SelectExpression.cs
Outdated
Show resolved
Hide resolved
@smitpatel, regarding application of set operations on SelectExpression with already-populated projections (this is the corresponding code in PushdownIntoSubquery), I couldn't repro this with the test below. For now I will simply place a NotImplementedExpression, we can always do this in a separate PR. public virtual Task Union_client_eval_FirstOrDefault(bool isAsync)
=> AssertFirstOrDefault<Customer>(isAsync, cs => cs
.Where(c => c.City == "Berlin")
.Union(cs.Where(c => c.City == "London"))
.OrderBy(c => c.Address)
.Select(c => Dummy.GetCustomerAddress(c))); |
OK guys, this seems more or less ready to me. It doesn't contain navigation/include support; @maumar if you want to take a look at this, go ahead, otherwise tomorrow morning I'll be looking at it - please let me know if you're on it so we don't do double work. Hopefully we can get this in for preview7... |
@@ -79,6 +80,28 @@ protected override Expression VisitSelect(SelectExpression selectExpression) | |||
subQueryIndent = _relationalCommandBuilder.Indent(); | |||
} | |||
|
|||
if (selectExpression.IsSetOperation) |
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.
Since we are not doing a lot of process in between, just use using syntax for Indent
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.
We only want to indent for subqueries (when alias != null)...
src/EFCore.Relational/Query/Pipeline/SqlExpressions/SelectExpression.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/Pipeline/SqlExpressions/SelectExpression.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/Pipeline/SqlExpressions/SelectExpression.cs
Outdated
Show resolved
Hide resolved
test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.SetOperations.cs
Outdated
Show resolved
Hide resolved
@smitpatel merged although there are some open questions, in order to make sure this gets into preview7. Let's continue the conversations on this issue and I'll fix as necessary. |
This is a first draft for set operation support (UNION/UNION ALL/INTERSECT/EXCEPT). @smitpatel I'm looking for feedback on the general direction before I go any further etc.
Some important notes on database-specific quirks/capabilities (which have informed the design) have been posted in #6812 (comment).
Design notes
Set operations are currently represented as a special kind of SelectExpression, with an enum marker has been added (SetOperationType). Each such SelectExpression represents a single set operation with exactly two operands.
RelationalQueryableMethodTranslatingExpressionVisitor performs pushdown of set operations into a subquery on most LINQ operations, in one place. As part of this, I have refactored translation of queryable operators into their own method.