25
25
import org .hibernate .boot .model .relational .Exportable ;
26
26
import org .hibernate .boot .model .relational .Sequence ;
27
27
import org .hibernate .boot .model .relational .SqlStringGenerationContext ;
28
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonArrayAggFunction ;
29
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonArrayAppendFunction ;
30
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonArrayFunction ;
31
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonArrayInsertFunction ;
32
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonExistsFunction ;
33
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonMergepatchFunction ;
34
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonObjectAggFunction ;
35
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonObjectFunction ;
36
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonQueryFunction ;
37
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonRemoveFunction ;
38
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonSetFunction ;
39
+ import org .hibernate .community .dialect .function .json .SingleStoreJsonValueFunction ;
28
40
import org .hibernate .dialect .DatabaseVersion ;
29
41
import org .hibernate .dialect .Dialect ;
30
42
import org .hibernate .dialect .DmlTargetColumnQualifierSupport ;
65
77
import org .hibernate .mapping .UniqueKey ;
66
78
import org .hibernate .metamodel .mapping .EntityMappingType ;
67
79
import org .hibernate .metamodel .spi .RuntimeModelCreationContext ;
80
+ import org .hibernate .query .common .TemporalUnit ;
68
81
import org .hibernate .query .sqm .CastType ;
69
82
import org .hibernate .query .sqm .IntervalType ;
70
- import org .hibernate .query .common .TemporalUnit ;
71
83
import org .hibernate .query .sqm .function .SqmFunctionRegistry ;
72
- import org .hibernate .query .sqm .mutation .spi .AfterUseAction ;
73
- import org .hibernate .query .sqm .mutation .spi .BeforeUseAction ;
74
84
import org .hibernate .query .sqm .mutation .internal .temptable .LocalTemporaryTableInsertStrategy ;
75
85
import org .hibernate .query .sqm .mutation .internal .temptable .LocalTemporaryTableMutationStrategy ;
86
+ import org .hibernate .query .sqm .mutation .spi .AfterUseAction ;
87
+ import org .hibernate .query .sqm .mutation .spi .BeforeUseAction ;
76
88
import org .hibernate .query .sqm .mutation .spi .SqmMultiTableInsertStrategy ;
77
89
import org .hibernate .query .sqm .mutation .spi .SqmMultiTableMutationStrategy ;
78
90
import org .hibernate .query .sqm .produce .function .FunctionParameterType ;
84
96
import org .hibernate .sql .ast .tree .Statement ;
85
97
import org .hibernate .sql .exec .spi .JdbcOperation ;
86
98
import org .hibernate .tool .schema .spi .Exporter ;
87
- import org .hibernate .type .BasicType ;
88
99
import org .hibernate .type .BasicTypeRegistry ;
89
100
import org .hibernate .type .NullType ;
90
101
import org .hibernate .type .SqlTypes ;
100
111
import org .hibernate .type .descriptor .sql .internal .NativeEnumDdlTypeImpl ;
101
112
import org .hibernate .type .descriptor .sql .internal .NativeOrdinalEnumDdlTypeImpl ;
102
113
import org .hibernate .type .descriptor .sql .spi .DdlTypeRegistry ;
114
+ import org .hibernate .type .spi .TypeConfiguration ;
103
115
104
116
import jakarta .persistence .TemporalType ;
105
117
106
118
import static org .hibernate .exception .spi .TemplatedViolatedConstraintNameExtractor .extractUsingTemplate ;
107
- import static org .hibernate .query .sqm .produce .function .FunctionParameterType .ANY ;
108
119
import static org .hibernate .query .sqm .produce .function .FunctionParameterType .NUMERIC ;
109
- import static org .hibernate .query .sqm .produce .function .FunctionParameterType .STRING ;
110
120
import static org .hibernate .type .SqlTypes .BIGINT ;
111
121
import static org .hibernate .type .SqlTypes .BINARY ;
112
122
import static org .hibernate .type .SqlTypes .BIT ;
@@ -326,7 +336,7 @@ public void appendDateTimeLiteral(
326
336
break ;
327
337
case TIMESTAMP :
328
338
if ( temporalAccessor instanceof ZonedDateTime ) {
329
- temporalAccessor = ( (ZonedDateTime ) temporalAccessor ).toOffsetDateTime ();
339
+ temporalAccessor = ((ZonedDateTime ) temporalAccessor ).toOffsetDateTime ();
330
340
}
331
341
appender .appendSql ( "timestamp('" );
332
342
appendAsTimestampWithMicros (
@@ -418,15 +428,16 @@ public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() {
418
428
return EXTRACTOR ;
419
429
}
420
430
421
- private static final ViolatedConstraintNameExtractor EXTRACTOR = new TemplatedViolatedConstraintNameExtractor ( sqle -> {
422
- final String sqlState = JdbcExceptionHelper .extractSqlState ( sqle );
423
- if ( sqlState != null ) {
424
- if ( Integer .parseInt ( sqlState ) == 23000 ) {
425
- return extractUsingTemplate ( " for key '" , "'" , sqle .getMessage () );
426
- }
427
- }
428
- return null ;
429
- } );
431
+ private static final ViolatedConstraintNameExtractor EXTRACTOR = new TemplatedViolatedConstraintNameExtractor (
432
+ sqle -> {
433
+ final String sqlState = JdbcExceptionHelper .extractSqlState ( sqle );
434
+ if ( sqlState != null ) {
435
+ if ( Integer .parseInt ( sqlState ) == 23000 ) {
436
+ return extractUsingTemplate ( " for key '" , "'" , sqle .getMessage () );
437
+ }
438
+ }
439
+ return null ;
440
+ } );
430
441
431
442
@ Override
432
443
public boolean qualifyIndexName () {
@@ -521,14 +532,18 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR
521
532
.build () );
522
533
523
534
ddlTypeRegistry .addDescriptor ( CapacityDependentDdlType .builder (
524
- NCLOB ,
525
- columnType ( NCLOB ),
526
- castType ( NCHAR ),
527
- this
528
- ).withTypeCapacity ( maxTinyLobLen , "tinytext character set utf8" ).withTypeCapacity (
529
- maxMediumLobLen ,
530
- "mediumtext character set utf8"
531
- ).withTypeCapacity ( maxLobLen , "text character set utf8" ).build () );
535
+ NCLOB ,
536
+ columnType ( NCLOB ),
537
+ castType ( NCHAR ),
538
+ this
539
+ )
540
+ .withTypeCapacity (
541
+ maxTinyLobLen ,
542
+ "tinytext character set utf8"
543
+ )
544
+ .withTypeCapacity ( maxMediumLobLen , "mediumtext character set utf8" )
545
+ .withTypeCapacity ( maxLobLen , "text character set utf8" )
546
+ .build () );
532
547
533
548
ddlTypeRegistry .addDescriptor ( new NativeEnumDdlTypeImpl ( this ) );
534
549
ddlTypeRegistry .addDescriptor ( new NativeOrdinalEnumDdlTypeImpl ( this ) );
@@ -586,14 +601,13 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
586
601
commonFunctionFactory .inverseDistributionOrderedSetAggregates_windowEmulation ();
587
602
commonFunctionFactory .listagg_groupConcat ();
588
603
SqmFunctionRegistry functionRegistry = functionContributions .getFunctionRegistry ();
604
+ final TypeConfiguration typeConfiguration = functionContributions .getTypeConfiguration ();
589
605
BasicTypeRegistry basicTypeRegistry = functionContributions .getTypeConfiguration ().getBasicTypeRegistry ();
590
- functionRegistry
591
- .namedDescriptorBuilder ( "time" )
606
+ functionRegistry .namedDescriptorBuilder ( "time" )
592
607
.setExactArgumentCount ( 1 )
593
608
.setInvariantType ( basicTypeRegistry .resolve ( StandardBasicTypes .STRING ) )
594
609
.register ();
595
- functionRegistry
596
- .patternDescriptorBuilder ( "median" , "median(?1) over ()" )
610
+ functionRegistry .patternDescriptorBuilder ( "median" , "median(?1) over ()" )
597
611
.setInvariantType ( basicTypeRegistry .resolve ( StandardBasicTypes .DOUBLE ) )
598
612
.setExactArgumentCount ( 1 )
599
613
.setParameterTypes ( NUMERIC )
@@ -610,45 +624,18 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
610
624
.setParameterTypes ( FunctionParameterType .INTEGER )
611
625
.register ();
612
626
functionRegistry .registerAlternateKey ( "char" , "chr" );
613
- BasicType <Boolean > booleanType = basicTypeRegistry .resolve ( StandardBasicTypes .BOOLEAN );
614
- functionRegistry .namedDescriptorBuilder ( "json_array_contains_string" )
615
- .setInvariantType ( booleanType )
616
- .setExactArgumentCount ( 2 )
617
- .setParameterTypes ( ANY , STRING )
618
- .register ();
619
- functionRegistry .registerAlternateKey ( "json_array_contains" , "json_array_contains_string" );
620
- functionRegistry .namedDescriptorBuilder ( "json_array_contains_json" )
621
- .setInvariantType ( booleanType )
622
- .setExactArgumentCount ( 2 )
623
- .setParameterTypes ( ANY , ANY )
624
- .register ();
625
- functionRegistry .namedDescriptorBuilder ( "json_array_contains_double" )
626
- .setInvariantType ( booleanType )
627
- .setExactArgumentCount ( 2 )
628
- .setParameterTypes ( ANY , NUMERIC )
629
- .register ();
630
- functionRegistry .namedDescriptorBuilder ( "json_match_any_exists" )
631
- .setInvariantType ( booleanType )
632
- .setMinArgumentCount ( 1 )
633
- .register ();
634
- functionRegistry .namedDescriptorBuilder ( "json_match_any" )
635
- .setInvariantType ( booleanType )
636
- .setMinArgumentCount ( 1 )
637
- .register ();
638
- functionRegistry .namedDescriptorBuilder ( "json_extract_string" )
639
- .setInvariantType ( basicTypeRegistry .resolve ( StandardBasicTypes .STRING ) )
640
- .setMinArgumentCount ( 1 )
641
- .register ();
642
- functionRegistry .namedDescriptorBuilder ( "json_extract_double" )
643
- .setInvariantType ( basicTypeRegistry .resolve ( StandardBasicTypes .DOUBLE ) )
644
- .setMinArgumentCount ( 1 )
645
- .register ();
646
- functionRegistry .namedDescriptorBuilder ( "json_extract_bigint" )
647
- .setInvariantType ( basicTypeRegistry .resolve ( StandardBasicTypes .BIG_INTEGER ) )
648
- .setMinArgumentCount ( 1 )
649
- .register ();
650
- functionRegistry .registerAlternateKey ( "json_extract" , "json_extract_string" );
651
- functionRegistry .registerAlternateKey ( "json_extract_json" , "json_extract_string" );
627
+ functionRegistry .register ( "json_object" , new SingleStoreJsonObjectFunction ( typeConfiguration ) );
628
+ functionRegistry .register ( "json_array" , new SingleStoreJsonArrayFunction ( typeConfiguration ) );
629
+ functionRegistry .register ( "json_value" , new SingleStoreJsonValueFunction ( typeConfiguration ) );
630
+ functionRegistry .register ( "json_exists" , new SingleStoreJsonExistsFunction ( typeConfiguration ) );
631
+ functionRegistry .register ( "json_query" , new SingleStoreJsonQueryFunction ( typeConfiguration ) );
632
+ functionRegistry .register ( "json_arrayagg" , new SingleStoreJsonArrayAggFunction ( typeConfiguration ) );
633
+ functionRegistry .register ( "json_objectagg" , new SingleStoreJsonObjectAggFunction ( typeConfiguration ) );
634
+ functionRegistry .register ( "json_set" , new SingleStoreJsonSetFunction ( typeConfiguration ) );
635
+ functionRegistry .register ( "json_remove" , new SingleStoreJsonRemoveFunction ( typeConfiguration ) );
636
+ functionRegistry .register ( "json_mergepatch" , new SingleStoreJsonMergepatchFunction ( typeConfiguration ) );
637
+ functionRegistry .register ( "json_array_append" , new SingleStoreJsonArrayAppendFunction ( typeConfiguration ) );
638
+ functionRegistry .register ( "json_array_insert" , new SingleStoreJsonArrayInsertFunction ( typeConfiguration ) );
652
639
}
653
640
654
641
@@ -978,7 +965,8 @@ public static Replacer datetimeFormat(String format) {
978
965
979
966
@ Override
980
967
public String getDropForeignKeyString () {
981
- throw new UnsupportedOperationException ( "SingleStore does not support foreign keys and referential integrity" );
968
+ throw new UnsupportedOperationException (
969
+ "SingleStore does not support foreign keys and referential integrity" );
982
970
}
983
971
984
972
@ Override
@@ -1024,12 +1012,12 @@ public boolean canCreateCatalog() {
1024
1012
1025
1013
@ Override
1026
1014
public String [] getCreateCatalogCommand (String catalogName ) {
1027
- return new String [] { "create database " + catalogName };
1015
+ return new String [] {"create database " + catalogName };
1028
1016
}
1029
1017
1030
1018
@ Override
1031
1019
public String [] getDropCatalogCommand (String catalogName ) {
1032
- return new String [] { "drop database " + catalogName };
1020
+ return new String [] {"drop database " + catalogName };
1033
1021
}
1034
1022
1035
1023
@ Override
@@ -1249,13 +1237,14 @@ public String getAddForeignKeyConstraintString(
1249
1237
String referencedTable ,
1250
1238
String [] primaryKey ,
1251
1239
boolean referencesPrimaryKey ) {
1252
- throw new UnsupportedOperationException ( "SingleStore does not support foreign keys and referential integrity." );
1240
+ throw new UnsupportedOperationException (
1241
+ "SingleStore does not support foreign keys and referential integrity." );
1253
1242
}
1254
1243
1255
1244
@ Override
1256
- public String getAddForeignKeyConstraintString (
1257
- String constraintName , String foreignKeyDefinition ) {
1258
- throw new UnsupportedOperationException ( "SingleStore does not support foreign keys and referential integrity." );
1245
+ public String getAddForeignKeyConstraintString (String constraintName , String foreignKeyDefinition ) {
1246
+ throw new UnsupportedOperationException (
1247
+ "SingleStore does not support foreign keys and referential integrity." );
1259
1248
}
1260
1249
1261
1250
@ Override
0 commit comments