-
Notifications
You must be signed in to change notification settings - Fork 934
NH-3944 - preliminary work, Nh clauses eliminated. #594
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,16 @@ namespace NHibernate.Linq.GroupBy | |
{ | ||
internal static class PagingRewriter | ||
{ | ||
private static readonly System.Type[] PagingResultOperators = new[] | ||
{ | ||
typeof (SkipResultOperator), | ||
typeof (TakeResultOperator), | ||
}; | ||
private static readonly System.Type[] PagingResultOperators = | ||
new[] | ||
{ | ||
typeof (SkipResultOperator), | ||
typeof (TakeResultOperator), | ||
}; | ||
|
||
public static void ReWrite(QueryModel queryModel) | ||
{ | ||
var subQueryExpression = queryModel.MainFromClause.FromExpression as SubQueryExpression; | ||
|
||
if (subQueryExpression != null && | ||
if (queryModel.MainFromClause.FromExpression is SubQueryExpression subQueryExpression && | ||
subQueryExpression.QueryModel.ResultOperators.All(x => PagingResultOperators.Contains(x.GetType()))) | ||
{ | ||
FlattenSubQuery(subQueryExpression, queryModel); | ||
|
@@ -28,7 +27,7 @@ public static void ReWrite(QueryModel queryModel) | |
|
||
private static void FlattenSubQuery(SubQueryExpression subQueryExpression, QueryModel queryModel) | ||
{ | ||
// we can not flattern subquery if outer query has body clauses. | ||
// we can not flatten subquery if outer query has body clauses. | ||
var subQueryModel = subQueryExpression.QueryModel; | ||
var subQueryMainFromClause = subQueryModel.MainFromClause; | ||
if (queryModel.BodyClauses.Count == 0) | ||
|
@@ -46,9 +45,13 @@ private static void FlattenSubQuery(SubQueryExpression subQueryExpression, Query | |
{ | ||
var cro = new ContainsResultOperator(new QuerySourceReferenceExpression(subQueryMainFromClause)); | ||
|
||
// Cloning may cause having/join/with clauses listed in VisitorParameters to no more be matched. | ||
// Not a problem for now, because those clauses imply a projection, which is not supported | ||
// by the "new WhereClause(new SubQueryExpression(newSubQueryModel))" below. See | ||
// SingleKeyGroupAndCountWithHavingClausePagingAndOuterWhere test by example. | ||
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. This assertion was tested by adding following test to [Test, Explicit("Demonstrate an unsupported case for PagingRewriter")]
public void SingleKeyGroupAndCountWithHavingClausePagingAndOuterWhere()
{
var orderCounts = db.Orders
.GroupBy(o => o.Customer.CompanyName)
.Where(g => g.Count() > 10)
.Select(g => new { CompanyName = g.Key, OrderCount = g.Count() })
.OrderBy(oc => oc.CompanyName)
.Skip(5)
.Take(10)
.Where(oc => oc.CompanyName.Contains("F"))
.ToList();
Assert.That(orderCounts, Has.Count.EqualTo(3));
var frankRow = orderCounts.Single(row => row.CompanyName == "Frankenversand");
Assert.That(frankRow.OrderCount, Is.EqualTo(15));
} The
Which lets me think this flattening process does not support projection (the I have included that test case in this PR just now. |
||
var newSubQueryModel = subQueryModel.Clone(); | ||
newSubQueryModel.ResultOperators.Add(cro); | ||
newSubQueryModel.ResultTypeOverride = typeof (bool); | ||
newSubQueryModel.ResultTypeOverride = typeof(bool); | ||
|
||
var where = new WhereClause(new SubQueryExpression(newSubQueryModel)); | ||
queryModel.BodyClauses.Add(where); | ||
|
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.
Juste letting them in the model for ensuring any later expression transformation get applied to them.
They will not be added as HQL where because the query model visitor now check each where clause with the visitor parameters. If they are known as having clauses, they will be added as HQL having clauses instead of where.