From 9080a387fa88d72cf12e0d77350bb0543a9579f3 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 4 Jan 2023 18:02:22 +0100 Subject: [PATCH] Fix HANA test failures on CI --- .../org/hibernate/dialect/AbstractHANADialect.java | 1 + .../dialect/function/CommonFunctionFactory.java | 14 ++++++++++++++ ...ANASchemaMigrationTargetScriptCreationTest.java | 13 ++++++------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java index 954e2b2b12..3f4827f451 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java @@ -397,6 +397,7 @@ public abstract class AbstractHANADialect extends Dialect { functionFactory.cosh(); functionFactory.sinh(); functionFactory.tanh(); + functionFactory.trunc_roundMode(); functionFactory.log10_log(); functionFactory.log(); functionFactory.bitand(); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java index 199670b43e..2087f53215 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java @@ -362,6 +362,20 @@ public class CommonFunctionFactory { .register(); } + /** + * SAP HANA + */ + public void trunc_roundMode() { + functionRegistry.registerUnaryBinaryPattern( + "trunc", + "round(?1,0,round_down)", + "round(?1,?2,round_down)", + NUMERIC, INTEGER, + typeConfiguration + ).setArgumentListSignature( "(NUMERIC number[, INTEGER places])" ); + functionRegistry.registerAlternateKey( "truncate", "trunc" ); + } + /** * Returns double between 0.0 and 1.0. First call may specify a seed value. */ diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/HANASchemaMigrationTargetScriptCreationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/HANASchemaMigrationTargetScriptCreationTest.java index 1c58b818e9..59ff64586e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/HANASchemaMigrationTargetScriptCreationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/HANASchemaMigrationTargetScriptCreationTest.java @@ -101,8 +101,7 @@ public class HANASchemaMigrationTargetScriptCreationTest extends BaseCoreFunctio public void testTargetScriptIsCreatedStringTypeDefault() throws Exception { this.rebuildSessionFactory(); String fileContent = new String( Files.readAllBytes( this.output.toPath() ) ); - Pattern fileContentPattern = Pattern - .compile( "create( (column|row))? table test_entity \\(field " + this.varcharType + ".+, b boolean.+, c " + this.varcharType + ".+, lob " + this.clobType + ".+" ); + Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(b boolean[^,]+, c " + this.varcharType + "[^,]+, field " + this.varcharType + "[^,]+, lob " + this.clobType ); Matcher fileContentMatcher = fileContentPattern.matcher( fileContent.toLowerCase() ); assertThat( "Script file : " + fileContent.toLowerCase(), @@ -117,7 +116,7 @@ public class HANASchemaMigrationTargetScriptCreationTest extends BaseCoreFunctio config.setProperty( "hibernate.dialect.hana.use_unicode_string_types", "true" ); } ); String fileContent = new String( Files.readAllBytes( this.output.toPath() ) ); - Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(field nvarchar.+, b boolean.+, c nvarchar.+, lob nclob" ); + Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(b boolean[^,]+, c nvarchar[^,]+, field nvarchar[^,]+, lob nclob" ); Matcher fileContentMatcher = fileContentPattern.matcher( fileContent.toLowerCase() ); assertThat( "Script file : " + fileContent.toLowerCase(), @@ -132,7 +131,7 @@ public class HANASchemaMigrationTargetScriptCreationTest extends BaseCoreFunctio config.setProperty( "hibernate.dialect.hana.use_unicode_string_types", "false" ); } ); String fileContent = new String( Files.readAllBytes( this.output.toPath() ) ); - Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(field " + this.varcharType + ".+, b boolean.+, c " + this.varcharType + ".+, lob " + this.clobType ); + Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(b boolean[^,]+, c " + this.varcharType + "[^,]+, field " + this.varcharType + "[^,]+, lob " + this.clobType ); Matcher fileContentMatcher = fileContentPattern.matcher( fileContent.toLowerCase() ); assertThat( "Script file : " + fileContent.toLowerCase(), @@ -145,7 +144,7 @@ public class HANASchemaMigrationTargetScriptCreationTest extends BaseCoreFunctio public void testTargetScriptIsCreatedBooleanTypeDefault() throws Exception { this.rebuildSessionFactory(); String fileContent = new String( Files.readAllBytes( this.output.toPath() ) ); - Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(field " + this.varcharType + ".+, b boolean.+, c " + this.varcharType + ".+, lob " + this.clobType ); + Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(b boolean[^,]+, c " + this.varcharType + "[^,]+, field " + this.varcharType + "[^,]+, lob " + this.clobType ); Matcher fileContentMatcher = fileContentPattern.matcher( fileContent.toLowerCase() ); assertThat( "Script file : " + fileContent.toLowerCase(), @@ -160,7 +159,7 @@ public class HANASchemaMigrationTargetScriptCreationTest extends BaseCoreFunctio config.setProperty( "hibernate.dialect.hana.use_legacy_boolean_type", "true" ); } ); String fileContent = new String( Files.readAllBytes( this.output.toPath() ) ); - Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(field " + this.varcharType + ".+, b tinyint.+, c " + this.varcharType + ".+, lob " + this.clobType ); + Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(b tinyint[^,]+, c " + this.varcharType + "[^,]+, field " + this.varcharType + "[^,]+, lob " + this.clobType ); Matcher fileContentMatcher = fileContentPattern.matcher( fileContent.toLowerCase() ); assertThat( "Script file : " + fileContent.toLowerCase(), @@ -175,7 +174,7 @@ public class HANASchemaMigrationTargetScriptCreationTest extends BaseCoreFunctio config.setProperty( "hibernate.dialect.hana.use_legacy_boolean_type", "false" ); } ); String fileContent = new String( Files.readAllBytes( this.output.toPath() ) ); - Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(field " + this.varcharType + ".+, b boolean.+, c " + this.varcharType + ".+, lob " + this.clobType ); + Pattern fileContentPattern = Pattern.compile( "create( (column|row))? table test_entity \\(b boolean[^,]+, c " + this.varcharType + "[^,]+, field " + this.varcharType + "[^,]+, lob " + this.clobType ); Matcher fileContentMatcher = fileContentPattern.matcher( fileContent.toLowerCase() ); assertThat( "Script file : " + fileContent.toLowerCase(),