2525import org .hibernate .boot .model .relational .Exportable ;
2626import org .hibernate .boot .model .relational .Sequence ;
2727import 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 ;
2840import org .hibernate .dialect .DatabaseVersion ;
2941import org .hibernate .dialect .Dialect ;
3042import org .hibernate .dialect .DmlTargetColumnQualifierSupport ;
6577import org .hibernate .mapping .UniqueKey ;
6678import org .hibernate .metamodel .mapping .EntityMappingType ;
6779import org .hibernate .metamodel .spi .RuntimeModelCreationContext ;
80+ import org .hibernate .query .common .TemporalUnit ;
6881import org .hibernate .query .sqm .CastType ;
6982import org .hibernate .query .sqm .IntervalType ;
70- import org .hibernate .query .common .TemporalUnit ;
7183import org .hibernate .query .sqm .function .SqmFunctionRegistry ;
72- import org .hibernate .query .sqm .mutation .spi .AfterUseAction ;
73- import org .hibernate .query .sqm .mutation .spi .BeforeUseAction ;
7484import org .hibernate .query .sqm .mutation .internal .temptable .LocalTemporaryTableInsertStrategy ;
7585import 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 ;
7688import org .hibernate .query .sqm .mutation .spi .SqmMultiTableInsertStrategy ;
7789import org .hibernate .query .sqm .mutation .spi .SqmMultiTableMutationStrategy ;
7890import org .hibernate .query .sqm .produce .function .FunctionParameterType ;
8496import org .hibernate .sql .ast .tree .Statement ;
8597import org .hibernate .sql .exec .spi .JdbcOperation ;
8698import org .hibernate .tool .schema .spi .Exporter ;
87- import org .hibernate .type .BasicType ;
8899import org .hibernate .type .BasicTypeRegistry ;
89100import org .hibernate .type .NullType ;
90101import org .hibernate .type .SqlTypes ;
100111import org .hibernate .type .descriptor .sql .internal .NativeEnumDdlTypeImpl ;
101112import org .hibernate .type .descriptor .sql .internal .NativeOrdinalEnumDdlTypeImpl ;
102113import org .hibernate .type .descriptor .sql .spi .DdlTypeRegistry ;
114+ import org .hibernate .type .spi .TypeConfiguration ;
103115
104116import jakarta .persistence .TemporalType ;
105117
106118import static org .hibernate .exception .spi .TemplatedViolatedConstraintNameExtractor .extractUsingTemplate ;
107- import static org .hibernate .query .sqm .produce .function .FunctionParameterType .ANY ;
108119import static org .hibernate .query .sqm .produce .function .FunctionParameterType .NUMERIC ;
109- import static org .hibernate .query .sqm .produce .function .FunctionParameterType .STRING ;
110120import static org .hibernate .type .SqlTypes .BIGINT ;
111121import static org .hibernate .type .SqlTypes .BINARY ;
112122import static org .hibernate .type .SqlTypes .BIT ;
@@ -326,7 +336,7 @@ public void appendDateTimeLiteral(
326336 break ;
327337 case TIMESTAMP :
328338 if ( temporalAccessor instanceof ZonedDateTime ) {
329- temporalAccessor = ( (ZonedDateTime ) temporalAccessor ).toOffsetDateTime ();
339+ temporalAccessor = ((ZonedDateTime ) temporalAccessor ).toOffsetDateTime ();
330340 }
331341 appender .appendSql ( "timestamp('" );
332342 appendAsTimestampWithMicros (
@@ -418,15 +428,16 @@ public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() {
418428 return EXTRACTOR ;
419429 }
420430
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+ } );
430441
431442 @ Override
432443 public boolean qualifyIndexName () {
@@ -521,14 +532,18 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR
521532 .build () );
522533
523534 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 () );
532547
533548 ddlTypeRegistry .addDescriptor ( new NativeEnumDdlTypeImpl ( this ) );
534549 ddlTypeRegistry .addDescriptor ( new NativeOrdinalEnumDdlTypeImpl ( this ) );
@@ -586,14 +601,13 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
586601 commonFunctionFactory .inverseDistributionOrderedSetAggregates_windowEmulation ();
587602 commonFunctionFactory .listagg_groupConcat ();
588603 SqmFunctionRegistry functionRegistry = functionContributions .getFunctionRegistry ();
604+ final TypeConfiguration typeConfiguration = functionContributions .getTypeConfiguration ();
589605 BasicTypeRegistry basicTypeRegistry = functionContributions .getTypeConfiguration ().getBasicTypeRegistry ();
590- functionRegistry
591- .namedDescriptorBuilder ( "time" )
606+ functionRegistry .namedDescriptorBuilder ( "time" )
592607 .setExactArgumentCount ( 1 )
593608 .setInvariantType ( basicTypeRegistry .resolve ( StandardBasicTypes .STRING ) )
594609 .register ();
595- functionRegistry
596- .patternDescriptorBuilder ( "median" , "median(?1) over ()" )
610+ functionRegistry .patternDescriptorBuilder ( "median" , "median(?1) over ()" )
597611 .setInvariantType ( basicTypeRegistry .resolve ( StandardBasicTypes .DOUBLE ) )
598612 .setExactArgumentCount ( 1 )
599613 .setParameterTypes ( NUMERIC )
@@ -610,45 +624,18 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
610624 .setParameterTypes ( FunctionParameterType .INTEGER )
611625 .register ();
612626 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 ) );
652639 }
653640
654641
@@ -978,7 +965,8 @@ public static Replacer datetimeFormat(String format) {
978965
979966 @ Override
980967 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" );
982970 }
983971
984972 @ Override
@@ -1024,12 +1012,12 @@ public boolean canCreateCatalog() {
10241012
10251013 @ Override
10261014 public String [] getCreateCatalogCommand (String catalogName ) {
1027- return new String [] { "create database " + catalogName };
1015+ return new String [] {"create database " + catalogName };
10281016 }
10291017
10301018 @ Override
10311019 public String [] getDropCatalogCommand (String catalogName ) {
1032- return new String [] { "drop database " + catalogName };
1020+ return new String [] {"drop database " + catalogName };
10331021 }
10341022
10351023 @ Override
@@ -1249,13 +1237,14 @@ public String getAddForeignKeyConstraintString(
12491237 String referencedTable ,
12501238 String [] primaryKey ,
12511239 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." );
12531242 }
12541243
12551244 @ 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." );
12591248 }
12601249
12611250 @ Override
0 commit comments