Skip to content

Commit 2f8e52d

Browse files
committed
[HHH-19365]Hyperbolic functions
1 parent f9ffd5a commit 2f8e52d

File tree

6 files changed

+42
-42
lines changed

6 files changed

+42
-42
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,6 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
520520
functionFactory.degrees();
521521
functionFactory.log();
522522
functionFactory.mod_operator();
523-
functionFactory.log10();
524-
functionFactory.tanh();
525-
functionFactory.sinh();
526-
functionFactory.cosh();
527523
functionFactory.moreHyperbolic();
528524
functionFactory.cbrt();
529525
functionFactory.pi();

hibernate-core/src/main/java/org/hibernate/dialect/function/json/GaussDBJsonQueryFunction.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.Map;
1818

1919
/**
20-
* PostgreSQL json_query function.
20+
* GaussDB json_query function.
2121
*/
2222
public class GaussDBJsonQueryFunction extends JsonQueryFunction {
2323

@@ -44,11 +44,13 @@ protected void render(
4444
final Map<String, Expression> passingExpressions = passingClause.getPassingExpressions();
4545
final Iterator<Map.Entry<String, Expression>> iterator = passingExpressions.entrySet().iterator();
4646
Map.Entry<String, Expression> entry = iterator.next();
47-
literalValue = literalValue.replace( "$"+entry.getKey(), walker.getLiteralValue( entry.getValue()).toString() );
47+
literalValue = literalValue.replace( "$" + entry.getKey(),
48+
walker.getLiteralValue( entry.getValue() ).toString() );
4849
while ( iterator.hasNext() ) {
4950
entry = iterator.next();
5051
sqlAppender.appendSql( ',' );
51-
literalValue = literalValue.replace( "$"+entry.getKey(), walker.getLiteralValue( entry.getValue()).toString() );
52+
literalValue = literalValue.replace( "$" + entry.getKey(),
53+
walker.getLiteralValue( entry.getValue() ).toString() );
5254
}
5355
}
5456

hibernate-core/src/main/java/org/hibernate/dialect/function/json/GaussDBJsonValueFunction.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected void render(
3636
ReturnableType<?> returnType,
3737
SqlAstTranslator<?> walker) {
3838

39-
if (arguments.returningType() != null) {
39+
if ( arguments.returningType() != null ) {
4040
sqlAppender.appendSql( "(" );
4141
}
4242
arguments.jsonDocument().accept( walker );
@@ -48,17 +48,19 @@ protected void render(
4848
final Map<String, Expression> passingExpressions = passingClause.getPassingExpressions();
4949
final Iterator<Map.Entry<String, Expression>> iterator = passingExpressions.entrySet().iterator();
5050
Map.Entry<String, Expression> entry = iterator.next();
51-
literalValue = literalValue.replace( "$"+entry.getKey(), walker.getLiteralValue( entry.getValue()).toString() );
51+
literalValue = literalValue.replace( "$" + entry.getKey(),
52+
walker.getLiteralValue( entry.getValue() ).toString() );
5253
while ( iterator.hasNext() ) {
5354
entry = iterator.next();
5455
sqlAppender.appendSql( ',' );
55-
literalValue = literalValue.replace( "$"+entry.getKey(), walker.getLiteralValue( entry.getValue()).toString() );
56+
literalValue = literalValue.replace( "$" + entry.getKey(),
57+
walker.getLiteralValue( entry.getValue() ).toString() );
5658
}
5759
}
5860

5961
sqlAppender.append( JsonHelper.parseJsonPath( literalValue ) );
6062
sqlAppender.appendSql( "}'" );
61-
if (arguments.returningType() != null) {
63+
if ( arguments.returningType() != null ) {
6264
sqlAppender.appendSql( ")::" );
6365
arguments.returningType().accept( walker );
6466
}

hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JsonHelper.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,33 @@ public static String arrayToString(
9898
return sb.toString();
9999
}
100100

101+
public static String parseJsonPath(String path) {
102+
if (path == null || !path.startsWith("$")) {
103+
throw new IllegalArgumentException("Invalid JSON path");
104+
}
105+
106+
List<String> result = new ArrayList<>();
107+
String[] parts = path.substring(1).split("\\.");
108+
109+
for (String part : parts) {
110+
while (part.contains("[")) {
111+
int start = part.indexOf("[");
112+
int end = part.indexOf("]", start);
113+
if (end == -1) {
114+
throw new IllegalArgumentException("Invalid JSON path format");
115+
}
116+
result.add(part.substring(0, start));
117+
result.add(part.substring(start + 1, end));
118+
part = part.substring(end + 1);
119+
}
120+
if (!part.isEmpty()) {
121+
result.add(part);
122+
}
123+
}
124+
125+
return String.join(",", result);
126+
}
127+
101128
private static void toString(EmbeddableMappingType embeddableMappingType, Object value, WrapperOptions options, JsonAppender appender) {
102129
toString( embeddableMappingType, options, appender, value, '{' );
103130
appender.append( '}' );
@@ -1626,30 +1653,4 @@ public <T> T[] toArray(T[] a) {
16261653
}
16271654
}
16281655

1629-
public static String parseJsonPath(String path) {
1630-
if (path == null || !path.startsWith("$")) {
1631-
throw new IllegalArgumentException("Invalid JSON path");
1632-
}
1633-
1634-
List<String> result = new ArrayList<>();
1635-
String[] parts = path.substring(1).split("\\.");
1636-
1637-
for (String part : parts) {
1638-
while (part.contains("[")) {
1639-
int start = part.indexOf("[");
1640-
int end = part.indexOf("]", start);
1641-
if (end == -1) {
1642-
throw new IllegalArgumentException("Invalid JSON path format");
1643-
}
1644-
result.add(part.substring(0, start));
1645-
result.add(part.substring(start + 1, end));
1646-
part = part.substring(end + 1);
1647-
}
1648-
if (!part.isEmpty()) {
1649-
result.add(part);
1650-
}
1651-
}
1652-
1653-
return String.join(",", result);
1654-
}
16551656
}

hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ public void testCastFunction(SessionFactoryScope scope) {
10211021
assertThat( session.createQuery("select cast('1911-10-09' as Date)", Date.class).getSingleResult(), instanceOf(Date.class) );
10221022
assertThat( session.createQuery("select cast('1911-10-09 12:13:14.123' as Timestamp)", Timestamp.class).getSingleResult(), instanceOf(Timestamp.class) );
10231023

1024-
assertThat( session.createQuery("select cast(date 1911-10-09 as String)", String.class).getSingleResult(), is("1911-10-09") );
1024+
assertThat( session.createQuery("select cast(date 1911-10-09 as String)", String.class).getSingleResult(), anyOf( is("1911-10-09"), is("1911-10-09 00:00:00") ) );
10251025
assertThat( session.createQuery("select cast(time 12:13:14 as String)", String.class).getSingleResult(), anyOf( is("12:13:14"), is("12:13:14.0000"), is("12.13.14") ) );
10261026
assertThat( session.createQuery("select cast(datetime 1911-10-09 12:13:14 as String)", String.class).getSingleResult(), anyOf( startsWith("1911-10-09 12:13:14"), startsWith("1911-10-09-12.13.14") ) );
10271027

@@ -1222,7 +1222,8 @@ public void testStrFunction(SessionFactoryScope scope) {
12221222
session.createQuery("select str(e.id), str(e.theInt), str(e.theDouble) from EntityOfBasics e", Object[].class)
12231223
.list();
12241224
assertThat( session.createQuery("select str(69)", String.class).getSingleResult(), is("69") );
1225-
assertThat( session.createQuery("select str(date 1911-10-09)", String.class).getSingleResult(), is("1911-10-09") );
1225+
// str() do not specify the standard of date & time format
1226+
assertThat( session.createQuery("select str(date 1911-10-09)", String.class).getSingleResult(), anyOf( is("1911-10-09"), is( "1911-10-09 00:00:00" ) ) );
12261227
assertThat( session.createQuery("select str(time 12:13:14)", String.class).getSingleResult(), anyOf( is( "12:13:14"), is( "12:13:14.0000"), is( "12.13.14") ) );
12271228
}
12281229
);
@@ -2288,7 +2289,6 @@ public void testExtractFunctionWithAssertions(SessionFactoryScope scope) {
22882289

22892290
@Test
22902291
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsFormat.class)
2291-
@SkipForDialect( dialectClass = GaussDBDialect.class, reason = "maybe concurrency")
22922292
public void testFormat(SessionFactoryScope scope) {
22932293
scope.inTransaction(
22942294
session -> {
@@ -2323,7 +2323,6 @@ public void testFormatTime(SessionFactoryScope scope) {
23232323

23242324
@Test
23252325
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsMedian.class)
2326-
@SkipForDialect( dialectClass = GaussDBDialect.class, reason = "maybe concurrency")
23272326
public void testMedian(SessionFactoryScope scope) {
23282327
scope.inTransaction(
23292328
session -> {
@@ -2345,7 +2344,6 @@ public void testMedian(SessionFactoryScope scope) {
23452344
}
23462345

23472346
@Test
2348-
@SkipForDialect( dialectClass = GaussDBDialect.class, reason = "type:resolved.Function sinh(double precision) does not exist.")
23492347
public void testHyperbolic(SessionFactoryScope scope) {
23502348
scope.inTransaction(
23512349
session -> {

hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ public boolean apply(Dialect dialect) {
535535
|| dialect instanceof SybaseDialect
536536
|| dialect instanceof DerbyDialect
537537
|| dialect instanceof FirebirdDialect
538+
|| dialect instanceof GaussDBDialect
538539
|| dialect instanceof DB2Dialect && ( (DB2Dialect) dialect ).getDB2Version().isBefore( 11 ) );
539540
}
540541
}

0 commit comments

Comments
 (0)