Skip to content

Commit 8dfc2a5

Browse files
committed
HHH-18604 Add json_array_append function
1 parent 4a6c555 commit 8dfc2a5

File tree

22 files changed

+477
-0
lines changed

22 files changed

+477
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,7 @@ it is necessary to enable the `hibernate.query.hql.json_functions_enabled` confi
16421642
| `json_set()` | Inserts/Replaces a value by JSON path within a JSON document
16431643
| `json_remove()` | Removes a value by JSON path within a JSON document
16441644
| `json_mergepatch()` | Merges JSON documents by performing an https://tools.ietf.org/html/rfc7396[RFC 7396] compliant merge
1645+
| `json_array_append()` | Appends to a JSON array of a JSON document by JSON path
16451646
|===
16461647
16471648
@@ -2113,6 +2114,26 @@ include::{json-example-dir-hql}/JsonMergepatchTest.java[tags=hql-json-mergepatch
21132114
21142115
WARNING: SAP HANA, DB2, SQL Server, H2 and HSQLDB do not support this function. On PostgreSQL, this function is emulated.
21152116
2117+
[[hql-json-array-append-function]]
2118+
===== `json_array_append()`
2119+
2120+
Appends a value by JSON path to a JSON array within a JSON document.
2121+
The function takes 3 arguments, the json document, the json path and the value to append.
2122+
2123+
If the value within the JSON document as identified by the JSON path is not a JSON array,
2124+
it is auto-wrapped into an array.
2125+
When no value exists for a JSON path, the document is not changed.
2126+
2127+
[[hql-json-array-append-example]]
2128+
====
2129+
[source, java, indent=0]
2130+
----
2131+
include::{json-example-dir-hql}/JsonArrayAppendTest.java[tags=hql-json-array-append-example]
2132+
----
2133+
====
2134+
2135+
WARNING: SAP HANA, DB2, H2 and HSQLDB do not support this function.
2136+
21162137
[[hql-user-defined-functions]]
21172138
==== Native and user-defined functions
21182139

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
513513
functionFactory.jsonReplace_postgresql();
514514
functionFactory.jsonInsert_postgresql();
515515
functionFactory.jsonMergepatch_postgresql();
516+
functionFactory.jsonArrayAppend_postgresql();
516517

517518
// Postgres uses # instead of ^ for XOR
518519
functionContributions.getFunctionRegistry().patternDescriptorBuilder( "bitxor", "(?1#?2)" )

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
9595
commonFunctionFactory.jsonQuery_mariadb();
9696
commonFunctionFactory.jsonArrayAgg_mariadb();
9797
commonFunctionFactory.jsonObjectAgg_mariadb();
98+
commonFunctionFactory.jsonArrayAppend_mariadb();
9899
if ( getVersion().isSameOrAfter( 10, 3, 3 ) ) {
99100
commonFunctionFactory.inverseDistributionOrderedSetAggregates_windowEmulation();
100101
functionContributions.getFunctionRegistry().patternDescriptorBuilder( "median", "median(?1) over ()" )

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
665665
functionFactory.jsonReplace_mysql();
666666
functionFactory.jsonInsert_mysql();
667667
functionFactory.jsonMergepatch_mysql();
668+
functionFactory.jsonArrayAppend_mysql();
668669
}
669670
}
670671

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
@@ -322,6 +322,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
322322
functionFactory.jsonReplace_oracle();
323323
functionFactory.jsonInsert_oracle();
324324
functionFactory.jsonMergepatch_oracle();
325+
functionFactory.jsonArrayAppend_oracle();
325326
}
326327
}
327328

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
@@ -663,6 +663,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
663663
functionFactory.jsonReplace_postgresql();
664664
functionFactory.jsonInsert_postgresql();
665665
functionFactory.jsonMergepatch_postgresql();
666+
functionFactory.jsonArrayAppend_postgresql();
666667

667668
if ( getVersion().isSameOrAfter( 9, 4 ) ) {
668669
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
@@ -410,6 +410,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
410410
functionFactory.jsonRemove_sqlserver();
411411
functionFactory.jsonReplace_sqlserver();
412412
functionFactory.jsonInsert_sqlserver();
413+
functionFactory.jsonArrayAppend_sqlserver();
413414
}
414415
if ( getVersion().isSameOrAfter( 14 ) ) {
415416
functionFactory.listagg_stringAggWithinGroup( "varchar(max)" );

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
480480
functionFactory.jsonReplace_postgresql();
481481
functionFactory.jsonInsert_postgresql();
482482
functionFactory.jsonMergepatch_postgresql();
483+
functionFactory.jsonArrayAppend_postgresql();
483484

484485
// Postgres uses # instead of ^ for XOR
485486
functionContributions.getFunctionRegistry().patternDescriptorBuilder( "bitxor", "(?1#?2)" )

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
9898
commonFunctionFactory.jsonQuery_mariadb();
9999
commonFunctionFactory.jsonArrayAgg_mariadb();
100100
commonFunctionFactory.jsonObjectAgg_mariadb();
101+
commonFunctionFactory.jsonArrayAppend_mariadb();
101102
commonFunctionFactory.inverseDistributionOrderedSetAggregates_windowEmulation();
102103
functionContributions.getFunctionRegistry().patternDescriptorBuilder( "median", "median(?1) over ()" )
103104
.setInvariantType( functionContributions.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.DOUBLE ) )

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
650650
functionFactory.jsonReplace_mysql();
651651
functionFactory.jsonInsert_mysql();
652652
functionFactory.jsonMergepatch_mysql();
653+
functionFactory.jsonArrayAppend_mysql();
653654
}
654655

655656
@Override

0 commit comments

Comments
 (0)