HHH-20262: Spanner PG: Fix Tests Phase 3#11991
HHH-20262: Spanner PG: Fix Tests Phase 3#11991sakthivelmanii wants to merge 1 commit intohibernate:mainfrom
Conversation
|
@beikov This is the last PR for Spanner PG dialect which fixes all the tests. |
| @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) | ||
| @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsUnnest.class) | ||
| @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJsonAggregate.class) | ||
| @SkipForDialect( dialectClass = SpannerPostgreSQLDialect.class, reason = "Spanner PG doesn't support LATERAL JOIN") |
There was a problem hiding this comment.
Since this seems to depend on json_table to work correctly, I would prefer to see this:
| @SkipForDialect( dialectClass = SpannerPostgreSQLDialect.class, reason = "Spanner PG doesn't support LATERAL JOIN") | |
| @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJsonTable.class) |
| } | ||
|
|
||
| @Test | ||
| @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsArrayPosition.class) |
There was a problem hiding this comment.
I would prefer if you add a new check that checks for definesFunction( dialect, "array_contains_nullable" ).
| @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsArrayPosition.class) | |
| @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsArrayContainsNullable.class) |
| } | ||
|
|
||
| @Test | ||
| @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsArrayPosition.class) |
There was a problem hiding this comment.
Again, I would prefer if you add a new check that checks for definesFunction( dialect, "array_contains_nullable" ).
| @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsArrayPosition.class) | |
| @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsArrayContainsNullable.class) |
| functionFactory.arrayConcat_postgresql(); | ||
| functionFactory.arrayPrepend_postgresql(); | ||
| functionFactory.arrayAppend_postgresql(); | ||
| functionFactory.arrayContains_postgresql(); |
There was a problem hiding this comment.
This is what I mean, i.e. don't register array_contains_nullable since you can't implement it.
| functionFactory.arrayContains_postgresql(); | |
| functionRegistry.register( "array_contains", new ArrayContainsOperatorFunction( false, typeConfiguration ) ); | |
| functionRegistry.register( "array_includes", new ArrayIncludesOperatorFunction( false, typeConfiguration ) ); | |
| functionRegistry.register( "array_includes_nullable", new ArrayIncludesOperatorFunction( true, typeConfiguration ) ); |
| .filter( collection -> Objects.nonNull( collection.getCollectionTable() ) ) | ||
| .filter( collection -> collection.getCollectionTable().equals( targetTable ) ) |
There was a problem hiding this comment.
| .filter( collection -> Objects.nonNull( collection.getCollectionTable() ) ) | |
| .filter( collection -> collection.getCollectionTable().equals( targetTable ) ) | |
| .filter( collection -> collection.getCollectionTable() == targetTable ) |
| return metadata.getCollectionBindings().stream() | ||
| .filter( collection -> Objects.nonNull( collection.getCollectionTable() ) ) | ||
| .filter( collection -> collection.getCollectionTable().equals( targetTable ) ) | ||
| .anyMatch( collection -> collection.getElement() instanceof SimpleValue ); |
There was a problem hiding this comment.
| .anyMatch( collection -> collection.getElement() instanceof SimpleValue ); | |
| .anyMatch( collection -> collection.getElement() instanceof SimpleValue && !( collection.getElement() instanceof ToOne )); |
| } | ||
|
|
||
| private boolean isHistoryOrAuditedTable(Table table) { | ||
| return table.getName().endsWith( "_history" ) || table.getName().endsWith( "_aud" ); |
There was a problem hiding this comment.
It seems to me that this is a safer way to check if a table is an audit table:
| return table.getName().endsWith( "_history" ) || table.getName().endsWith( "_aud" ); | |
| return metadata.getCollectionBindings().stream() | |
| .anyMatch( collection -> collection.getAuxiliaryTable() == targetTable ) | |
| || metadata.getEntityBindings().stream() | |
| .filter( entity -> entity instanceof RootClass ) | |
| .anyMatch( entity -> ((RootClass) entity).getAuxiliaryTable() == targetTable ); |
| sqlAppender.appendSql( "jsonb_strip_nulls(jsonb_build_array" ); | ||
| } | ||
| else { | ||
| sqlAppender.appendSql( "jsonb_build_array" ); | ||
| } | ||
|
|
||
| char separator = '('; | ||
| for ( int i = 0; i < argumentsCount; i++ ) { | ||
| sqlAppender.appendSql( separator ); | ||
| sqlAstArguments.get( i ).accept( walker ); | ||
| separator = ','; | ||
| } | ||
| sqlAppender.appendSql( ')' ); | ||
|
|
||
| if ( nullBehavior == JsonNullBehavior.ABSENT ) { | ||
| sqlAppender.appendSql( ')' ); |
There was a problem hiding this comment.
According to the documentation, jsonb_strip_nulls only works on object values, not array values, so you need this instead:
| sqlAppender.appendSql( "jsonb_strip_nulls(jsonb_build_array" ); | |
| } | |
| else { | |
| sqlAppender.appendSql( "jsonb_build_array" ); | |
| } | |
| char separator = '('; | |
| for ( int i = 0; i < argumentsCount; i++ ) { | |
| sqlAppender.appendSql( separator ); | |
| sqlAstArguments.get( i ).accept( walker ); | |
| separator = ','; | |
| } | |
| sqlAppender.appendSql( ')' ); | |
| if ( nullBehavior == JsonNullBehavior.ABSENT ) { | |
| sqlAppender.appendSql( ')' ); | |
| sqlAppender.appendSql( "jsonb_path_query_array(jsonb_build_array" ); | |
| } | |
| else { | |
| sqlAppender.appendSql( "jsonb_build_array" ); | |
| } | |
| char separator = '('; | |
| for ( int i = 0; i < argumentsCount; i++ ) { | |
| sqlAppender.appendSql( separator ); | |
| sqlAstArguments.get( i ).accept( walker ); | |
| separator = ','; | |
| } | |
| sqlAppender.appendSql( ')' ); | |
| if ( nullBehavior == JsonNullBehavior.ABSENT ) { | |
| sqlAppender.appendSql( ",'$[*] ? (@ != null)')" ); |
There was a problem hiding this comment.
Unfortunately, Spanner doesn't support jsonb_path_query_array.
| } | ||
|
|
||
| @Test | ||
| @SkipForDialect(dialectClass = org.hibernate.community.dialect.SpannerPostgreSQLDialect.class, reason = "Spanner PG does not support values in from clause") |
There was a problem hiding this comment.
After the fix I proposed to SpannerPostgreSQLJsonArrayFunction, you should be able to revert the changes to this file.
0d5c0a4 to
4c77282
Compare
[Please describe here what your change is about]
$related errorsBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
Please make sure that the following tasks are completed:
Tasks specific to HHH-20262 (Sub-task):
documentation/src/main/asciidoc/userguidefor all features,documentation/src/main/asciidoc/introductionfor main features, links from existing documentationmigration-guide.adoc(breaking changes) andwhats-new.adoc(new features/improvements)https://hibernate.atlassian.net/browse/HHH-20262