-
Notifications
You must be signed in to change notification settings - Fork 934
Reduce cast usage for COUNT aggregate and add support for Mssql count_big #2061
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
93cd848
3a8dc8c
df065e1
5f5ad60
83715ee
bc4b6e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Collections.Generic; | ||
using NHibernate.Engine; | ||
using NHibernate.Type; | ||
|
||
namespace NHibernate.Dialect.Function | ||
{ | ||
// 6.0 TODO: Merge into ISQLFunction | ||
internal interface ISQLFunctionExtended : ISQLFunction | ||
{ | ||
/// <summary> | ||
/// The function name or <see langword="null"/> when multiple functions/operators/statements are used. | ||
/// </summary> | ||
string FunctionName { get; } | ||
|
||
/// <summary> | ||
/// Get the type that will be effectively returned by the underlying database. | ||
/// </summary> | ||
/// <param name="argumentTypes">The types of arguments.</param> | ||
/// <param name="mapping">The mapping for retrieving the argument sql types.</param> | ||
/// <param name="throwOnError">Whether to throw when the number of arguments is invalid or they are not supported.</param> | ||
/// <returns>The type returned by the underlying database or <see langword="null"/> when the number of arguments | ||
/// is invalid or they are not supported.</returns> | ||
/// <exception cref="QueryException">When <paramref name="throwOnError"/> is set to <see langword="true"/> and the | ||
/// number of arguments is invalid or they are not supported.</exception> | ||
IType GetEffectiveReturnType(IEnumerable<IType> argumentTypes, IMapping mapping, bool throwOnError); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -286,7 +286,8 @@ protected virtual void RegisterKeywords() | |||||
|
||||||
protected virtual void RegisterFunctions() | ||||||
{ | ||||||
RegisterFunction("count", new CountBigQueryFunction()); | ||||||
RegisterFunction("count", new CountQueryFunction()); | ||||||
RegisterFunction("count_big", new CountBigQueryFunction()); | ||||||
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. Isn't this still causing the breaking change you were writing about?
This changes the registration of HQL 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.
For HQL nothing is changed, the new |
||||||
|
||||||
RegisterFunction("abs", new StandardSQLFunction("abs")); | ||||||
RegisterFunction("absval", new StandardSQLFunction("absval")); | ||||||
|
@@ -704,11 +705,15 @@ protected virtual string GetSelectExistingObject(string catalog, string schema, | |||||
[Serializable] | ||||||
protected class CountBigQueryFunction : ClassicAggregateFunction | ||||||
{ | ||||||
public CountBigQueryFunction() : base("count_big", true) { } | ||||||
public CountBigQueryFunction() : base("count_big", true, NHibernateUtil.Int64) { } | ||||||
} | ||||||
|
||||||
public override IType ReturnType(IType columnType, IMapping mapping) | ||||||
[Serializable] | ||||||
private class CountQueryFunction : CountQueryFunctionInfo | ||||||
{ | ||||||
public override IType GetEffectiveReturnType(IEnumerable<IType> argumentTypes, IMapping mapping, bool throwOnError) | ||||||
{ | ||||||
return NHibernateUtil.Int64; | ||||||
return NHibernateUtil.Int32; | ||||||
} | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,7 +150,7 @@ selectExpr | |
; | ||
|
||
count | ||
: ^(COUNT { Out("count("); } ( distinctOrAll ) ? countExpr { Out(")"); } ) | ||
: ^(c=COUNT { OutAggregateFunctionName(c); Out("("); } ( distinctOrAll ) ? countExpr { Out(")"); } ) | ||
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. Does this invalidate my previous comment? I mean, was this causing the SQL-Server HQL 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.
Correct, |
||
; | ||
|
||
distinctOrAll | ||
|
@@ -344,7 +344,7 @@ caseExpr | |
; | ||
|
||
aggregate | ||
: ^(a=AGGREGATE { Out(a); Out("("); } expr { Out(")"); } ) | ||
: ^(a=AGGREGATE { OutAggregateFunctionName(a); Out("("); } expr { Out(")"); } ) | ||
; | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System; | ||
using Antlr.Runtime; | ||
using NHibernate.Dialect.Function; | ||
using NHibernate.Type; | ||
using NHibernate.Hql.Ast.ANTLR.Util; | ||
|
||
|
@@ -19,6 +20,19 @@ public AggregateNode(IToken token) | |
{ | ||
} | ||
|
||
public string FunctionName | ||
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. I think this could be an overgeneralization and should be refactored into a node-specific code unless you see that it can be extended for functions other than 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 may be extended for string concatenation, which is supported by some databases (Sql server, MySql, Postgresql and Oracle), where different function names are used ( 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. @maca88 can you provide some sort of prototype of string_agg? I'm dying to use this with linq provider 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. To my knowledge it is not possible to implement it without modifying NHibernate source code. It is on my todo list for the next release, so unfortunately you will have to wait. |
||
{ | ||
get | ||
{ | ||
if (SessionFactoryHelper.FindSQLFunction(Text) is ISQLFunctionExtended sqlFunction) | ||
{ | ||
return sqlFunction.FunctionName; | ||
} | ||
|
||
return Text; | ||
} | ||
} | ||
|
||
public override IType DataType | ||
{ | ||
get | ||
|
@@ -31,6 +45,7 @@ public override IType DataType | |
base.DataType = value; | ||
} | ||
} | ||
|
||
public override void SetScalarColumnText(int i) | ||
{ | ||
ColumnHelper.GenerateSingleScalarColumn(ASTFactory, this, i); | ||
|
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 think this should be renamed to
Name
to reduce need of obsoleting things.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.
Why not, renamed in #2359.