Skip to content

Commit eed6157

Browse files
committed
HHH-18497 Add xmlagg function
1 parent c1b3aa2 commit eed6157

File tree

25 files changed

+619
-2
lines changed

25 files changed

+619
-2
lines changed

documentation/src/main/asciidoc/userguide/chapters/query/hql/QueryLanguage.adoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,6 +2178,7 @@ it is necessary to enable the `hibernate.query.hql.xml_functions_enabled` config
21782178
| `xmlpi()` | Constructs an XML processing instruction
21792179
| `xmlquery()` | Extracts content from XML document using XQuery or XPath
21802180
| `xmlexists()` | Checks if an XQuery or XPath expression exists in an XML document
2181+
| `xmlagg()` | Aggregates XML elements by concatenation
21812182
|===
21822183
21832184
@@ -2350,6 +2351,30 @@ include::{xml-example-dir-hql}/XmlExistsTest.java[tags=hql-xmlexists-example]
23502351
23512352
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
23522353
2354+
[[hql-xmlagg-function]]
2355+
===== `xmlagg()`
2356+
2357+
Aggregates XML elements by concatenation.
2358+
2359+
[[hql-xmlexists-bnf]]
2360+
[source, antlrv4, indent=0]
2361+
----
2362+
include::{extrasdir}/xmlagg_bnf.txt[]
2363+
----
2364+
2365+
This aggregate function is similar to an <<hql-aggregate-functions-orderedset,_ordered set aggregate function_>>
2366+
since it allows to specify the order in which elements are aggregated, but uses a special syntax.
2367+
2368+
[[hql-xmlagg-example]]
2369+
====
2370+
[source, java, indent=0]
2371+
----
2372+
include::{xml-example-dir-hql}/XmlAggTest.java[tags=hql-xmlagg-example]
2373+
----
2374+
====
2375+
2376+
WARNING: SAP HANA, MySQL, MariaDB and HSQLDB do not support this function.
2377+
23532378
[[hql-user-defined-functions]]
23542379
==== Native and user-defined functions
23552380
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"xmlagg(" expression orderByClause? ")" filterClause? overClause?

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
448448
functionFactory.xmlpi();
449449
functionFactory.xmlquery_db2();
450450
functionFactory.xmlexists();
451+
functionFactory.xmlagg();
451452
}
452453

453454
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacyDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
333333
functionFactory.xmlpi();
334334
functionFactory.xmlquery_oracle();
335335
functionFactory.xmlexists();
336+
functionFactory.xmlagg();
336337
}
337338

338339
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
676676
functionFactory.xmlpi();
677677
functionFactory.xmlquery_postgresql();
678678
functionFactory.xmlexists();
679+
functionFactory.xmlagg();
679680

680681
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
681682
functionFactory.makeDateTimeTimestamp();

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
420420
functionFactory.xmlpi_sqlserver();
421421
functionFactory.xmlquery_sqlserver();
422422
functionFactory.xmlexists_sqlserver();
423+
functionFactory.xmlagg_sqlserver();
423424
if ( getVersion().isSameOrAfter( 14 ) ) {
424425
functionFactory.listagg_stringAggWithinGroup( "varchar(max)" );
425426
functionFactory.jsonArrayAgg_sqlserver( getVersion().isSameOrAfter( 16 ) );

hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlLexer.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ WITH : [wW] [iI] [tT] [hH];
330330
WITHIN : [wW] [iI] [tT] [hH] [iI] [nN];
331331
WITHOUT : [wW] [iI] [tT] [hH] [oO] [uU] [tT];
332332
WRAPPER : [wW] [rR] [aA] [pP] [pP] [eE] [rR];
333+
XMLAGG : [xX] [mM] [lL] [aA] [gG] [gG];
333334
XMLATTRIBUTES : [xX] [mM] [lL] [aA] [tT] [tT] [rR] [iI] [bB] [uU] [tT] [eE] [sS];
334335
XMLELEMENT : [xX] [mM] [lL] [eE] [lL] [eE] [mM] [eE] [nN] [tT];
335336
XMLEXISTS : [xX] [mM] [lL] [eE] [xX] [iI] [sS] [tT] [sS];

hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlParser.g4

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,7 @@ xmlFunction
17231723
| xmlpiFunction
17241724
| xmlqueryFunction
17251725
| xmlexistsFunction
1726+
| xmlaggFunction
17261727
;
17271728

17281729
/**
@@ -1767,6 +1768,13 @@ xmlexistsFunction
17671768
: XMLEXISTS LEFT_PAREN expression PASSING expression RIGHT_PAREN
17681769
;
17691770

1771+
/**
1772+
* The 'xmlexists()' function
1773+
*/
1774+
xmlaggFunction
1775+
: XMLAGG LEFT_PAREN expression orderByClause? RIGHT_PAREN filterClause? overClause?
1776+
;
1777+
17701778
/**
17711779
* Support for "soft" keywords which may be used as identifiers
17721780
*
@@ -1973,6 +1981,7 @@ xmlexistsFunction
19731981
| WITHIN
19741982
| WITHOUT
19751983
| WRAPPER
1984+
| XMLAGG
19761985
| XMLATTRIBUTES
19771986
| XMLELEMENT
19781987
| XMLEXISTS

hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
433433
functionFactory.xmlpi();
434434
functionFactory.xmlquery_db2();
435435
functionFactory.xmlexists();
436+
functionFactory.xmlagg();
436437
}
437438

438439
@Override

hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
423423
functionFactory.xmlpi();
424424
functionFactory.xmlquery_oracle();
425425
functionFactory.xmlexists();
426+
functionFactory.xmlagg();
426427
}
427428

428429
@Override

0 commit comments

Comments
 (0)