-
Notifications
You must be signed in to change notification settings - Fork 928
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
Reduce cast usage for aggregate functions #2036
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.
Some of the logic is not necessary and/or, probably, needs to be extended to other functions of similar nature.
I've made a more sophisticated logic that can be used also for other aggregates like |
: persister.EntityMetamodel.PropertyTypes[index.Value]; | ||
} | ||
|
||
private string TryGetEntityName(MemberExpression memberExpression) |
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.
Copied from #1996.
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.
After doing #2079 I found out that this method does not cover all cases. I will update this method and try to add additional tests that cover the edge cases.
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.
? _hqlTreeBuilder.Cast(VisitExpression(expression.Operand).AsExpression(), expression.Type) | ||
// Make a transparent cast when an IType exists, so that it can be used to retrieve the value from the data reader | ||
: existType | ||
? _hqlTreeBuilder.TransparentCast(VisitExpression(expression.Operand).AsExpression(), expression.Type) |
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.
I have to recheck this as TransparentCast
does support only a few types.
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.
Added an additional check for calling TransparentCast
, as there is an edge case when casting to a custom registered type.
Set to WIP as I need to revisit this PR, see the comments above. |
@@ -225,10 +213,24 @@ public static class ExpressionsHelper | |||
out currentComponentType); | |||
break; | |||
case IAbstractComponentType componentType: | |||
// Concatenate the component property path in order to be able to use EntityMetamodel.GetPropertyType to retrieve the type. | |||
// As GetPropertyType supports only components, do not concatenate when dealing with collection composite elements or elements. | |||
if (!currentType.IsAnyType) |
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.
Thanks for cleaning the code. I've removed this condition as it is no longer needed because AnyType
also implements IAssociationType
, so it will be handled by the above case
.
if (memberPaths.Count == 0) | ||
{ | ||
memberPath = currentEntityPersister != null || currentComponentType != null ? member.Path : null; | ||
mappedType = GetType(currentEntityPersister, currentType, member, sessionFactory, 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.
Are you using this GetType
method in other PRs? If no, I think the last argument needs to be removed.
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.
No, I've removed it.
I've updated the |
sqlType = factory.Dialect.GetCastTypeName(sqlTypeCodes[0]); | ||
if (sqlType == null) | ||
{ | ||
//TODO: never reached, since GetTypeName() actually throws an exception! |
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.
It doesn't make sense using the type name when the dialect doesn't support the cast. If the cast would be supported, GetCastTypeName
should return it.
2e2f42f
to
17422d7
Compare
Rebased. |
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.
I have adjusted the TryGetMappedTests.Assert...
names for them to be more explicit.
And I have adjusted this PR title.
This PR uses the dialect specific SUM function to determine whether cast is needed or not and also takes nullable types into consideration, which fixes #2029.
Note:
The cast usage was not reduced for SQLite as it needs it when
sum
expression contains a parameter.Edit: this PR has been extended to other aggregate functions.