Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,22 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {
doubleType
);

if ( getVersion().isSameOrAfter( 4, 0 ) ) {
Arrays.asList( "md5", "sha1", "sha256", "sha512" )
.forEach( hash -> functionRegistry.registerPattern(
hash,
"crypt_hash(?1 using " + hash + ")",
byteArrayType
) );
functionRegistry.registerAlternateKey( "sha", "sha1" );
functionRegistry.registerPattern(
"crc32",
"hash(?1 using crc32)",
integerType
);
if ( getVersion().isSameOrAfter( 3 ) ) {
functionFactory.windowFunctions();
if ( getVersion().isSameOrAfter( 4, 0 ) ) {
Arrays.asList( "md5", "sha1", "sha256", "sha512" )
.forEach( hash -> functionRegistry.registerPattern(
hash,
"crypt_hash(?1 using " + hash + ")",
byteArrayType
) );
functionRegistry.registerAlternateKey( "sha", "sha1" );
functionRegistry.registerPattern(
"crc32",
"hash(?1 using crc32)",
integerType
);
}
}

functionFactory.listagg_list( "varchar" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {

queryEngine.getSqmFunctionRegistry().register( "least", new CaseLeastGreatestEmulation( true ) );
queryEngine.getSqmFunctionRegistry().register( "greatest", new CaseLeastGreatestEmulation( false ) );
if ( supportsWindowFunctions() ) {
functionFactory.windowFunctions();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {
.register();

// No idea since when this is supported
functionFactory.windowFunctions();
functionFactory.listagg( null );
functionFactory.inverseDistributionOrderedSetAggregates();
functionFactory.hypotheticalOrderedSetAggregates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {
.setParameterTypes(NUMERIC)
.register();
}
functionFactory.windowFunctions();
functionFactory.listagg_groupConcat();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ protected String columnType(int jdbcTypeCode) {
@Override
public void initializeFunctionRegistry(QueryEngine queryEngine) {
super.initializeFunctionRegistry( queryEngine );
new CommonFunctionFactory( queryEngine ).listagg_list( "varchar" );
final CommonFunctionFactory functionFactory = new CommonFunctionFactory( queryEngine );
functionFactory.listagg_list( "varchar" );
if ( getVersion().isSameOrAfter( 12 ) ) {
functionFactory.windowFunctions();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {
}

// No idea since when this is supported
functionFactory.windowFunctions();
functionFactory.inverseDistributionOrderedSetAggregates();
functionFactory.hypotheticalOrderedSetAggregates();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ ANY : [aA] [nN] [yY];
AS : [aA] [sS];
ASC : [aA] [sS] [cC];
AVG : [aA] [vV] [gG];
BY : [bB] [yY];
BETWEEN : [bB] [eE] [tT] [wW] [eE] [eE] [nN];
BOTH : [bB] [oO] [tT] [hH];
BY : [bB] [yY];
CASE : [cC] [aA] [sS] [eE];
CAST : [cC] [aA] [sS] [tT];
COLLATE : [cC] [oO] [lL] [lL] [aA] [tT] [eE];
Expand Down Expand Up @@ -176,19 +176,24 @@ ERROR : [eE] [rR] [rR] [oO] [rR];
ESCAPE : [eE] [sS] [cC] [aA] [pP] [eE];
EVERY : [eE] [vV] [eE] [rR] [yY];
EXCEPT : [eE] [xX] [cC] [eE] [pP] [tT];
EXCLUDE : [eE] [xX] [cC] [lL] [uU] [dD] [eE];
EXISTS : [eE] [xX] [iI] [sS] [tT] [sS];
EXTRACT : [eE] [xX] [tT] [rR] [aA] [cC] [tT];
FETCH : [fF] [eE] [tT] [cC] [hH];
FILTER : [fF] [iI] [lL] [tT] [eE] [rR];
FIRST : [fF] [iI] [rR] [sS] [tT];
FROM : [fF] [rR] [oO] [mM];
FOLLOWING : [fF] [oO] [lL] [lL] [oO] [wW] [iI] [nN] [gG];
FOR : [fF] [oO] [rR];
FORMAT : [fF] [oO] [rR] [mM] [aA] [tT];
FROM : [fF] [rR] [oO] [mM];
FULL : [fF] [uU] [lL] [lL];
FUNCTION : [fF] [uU] [nN] [cC] [tT] [iI] [oO] [nN];
GROUP : [gG] [rR] [oO] [uU] [pP];
GROUPS : [gG] [rR] [oO] [uU] [pP] [sS];
HAVING : [hH] [aA] [vV] [iI] [nN] [gG];
HOUR : [hH] [oO] [uU] [rR];
IGNORE : [iI] [gG] [nN] [oO] [rR] [eE];
ILIKE : [iI] [lL] [iI] [kK] [eE];
IN : [iI] [nN];
INDEX : [iI] [nN] [dD] [eE] [xX];
INDICES : [iI] [nN] [dD] [iI] [cC] [eE] [sS];
Expand All @@ -204,7 +209,6 @@ LAST : [lL] [aA] [sS] [tT];
LEADING : [lL] [eE] [aA] [dD] [iI] [nN] [gG];
LEFT : [lL] [eE] [fF] [tT];
LIKE : [lL] [iI] [kK] [eE];
ILIKE : [iI] [lL] [iI] [kK] [eE];
LIMIT : [lL] [iI] [mM] [iI] [tT];
LIST : [lL] [iI] [sS] [tT];
LISTAGG : [lL] [iI] [sS] [tT] [aA] [gG] [gG];
Expand All @@ -215,18 +219,19 @@ LOCAL_TIME : [lL] [oO] [cC] [aA] [lL] '_' [tT] [iI] [mM] [eE];
MAP : [mM] [aA] [pP];
MAX : [mM] [aA] [xX];
MAXELEMENT : [mM] [aA] [xX] [eE] [lL] [eE] [mM] [eE] [nN] [tT];
MIN : [mM] [iI] [nN];
MAXINDEX : [mM] [aA] [xX] [iI] [nN] [dD] [eE] [xX];
MEMBER : [mM] [eE] [mM] [bB] [eE] [rR];
MICROSECOND : [mM] [iI] [cC] [rR] [oO] [sS] [eE] [cC] [oO] [nN] [dD];
MILLISECOND : [mM] [iI] [lL] [lL] [iI] [sS] [eE] [cC] [oO] [nN] [dD];
MIN : [mM] [iI] [nN];
MINELEMENT : [mM] [iI] [nN] [eE] [lL] [eE] [mM] [eE] [nN] [tT];
MININDEX : [mM] [iI] [nN] [iI] [nN] [dD] [eE] [xX];
MINUTE : [mM] [iI] [nN] [uU] [tT] [eE];
MONTH : [mM] [oO] [nN] [tT] [hH];
NANOSECOND : [nN] [aA] [nN] [oO] [sS] [eE] [cC] [oO] [nN] [dD];
NEXT : [nN] [eE] [xX] [tT];
NEW : [nN] [eE] [wW];
NEXT : [nN] [eE] [xX] [tT];
NO : [nN] [oO];
NOT : [nN] [oO] [tT];
NULLS : [nN] [uU] [lL] [lL] [sS];
OBJECT : [oO] [bB] [jJ] [eE] [cC] [tT];
Expand All @@ -237,18 +242,24 @@ ON : [oO] [nN];
ONLY : [oO] [nN] [lL] [yY];
OR : [oO] [rR];
ORDER : [oO] [rR] [dD] [eE] [rR];
OTHERS : [oO] [tT] [hH] [eE] [rR] [sS];
OUTER : [oO] [uU] [tT] [eE] [rR];
OVER : [oO] [vV] [eE] [rR];
OVERFLOW : [oO] [vV] [eE] [rR] [fF] [lL] [oO] [wW];
OVERLAY : [oO] [vV] [eE] [rR] [lL] [aA] [yY];
PAD : [pP] [aA] [dD];
PARTITION : [pP] [aA] [rR] [tT] [iI] [tT] [iI] [oO] [nN];
PERCENT : [pP] [eE] [rR] [cC] [eE] [nN] [tT];
PLACING : [pP] [lL] [aA] [cC] [iI] [nN] [gG];
POSITION : [pP] [oO] [sS] [iI] [tT] [iI] [oO] [nN];
PRECEDING : [pP] [rR] [eE] [cC] [eE] [dD] [iI] [nN] [gG];
QUARTER : [qQ] [uU] [aA] [rR] [tT] [eE] [rR];
RANGE : [rR] [aA] [nN] [gG] [eE];
RESPECT : [rR] [eE] [sS] [pP] [eE] [cC] [tT];
RIGHT : [rR] [iI] [gG] [hH] [tT];
ROLLUP : [rR] [oO] [lL] [lL] [uU] [pP];
ROWS : [rR] [oO] [wW] [sS];
ROW : [rR] [oO] [wW];
ROWS : [rR] [oO] [wW] [sS];
SECOND : [sS] [eE] [cC] [oO] [nN] [dD];
SELECT : [sS] [eE] [lL] [eE] [cC] [tT];
SET : [sS] [eE] [tT];
Expand All @@ -267,6 +278,7 @@ TREAT : [tT] [rR] [eE] [aA] [tT];
TRIM : [tT] [rR] [iI] [mM];
TRUNCATE : [tT] [rR] [uU] [nN] [cC] [aA] [tT] [eE];
TYPE : [tT] [yY] [pP] [eE];
UNBOUNDED : [uU] [nN] [bB] [oO] [uU] [nN] [dD] [eE] [dD];
UNION : [uU] [nN] [iI] [oO] [nN];
UPDATE : [uU] [pP] [dD] [aA] [tT] [eE];
VALUE : [vV] [aA] [lL] [uU] [eE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ jpaNonstandardFunctionName
* The function name, followed by a parenthesized list of comma-separated expressions
*/
genericFunction
: genericFunctionName LEFT_PAREN (genericFunctionArguments | ASTERISK)? RIGHT_PAREN withinGroupClause? filterClause?
: genericFunctionName LEFT_PAREN (genericFunctionArguments | ASTERISK)? RIGHT_PAREN nthSideClause? nullsClause? withinGroupClause? filterClause? overClause?
;

/**
Expand Down Expand Up @@ -1052,7 +1052,7 @@ aggregateFunction
* The functions 'every()' and 'all()' are synonyms
*/
everyFunction
: (EVERY|ALL) LEFT_PAREN predicate RIGHT_PAREN filterClause?
: (EVERY|ALL) LEFT_PAREN predicate RIGHT_PAREN filterClause? overClause?
| (EVERY|ALL) LEFT_PAREN subquery RIGHT_PAREN
| (EVERY|ALL) (ELEMENTS|INDICES) LEFT_PAREN simplePath RIGHT_PAREN
;
Expand All @@ -1061,7 +1061,7 @@ everyFunction
* The functions 'any()' and 'some()' are synonyms
*/
anyFunction
: (ANY|SOME) LEFT_PAREN predicate RIGHT_PAREN filterClause?
: (ANY|SOME) LEFT_PAREN predicate RIGHT_PAREN filterClause? overClause?
| (ANY|SOME) LEFT_PAREN subquery RIGHT_PAREN
| (ANY|SOME) (ELEMENTS|INDICES) LEFT_PAREN simplePath RIGHT_PAREN
;
Expand All @@ -1070,7 +1070,7 @@ anyFunction
* The 'listagg()' ordered set-aggregate function
*/
listaggFunction
: LISTAGG LEFT_PAREN DISTINCT? expressionOrPredicate COMMA expressionOrPredicate onOverflowClause? RIGHT_PAREN withinGroupClause? filterClause?
: LISTAGG LEFT_PAREN DISTINCT? expressionOrPredicate COMMA expressionOrPredicate onOverflowClause? RIGHT_PAREN withinGroupClause? filterClause? overClause?
;

/**
Expand All @@ -1094,6 +1094,74 @@ filterClause
: FILTER LEFT_PAREN whereClause RIGHT_PAREN
;

/**
* A `nulls` clause: what should a value access window function do when encountering a `null`
*/
nullsClause
: RESPECT NULLS
| IGNORE NULLS
;

/**
* A `nulls` clause: what should a value access window function do when encountering a `null`
*/
nthSideClause
: FROM FIRST
| FROM LAST
;

/**
* A 'over' clause: the specification of a window within which the function should act
*/
overClause
: OVER LEFT_PAREN partitionClause? orderByClause? frameClause? RIGHT_PAREN
;

/**
* A 'partition' clause: the specification the group within which a function should act in a window
*/
partitionClause
: PARTITION BY expression (COMMA expression)*
;

/**
* A 'frame' clause: the specification the content of the window
*/
frameClause
: (RANGE|ROWS|GROUPS) frameStart frameExclusion?
| (RANGE|ROWS|GROUPS) BETWEEN frameStart AND frameEnd frameExclusion?
;

/**
* The start of the window content
*/
frameStart
: UNBOUNDED PRECEDING
| expression PRECEDING
| CURRENT ROW
| expression FOLLOWING
;

/**
* The end of the window content
*/
frameEnd
: expression PRECEDING
| CURRENT ROW
| expression FOLLOWING
| UNBOUNDED FOLLOWING
;

/**
* A 'exclusion' clause: the specification what to exclude from the window content
*/
frameExclusion
: EXCLUDE CURRENT ROW
| EXCLUDE GROUP
| EXCLUDE TIES
| EXCLUDE NO OTHERS
;

/**
* Any function with an irregular syntax for the argument list
*
Expand Down Expand Up @@ -1418,8 +1486,8 @@ identifier
| CURRENT_TIME
| CURRENT_TIMESTAMP
| DATE
| DAY
| DATETIME
| DAY
| DELETE
| DESC
| DISTINCT
Expand All @@ -1433,20 +1501,24 @@ identifier
| ESCAPE
| EVERY
| EXCEPT
| EXCLUDE
| EXISTS
| EXTRACT
| FETCH
| FILTER
| FIRST
| FOLLOWING
| FOR
| FORMAT
| FROM
| FULL
| FUNCTION
| GROUP
| GROUPS
| HAVING
| HOUR
| ID
| IGNORE
| ILIKE
| IN
| INDEX
Expand Down Expand Up @@ -1486,6 +1558,7 @@ identifier
| NATURALID
| NEW
| NEXT
| NO
| NOT
| NULLS
| OBJECT
Expand All @@ -1496,14 +1569,20 @@ identifier
| ONLY
| OR
| ORDER
| OTHERS
| OUTER
| OVER
| OVERFLOW
| OVERLAY
| PAD
| PARTITION
| PERCENT
| PLACING
| POSITION
| PRECEDING
| QUARTER
| RANGE
| RESPECT
| RIGHT
| ROLLUP
| ROW
Expand All @@ -1526,6 +1605,7 @@ identifier
| TRIM
| TRUNCATE
| TYPE
| UNBOUNDED
| UNION
| UPDATE
| VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {
functionFactory.everyAny_minMaxCase();
functionFactory.bitLength_pattern( "length(to_binary(?1))*8" );

functionFactory.windowFunctions();
functionFactory.listagg_stringAgg( "varchar" );
functionFactory.inverseDistributionOrderedSetAggregates();
functionFactory.hypotheticalOrderedSetAggregates_windowEmulation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {
.setArgumentsValidator( CommonFunctionFactory.formatValidator() )
.setArgumentListSignature("(TEMPORAL datetime as STRING pattern)")
.register();
functionFactory.windowFunctions();
functionFactory.listagg_stringAgg( "string" );
functionFactory.inverseDistributionOrderedSetAggregates();
functionFactory.hypotheticalOrderedSetAggregates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {
.setArgumentListSignature("(STRING string, STRING pattern)")
.register();

functionFactory.windowFunctions();
if ( getDB2Version().isSameOrAfter( 9, 5 ) ) {
functionFactory.listagg( null );
if ( getDB2Version().isSameOrAfter( 11, 1 ) ) {
Expand Down
Loading