Skip to content

Commit bfb9fcc

Browse files
committed
HHH-17355 Unify array_contains and array_contains_all as well as deprecate FunctionRenderingSupport in favor of new FunctionRenderer contract
1 parent 5506714 commit bfb9fcc

File tree

144 files changed

+1616
-1240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+1616
-1240
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ The result of `array_contains` is undefined when the second argument is an array
12331233
====
12341234
[source, JAVA, indent=0]
12351235
----
1236-
include::{array-example-dir-hql}/ArrayContainsAllTest.java[tags=hql-array-contains-all-example]
1236+
include::{array-example-dir-hql}/ArrayContainsArrayTest.java[tags=hql-array-contains-array-example]
12371237
----
12381238
====
12391239
@@ -1243,7 +1243,7 @@ To search for `null` elements, the `array_contains_nullable` function must be us
12431243
====
12441244
[source, JAVA, indent=0]
12451245
----
1246-
include::{array-example-dir-hql}/ArrayContainsAllTest.java[tags=hql-array-contains-all-nullable-example]
1246+
include::{array-example-dir-hql}/ArrayContainsArrayTest.java[tags=hql-array-contains-array-nullable-example]
12471247
----
12481248
====
12491249

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,15 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
461461
functionFactory.listagg_stringAgg( "string" );
462462
functionFactory.inverseDistributionOrderedSetAggregates();
463463
functionFactory.hypotheticalOrderedSetAggregates_windowEmulation();
464-
functionFactory.array_casting();
464+
functionFactory.array_postgresql();
465465
functionFactory.arrayAggregate();
466-
functionFactory.arrayContains_operator();
467-
functionFactory.arrayContainsNull_array_position();
468466
functionFactory.arrayPosition_postgresql();
469467
functionFactory.arrayLength_cardinality();
470468
functionFactory.arrayConcat_postgresql();
471469
functionFactory.arrayPrepend_postgresql();
472470
functionFactory.arrayAppend_postgresql();
473-
functionFactory.arrayContainsAll_operator();
474-
functionFactory.arrayOverlaps_operator();
475-
functionFactory.arrayContainsAllNullable_operator();
476-
functionFactory.arrayOverlapsNullable_unnest();
471+
functionFactory.arrayContains_postgresql();
472+
functionFactory.arrayOverlaps_postgresql();
477473
functionFactory.arrayGet_bracket();
478474
functionFactory.arraySet_unnest();
479475
functionFactory.arrayRemove();

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,22 +372,18 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
372372
functionFactory.listagg( null );
373373
functionFactory.array();
374374
functionFactory.arrayAggregate();
375-
functionFactory.arrayContains();
376-
functionFactory.arrayContainsNull();
377375
functionFactory.arrayLength_cardinality();
378376
functionFactory.arrayConcat_operator();
379377
functionFactory.arrayPrepend_operator();
380378
functionFactory.arrayAppend_operator();
381-
functionFactory.arrayContainsAll_h2();
382-
functionFactory.arrayOverlaps_h2();
383-
functionFactory.arrayContainsAllNullable_h2();
384-
functionFactory.arrayOverlapsNullable_h2();
379+
functionFactory.arrayContains_h2( getMaximumArraySize() );
380+
functionFactory.arrayOverlaps_h2( getMaximumArraySize() );
385381
functionFactory.arrayGet_h2();
386-
functionFactory.arraySet_h2();
387-
functionFactory.arrayRemove_h2();
388-
functionFactory.arrayRemoveIndex_h2();
382+
functionFactory.arraySet_h2( getMaximumArraySize() );
383+
functionFactory.arrayRemove_h2( getMaximumArraySize() );
384+
functionFactory.arrayRemoveIndex_h2( getMaximumArraySize() );
389385
functionFactory.arraySlice();
390-
functionFactory.arrayReplace_h2();
386+
functionFactory.arrayReplace_h2( getMaximumArraySize() );
391387
}
392388
else {
393389
// Use group_concat until 2.x as listagg was buggy
@@ -399,6 +395,16 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
399395
}
400396
}
401397

398+
/**
399+
* H2 requires a very special emulation, because {@code unnest} is pretty much useless,
400+
* due to https://github.com/h2database/h2database/issues/1815.
401+
* This emulation uses {@code array_get}, {@code array_length} and {@code system_range} functions to roughly achieve the same,
402+
* but requires that {@code system_range} is fed with a "maximum array size".
403+
*/
404+
protected int getMaximumArraySize() {
405+
return 1000;
406+
}
407+
402408
@Override
403409
public void augmentPhysicalTableTypes(List<String> tableTypesList) {
404410
if ( getVersion().isSameOrAfter( 2 ) ) {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,15 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
247247
functionFactory.rownum();
248248
}
249249
functionFactory.listagg_groupConcat();
250-
functionFactory.array();
250+
functionFactory.array_hsql();
251251
functionFactory.arrayAggregate();
252-
functionFactory.arrayContains_hsql();
253-
functionFactory.arrayContainsNull_hsql();
254252
functionFactory.arrayPosition_hsql();
255253
functionFactory.arrayLength_cardinality();
256254
functionFactory.arrayConcat_operator();
257255
functionFactory.arrayPrepend_operator();
258256
functionFactory.arrayAppend_operator();
259-
functionFactory.arrayContainsAll_hsql();
257+
functionFactory.arrayContains_hsql();
260258
functionFactory.arrayOverlaps_hsql();
261-
functionFactory.arrayContainsAllNullable_hsql();
262-
functionFactory.arrayOverlapsNullable_unnest();
263259
functionFactory.arrayGet_unnest();
264260
functionFactory.arraySet_hsql();
265261
functionFactory.arrayRemove_hsql();

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,13 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
285285

286286
functionFactory.array_oracle();
287287
functionFactory.arrayAggregate_jsonArrayagg();
288-
functionFactory.arrayContains_oracle();
289-
functionFactory.arrayContainsNull_oracle();
290288
functionFactory.arrayPosition_oracle();
291289
functionFactory.arrayLength_oracle();
292290
functionFactory.arrayConcat_oracle();
293291
functionFactory.arrayPrepend_oracle();
294292
functionFactory.arrayAppend_oracle();
295-
functionFactory.arrayContainsAll_oracle();
293+
functionFactory.arrayContains_oracle();
296294
functionFactory.arrayOverlaps_oracle();
297-
functionFactory.arrayContainsAllNullable_oracle();
298-
functionFactory.arrayOverlapsNullable_oracle();
299295
functionFactory.arrayGet_oracle();
300296
functionFactory.arraySet_oracle();
301297
functionFactory.arrayRemove_oracle();

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,19 +581,15 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
581581
functionFactory.locate_positionSubstring();
582582
functionFactory.windowFunctions();
583583
functionFactory.listagg_stringAgg( "varchar" );
584-
functionFactory.array_casting();
584+
functionFactory.array_postgresql();
585585
functionFactory.arrayAggregate();
586-
functionFactory.arrayContains_operator();
587-
functionFactory.arrayContainsNull_array_position();
588586
functionFactory.arrayPosition_postgresql();
589587
functionFactory.arrayLength_cardinality();
590588
functionFactory.arrayConcat_postgresql();
591589
functionFactory.arrayPrepend_postgresql();
592590
functionFactory.arrayAppend_postgresql();
593-
functionFactory.arrayContainsAll_operator();
594-
functionFactory.arrayOverlaps_operator();
595-
functionFactory.arrayContainsAllNullable_operator();
596-
functionFactory.arrayOverlapsNullable_unnest();
591+
functionFactory.arrayContains_postgresql();
592+
functionFactory.arrayOverlaps_postgresql();
597593
functionFactory.arrayGet_bracket();
598594
functionFactory.arraySet_unnest();
599595
functionFactory.arrayRemove();

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,19 +448,15 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
448448
functionFactory.listagg_stringAgg( "string" );
449449
functionFactory.inverseDistributionOrderedSetAggregates();
450450
functionFactory.hypotheticalOrderedSetAggregates_windowEmulation();
451-
functionFactory.array_casting();
451+
functionFactory.array_postgresql();
452452
functionFactory.arrayAggregate();
453-
functionFactory.arrayContains_operator();
454-
functionFactory.arrayContainsNull_array_position();
455453
functionFactory.arrayPosition_postgresql();
456454
functionFactory.arrayLength_cardinality();
457455
functionFactory.arrayConcat_postgresql();
458456
functionFactory.arrayPrepend_postgresql();
459457
functionFactory.arrayAppend_postgresql();
460-
functionFactory.arrayContainsAll_operator();
461-
functionFactory.arrayOverlaps_operator();
462-
functionFactory.arrayContainsAllNullable_operator();
463-
functionFactory.arrayOverlapsNullable_unnest();
458+
functionFactory.arrayContains_postgresql();
459+
functionFactory.arrayOverlaps_postgresql();
464460
functionFactory.arrayGet_bracket();
465461
functionFactory.arraySet_unnest();
466462
functionFactory.arrayRemove();

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,22 +311,28 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
311311
functionFactory.hypotheticalOrderedSetAggregates();
312312
functionFactory.array();
313313
functionFactory.arrayAggregate();
314-
functionFactory.arrayContains();
315-
functionFactory.arrayContainsNull();
316314
functionFactory.arrayLength_cardinality();
317315
functionFactory.arrayConcat_operator();
318316
functionFactory.arrayPrepend_operator();
319317
functionFactory.arrayAppend_operator();
320-
functionFactory.arrayContainsAll_h2();
321-
functionFactory.arrayOverlaps_h2();
322-
functionFactory.arrayContainsAllNullable_h2();
323-
functionFactory.arrayOverlapsNullable_h2();
318+
functionFactory.arrayContains_h2( getMaximumArraySize() );
319+
functionFactory.arrayOverlaps_h2( getMaximumArraySize() );
324320
functionFactory.arrayGet_h2();
325-
functionFactory.arraySet_h2();
326-
functionFactory.arrayRemove_h2();
327-
functionFactory.arrayRemoveIndex_h2();
321+
functionFactory.arraySet_h2( getMaximumArraySize() );
322+
functionFactory.arrayRemove_h2( getMaximumArraySize() );
323+
functionFactory.arrayRemoveIndex_h2( getMaximumArraySize() );
328324
functionFactory.arraySlice();
329-
functionFactory.arrayReplace_h2();
325+
functionFactory.arrayReplace_h2( getMaximumArraySize() );
326+
}
327+
328+
/**
329+
* H2 requires a very special emulation, because {@code unnest} is pretty much useless,
330+
* due to https://github.com/h2database/h2database/issues/1815.
331+
* This emulation uses {@code array_get}, {@code array_length} and {@code system_range} functions to roughly achieve the same,
332+
* but requires that {@code system_range} is fed with a "maximum array size".
333+
*/
334+
protected int getMaximumArraySize() {
335+
return 1000;
330336
}
331337

332338
@Override

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,15 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
187187
// from v. 2.2.0 ROWNUM() is supported in all modes as the equivalent of Oracle ROWNUM
188188
functionFactory.rownum();
189189
functionFactory.listagg_groupConcat();
190-
functionFactory.array();
190+
functionFactory.array_hsql();
191191
functionFactory.arrayAggregate();
192-
functionFactory.arrayContains_hsql();
193-
functionFactory.arrayContainsNull_hsql();
194192
functionFactory.arrayPosition_hsql();
195193
functionFactory.arrayLength_cardinality();
196194
functionFactory.arrayConcat_operator();
197195
functionFactory.arrayPrepend_operator();
198196
functionFactory.arrayAppend_operator();
199-
functionFactory.arrayContainsAll_hsql();
197+
functionFactory.arrayContains_hsql();
200198
functionFactory.arrayOverlaps_hsql();
201-
functionFactory.arrayContainsAllNullable_hsql();
202-
functionFactory.arrayOverlapsNullable_unnest();
203199
functionFactory.arrayGet_unnest();
204200
functionFactory.arraySet_hsql();
205201
functionFactory.arrayRemove_hsql();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ public void addAuxiliaryDatabaseObjects(
284284
);
285285
database.addAuxiliaryDatabaseObject(
286286
new NamedAuxiliaryDatabaseObject(
287-
arrayTypeName + "_contains_all",
287+
arrayTypeName + "_contains",
288288
database.getDefaultNamespace(),
289289
new String[]{
290-
"create or replace function " + arrayTypeName + "_contains_all(haystack in " + arrayTypeName +
290+
"create or replace function " + arrayTypeName + "_contains(haystack in " + arrayTypeName +
291291
", needle in " + arrayTypeName + ", nullable in number) return number deterministic is found number(1,0); begin " +
292292
"if haystack is null or needle is null then return null; end if; " +
293293
"for i in 1 .. needle.count loop " +
@@ -300,7 +300,7 @@ public void addAuxiliaryDatabaseObjects(
300300
"return 1; " +
301301
"end;"
302302
},
303-
new String[] { "drop function " + arrayTypeName + "_contains_all" },
303+
new String[] { "drop function " + arrayTypeName + "_contains" },
304304
emptySet(),
305305
false
306306
)

0 commit comments

Comments
 (0)