@@ -441,7 +441,7 @@ private void ensureIndexesExists() {
441
441
{
442
442
SimpleStatement indexStmt = SchemaBuilder .createIndex (this .schema .index )
443
443
.ifNotExists ()
444
- .custom ("SAI " )
444
+ .custom ("StorageAttachedIndex " )
445
445
.onTable (this .schema .keyspace , this .schema .table )
446
446
.andColumn (this .schema .embedding )
447
447
.build ();
@@ -457,7 +457,7 @@ private void ensureIndexesExists() {
457
457
458
458
SimpleStatement indexStmt = SchemaBuilder .createIndex (String .format ("%s_idx" , metadata .name ()))
459
459
.ifNotExists ()
460
- .custom ("SAI " )
460
+ .custom ("StorageAttachedIndex " )
461
461
.onTable (this .schema .keyspace , this .schema .table )
462
462
.andColumn (metadata .name ())
463
463
.build ();
@@ -468,39 +468,41 @@ private void ensureIndexesExists() {
468
468
}
469
469
470
470
private void ensureTableExists (int vectorDimension ) {
471
+ if (this .session .getMetadata ().getKeyspace (this .schema .keyspace ).get ().getTable (this .schema .table ).isEmpty ()) {
471
472
472
- CreateTable createTable = null ;
473
+ CreateTable createTable = null ;
473
474
474
- CreateTableStart createTableStart = SchemaBuilder .createTable (this .schema .keyspace , this .schema .table )
475
- .ifNotExists ();
475
+ CreateTableStart createTableStart = SchemaBuilder .createTable (this .schema .keyspace , this .schema .table )
476
+ .ifNotExists ();
476
477
477
- for (SchemaColumn partitionKey : this .schema .partitionKeys ) {
478
- createTable = (null != createTable ? createTable : createTableStart ).withPartitionKey (partitionKey .name ,
479
- partitionKey .type );
480
- }
481
- for (SchemaColumn clusteringKey : this .schema .clusteringKeys ) {
482
- createTable = createTable .withClusteringColumn (clusteringKey .name , clusteringKey .type );
483
- }
478
+ for (SchemaColumn partitionKey : this .schema .partitionKeys ) {
479
+ createTable = (null != createTable ? createTable : createTableStart ).withPartitionKey (partitionKey .name ,
480
+ partitionKey .type );
481
+ }
482
+ for (SchemaColumn clusteringKey : this .schema .clusteringKeys ) {
483
+ createTable = createTable .withClusteringColumn (clusteringKey .name , clusteringKey .type );
484
+ }
484
485
485
- createTable = createTable .withColumn (this .schema .content , DataTypes .TEXT );
486
+ createTable = createTable .withColumn (this .schema .content , DataTypes .TEXT );
486
487
487
- for (SchemaColumn metadata : this .schema .metadataColumns ) {
488
- createTable = createTable .withColumn (metadata .name (), metadata .type ());
489
- }
490
-
491
- // https://datastax-oss.atlassian.net/browse/JAVA-3118
492
- // .withColumn(config.embedding, new DefaultVectorType(DataTypes.FLOAT,
493
- // vectorDimension));
494
-
495
- StringBuilder tableStmt = new StringBuilder (createTable .asCql ());
496
- tableStmt .setLength (tableStmt .length () - 1 );
497
- tableStmt .append (',' )
498
- .append (this .schema .embedding )
499
- .append (" vector<float," )
500
- .append (vectorDimension )
501
- .append (">)" );
502
- logger .debug ("Executing {}" , tableStmt .toString ());
503
- this .session .execute (tableStmt .toString ());
488
+ for (SchemaColumn metadata : this .schema .metadataColumns ) {
489
+ createTable = createTable .withColumn (metadata .name (), metadata .type ());
490
+ }
491
+
492
+ // https://datastax-oss.atlassian.net/browse/JAVA-3118
493
+ // .withColumn(config.embedding, new DefaultVectorType(DataTypes.FLOAT,
494
+ // vectorDimension));
495
+
496
+ StringBuilder tableStmt = new StringBuilder (createTable .asCql ());
497
+ tableStmt .setLength (tableStmt .length () - 1 );
498
+ tableStmt .append (',' )
499
+ .append (this .schema .embedding )
500
+ .append (" vector<float," )
501
+ .append (vectorDimension )
502
+ .append (">)" );
503
+ logger .debug ("Executing {}" , tableStmt .toString ());
504
+ this .session .execute (tableStmt .toString ());
505
+ }
504
506
}
505
507
506
508
private void ensureTableColumnsExist (int vectorDimension ) {
@@ -563,14 +565,15 @@ private void ensureTableColumnsExist(int vectorDimension) {
563
565
}
564
566
565
567
private void ensureKeyspaceExists () {
568
+ if (this .session .getMetadata ().getKeyspace (this .schema .keyspace ).isEmpty ()) {
569
+ SimpleStatement keyspaceStmt = SchemaBuilder .createKeyspace (this .schema .keyspace )
570
+ .ifNotExists ()
571
+ .withSimpleStrategy (1 )
572
+ .build ();
566
573
567
- SimpleStatement keyspaceStmt = SchemaBuilder .createKeyspace (this .schema .keyspace )
568
- .ifNotExists ()
569
- .withSimpleStrategy (1 )
570
- .build ();
571
-
572
- logger .debug ("Executing {}" , keyspaceStmt .getQuery ());
573
- this .session .execute (keyspaceStmt );
574
+ logger .debug ("Executing {}" , keyspaceStmt .getQuery ());
575
+ this .session .execute (keyspaceStmt );
576
+ }
574
577
}
575
578
576
579
}
0 commit comments