Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.stargate.sgv2.jsonapi.config.constants.TableCommentConstants;
import io.stargate.sgv2.jsonapi.exception.DatabaseException;
import io.stargate.sgv2.jsonapi.exception.SchemaException;
import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache;
import io.stargate.sgv2.jsonapi.service.cqldriver.executor.QueryExecutor;
import io.stargate.sgv2.jsonapi.service.cqldriver.override.ExtendedCreateIndex;
import io.stargate.sgv2.jsonapi.service.cqldriver.override.ExtendedVectorType;
Expand All @@ -50,29 +49,118 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public record CreateCollectionOperation(
CommandContext<KeyspaceSchemaObject> commandContext,
DatabaseLimitsConfig dbLimitsConfig,
CQLSessionCache cqlSessionCache,
CqlIdentifier collectionName,
int ddlDelayMillis,
boolean tooManyIndexesRollbackEnabled,
// nullable
CreateCollectionCommand.Options.DocIdDesc docIdDesc,
// nullable
CreateCollectionCommand.Options.IndexingDesc indexingDesc,
// nullable
CreateCollectionCommand.Options.VectorSearchDesc vectorDesc,
SchemaHolder<CollectionLexicalDef> lexicalDef,
SchemaHolder<CollectionRerankDef> rerankDef)
implements Operation<CollectionSchemaObject> {
/** Creates a new collection in the target keyspace using the SuperShredding table model */
public class CreateCollectionOperation implements Operation<KeyspaceSchemaObject> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from record to class, because it should never have been a record.


private static final Logger LOGGER = LoggerFactory.getLogger(CreateCollectionOperation.class);

private static final CollectionTableMatcher COLLECTION_MATCHER = new CollectionTableMatcher();

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private final CommandContext<KeyspaceSchemaObject> commandContext;
private final DatabaseLimitsConfig dbLimitsConfig;
private final CqlIdentifier collectionName;
private final int ddlDelayMillis;
private final boolean tooManyIndexesRollbackEnabled;
// nullable
private final CreateCollectionCommand.Options.DocIdDesc docIdDesc;
// nullable
private final CreateCollectionCommand.Options.IndexingDesc indexingDesc;
// nullable
private final CreateCollectionCommand.Options.VectorSearchDesc vectorDesc;
private final SchemaHolder<CollectionLexicalDef> lexicalDef;
private final SchemaHolder<CollectionRerankDef> rerankDef;

public CreateCollectionOperation(
CommandContext<KeyspaceSchemaObject> commandContext,
DatabaseLimitsConfig dbLimitsConfig,
CqlIdentifier collectionName,
int ddlDelayMillis,
boolean tooManyIndexesRollbackEnabled,
// nullable
CreateCollectionCommand.Options.DocIdDesc docIdDesc,
// nullable
CreateCollectionCommand.Options.IndexingDesc indexingDesc,
// nullable
CreateCollectionCommand.Options.VectorSearchDesc vectorDesc,
SchemaHolder<CollectionLexicalDef> lexicalDef,
SchemaHolder<CollectionRerankDef> rerankDef) {
this.commandContext = commandContext;
this.dbLimitsConfig = dbLimitsConfig;
this.collectionName = collectionName;
this.ddlDelayMillis = ddlDelayMillis;
this.tooManyIndexesRollbackEnabled = tooManyIndexesRollbackEnabled;
this.docIdDesc = docIdDesc;
this.indexingDesc = indexingDesc;
this.vectorDesc = vectorDesc;
this.lexicalDef = lexicalDef;
this.rerankDef = rerankDef;
}

/**
* Present and visible because the old testing relied on this being a record, keeping until we
* review the testing in more detail and determine if needed.
*/
@VisibleForTesting
public CqlIdentifier collectionName() {
return collectionName;
}

/**
* Present and visible because the old testing relied on this being a record, keeping until we
* review the testing in more detail and determine if needed.
*/
@VisibleForTesting
public CommandContext<KeyspaceSchemaObject> commandContext() {
return commandContext;
}

/**
* Present and visible because the old testing relied on this being a record, keeping until we
* review the testing in more detail and determine if needed.
*/
@VisibleForTesting
public CreateCollectionCommand.Options.DocIdDesc docIdDesc() {
return docIdDesc;
}

/**
* Present and visible because the old testing relied on this being a record, keeping until we
* review the testing in more detail and determine if needed.
*/
@VisibleForTesting
public CreateCollectionCommand.Options.IndexingDesc indexingDesc() {
return indexingDesc;
}

/**
* Present and visible because the old testing relied on this being a record, keeping until we
* review the testing in more detail and determine if needed.
*/
@VisibleForTesting
public CreateCollectionCommand.Options.VectorSearchDesc vectorDesc() {
return vectorDesc;
}

/**
* Present and visible because the old testing relied on this being a record, keeping until we
* review the testing in more detail and determine if needed.
*/
@VisibleForTesting
public SchemaHolder<CollectionLexicalDef> lexicalDef() {
return lexicalDef;
}

/**
* Present and visible because the old testing relied on this being a record, keeping until we
* review the testing in more detail and determine if needed.
*/
@VisibleForTesting
public SchemaHolder<CollectionRerankDef> rerankDef() {
return rerankDef;
}

@Override
public Uni<Supplier<CommandResult>> execute(
RequestContext requestContext, QueryExecutor queryExecutor) {
Expand Down Expand Up @@ -112,7 +200,7 @@ public Uni<Supplier<CommandResult>> execute(
requestContext,
queryExecutor,
initialTableComment,
lexicalDef().runningValue(),
lexicalDef.runningValue(),
false);
}

Expand Down Expand Up @@ -158,11 +246,11 @@ public Uni<Supplier<CommandResult>> execute(
// NOTE: FROM NOW ON WE NEED TO USE THE OVERRIDEN VALUE, (which may or may not be
// actually overidden)
var overrideLexicalDef =
lexicalDef()
lexicalDef
.replaceIfMissing(existingCollectionSettings.lexicalDefSchemaValue())
.value();
var overrideRerankDef =
rerankDef()
rerankDef
.replaceIfMissing(existingCollectionSettings.rerankDefSchemaValue())
.value();

Expand Down Expand Up @@ -212,7 +300,7 @@ public Uni<Supplier<CommandResult>> execute(

@VisibleForTesting
String generateTableComment() {
return generateTableComment(lexicalDef(), rerankDef());
return generateTableComment(lexicalDef, rerankDef);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.stargate.sgv2.jsonapi.service.embedding.configuration.EmbeddingProvidersConfig;
import io.stargate.sgv2.jsonapi.service.operation.Operation;
import io.stargate.sgv2.jsonapi.service.provider.ApiModelSupport;
import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject;
import java.util.*;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand All @@ -20,7 +21,9 @@
* CommandStatus#EXISTING_EMBEDDING_PROVIDERS} command status.
*/
public record FindEmbeddingProvidersOperation(
FindEmbeddingProvidersCommand command, EmbeddingProvidersConfig config) implements Operation {
FindEmbeddingProvidersCommand command, EmbeddingProvidersConfig config)
implements Operation<DatabaseSchemaObject> {

@Override
public Uni<Supplier<CommandResult>> execute(
RequestContext dataApiRequestInfo, QueryExecutor queryExecutor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public Operation resolveKeyspaceCommand(
return new CreateCollectionOperation(
context,
dbLimitsConfig,
context.cqlSessionCache(),
collectionName,
operationsConfig.databaseConfig().ddlDelayMillis(),
operationsConfig.tooManyIndexesRollbackEnabled(),
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/io/stargate/sgv2/jsonapi/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.micrometer.core.instrument.MeterRegistry;
import io.stargate.sgv2.jsonapi.api.model.command.CommandConfig;
import io.stargate.sgv2.jsonapi.api.model.command.CommandContext;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class TestConstants {
public final String APP_NAME;
public final DatabaseType DATABASE_TYPE;
public final TenantFactory SINGLETON_TENANT_FACTORY;
public final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

// ============================================================
// Names
Expand Down
Loading