diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/CommandContext.java b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/CommandContext.java index 77db77b143..9cc978b6b4 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/CommandContext.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/CommandContext.java @@ -9,15 +9,22 @@ import io.stargate.sgv2.jsonapi.config.feature.ApiFeature; import io.stargate.sgv2.jsonapi.config.feature.ApiFeatures; import io.stargate.sgv2.jsonapi.config.feature.FeaturesConfig; +import io.stargate.sgv2.jsonapi.logging.LoggingMDCContext; import io.stargate.sgv2.jsonapi.metrics.CommandFeatures; import io.stargate.sgv2.jsonapi.metrics.JsonProcessingMetricsReporter; import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.*; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProvider; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProviderFactory; import io.stargate.sgv2.jsonapi.service.reranking.operation.RerankingProviderFactory; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; /** @@ -29,13 +36,16 @@ * context for a specific request call {@link BuilderSupplier#getBuilder(SchemaObject)} to get a * {@link BuilderSupplier.Builder} to configure the context for the request. * - *

+ *

NOTE: When {@link BuilderSupplier.Builder#build()} is called it will call {@link + * #addToMDC()} so that the context is added to the logging MDC for the duration of the request. The + * context must be closed via {@link #close()} to remove it from the MDC, this should be done at the + * last possible time in the resource handler so all log messages have the context. * * @param The schema object type that this context is for. There are times we need to lock * this down to the specific type, if so use the "as" methods such as {@link * CommandContext#asCollectionContext()} */ -public class CommandContext { +public class CommandContext implements LoggingMDCContext { // Common for all instances private final JsonProcessingMetricsReporter jsonProcessingMetricsReporter; @@ -47,11 +57,15 @@ public class CommandContext { // Request specific private final SchemaT schemaObject; + private final RequestTracing requestTracing; + private final RequestContext requestContext; private final EmbeddingProvider embeddingProvider; // to be removed later, this is a single provider private final String commandName; // TODO: remove the command name, but it is used in 14 places - private final RequestContext requestContext; - private RequestTracing requestTracing; + + // both per request list of objects that want to update the logging MDC context, + // add to this list in the ctor. See {@link #addToMDC()} and {@link #removeFromMDC()} + private final List loggingMDCContexts = new ArrayList<>(); // see accessors private FindAndRerankCommand.HybridLimits hybridLimits; @@ -77,19 +91,23 @@ private CommandContext( RerankingProviderFactory rerankingProviderFactory, MeterRegistry meterRegistry) { - this.schemaObject = schemaObject; - this.embeddingProvider = embeddingProvider; - this.commandName = commandName; - this.requestContext = requestContext; - - this.jsonProcessingMetricsReporter = jsonProcessingMetricsReporter; + // Common for all instances this.cqlSessionCache = cqlSessionCache; this.commandConfig = commandConfig; this.embeddingProviderFactory = embeddingProviderFactory; + this.jsonProcessingMetricsReporter = jsonProcessingMetricsReporter; + this.meterRegistry = meterRegistry; this.rerankingProviderFactory = rerankingProviderFactory; + // Request specific + this.embeddingProvider = embeddingProvider; // to be removed later, this is a single provider + this.requestContext = requestContext; + this.schemaObject = schemaObject; + this.commandName = commandName; // TODO: remove the command name, but it is used in 14 places this.apiFeatures = apiFeatures; - this.meterRegistry = meterRegistry; + + this.loggingMDCContexts.add(this.requestContext); + this.loggingMDCContexts.add(this.schemaObject.identifier()); var anyTracing = apiFeatures().isFeatureEnabled(ApiFeature.REQUEST_TRACING) @@ -191,34 +209,34 @@ public MeterRegistry meterRegistry() { } public boolean isCollectionContext() { - return schemaObject().type() == CollectionSchemaObject.TYPE; + return schemaObject().type() == SchemaObjectType.COLLECTION; } @SuppressWarnings("unchecked") public CommandContext asCollectionContext() { - checkSchemaObjectType(CollectionSchemaObject.TYPE); + checkSchemaObjectType(SchemaObjectType.COLLECTION); return (CommandContext) this; } @SuppressWarnings("unchecked") public CommandContext asTableContext() { - checkSchemaObjectType(TableSchemaObject.TYPE); + checkSchemaObjectType(SchemaObjectType.TABLE); return (CommandContext) this; } @SuppressWarnings("unchecked") public CommandContext asKeyspaceContext() { - checkSchemaObjectType(KeyspaceSchemaObject.TYPE); + checkSchemaObjectType(SchemaObjectType.KEYSPACE); return (CommandContext) this; } @SuppressWarnings("unchecked") public CommandContext asDatabaseContext() { - checkSchemaObjectType(DatabaseSchemaObject.TYPE); + checkSchemaObjectType(SchemaObjectType.DATABASE); return (CommandContext) this; } - private void checkSchemaObjectType(SchemaObject.SchemaObjectType expectedType) { + private void checkSchemaObjectType(SchemaObjectType expectedType) { Preconditions.checkArgument( schemaObject().type() == expectedType, "SchemaObject type actual was %s expected was %s ", @@ -226,6 +244,24 @@ private void checkSchemaObjectType(SchemaObject.SchemaObjectType expectedType) { expectedType); } + @Override + public void addToMDC() { + loggingMDCContexts.forEach(LoggingMDCContext::addToMDC); + } + + @Override + public void removeFromMDC() { + loggingMDCContexts.forEach(LoggingMDCContext::removeFromMDC); + } + + /** + * NOTE: Not using AutoCloseable because it created a lot of linting warnings, we only want to + * close this in the request resource handler. + */ + public void close() throws Exception { + removeFromMDC(); + } + /** * Configure the BuilderSupplier with resources and config that will be used for all the {@link * CommandContext} that will be created. Then called {@link @@ -341,18 +377,21 @@ public CommandContext build() { Objects.requireNonNull(commandName, "commandName must not be null"); Objects.requireNonNull(requestContext, "requestContext must not be null"); - return new CommandContext<>( - schemaObject, - embeddingProvider, - commandName, - requestContext, - jsonProcessingMetricsReporter, - cqlSessionCache, - commandConfig, - apiFeatures, - embeddingProviderFactory, - rerankingProviderFactory, - meterRegistry); + var context = + new CommandContext<>( + schemaObject, + embeddingProvider, + commandName, + requestContext, + jsonProcessingMetricsReporter, + cqlSessionCache, + commandConfig, + apiFeatures, + embeddingProviderFactory, + rerankingProviderFactory, + meterRegistry); + context.addToMDC(); + return context; } } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/CommandTarget.java b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/CommandTarget.java index b4f7ab96bf..f3abac12ac 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/CommandTarget.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/CommandTarget.java @@ -4,9 +4,8 @@ * The schema object a command can be called against. * *

Example: creteTable runs against the Keyspace , so target is the Keyspace aaron 13 - nove - - * 2024 - not using the {@link - * io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject.SchemaObjectType} because this - * also needs the SYSTEM value, and the schema object design prob needs improvement + * 2024 - not using the {@link io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObjectType} + * because this also needs the SYSTEM value, and the schema object design prob needs improvement */ public enum CommandTarget { COLLECTION, diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/FilterClauseBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/FilterClauseBuilder.java index e66bc334c9..fc0ad670fe 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/FilterClauseBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/FilterClauseBuilder.java @@ -7,9 +7,9 @@ import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.config.constants.DocumentConstants; import io.stargate.sgv2.jsonapi.exception.FilterException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.collections.DocumentId; import io.stargate.sgv2.jsonapi.service.shredding.collections.JsonExtensionType; import io.stargate.sgv2.jsonapi.util.JsonUtil; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/SortClauseBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/SortClauseBuilder.java index 995d76668c..a25765591d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/SortClauseBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/SortClauseBuilder.java @@ -6,9 +6,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.SortDefinition; import io.stargate.sgv2.jsonapi.api.model.command.clause.sort.SortClause; import io.stargate.sgv2.jsonapi.exception.SortException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.JsonUtil; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableFilterClauseBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableFilterClauseBuilder.java index a4f156465e..311ad18eb3 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableFilterClauseBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableFilterClauseBuilder.java @@ -8,9 +8,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.*; import io.stargate.sgv2.jsonapi.api.model.command.table.definition.datatype.MapComponentDesc; import io.stargate.sgv2.jsonapi.exception.FilterException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.MapSetListFilterComponent; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTypeName; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil; import java.util.*; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableSortClauseBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableSortClauseBuilder.java index a4b88b2fdc..07781c03c9 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableSortClauseBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableSortClauseBuilder.java @@ -13,9 +13,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.clause.sort.SortClause; import io.stargate.sgv2.jsonapi.api.model.command.clause.sort.SortExpression; import io.stargate.sgv2.jsonapi.exception.SortException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDefContainer; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil; import io.stargate.sgv2.jsonapi.util.JsonUtil; import java.util.ArrayList; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/v1/CollectionResource.java b/src/main/java/io/stargate/sgv2/jsonapi/api/v1/CollectionResource.java index b3491fea6c..8b5a5f5527 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/v1/CollectionResource.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/v1/CollectionResource.java @@ -1,6 +1,7 @@ package io.stargate.sgv2.jsonapi.api.v1; import static io.stargate.sgv2.jsonapi.config.constants.DocumentConstants.Fields.VECTOR_EMBEDDING_TEXT_FIELD; +import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierFromUserInput; import io.micrometer.core.instrument.MeterRegistry; import io.smallrye.mutiny.Uni; @@ -31,13 +32,14 @@ import io.stargate.sgv2.jsonapi.exception.mappers.ThrowableCommandResultSupplier; import io.stargate.sgv2.jsonapi.metrics.JsonProcessingMetricsReporter; import io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionCacheSupplier; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaCache; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorColumnDefinition; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProvider; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProviderFactory; import io.stargate.sgv2.jsonapi.service.processor.MeteredCommandProcessor; import io.stargate.sgv2.jsonapi.service.reranking.operation.RerankingProviderFactory; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectCacheSupplier; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; +import io.stargate.sgv2.jsonapi.service.schema.UnscopedSchemaObjectIdentifier; import jakarta.inject.Inject; import jakarta.validation.Valid; import jakarta.validation.constraints.NotEmpty; @@ -60,6 +62,8 @@ import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement; import org.eclipse.microprofile.openapi.annotations.tags.Tag; import org.jboss.resteasy.reactive.RestResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Path(CollectionResource.BASE_PATH) @Produces(MediaType.APPLICATION_JSON) @@ -67,6 +71,7 @@ @SecurityRequirement(name = OpenApiConstants.SecuritySchemes.TOKEN) @Tag(ref = "Documents") public class CollectionResource { + private static final Logger LOGGER = LoggerFactory.getLogger(CollectionResource.class); public static final String BASE_PATH = GeneralResource.BASE_PATH + "/{keyspace}/{collection}"; @@ -75,20 +80,23 @@ public class CollectionResource { // TODO remove apiFeatureConfig as a property after cleanup for how we get schema from cache @Inject private FeaturesConfig apiFeatureConfig; @Inject private RequestContext requestContext; - @Inject private SchemaCache schemaCache; + private final SchemaObjectCacheSupplier schemaObjectCacheSupplier; private final CommandContext.BuilderSupplier contextBuilderSupplier; private final EmbeddingProviderFactory embeddingProviderFactory; private final MeteredCommandProcessor meteredCommandProcessor; @Inject public CollectionResource( + SchemaObjectCacheSupplier schemaObjectCacheSupplier, MeteredCommandProcessor meteredCommandProcessor, MeterRegistry meterRegistry, JsonProcessingMetricsReporter jsonProcessingMetricsReporter, CqlSessionCacheSupplier sessionCacheSupplier, EmbeddingProviderFactory embeddingProviderFactory, RerankingProviderFactory rerankingProviderFactory) { + + this.schemaObjectCacheSupplier = schemaObjectCacheSupplier; this.embeddingProviderFactory = embeddingProviderFactory; this.meteredCommandProcessor = meteredCommandProcessor; @@ -198,12 +206,15 @@ public Uni> postCommand( @NotNull @Valid CollectionCommand command, @PathParam("keyspace") @NotEmpty String keyspace, @PathParam("collection") @NotEmpty String collection) { - return schemaCache - .getSchemaObject( - requestContext, - keyspace, - collection, - CommandType.DDL.equals(command.commandName().getCommandType())) + + var name = + new UnscopedSchemaObjectIdentifier.DefaultKeyspaceScopedName( + cqlIdentifierFromUserInput(keyspace), cqlIdentifierFromUserInput(collection)); + var forceRefresh = CommandType.DDL.equals(command.commandName().getCommandType()); + + return schemaObjectCacheSupplier + .get() + .getTableBased(requestContext, name, requestContext.userAgent(), forceRefresh) .onItemOrFailure() .transformToUni( (schemaObject, throwable) -> { @@ -219,19 +230,17 @@ public Uni> postCommand( // otherwise use generic for now return Uni.createFrom().item(new ThrowableCommandResultSupplier(error)); } else { - // TODO No need for the else clause here, simplify - // TODO: This needs to change, currently it is only checking if there is vectorize // for the $vector column in a collection VectorColumnDefinition vectorColDef = null; - if (schemaObject.type() == SchemaObject.SchemaObjectType.COLLECTION) { + if (schemaObject.type() == SchemaObjectType.COLLECTION) { vectorColDef = schemaObject .vectorConfig() .getColumnDefinition(VECTOR_EMBEDDING_TEXT_FIELD) .orElse(null); - } else if (schemaObject.type() == SchemaObject.SchemaObjectType.TABLE) { + } else if (schemaObject.type() == SchemaObjectType.TABLE) { vectorColDef = schemaObject .vectorConfig() @@ -262,7 +271,20 @@ public Uni> postCommand( .withRequestContext(requestContext) .build(); - return meteredCommandProcessor.processCommand(commandContext, command); + return meteredCommandProcessor + .processCommand(commandContext, command) + .onTermination() + .invoke( + () -> { + try { + commandContext.close(); + } catch (Exception e) { + LOGGER.error( + "Error closing the command context for requestContext={}", + requestContext, + e); + } + }); } }) .map(commandResult -> commandResult.toRestResponse()); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/v1/GeneralResource.java b/src/main/java/io/stargate/sgv2/jsonapi/api/v1/GeneralResource.java index 033360a601..e9c5cd4335 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/v1/GeneralResource.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/v1/GeneralResource.java @@ -11,10 +11,11 @@ import io.stargate.sgv2.jsonapi.config.constants.OpenApiConstants; import io.stargate.sgv2.jsonapi.metrics.JsonProcessingMetricsReporter; import io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionCacheSupplier; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProviderFactory; import io.stargate.sgv2.jsonapi.service.processor.MeteredCommandProcessor; import io.stargate.sgv2.jsonapi.service.reranking.operation.RerankingProviderFactory; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectCacheSupplier; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectIdentifier; import jakarta.inject.Inject; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; @@ -33,6 +34,8 @@ import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement; import org.eclipse.microprofile.openapi.annotations.tags.Tag; import org.jboss.resteasy.reactive.RestResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Path(GeneralResource.BASE_PATH) @Produces(MediaType.APPLICATION_JSON) @@ -40,21 +43,27 @@ @SecurityRequirement(name = OpenApiConstants.SecuritySchemes.TOKEN) @Tag(ref = "General") public class GeneralResource { + private static final Logger LOGGER = LoggerFactory.getLogger(GeneralResource.class); + public static final String BASE_PATH = "/v1"; @Inject private RequestContext requestContext; + private final SchemaObjectCacheSupplier schemaObjectCacheSupplier; private final CommandContext.BuilderSupplier contextBuilderSupplier; private final MeteredCommandProcessor meteredCommandProcessor; @Inject public GeneralResource( + SchemaObjectCacheSupplier schemaObjectCacheSupplier, MeteredCommandProcessor meteredCommandProcessor, MeterRegistry meterRegistry, JsonProcessingMetricsReporter jsonProcessingMetricsReporter, CqlSessionCacheSupplier sessionCacheSupplier, EmbeddingProviderFactory embeddingProviderFactory, RerankingProviderFactory rerankingProviderFactory) { + + this.schemaObjectCacheSupplier = schemaObjectCacheSupplier; this.meteredCommandProcessor = meteredCommandProcessor; contextBuilderSupplier = @@ -98,16 +107,36 @@ public GeneralResource( @POST public Uni> postCommand(@NotNull @Valid GeneralCommand command) { - var commandContext = - contextBuilderSupplier - .getBuilder(new DatabaseSchemaObject()) - .withCommandName(command.getClass().getSimpleName()) - .withRequestContext(requestContext) - .build(); + var dbIdentifier = SchemaObjectIdentifier.forDatabase(requestContext.tenant()); + + return schemaObjectCacheSupplier + .get() + .getDatabase(requestContext, dbIdentifier, requestContext.userAgent(), false) + .flatMap( + databaseSchemaObject -> { + var commandContext = + contextBuilderSupplier + .getBuilder(databaseSchemaObject) + .withCommandName(command.getClass().getSimpleName()) + .withRequestContext(requestContext) + .build(); - return meteredCommandProcessor - .processCommand(commandContext, command) - // map to 2xx unless overridden by error - .map(commandResult -> commandResult.toRestResponse()); + return meteredCommandProcessor + .processCommand(commandContext, command) + // map to 2xx unless overridden by error + .map(commandResult -> commandResult.toRestResponse()) + .onTermination() + .invoke( + () -> { + try { + commandContext.close(); + } catch (Exception e) { + LOGGER.error( + "Error closing the command context for requestContext={}", + requestContext, + e); + } + }); + }); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/v1/KeyspaceResource.java b/src/main/java/io/stargate/sgv2/jsonapi/api/v1/KeyspaceResource.java index ff4f9dda11..fc9b1c7660 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/v1/KeyspaceResource.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/v1/KeyspaceResource.java @@ -1,5 +1,7 @@ package io.stargate.sgv2.jsonapi.api.v1; +import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierFromUserInput; + import io.micrometer.core.instrument.MeterRegistry; import io.smallrye.mutiny.Uni; import io.stargate.sgv2.jsonapi.ConfigPreLoader; @@ -11,10 +13,11 @@ import io.stargate.sgv2.jsonapi.config.constants.OpenApiConstants; import io.stargate.sgv2.jsonapi.metrics.JsonProcessingMetricsReporter; import io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionCacheSupplier; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProviderFactory; import io.stargate.sgv2.jsonapi.service.processor.MeteredCommandProcessor; import io.stargate.sgv2.jsonapi.service.reranking.operation.RerankingProviderFactory; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectCacheSupplier; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectIdentifier; import jakarta.inject.Inject; import jakarta.validation.Valid; import jakarta.validation.constraints.NotEmpty; @@ -37,6 +40,8 @@ import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement; import org.eclipse.microprofile.openapi.annotations.tags.Tag; import org.jboss.resteasy.reactive.RestResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Path(KeyspaceResource.BASE_PATH) @Produces(MediaType.APPLICATION_JSON) @@ -44,22 +49,27 @@ @SecurityRequirement(name = OpenApiConstants.SecuritySchemes.TOKEN) @Tag(ref = "Keyspaces") public class KeyspaceResource { + private static final Logger LOGGER = LoggerFactory.getLogger(KeyspaceResource.class); public static final String BASE_PATH = GeneralResource.BASE_PATH + "/{keyspace}"; @Inject private RequestContext requestContext; + private final SchemaObjectCacheSupplier schemaObjectCacheSupplier; private final CommandContext.BuilderSupplier contextBuilderSupplier; private final MeteredCommandProcessor meteredCommandProcessor; @Inject public KeyspaceResource( + SchemaObjectCacheSupplier schemaObjectCacheSupplier, MeteredCommandProcessor meteredCommandProcessor, MeterRegistry meterRegistry, JsonProcessingMetricsReporter jsonProcessingMetricsReporter, CqlSessionCacheSupplier sessionCacheSupplier, EmbeddingProviderFactory embeddingProviderFactory, RerankingProviderFactory rerankingProviderFactory) { + + this.schemaObjectCacheSupplier = schemaObjectCacheSupplier; this.meteredCommandProcessor = meteredCommandProcessor; contextBuilderSupplier = @@ -139,18 +149,41 @@ public Uni> postCommand( // CommandContext commandContext = new CommandContext(keyspace, null); // HACK TODO: The above did not set a command name on the command context, how did that work ? - var commandContext = - contextBuilderSupplier - .getBuilder(new KeyspaceSchemaObject(keyspace)) - .withEmbeddingProvider(null) - .withCommandName(command.getClass().getSimpleName()) - .withRequestContext(requestContext) - .build(); + var keyspaceIdentifier = + SchemaObjectIdentifier.forKeyspace( + requestContext.tenant(), cqlIdentifierFromUserInput(keyspace)); + + // Force refresh on all keyspace commands because they are all DDL commands + return schemaObjectCacheSupplier + .get() + .getKeyspace(requestContext, keyspaceIdentifier, requestContext.userAgent(), true) + .flatMap( + keyspaceSchemaObject -> { + var commandContext = + contextBuilderSupplier + .getBuilder(keyspaceSchemaObject) + .withEmbeddingProvider(null) + .withCommandName(command.getClass().getSimpleName()) + .withRequestContext(requestContext) + .build(); - // call processor - return meteredCommandProcessor - .processCommand(commandContext, command) - // map to 2xx unless overridden by error - .map(commandResult -> commandResult.toRestResponse()); + // call processor + return meteredCommandProcessor + .processCommand(commandContext, command) + // map to 2xx unless overridden by error + .map(commandResult -> commandResult.toRestResponse()) + .onTermination() + .invoke( + () -> { + try { + commandContext.close(); + } catch (Exception e) { + LOGGER.error( + "Error closing the command context for requestContext={}", + requestContext, + e); + } + }); + }); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorFormatters.java b/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorFormatters.java index fd4f2bc425..b4ec28b50b 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorFormatters.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorFormatters.java @@ -1,12 +1,15 @@ package io.stargate.sgv2.jsonapi.exception; +import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierToMessageString; + import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata; import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; import com.datastax.oss.driver.api.core.type.DataType; import io.stargate.sgv2.jsonapi.api.model.command.table.definition.datatype.ColumnDesc; import io.stargate.sgv2.jsonapi.config.constants.ErrorObjectV2Constants.TemplateVars; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.UnscopedSchemaObjectIdentifier; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDefContainer; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiDataType; @@ -145,6 +148,26 @@ public static Map errVars(SchemaObject schemaObject, Throwable e return errVars(schemaObject, exception, null); } + public static Map errVars(UnscopedSchemaObjectIdentifier name) { + return errVars(name, null); + } + + public static Map errVars( + UnscopedSchemaObjectIdentifier name, Consumer> consumer) { + + Map map = new HashMap<>(); + + map.put(TemplateVars.KEYSPACE, cqlIdentifierToMessageString(name.keyspace())); + map.put( + TemplateVars.TABLE, + name.objectName() == null ? "" : cqlIdentifierToMessageString(name.objectName())); + + if (consumer != null) { + consumer.accept(map); + } + return map; + } + /** * Adds variables to a map for the schemaObject and Throwable then calls * the consumer to add more. @@ -179,8 +202,10 @@ public static Map errVars( Map map = new HashMap<>(); if (schemaObject != null) { map.put(TemplateVars.SCHEMA_TYPE, schemaObject.type().name()); - map.put(TemplateVars.KEYSPACE, schemaObject.name().keyspace()); - map.put(TemplateVars.TABLE, schemaObject.name().table()); + map.put( + TemplateVars.KEYSPACE, + cqlIdentifierToMessageString(schemaObject.identifier().keyspace())); + map.put(TemplateVars.TABLE, cqlIdentifierToMessageString(schemaObject.identifier().table())); } if (exception != null) { map.put(TemplateVars.ERROR_CLASS, exception.getClass().getSimpleName()); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/exception/SchemaException.java b/src/main/java/io/stargate/sgv2/jsonapi/exception/SchemaException.java index e1fc126925..2ff041965c 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/exception/SchemaException.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/exception/SchemaException.java @@ -47,6 +47,7 @@ public enum Code implements ErrorCode { MISSING_DIMENSION_IN_VECTOR_COLUMN, MISSING_FIELDS_FOR_TYPE_CREATION, MISSING_PARTITION_COLUMNS, + UNKNOWN_COLLECTION_OR_TABLE, UNKNOWN_DATA_TYPE, UNKNOWN_INDEX_COLUMN, UNKNOWN_INDEX_TYPE, diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/CQLSessionCache.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/CQLSessionCache.java index e77f88da94..3acd54ad65 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/CQLSessionCache.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/CQLSessionCache.java @@ -10,7 +10,6 @@ import io.stargate.sgv2.jsonapi.api.request.RequestContext; import io.stargate.sgv2.jsonapi.api.request.UserAgent; import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; import io.stargate.sgv2.jsonapi.util.DynamicTTLCache; import java.time.Duration; import java.util.ArrayList; @@ -185,21 +184,6 @@ public Uni getSession(RequestContext requestContext) { requestContext.tenant(), requestContext.authToken(), requestContext.userAgent()); } - /** - * Gets or creates a {@link CqlSession} for the provided DB Request Context - * - * @param requestContext {@link CommandQueryExecutor.DBRequestContext} to get the session for. - * @return A Uni with the {@link CqlSession} for this tenant and credentials, the session maybe - * newly created or reused from the cache. - */ - public Uni getSession(CommandQueryExecutor.DBRequestContext requestContext) { - Objects.requireNonNull(requestContext, "requestContext must not be null"); - - // Validation happens when creating the credentials and session key - return getSession( - requestContext.tenant(), requestContext.authToken(), requestContext.userAgent()); - } - /** * Retrieves or creates a {@link CqlSession} for the specified tenant and authentication token. * diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/CqlSessionCacheSupplier.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/CqlSessionCacheSupplier.java index a8fcffb5a5..fdbe3acac7 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/CqlSessionCacheSupplier.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/CqlSessionCacheSupplier.java @@ -4,7 +4,7 @@ import io.stargate.sgv2.jsonapi.api.request.UserAgent; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.metrics.MetricsTenantDeactivationConsumer; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaCache; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectCacheSupplier; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import java.time.Duration; @@ -29,13 +29,12 @@ public CqlSessionCacheSupplier( @ConfigProperty(name = "quarkus.application.name") String applicationName, OperationsConfig operationsConfig, MeterRegistry meterRegistry, - SchemaCache schemaCache // aaron - later changes remove this dependency - ) { + SchemaObjectCacheSupplier schemaObjectCacheSupplier) { Objects.requireNonNull(applicationName, "applicationName must not be null"); Objects.requireNonNull(operationsConfig, "operationsConfig must not be null"); Objects.requireNonNull(meterRegistry, "meterRegistry must not be null"); - Objects.requireNonNull(schemaCache, "schemaCache must not be null"); + Objects.requireNonNull(schemaObjectCacheSupplier, "schemaObjectCacheSupplier must not be null"); var dbConfig = operationsConfig.databaseConfig(); @@ -46,13 +45,15 @@ public CqlSessionCacheSupplier( dbConfig.userName(), dbConfig.password()); + var schemaObjectCache = schemaObjectCacheSupplier.get(); + var sessionFactory = new CqlSessionFactory( applicationName, dbConfig.localDatacenter(), dbConfig.cassandraEndPoints(), dbConfig.cassandraPort(), - schemaCache::getSchemaChangeListener); + schemaObjectCache::getSchemaChangeListener); singleton = new CQLSessionCache( @@ -63,9 +64,7 @@ public CqlSessionCacheSupplier( credentialsFactory, sessionFactory, meterRegistry, - List.of( - schemaCache.getDeactivatedTenantConsumer(), - new MetricsTenantDeactivationConsumer(meterRegistry))); + List.of(new MetricsTenantDeactivationConsumer(meterRegistry))); } /** Gets the singleton instance of the {@link CQLSessionCache}. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/CommandQueryExecutor.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/CommandQueryExecutor.java index 2464473ee8..411a30f86b 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/CommandQueryExecutor.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/CommandQueryExecutor.java @@ -10,9 +10,7 @@ import com.google.common.annotations.VisibleForTesting; import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; -import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.api.request.UserAgent; -import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; +import io.stargate.sgv2.jsonapi.api.request.RequestContext; import io.stargate.sgv2.jsonapi.service.cqldriver.AccumulatingAsyncResultSet; import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; import java.util.Objects; @@ -40,7 +38,8 @@ public class CommandQueryExecutor { public enum QueryTarget { TABLE, - COLLECTION; + COLLECTION, + SCHEMA; final String profilePrefix; @@ -63,15 +62,14 @@ private enum QueryType { } private final CQLSessionCache cqlSessionCache; - private final DBRequestContext dbRequestContext; + private final RequestContext requestContext; private final QueryTarget queryTarget; public CommandQueryExecutor( - CQLSessionCache cqlSessionCache, DBRequestContext dbRequestContext, QueryTarget queryTarget) { + CQLSessionCache cqlSessionCache, RequestContext requestContext, QueryTarget queryTarget) { this.cqlSessionCache = Objects.requireNonNull(cqlSessionCache, "cqlSessionCache must not be null"); - this.dbRequestContext = - Objects.requireNonNull(dbRequestContext, "dbRequestContext must not be null"); + this.requestContext = requestContext; this.queryTarget = queryTarget; } @@ -187,7 +185,7 @@ public Uni executeCreateSchema(SimpleStatement statement) { * @return Uni of the {@link CqlSession} */ private Uni session() { - return cqlSessionCache.getSession(dbRequestContext); + return cqlSessionCache.getSession(requestContext); } private String getExecutionProfile(QueryType queryType) { @@ -201,27 +199,8 @@ private SimpleStatement withExecutionProfile(SimpleStatement statement, QueryTyp @VisibleForTesting public Uni executeAndWrap(SimpleStatement statement) { - // changing tracing creates a new object, avoid if not needed - var execStatement = - dbRequestContext.tracingEnabled() != statement.isTracing() - ? statement.setTracing(dbRequestContext.tracingEnabled()) - : statement; - return session() .flatMap( - session -> Uni.createFrom().completionStage(() -> session.executeAsync(execStatement))); - } - - // Aaron - Feb 3 - temp rename while factoring full RequestContext - public record DBRequestContext( - Tenant tenant, String authToken, UserAgent userAgent, boolean tracingEnabled) { - - public DBRequestContext(CommandContext commandContext) { - this( - commandContext.requestContext().tenant(), - commandContext.requestContext().authToken(), - commandContext.requestContext().userAgent(), - commandContext.requestTracing().enabled()); - } + session -> Uni.createFrom().completionStage(() -> session.executeAsync(statement))); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DatabaseSchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DatabaseSchemaObject.java deleted file mode 100644 index d96b7d0834..0000000000 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DatabaseSchemaObject.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.stargate.sgv2.jsonapi.service.cqldriver.executor; - -public class DatabaseSchemaObject extends SchemaObject { - - public static final SchemaObjectType TYPE = SchemaObjectType.DATABASE; - - public DatabaseSchemaObject() { - super(TYPE, SchemaObjectName.MISSING); - } - - @Override - public VectorConfig vectorConfig() { - return VectorConfig.NOT_ENABLED_CONFIG; - } - - @Override - public IndexUsage newIndexUsage() { - return IndexUsage.NO_OP; - } -} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandler.java index c7f1829a31..9a85eb0f82 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandler.java @@ -8,6 +8,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.core.servererrors.*; import io.stargate.sgv2.jsonapi.exception.DatabaseException; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.util.CqlPrintUtil; import java.util.*; import java.util.function.BiFunction; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/KeyspaceSchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/KeyspaceSchemaObject.java deleted file mode 100644 index 1f1fbc7436..0000000000 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/KeyspaceSchemaObject.java +++ /dev/null @@ -1,61 +0,0 @@ -package io.stargate.sgv2.jsonapi.service.cqldriver.executor; - -import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; - -public class KeyspaceSchemaObject extends SchemaObject { - - public static final SchemaObjectType TYPE = SchemaObjectType.KEYSPACE; - - /** Represents missing schema, e.g. when we are running a create table. */ - public static final KeyspaceSchemaObject MISSING = - new KeyspaceSchemaObject(SchemaObjectName.MISSING); - - public KeyspaceSchemaObject(String keyspace) { - this(newObjectName(keyspace)); - } - - public KeyspaceSchemaObject(SchemaObjectName name) { - super(TYPE, name); - } - - /** - * Construct a {@link KeyspaceSchemaObject} that represents the keyspace the collection is in. - * - * @param collection - * @return - */ - public static KeyspaceSchemaObject fromSchemaObject(CollectionSchemaObject collection) { - return new KeyspaceSchemaObject(newObjectName(collection.name.keyspace())); - } - - /** - * Construct a {@link KeyspaceSchemaObject} that represents the keyspace the collection is in. - * - * @param table - * @return - */ - public static KeyspaceSchemaObject fromSchemaObject(TableSchemaObject table) { - return new KeyspaceSchemaObject(newObjectName(table.name.keyspace())); - } - - @Override - public VectorConfig vectorConfig() { - return VectorConfig.NOT_ENABLED_CONFIG; - } - - @Override - public IndexUsage newIndexUsage() { - return IndexUsage.NO_OP; - } - - /** - * Centralised creation of the name for a Keyspace so we always use the correct marker object for - * collection name - * - * @param keyspaceName - * @return - */ - private static SchemaObjectName newObjectName(String keyspaceName) { - return new SchemaObjectName(keyspaceName, SchemaObjectName.MISSING_NAME); - } -} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaCache.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaCache.java index beea3fb4b1..af8f2438ac 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaCache.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaCache.java @@ -1,305 +1,316 @@ -package io.stargate.sgv2.jsonapi.service.cqldriver.executor; - -import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata; -import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener; -import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListenerBase; -import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; -import com.datastax.oss.driver.api.core.session.Session; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.benmanes.caffeine.cache.Caffeine; -import com.github.benmanes.caffeine.cache.LoadingCache; -import com.google.common.annotations.VisibleForTesting; -import io.smallrye.mutiny.Uni; -import io.stargate.sgv2.jsonapi.api.request.RequestContext; -import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; -import io.stargate.sgv2.jsonapi.api.request.tenant.TenantFactory; -import io.stargate.sgv2.jsonapi.config.DatabaseType; -import io.stargate.sgv2.jsonapi.config.OperationsConfig; -import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; -import io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionCacheSupplier; -import io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionFactory; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; -import java.util.Objects; -import java.util.Optional; -import org.jspecify.annotations.NonNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Top level entry for caching the keyspaces and tables from the backend db - * - *

IMPORTANT: use {@link #getSchemaChangeListener()} and {@link #getDeactivatedTenantConsumer()} - * to get callbacks to evict the cache when the schema changes or a tenant is deactivated. This - * should be handled in {@link CqlSessionCacheSupplier} - * - *

TODO: There should be a single level cache of keyspace,table not two levels, it will be easier - * to size and manage https://github.com/stargate/data-api/issues/2070 - */ -@ApplicationScoped -public class SchemaCache { - private static final Logger LOGGER = LoggerFactory.getLogger(SchemaCache.class); - - private final CqlSessionCacheSupplier sessionCacheSupplier; - private final DatabaseType databaseType; - private final ObjectMapper objectMapper; - private final TableCacheFactory tableCacheFactory; - private final OperationsConfig operationsConfig; - - /** caching the keyspaces we know about which then have all the tables / collections under them */ - private final LoadingCache keyspaceCache; - - @Inject - public SchemaCache( - CqlSessionCacheSupplier sessionCacheSupplier, - ObjectMapper objectMapper, - OperationsConfig operationsConfig) { - this(sessionCacheSupplier, objectMapper, operationsConfig, TableBasedSchemaCache::new); - } - - /** - * NOTE: must not use the sessionCacheSupplier in the ctor or because it will create a circular - * calls, because the sessionCacheSupplier calls schema cache to get listeners - */ - @VisibleForTesting - protected SchemaCache( - CqlSessionCacheSupplier sessionCacheSupplier, - ObjectMapper objectMapper, - OperationsConfig operationsConfig, - TableCacheFactory tableCacheFactory) { - - this.sessionCacheSupplier = - Objects.requireNonNull(sessionCacheSupplier, "sessionCacheSupplier must not be null"); - this.objectMapper = Objects.requireNonNull(objectMapper, "objectMapper must not be null"); - this.operationsConfig = operationsConfig; - this.databaseType = - Objects.requireNonNull(operationsConfig, "operationsConfig must not be null") - .databaseConfig() - .type(); - this.tableCacheFactory = - Objects.requireNonNull(tableCacheFactory, "tableCacheFactory must not be null"); - - // TODO: The size of the cache should be in configuration. - int cacheSize = 1000; - keyspaceCache = Caffeine.newBuilder().maximumSize(cacheSize).build(this::onLoad); - - LOGGER.info("SchemaCache created with max size {}", cacheSize); - } - - /** - * Gets a listener to use with the {@link CqlSessionFactory} to remove the schema cache entries - * when the DB sends schema change events. - */ - public SchemaChangeListener getSchemaChangeListener() { - return new SchemaCacheSchemaChangeListener(this); - } - - /** - * Gets a consumer to use with the {@link CQLSessionCache} to remove the schema cache entries when - * a tenant is deactivated. - */ - public CQLSessionCache.DeactivatedTenantListener getDeactivatedTenantConsumer() { - return new SchemaCacheDeactivatedTenantConsumer(this); - } - - /** Gets or loads the schema object for the given namespace and collection or table name. */ - public Uni getSchemaObject( - RequestContext requestContext, - String namespace, - String collectionName, - boolean forceRefresh) { - - Objects.requireNonNull(namespace, "namespace must not be null"); - - var tableBasedSchemaCache = - keyspaceCache.get(new KeyspaceCacheKey(requestContext.tenant(), namespace)); - Objects.requireNonNull( - tableBasedSchemaCache, "keyspaceCache must not return null tableBasedSchemaCache"); - return tableBasedSchemaCache.getSchemaObject(requestContext, collectionName, forceRefresh); - } - - private TableBasedSchemaCache onLoad(SchemaCache.KeyspaceCacheKey key) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("onLoad() - tenant: {}, keyspace: {}", key.tenant(), key.keyspace()); - } - - // Cannot get a session from the sessionCacheSupplier in the constructor because - // it will create a circular call. So need to wait until now to create the QueryExecutor - // this is OK, only happens when the table is not in the cache - var queryExecutor = new QueryExecutor(sessionCacheSupplier.get(), operationsConfig); - return tableCacheFactory.create(key.keyspace(), queryExecutor, objectMapper); - } - - /** For testing only - peek to see if the schema object is in the cache without loading it. */ - @VisibleForTesting - Optional peekSchemaObject(Tenant tenant, String keyspaceName, String tableName) { - - var tableBasedSchemaCache = - keyspaceCache.getIfPresent(new KeyspaceCacheKey(tenant, keyspaceName)); - if (tableBasedSchemaCache != null) { - return tableBasedSchemaCache.peekSchemaObject(tableName); - } - return Optional.empty(); - } - ; - - /** Removes the table from the cache if present. */ - void evictTable(Tenant tenant, String keyspace, String tableName) { - - if (LOGGER.isTraceEnabled()) { - LOGGER.trace( - "evictTable() - tenant: {}, keyspace: {}, tableName: {}", tenant, keyspace, tableName); - } - - var tableBasedSchemaCache = keyspaceCache.getIfPresent(new KeyspaceCacheKey(tenant, keyspace)); - if (tableBasedSchemaCache != null) { - tableBasedSchemaCache.evictCollectionSettingCacheEntry(tableName); - } - } - - /** Removes all keyspaces and table entries for the given tenant from the cache. */ - void evictAllKeyspaces(Tenant tenant) { - - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("evictAllKeyspaces() - tenant: {}", tenant); - } - - keyspaceCache.asMap().keySet().removeIf(key -> key.tenant().equals(tenant)); - } - - /** Removes the keyspace from the cache if present. */ - void evictKeyspace(Tenant tenant, String keyspace) { - - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("evictKeyspace() - tenant: {}, keyspace: {}", tenant, keyspace); - } - - keyspaceCache.invalidate(new KeyspaceCacheKey(tenant, keyspace)); - } - - /** Key for the Keyspace cache, we rely on the record hash and equals */ - record KeyspaceCacheKey(Tenant tenant, String keyspace) { - - KeyspaceCacheKey { - Objects.requireNonNull(tenant, "tenant must not be null"); - Objects.requireNonNull(keyspace, "namespace must not be null"); - } - } - - /** - * SchemaChangeListener for the schema cache, this is used to evict the cache entries when we get - * messages from the DB that the schema has changed. - * - *

NOTE: This relies on the sessionName being set correctly which should be in {@link - * io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionFactory} - * - *

A new schema change listener should be created for each CQL {@link Session} when it is - * created because the listener will first listen for {@link SchemaChangeListener#onSessionReady} - * and get the tenantID from the session name via {@link Session#getName}. - * - *

If the tenant is not set, null or blank, we log at ERROR rather than throw because the - * callback methods are called on driver async threads and exceptions there are unlikely to be - * passed back in the request response. - * - *

This could be non-static inner, but static to make testing easier so we can pass in the - * cache it is working with. - */ - static class SchemaCacheSchemaChangeListener extends SchemaChangeListenerBase { - - private static final Logger LOGGER = - LoggerFactory.getLogger(SchemaCacheSchemaChangeListener.class); - - private final SchemaCache schemaCache; - - private Tenant tenant = null; - - public SchemaCacheSchemaChangeListener(SchemaCache schemaCache) { - this.schemaCache = Objects.requireNonNull(schemaCache, "schemaCache must not be null"); - } - - private boolean hasTenantId(String context) { - - if (tenant == null || tenant.toString().isBlank()) { - LOGGER.error( - "SchemaCacheSchemaChangeListener tenant is null or blank when expected to be set - {}", - context); - return false; - } - return true; - } - - private void evictTable(String context, TableMetadata tableMetadata) { - - if (hasTenantId(context)) { - schemaCache.evictTable( - tenant, tableMetadata.getKeyspace().asInternal(), tableMetadata.getName().asInternal()); - } - } - - @Override - public void onSessionReady(@NonNull Session session) { - // This is called when the session is ready, we can get the tenant from the session name - // and set it in the listener so we can use it in the other methods. - tenant = TenantFactory.instance().create(session.getName()); - hasTenantId("onSessionReady called but sessionName() is null or blank"); - } - - /** - * When a table is dropped, evict from cache to reduce the size and avoid stale if it is - * re-created - */ - @Override - public void onTableDropped(@NonNull TableMetadata table) { - evictTable("onTableDropped", table); - } - - /** When a table is created, evict from cache to avoid stale if it was re-created */ - @Override - public void onTableCreated(@NonNull TableMetadata table) { - evictTable("onTableCreated", table); - } - - /** When a table is updated, evict from cache to avoid stale entries */ - @Override - public void onTableUpdated(@NonNull TableMetadata current, @NonNull TableMetadata previous) { - // table name can never change - evictTable("onTableUpdated", current); - } - - /** When keyspace dropped, we dont need any more of the tables in the cache */ - @Override - public void onKeyspaceDropped(@NonNull KeyspaceMetadata keyspace) { - if (hasTenantId("onKeyspaceDropped")) { - schemaCache.evictKeyspace(tenant, keyspace.getName().asInternal()); - } - } - } - - /** - * Listener for use with the {@link CQLSessionCache} to remove the schema cache entries when a - * tenant is deactivated. - */ - private static class SchemaCacheDeactivatedTenantConsumer - implements CQLSessionCache.DeactivatedTenantListener { - - private final SchemaCache schemaCache; - - public SchemaCacheDeactivatedTenantConsumer(SchemaCache schemaCache) { - this.schemaCache = Objects.requireNonNull(schemaCache, "schemaCache must not be null"); - } - - @Override - public void accept(Tenant tenant) { - // the sessions are keyed on the tenantID and the credentials, and one session can work with - // multiple keyspaces. So we need to evict all the keyspaces for the tenant - schemaCache.evictAllKeyspaces(tenant); - } - } - - /** Function to create a new TableBasedSchemaCache, so we can mock when testing */ - @FunctionalInterface - public interface TableCacheFactory { - TableBasedSchemaCache create( - String namespace, QueryExecutor queryExecutor, ObjectMapper objectMapper); - } -} +// package io.stargate.sgv2.jsonapi.service.cqldriver.executor; +// +// import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata; +// import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener; +// import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListenerBase; +// import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; +// import com.datastax.oss.driver.api.core.session.Session; +// import com.fasterxml.jackson.databind.ObjectMapper; +// import com.github.benmanes.caffeine.cache.Caffeine; +// import com.github.benmanes.caffeine.cache.LoadingCache; +// import com.google.common.annotations.VisibleForTesting; +// import io.smallrye.mutiny.Uni; +// import io.stargate.sgv2.jsonapi.api.request.RequestContext; +// import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; +// import io.stargate.sgv2.jsonapi.api.request.tenant.TenantFactory; +// import io.stargate.sgv2.jsonapi.config.DatabaseType; +// import io.stargate.sgv2.jsonapi.config.OperationsConfig; +// import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; +// import io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionCacheSupplier; +// import io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionFactory; +// import jakarta.enterprise.context.ApplicationScoped; +// import jakarta.inject.Inject; +// import java.util.Objects; +// import java.util.Optional; +// import org.jspecify.annotations.NonNull; +// import org.slf4j.Logger; +// import org.slf4j.LoggerFactory; +// +/// ** +// * TODO: @YUQI - DELETE WHEN SCHMEA OBJECT CACHE IS READY +// * +// *

Top level entry for caching the keyspaces and tables from the backend db +// * +// *

IMPORTANT: use {@link #getSchemaChangeListener()} and {@link +// #getDeactivatedTenantConsumer()} +// * to get callbacks to evict the cache when the schema changes or a tenant is deactivated. This +// * should be handled in {@link CqlSessionCacheSupplier} +// * +// *

TODO: There should be a single level cache of keyspace,table not two levels, it will be +// easier +// * to size and manage https://github.com/stargate/data-api/issues/2070 +// */ +// @ApplicationScoped +// public class SchemaCache { +// private static final Logger LOGGER = LoggerFactory.getLogger(SchemaCache.class); +// +// private final CqlSessionCacheSupplier sessionCacheSupplier; +// private final DatabaseType databaseType; +// private final ObjectMapper objectMapper; +// private final TableCacheFactory tableCacheFactory; +// private final OperationsConfig operationsConfig; +// +// /** caching the keyspaces we know about which then have all the tables / collections under them +// */ +// private final LoadingCache keyspaceCache; +// +// @Inject +// public SchemaCache( +// CqlSessionCacheSupplier sessionCacheSupplier, +// ObjectMapper objectMapper, +// OperationsConfig operationsConfig) { +// this(sessionCacheSupplier, objectMapper, operationsConfig, TableBasedSchemaCache::new); +// } +// +// /** +// * NOTE: must not use the sessionCacheSupplier in the ctor or because it will create a circular +// * calls, because the sessionCacheSupplier calls schema cache to get listeners +// */ +// @VisibleForTesting +// protected SchemaCache( +// CqlSessionCacheSupplier sessionCacheSupplier, +// ObjectMapper objectMapper, +// OperationsConfig operationsConfig, +// TableCacheFactory tableCacheFactory) { +// +// this.sessionCacheSupplier = +// Objects.requireNonNull(sessionCacheSupplier, "sessionCacheSupplier must not be null"); +// this.objectMapper = Objects.requireNonNull(objectMapper, "objectMapper must not be null"); +// this.operationsConfig = operationsConfig; +// this.databaseType = +// Objects.requireNonNull(operationsConfig, "operationsConfig must not be null") +// .databaseConfig() +// .type(); +// this.tableCacheFactory = +// Objects.requireNonNull(tableCacheFactory, "tableCacheFactory must not be null"); +// +// // TODO: The size of the cache should be in configuration. +// int cacheSize = 1000; +// keyspaceCache = Caffeine.newBuilder().maximumSize(cacheSize).build(this::onLoad); +// +// LOGGER.info("SchemaCache created with max size {}", cacheSize); +// } +// +// /** +// * Gets a listener to use with the {@link CqlSessionFactory} to remove the schema cache entries +// * when the DB sends schema change events. +// */ +// public SchemaChangeListener getSchemaChangeListener() { +// return new SchemaCacheSchemaChangeListener(this); +// } +// +// /** +// * Gets a consumer to use with the {@link CQLSessionCache} to remove the schema cache entries +// when +// * a tenant is deactivated. +// */ +// public CQLSessionCache.DeactivatedTenantListener getDeactivatedTenantConsumer() { +// return new SchemaCacheDeactivatedTenantConsumer(this); +// } +// +// /** Gets or loads the schema object for the given namespace and collection or table name. */ +// public Uni getSchemaObject( +// RequestContext requestContext, +// String namespace, +// String collectionName, +// boolean forceRefresh) { +// +// Objects.requireNonNull(namespace, "namespace must not be null"); +// +// var tableBasedSchemaCache = +// keyspaceCache.get(new KeyspaceCacheKey(requestContext.tenant(), namespace)); +// Objects.requireNonNull( +// tableBasedSchemaCache, "keyspaceCache must not return null tableBasedSchemaCache"); +// return tableBasedSchemaCache.getSchemaObject(requestContext, collectionName, forceRefresh); +// } +// +// private TableBasedSchemaCache onLoad(SchemaCache.KeyspaceCacheKey key) { +// if (LOGGER.isTraceEnabled()) { +// LOGGER.trace("onLoad() - tenant: {}, keyspace: {}", key.tenant(), key.keyspace()); +// } +// +// // Cannot get a session from the sessionCacheSupplier in the constructor because +// // it will create a circular call. So need to wait until now to create the QueryExecutor +// // this is OK, only happens when the table is not in the cache +// var queryExecutor = new QueryExecutor(sessionCacheSupplier.get(), operationsConfig); +// return tableCacheFactory.create(key.keyspace(), queryExecutor, objectMapper); +// } +// +// /** For testing only - peek to see if the schema object is in the cache without loading it. */ +// @VisibleForTesting +// Optional peekSchemaObject(Tenant tenant, String keyspaceName, String tableName) { +// +// var tableBasedSchemaCache = +// keyspaceCache.getIfPresent(new KeyspaceCacheKey(tenant, keyspaceName)); +// if (tableBasedSchemaCache != null) { +// return tableBasedSchemaCache.peekSchemaObject(tableName); +// } +// return Optional.empty(); +// } +// ; +// +// /** Removes the table from the cache if present. */ +// void evictTable(Tenant tenant, String keyspace, String tableName) { +// +// if (LOGGER.isTraceEnabled()) { +// LOGGER.trace( +// "evictTable() - tenant: {}, keyspace: {}, tableName: {}", tenant, keyspace, tableName); +// } +// +// var tableBasedSchemaCache = keyspaceCache.getIfPresent(new KeyspaceCacheKey(tenant, +// keyspace)); +// if (tableBasedSchemaCache != null) { +// tableBasedSchemaCache.evictCollectionSettingCacheEntry(tableName); +// } +// } +// +// /** Removes all keyspaces and table entries for the given tenant from the cache. */ +// void evictAllKeyspaces(Tenant tenant) { +// +// if (LOGGER.isTraceEnabled()) { +// LOGGER.trace("evictAllKeyspaces() - tenant: {}", tenant); +// } +// +// keyspaceCache.asMap().keySet().removeIf(key -> key.tenant().equals(tenant)); +// } +// +// /** Removes the keyspace from the cache if present. */ +// void evictKeyspace(Tenant tenant, String keyspace) { +// +// if (LOGGER.isTraceEnabled()) { +// LOGGER.trace("evictKeyspace() - tenant: {}, keyspace: {}", tenant, keyspace); +// } +// +// keyspaceCache.invalidate(new KeyspaceCacheKey(tenant, keyspace)); +// } +// +// /** Key for the Keyspace cache, we rely on the record hash and equals */ +// record KeyspaceCacheKey(Tenant tenant, String keyspace) { +// +// KeyspaceCacheKey { +// Objects.requireNonNull(tenant, "tenant must not be null"); +// Objects.requireNonNull(keyspace, "namespace must not be null"); +// } +// } +// +// /** +// * SchemaChangeListener for the schema cache, this is used to evict the cache entries when we +// get +// * messages from the DB that the schema has changed. +// * +// *

NOTE: This relies on the sessionName being set correctly which should be in {@link +// * io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionFactory} +// * +// *

A new schema change listener should be created for each CQL {@link Session} when it is +// * created because the listener will first listen for {@link +// SchemaChangeListener#onSessionReady} +// * and get the tenantID from the session name via {@link Session#getName}. +// * +// *

If the tenant is not set, null or blank, we log at ERROR rather than throw because the +// * callback methods are called on driver async threads and exceptions there are unlikely to be +// * passed back in the request response. +// * +// *

This could be non-static inner, but static to make testing easier so we can pass in the +// * cache it is working with. +// */ +// static class SchemaCacheSchemaChangeListener extends SchemaChangeListenerBase { +// +// private static final Logger LOGGER = +// LoggerFactory.getLogger(SchemaCacheSchemaChangeListener.class); +// +// private final SchemaCache schemaCache; +// +// private Tenant tenant = null; +// +// public SchemaCacheSchemaChangeListener(SchemaCache schemaCache) { +// this.schemaCache = Objects.requireNonNull(schemaCache, "schemaCache must not be null"); +// } +// +// private boolean hasTenantId(String context) { +// +// if (tenant == null || tenant.toString().isBlank()) { +// LOGGER.error( +// "SchemaCacheSchemaChangeListener tenant is null or blank when expected to be set - +// {}", +// context); +// return false; +// } +// return true; +// } +// +// private void evictTable(String context, TableMetadata tableMetadata) { +// +// if (hasTenantId(context)) { +// schemaCache.evictTable( +// tenant, tableMetadata.getKeyspace().asInternal(), +// tableMetadata.getName().asInternal()); +// } +// } +// +// @Override +// public void onSessionReady(@NonNull Session session) { +// // This is called when the session is ready, we can get the tenant from the session name +// // and set it in the listener so we can use it in the other methods. +// tenant = TenantFactory.instance().create(session.getName()); +// hasTenantId("onSessionReady called but sessionName() is null or blank"); +// } +// +// /** +// * When a table is dropped, evict from cache to reduce the size and avoid stale if it is +// * re-created +// */ +// @Override +// public void onTableDropped(@NonNull TableMetadata table) { +// evictTable("onTableDropped", table); +// } +// +// /** When a table is created, evict from cache to avoid stale if it was re-created */ +// @Override +// public void onTableCreated(@NonNull TableMetadata table) { +// evictTable("onTableCreated", table); +// } +// +// /** When a table is updated, evict from cache to avoid stale entries */ +// @Override +// public void onTableUpdated(@NonNull TableMetadata current, @NonNull TableMetadata previous) { +// // table name can never change +// evictTable("onTableUpdated", current); +// } +// +// /** When keyspace dropped, we dont need any more of the tables in the cache */ +// @Override +// public void onKeyspaceDropped(@NonNull KeyspaceMetadata keyspace) { +// if (hasTenantId("onKeyspaceDropped")) { +// schemaCache.evictKeyspace(tenant, keyspace.getName().asInternal()); +// } +// } +// } +// +// /** +// * Listener for use with the {@link CQLSessionCache} to remove the schema cache entries when a +// * tenant is deactivated. +// */ +// private static class SchemaCacheDeactivatedTenantConsumer +// implements CQLSessionCache.DeactivatedTenantListener { +// +// private final SchemaCache schemaCache; +// +// public SchemaCacheDeactivatedTenantConsumer(SchemaCache schemaCache) { +// this.schemaCache = Objects.requireNonNull(schemaCache, "schemaCache must not be null"); +// } +// +// @Override +// public void accept(Tenant tenant) { +// // the sessions are keyed on the tenantID and the credentials, and one session can work with +// // multiple keyspaces. So we need to evict all the keyspaces for the tenant +// schemaCache.evictAllKeyspaces(tenant); +// } +// } +// +// /** Function to create a new TableBasedSchemaCache, so we can mock when testing */ +// @FunctionalInterface +// public interface TableCacheFactory { +// TableBasedSchemaCache create( +// String namespace, QueryExecutor queryExecutor, ObjectMapper objectMapper); +// } +// } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaObject.java deleted file mode 100644 index 165890489a..0000000000 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaObject.java +++ /dev/null @@ -1,76 +0,0 @@ -package io.stargate.sgv2.jsonapi.service.cqldriver.executor; - -import io.stargate.sgv2.jsonapi.util.recordable.Recordable; -import java.util.Objects; - -/** A Collection or Table the command works on */ -public abstract class SchemaObject implements Recordable { - - // Because a lot of code needs to make decisions based on the type of the SchemaObject use an - // enum and we also have generics for strong type checking - public enum SchemaObjectType { - COLLECTION(Constants.COLLECTION), - DATABASE(Constants.DATABASE), - INDEX(Constants.INDEX), - KEYSPACE(Constants.KEYSPACE), - TABLE(Constants.TABLE), - UDT(Constants.UDT); - - /** Constants so the public HTTP API objects can use the same values. */ - public interface Constants { - String COLLECTION = "Collection"; - String DATABASE = "Database"; - String INDEX = "Index"; - String KEYSPACE = "Keyspace"; - String TABLE = "Table"; - String UDT = "Udt"; - } - - private final String apiName; - - SchemaObjectType(String apiName) { - this.apiName = Objects.requireNonNull(apiName, "apiName must not be null"); - } - - /** Gets the name to use when identifying this schema object type in the public API. */ - public String apiName() { - return apiName; - } - } - - protected final SchemaObjectType type; - protected final SchemaObjectName name; - - protected SchemaObject(SchemaObjectType type, SchemaObjectName name) { - this.type = type; - this.name = name; - } - - public SchemaObjectType type() { - return type; - } - - public SchemaObjectName name() { - return name; - } - - /** - * Subclasses must always return VectorConfig, if there is no vector config they should return - * VectorConfig.notEnabledVectorConfig(). - * - * @return - */ - public abstract VectorConfig vectorConfig(); - - /** - * Call to get an instance of the appropriate {@link IndexUsage} for this schema object - * - * @return non null, IndexUsage instance - */ - public abstract IndexUsage newIndexUsage(); - - @Override - public Recordable.DataRecorder recordTo(Recordable.DataRecorder dataRecorder) { - return dataRecorder.append("type", type).append("name", name); - } -} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaObjectName.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaObjectName.java deleted file mode 100644 index 00de4f348f..0000000000 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaObjectName.java +++ /dev/null @@ -1,46 +0,0 @@ -package io.stargate.sgv2.jsonapi.service.cqldriver.executor; - -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import io.stargate.sgv2.jsonapi.util.recordable.Recordable; -import org.slf4j.MDC; - -public record SchemaObjectName(String keyspace, String table) implements Recordable { - - // Marker object to use when the name is missing - public static final String MISSING_NAME = ""; - - public static final SchemaObjectName MISSING = new SchemaObjectName(MISSING_NAME, MISSING_NAME); - - @SuppressWarnings("StringEquality") - public SchemaObjectName(String keyspace, String table) { - // Check using reference equality for the missing value marker object, so we only allow empty - // string if that object is used. - Preconditions.checkArgument( - (MISSING_NAME == keyspace) || !Strings.isNullOrEmpty(keyspace), "keyspace cannot be null"); - Preconditions.checkArgument( - (MISSING_NAME == table) || !Strings.isNullOrEmpty(table), "table cannot be null"); - - this.keyspace = keyspace; - this.table = table; - } - - // TODO, check if MDC actually populates these logs as expected - public void addToMDC() { - // NOTE: MUST stay as namespace for logging analysis - MDC.put("namespace", keyspace); - - // NOTE: MUST stay as collection for logging analysis - MDC.put("collection", table); - } - - public void removeFromMDC() { - MDC.remove("namespace"); - MDC.remove("collection"); - } - - @Override - public DataRecorder recordTo(DataRecorder dataRecorder) { - return dataRecorder.append("keyspace", keyspace).append("table", table); - } -} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableBasedSchemaCache.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableBasedSchemaCache.java index 36ea24ee16..44345dc1a4 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableBasedSchemaCache.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableBasedSchemaCache.java @@ -1,126 +1,133 @@ -package io.stargate.sgv2.jsonapi.service.cqldriver.executor; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; -import io.smallrye.mutiny.Uni; -import io.stargate.sgv2.jsonapi.api.request.RequestContext; -import io.stargate.sgv2.jsonapi.exception.ErrorCodeV1; -import io.stargate.sgv2.jsonapi.exception.JsonApiException; -import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; -import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionTableMatcher; -import java.time.Duration; -import java.util.Map; -import java.util.Optional; - -/** Caches the vector enabled status for the namespace */ -// TODO: what is the vector status of a namespace ? vectors are per collection -// TODO: clarify the name of this class, it is a cache of the collections/ tables not a cache of -// namespaces ?? -public class TableBasedSchemaCache { - - public final String namespace; - - public final QueryExecutor queryExecutor; - - private final ObjectMapper objectMapper; - - // TODO: move the settings to config - // TODO: set the cache loader when creating the cache - private static final long CACHE_TTL_SECONDS = 300; - private static final long CACHE_MAX_SIZE = 1000; - private final Cache schemaObjectCache = - Caffeine.newBuilder() - .expireAfterWrite(Duration.ofSeconds(CACHE_TTL_SECONDS)) - .maximumSize(CACHE_MAX_SIZE) - .build(); - - public TableBasedSchemaCache( - String namespace, QueryExecutor queryExecutor, ObjectMapper objectMapper) { - this.namespace = namespace; - this.queryExecutor = queryExecutor; - this.objectMapper = objectMapper; - } - - protected Uni getSchemaObject( - RequestContext requestContext, String collectionName, boolean forceRefresh) { - - // TODO: why is this not using the loader pattern ? - SchemaObject schemaObject = null; - if (!forceRefresh) { - schemaObject = schemaObjectCache.getIfPresent(collectionName); - } - if (null != schemaObject) { - return Uni.createFrom().item(schemaObject); - } else { - return loadSchemaObject(requestContext, collectionName) - .onItemOrFailure() - .transformToUni( - (result, error) -> { - if (null != error) { - // not a valid collection schema - // TODO: Explain why this changes the error code - if (error instanceof JsonApiException - && ((JsonApiException) error).getErrorCode() - == ErrorCodeV1.VECTORIZECONFIG_CHECK_FAIL) { - return Uni.createFrom() - .failure( - ErrorCodeV1.INVALID_JSONAPI_COLLECTION_SCHEMA.toApiException( - "%s", collectionName)); - } - // collection does not exist - // TODO: DO NOT do a string starts with, use proper error structures - // again, why is this here, looks like it returns the same error code ? - // Guess: this a driver exception, not Data API's internal one - // ... seems unlikely as driver does not have concept of "Collection" (vs Tables)? - // (that is: "Collection" would refer to column datatype not "funny table"?) - if (error instanceof RuntimeException rte - && rte.getMessage().startsWith("Collection does not exist")) { - return Uni.createFrom() - .failure( - SchemaException.Code.COLLECTION_NOT_EXIST.get( - Map.of("collection", collectionName))); - } - return Uni.createFrom().failure(error); - } - schemaObjectCache.put(collectionName, result); - return Uni.createFrom().item(result); - }); - } - } - - Optional peekSchemaObject(String tableName) { - return Optional.ofNullable(schemaObjectCache.getIfPresent(tableName)); - } - - private Uni loadSchemaObject(RequestContext requestContext, String collectionName) { - - return queryExecutor - .getTableMetadata(requestContext, namespace, collectionName) - .onItem() - .transform( - optionalTable -> { - // TODO: AARON - I changed the logic here, needs to be checked - // TODO: error code here needs to be for collections and tables - var table = - optionalTable.orElseThrow( - () -> - SchemaException.Code.COLLECTION_NOT_EXIST.get( - Map.of("collection", collectionName))); - - // check if its a valid json API Table - // TODO: re-use the table matcher this is on the request hot path - if (new CollectionTableMatcher().test(table)) { - return CollectionSchemaObject.getCollectionSettings( - optionalTable.get(), objectMapper); - } - - return TableSchemaObject.from(table, objectMapper); - }); - } - - public void evictCollectionSettingCacheEntry(String collectionName) { - schemaObjectCache.invalidate(collectionName); - } -} +// package io.stargate.sgv2.jsonapi.service.cqldriver.executor; +// +// import com.fasterxml.jackson.databind.ObjectMapper; +// import com.github.benmanes.caffeine.cache.Cache; +// import com.github.benmanes.caffeine.cache.Caffeine; +// import io.smallrye.mutiny.Uni; +// import io.stargate.sgv2.jsonapi.api.request.RequestContext; +// import io.stargate.sgv2.jsonapi.exception.ErrorCodeV1; +// import io.stargate.sgv2.jsonapi.exception.JsonApiException; +// import io.stargate.sgv2.jsonapi.exception.SchemaException; +// import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; +// import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +// import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionTableMatcher; +// import java.time.Duration; +// import java.util.Map; +// import java.util.Optional; +// +/// ** +// * TODO: @YUQI - DELETE WHEN SCHMEA OBJECT CACHE IS READY +// * +// *

Caches the vector enabled status for the namespace +// */ +//// TODO: what is the vector status of a namespace ? vectors are per collection +//// TODO: clarify the name of this class, it is a cache of the collections/ tables not a cache of +//// namespaces ?? +// public class TableBasedSchemaCache { +// +// public final String namespace; +// +// public final QueryExecutor queryExecutor; +// +// private final ObjectMapper objectMapper; +// +// // TODO: move the settings to config +// // TODO: set the cache loader when creating the cache +// private static final long CACHE_TTL_SECONDS = 300; +// private static final long CACHE_MAX_SIZE = 1000; +// private final Cache schemaObjectCache = +// Caffeine.newBuilder() +// .expireAfterWrite(Duration.ofSeconds(CACHE_TTL_SECONDS)) +// .maximumSize(CACHE_MAX_SIZE) +// .build(); +// +// public TableBasedSchemaCache( +// String namespace, QueryExecutor queryExecutor, ObjectMapper objectMapper) { +// this.namespace = namespace; +// this.queryExecutor = queryExecutor; +// this.objectMapper = objectMapper; +// } +// +// protected Uni getSchemaObject( +// RequestContext requestContext, String collectionName, boolean forceRefresh) { +// +// // TODO: why is this not using the loader pattern ? +// SchemaObject schemaObject = null; +// if (!forceRefresh) { +// schemaObject = schemaObjectCache.getIfPresent(collectionName); +// } +// if (null != schemaObject) { +// return Uni.createFrom().item(schemaObject); +// } else { +// return loadSchemaObject(requestContext, collectionName) +// .onItemOrFailure() +// .transformToUni( +// (result, error) -> { +// if (null != error) { +// // not a valid collection schema +// // TODO: Explain why this changes the error code +// if (error instanceof JsonApiException +// && ((JsonApiException) error).getErrorCode() +// == ErrorCodeV1.VECTORIZECONFIG_CHECK_FAIL) { +// return Uni.createFrom() +// .failure( +// ErrorCodeV1.INVALID_JSONAPI_COLLECTION_SCHEMA.toApiException( +// "%s", collectionName)); +// } +// // collection does not exist +// // TODO: DO NOT do a string starts with, use proper error structures +// // again, why is this here, looks like it returns the same error code ? +// // Guess: this a driver exception, not Data API's internal one +// // ... seems unlikely as driver does not have concept of "Collection" (vs +// Tables)? +// // (that is: "Collection" would refer to column datatype not "funny table"?) +// if (error instanceof RuntimeException rte +// && rte.getMessage().startsWith("Collection does not exist")) { +// return Uni.createFrom() +// .failure( +// SchemaException.Code.COLLECTION_NOT_EXIST.get( +// Map.of("collection", collectionName))); +// } +// return Uni.createFrom().failure(error); +// } +// schemaObjectCache.put(collectionName, result); +// return Uni.createFrom().item(result); +// }); +// } +// } +// +// Optional peekSchemaObject(String tableName) { +// return Optional.ofNullable(schemaObjectCache.getIfPresent(tableName)); +// } +// +// private Uni loadSchemaObject(RequestContext requestContext, String collectionName) +// { +// +// return queryExecutor +// .getTableMetadata(requestContext, namespace, collectionName) +// .onItem() +// .transform( +// optionalTable -> { +// // TODO: AARON - I changed the logic here, needs to be checked +// // TODO: error code here needs to be for collections and tables +// var table = +// optionalTable.orElseThrow( +// () -> +// SchemaException.Code.COLLECTION_NOT_EXIST.get( +// Map.of("collection", collectionName))); +// +// // check if its a valid json API Table +// // TODO: re-use the table matcher this is on the request hot path +// if (new CollectionTableMatcher().test(table)) { +// return CollectionSchemaObject.getCollectionSettings( +// optionalTable.get(), objectMapper); +// } +// +// return TableSchemaObject.from(table, objectMapper); +// }); +// } +// +// public void evictCollectionSettingCacheEntry(String collectionName) { +// schemaObjectCache.invalidate(collectionName); +// } +// } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableBasedSchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableBasedSchemaObject.java deleted file mode 100644 index 083b64cc50..0000000000 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableBasedSchemaObject.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.stargate.sgv2.jsonapi.service.cqldriver.executor; - -import com.datastax.oss.driver.api.core.CqlIdentifier; -import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; - -public abstract class TableBasedSchemaObject extends SchemaObject { - - private final TableMetadata tableMetadata; - - protected TableBasedSchemaObject(SchemaObjectType type, TableMetadata tableMetadata) { - // uses asCql(pretty) so the names do not always include double quotes - this( - type, - tableMetadata == null - ? SchemaObjectName.MISSING - : new SchemaObjectName( - tableMetadata.getKeyspace().asCql(true), tableMetadata.getName().asCql(true)), - tableMetadata); - } - - // aaron- adding this ctor so for now the CollectionSchemaObject can set the schemaObjectName and - // have the tablemetdata - // be null because it is not used by any collection processing (currently). - protected TableBasedSchemaObject( - SchemaObjectType type, SchemaObjectName name, TableMetadata tableMetadata) { - // uses asCql(pretty) so the names do not always include double quotes - super(type, name); - this.tableMetadata = tableMetadata; - } - - public CqlIdentifier keyspaceName() { - return tableMetadata.getKeyspace(); - } - - public CqlIdentifier tableName() { - return tableMetadata.getName(); - } - - public TableMetadata tableMetadata() { - return tableMetadata; - } -} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/embedding/DataVectorizer.java b/src/main/java/io/stargate/sgv2/jsonapi/service/embedding/DataVectorizer.java index f26afda2fa..9058e07a67 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/embedding/DataVectorizer.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/embedding/DataVectorizer.java @@ -3,6 +3,7 @@ import static io.stargate.sgv2.jsonapi.config.constants.DocumentConstants.Fields.VECTOR_EMBEDDING_FIELD; import static io.stargate.sgv2.jsonapi.config.constants.DocumentConstants.Fields.VECTOR_EMBEDDING_TEXT_FIELD; import static io.stargate.sgv2.jsonapi.exception.ErrorCodeV1.EMBEDDING_PROVIDER_UNEXPECTED_RESPONSE; +import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierToMessageString; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -16,10 +17,10 @@ import io.stargate.sgv2.jsonapi.exception.DocumentException; import io.stargate.sgv2.jsonapi.exception.ErrorCodeV1; import io.stargate.sgv2.jsonapi.exception.JsonApiException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorColumnDefinition; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProvider; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTypeName; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiVectorType; @@ -100,7 +101,7 @@ public Uni vectorize(List documents) { if (!vectorizeTexts.isEmpty()) { if (embeddingProvider == null) { throw ErrorCodeV1.EMBEDDING_SERVICE_NOT_CONFIGURED.toApiException( - schemaObject.name().table()); + cqlIdentifierToMessageString(schemaObject.identifier().table())); } Uni> vectors = embeddingProvider @@ -167,7 +168,7 @@ public Uni vectorize(List documents) { public Uni vectorize(String vectorizeContent) { if (embeddingProvider == null) { throw ErrorCodeV1.EMBEDDING_SERVICE_NOT_CONFIGURED.toApiException( - schemaObject.name().table()); + cqlIdentifierToMessageString(schemaObject.identifier().table())); } Uni> vectors = embeddingProvider @@ -211,7 +212,7 @@ public Uni vectorize(SortClause sortClause) { if (sortClause.hasVectorizeSearchClause()) { if (embeddingProvider == null) { throw ErrorCodeV1.EMBEDDING_SERVICE_NOT_CONFIGURED.toApiException( - schemaObject.name().table()); + cqlIdentifierToMessageString(schemaObject.identifier().table())); } final List sortExpressions = sortClause.sortExpressions(); SortExpression expression = sortExpressions.getFirst(); @@ -299,7 +300,7 @@ private Uni> vectorizeTexts( // Copied from vectorize(List documents) above leaving as is for now if (embeddingProvider == null) { throw ErrorCodeV1.EMBEDDING_SERVICE_NOT_CONFIGURED.toApiException( - schemaObject.name().table()); + cqlIdentifierToMessageString(schemaObject.identifier().table())); } return embeddingProvider diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/embedding/DataVectorizerService.java b/src/main/java/io/stargate/sgv2/jsonapi/service/embedding/DataVectorizerService.java index 8d2db5702d..107d3b6378 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/embedding/DataVectorizerService.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/embedding/DataVectorizerService.java @@ -17,13 +17,13 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.UpdateOneCommand; import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonApiMetricsConfig; import io.stargate.sgv2.jsonapi.exception.*; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProvider; import io.stargate.sgv2.jsonapi.service.embedding.operation.MeteredEmbeddingProvider; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTypeName; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiVectorType; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import java.util.*; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/DeleteDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/DeleteDBTask.java index 35a2ddb370..d4f60af0fa 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/DeleteDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/DeleteDBTask.java @@ -7,10 +7,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.WhereCQLClause; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import java.util.ArrayList; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/DeleteDBTaskPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/DeleteDBTaskPage.java index 2d67418579..e73b594223 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/DeleteDBTaskPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/DeleteDBTaskPage.java @@ -4,10 +4,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTaskPage; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskAccumulator; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; /** * A page of results from a delete command, use {@link #builder()} to get a builder to pass to diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/GenericOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/GenericOperation.java index 7237b02d87..e5dafaeb32 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/GenericOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/GenericOperation.java @@ -5,6 +5,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.*; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.Objects; import java.util.function.Supplier; import org.slf4j.Logger; @@ -94,11 +95,7 @@ protected Multi startMulti(CommandContext commandContext) { var commandQueryExecutor = new CommandQueryExecutor( commandContext.cqlSessionCache(), - new CommandQueryExecutor.DBRequestContext( - commandContext.requestContext().tenant(), - commandContext.requestContext().authToken(), - commandContext.requestContext().userAgent(), - commandContext.requestTracing().enabled()), + commandContext.requestContext(), CommandQueryExecutor.QueryTarget.TABLE); // Common start pattern for all operations diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertAttempt.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertAttempt.java index 78861b41be..5934f5fc0c 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertAttempt.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertAttempt.java @@ -6,8 +6,8 @@ import com.datastax.oss.driver.api.querybuilder.insert.OngoingValues; import com.datastax.oss.driver.api.querybuilder.insert.RegularInsert; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.InsertValuesCQLClause; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.DocRowIdentifer; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertDBTask.java index fb7cdffee6..fecd2ff0b2 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertDBTask.java @@ -8,10 +8,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.InsertValuesCQLClause; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.DocRowIdentifer; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertDBTaskPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertDBTaskPage.java index 90b4072be5..7a5168a3b2 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertDBTaskPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertDBTaskPage.java @@ -7,10 +7,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; import io.stargate.sgv2.jsonapi.config.constants.ErrorObjectV2Constants; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTaskPage; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskAccumulator; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.DocRowIdentifer; import io.stargate.sgv2.jsonapi.service.shredding.tables.RowId; import java.util.*; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertOperationPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertOperationPage.java index be9aefe073..1d6413b3be 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertOperationPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/InsertOperationPage.java @@ -9,7 +9,7 @@ import io.stargate.sgv2.jsonapi.exception.APIException; import io.stargate.sgv2.jsonapi.exception.APIExceptionCommandErrorBuilder; import io.stargate.sgv2.jsonapi.exception.mappers.ThrowableToErrorMapper; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.DocRowIdentifer; import java.util.*; import java.util.function.BiConsumer; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListIndexesDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListIndexesDBTask.java index 24a6e37a51..fa73f493c2 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListIndexesDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListIndexesDBTask.java @@ -4,10 +4,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.table.SchemaDescSource; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiIndexDefContainer; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -43,10 +43,7 @@ private Optional indexesForTable() { if (!TABLE_MATCHER.test(tableMetadata)) { return Optional.empty(); } - var indexesContainer = - TableSchemaObject.from(tableMetadata, OBJECT_MAPPER) - .apiTableDef() - .indexesIncludingUnsupported(); + var indexesContainer = schemaObject.apiTableDef().indexesIncludingUnsupported(); if (LOGGER.isDebugEnabled()) { LOGGER.debug( "indexesForTable() - table: {} indexesContainer: {}", diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListTablesDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListTablesDBTask.java index edbe9b948f..64f5299c49 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListTablesDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListTablesDBTask.java @@ -4,10 +4,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.table.SchemaDescSource; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.List; import java.util.Objects; @@ -67,7 +67,10 @@ protected Object getSchema() { .values() .stream() .filter(TABLE_MATCHER) - .map(tableMetadata -> TableSchemaObject.from(tableMetadata, OBJECT_MAPPER)) + .map( + tableMetadata -> + TableSchemaObject.from( + schemaObject.identifier().tenant(), tableMetadata, OBJECT_MAPPER)) .map( tableSchemaObject -> tableSchemaObject diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListTypesDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListTypesDBTask.java index 8c6b7451b2..4e23e09adf 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListTypesDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ListTypesDBTask.java @@ -6,9 +6,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.table.SchemaDescSource; import io.stargate.sgv2.jsonapi.exception.checked.UnsupportedCqlType; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiUdtType; import io.stargate.sgv2.jsonapi.service.schema.tables.TypeBindingPoint; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/MetadataDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/MetadataDBTask.java index 587900db10..2955b8ca93 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/MetadataDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/MetadataDBTask.java @@ -11,11 +11,11 @@ import io.stargate.sgv2.jsonapi.service.cqldriver.EmptyAsyncResultSet; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.BaseTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.Task; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionTableMatcher; import io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil; import java.util.List; @@ -56,7 +56,11 @@ protected AsyncResultSetSupplier buildDBResultSupplier( CommandContext commandContext, CommandQueryExecutor queryExecutor) { return new MetadataAsyncResultSetSupplier( - commandContext, this, null, queryExecutor, schemaObject.name().keyspace()); + commandContext, + this, + null, + queryExecutor, + schemaObject.identifier().keyspace().asInternal()); } @Override diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/MetadataDBTaskPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/MetadataDBTaskPage.java index 03e45670bc..734d68ae7b 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/MetadataDBTaskPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/MetadataDBTaskPage.java @@ -4,10 +4,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTaskPage; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskAccumulator; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.function.Supplier; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/Operation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/Operation.java index 07d7e40f43..156a622917 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/Operation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/Operation.java @@ -6,7 +6,7 @@ import io.stargate.sgv2.jsonapi.api.request.RequestContext; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.QueryExecutor; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.function.Supplier; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttempt.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttempt.java index df0fa67863..108b341fa5 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttempt.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttempt.java @@ -10,7 +10,7 @@ import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.util.CqlPrintUtil; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.time.Duration; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptAccumulator.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptAccumulator.java index 0805fa3720..8d4f71264b 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptAccumulator.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptAccumulator.java @@ -1,7 +1,7 @@ package io.stargate.sgv2.jsonapi.service.operation; import io.smallrye.mutiny.Multi; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; /** * TODO: aaron 19 march 2025 - remove OperationAttempt and related code once Tasks are solid diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptContainer.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptContainer.java index c846ada50d..3f8dd19034 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptContainer.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptContainer.java @@ -1,6 +1,6 @@ package io.stargate.sgv2.jsonapi.service.operation; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.*; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptPage.java index 3698649618..ed8313667e 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptPage.java @@ -3,7 +3,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.Collections; import java.util.Objects; import java.util.Optional; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptPageBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptPageBuilder.java index 39c7a3ff4d..0f16264e2d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptPageBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/OperationAttemptPageBuilder.java @@ -1,7 +1,7 @@ package io.stargate.sgv2.jsonapi.service.operation; import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.function.Supplier; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ReadDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ReadDBTask.java index 5dd99a65e8..8193d3f752 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ReadDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ReadDBTask.java @@ -19,6 +19,7 @@ import io.stargate.sgv2.jsonapi.service.operation.query.*; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import java.time.Duration; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ReadDBTaskPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ReadDBTaskPage.java index 38c3e7ccf8..054b32889d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ReadDBTaskPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/ReadDBTaskPage.java @@ -3,9 +3,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.*; import io.stargate.sgv2.jsonapi.api.model.command.clause.sort.SortExpression; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CqlPagingState; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.*; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.*; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/SchemaDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/SchemaDBTask.java index a0de87f9ab..0c1c1d6573 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/SchemaDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/SchemaDBTask.java @@ -8,9 +8,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.time.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/SchemaDBTaskPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/SchemaDBTaskPage.java index d6a3980718..c77df641d3 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/SchemaDBTaskPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/SchemaDBTaskPage.java @@ -4,10 +4,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskAccumulator; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskPage; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.function.Supplier; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/TruncateDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/TruncateDBTask.java index b8af1a7338..457dcc83d6 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/TruncateDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/TruncateDBTask.java @@ -5,10 +5,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/TruncateDBTaskPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/TruncateDBTaskPage.java index 9ffb2ac9b4..c7b88dbc4d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/TruncateDBTaskPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/TruncateDBTaskPage.java @@ -4,11 +4,11 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTaskPage; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskAccumulator; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.function.Supplier; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTask.java index 8db887abd1..f9949b580c 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTask.java @@ -8,11 +8,11 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.UpdateValuesCQLClause; import io.stargate.sgv2.jsonapi.service.operation.query.WhereCQLClause; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.ArrayList; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTaskBuilder.java index 2a2c2d0ae2..0f09a8b5c7 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTaskBuilder.java @@ -3,11 +3,11 @@ import com.datastax.oss.driver.api.querybuilder.update.Update; import io.stargate.sgv2.jsonapi.exception.FilterException; import io.stargate.sgv2.jsonapi.exception.WithWarnings; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.UpdateValuesCQLClause; import io.stargate.sgv2.jsonapi.service.operation.query.WhereCQLClause; import io.stargate.sgv2.jsonapi.service.operation.tables.WhereCQLClauseAnalyzer; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTaskPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTaskPage.java index d9c7829d45..023e23af86 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTaskPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/UpdateDBTaskPage.java @@ -4,10 +4,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.DBTaskPage; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskAccumulator; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; /** * A page of results from a update command, use {@link #builder()} to get a builder to pass to diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/CountCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/CountCollectionOperation.java index d70471596c..ee70758ed4 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/CountCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/CountCollectionOperation.java @@ -56,8 +56,8 @@ private SimpleStatement buildSelectQuery() { .count() .as("count") .from( - commandContext.schemaObject().name().keyspace(), - commandContext.schemaObject().name().table()) + commandContext.schemaObject().identifier().keyspace().asInternal(), + commandContext.schemaObject().identifier().table().asInternal()) .where(expressions.get(0)) .build(); } else { @@ -66,8 +66,8 @@ private SimpleStatement buildSelectQuery() { .select() .column("key") .from( - commandContext.schemaObject().name().keyspace(), - commandContext.schemaObject().name().table()) + commandContext.schemaObject().identifier().keyspace().asInternal(), + commandContext.schemaObject().identifier().table().asInternal()) .where(expressions.get(0)) .limit(limit + 1) .build(); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/CreateCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/CreateCollectionOperation.java index 16c29f1fcf..50338d070a 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/CreateCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/CreateCollectionOperation.java @@ -20,10 +20,10 @@ import io.stargate.sgv2.jsonapi.exception.JsonApiException; import io.stargate.sgv2.jsonapi.exception.SchemaException; import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.QueryExecutor; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.schema.EmbeddingSourceModel; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.SimilarityFunction; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionLexicalConfig; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionRerankDef; @@ -127,7 +127,7 @@ public Uni> execute( logger.info( "Executing CreateCollectionOperation for {}.{} with definition: {}", - commandContext.schemaObject().name().keyspace(), + commandContext.schemaObject().identifier().keyspace(), name, comment); @@ -141,8 +141,7 @@ public Uni> execute( // refactor to make // this operation fully Async, without refactoring all the logic. KeyspaceMetadata currKeyspace = - allKeyspaces.get( - CqlIdentifier.fromInternal(commandContext.schemaObject().name().keyspace())); + allKeyspaces.get(commandContext.schemaObject().identifier().keyspace()); if (currKeyspace == null) { return Uni.createFrom() @@ -162,7 +161,8 @@ public Uni> execute( // if table exists, compare existingCollectionSettings and newCollectionSettings CollectionSchemaObject existingCollectionSettings = - CollectionSchemaObject.getCollectionSettings(tableMetadata, objectMapper); + CollectionSchemaObject.getCollectionSettings( + requestContext.tenant(), tableMetadata, objectMapper); // Use the fromNameOrDefault() so if not specified it will default var embeddingSourceModel = @@ -176,9 +176,8 @@ public Uni> execute( () -> SimilarityFunction.getUnknownFunctionException(vectorFunction)); CollectionSchemaObject newCollectionSettings = - CollectionSchemaObject.getCollectionSettings( - currKeyspace.getName().asInternal(), - name, + CollectionSchemaObject.createCollectionSettings( + commandContext.schemaObject().identifier(), tableMetadata, vectorSearch, vectorSize, @@ -221,7 +220,7 @@ public Uni> execute( logger.info( "CreateCollectionOperation for {}.{} with existing legacy lexical/reranking settings, new settings differ. Tried to unify, result: {}" + " Old settings: {}, New settings: {}", - commandContext.schemaObject().name().keyspace(), + commandContext.schemaObject().identifier().keyspace(), name, settingsAreEqual, existingCollectionSettings, @@ -230,7 +229,7 @@ public Uni> execute( logger.info( "CreateCollectionOperation for {}.{} with different settings (but not old legacy lexical/reranking settings), cannot unify." + " Old settings: {}, New settings: {}", - commandContext.schemaObject().name().keyspace(), + commandContext.schemaObject().identifier().keyspace(), name, existingCollectionSettings, newCollectionSettings); @@ -266,7 +265,7 @@ private Uni> executeCollectionCreation( queryExecutor.executeCreateSchemaChange( dataApiRequestInfo, getCreateTable( - commandContext.schemaObject().name().keyspace(), + commandContext.schemaObject().identifier().keyspace().asInternal(), name, vectorSearch, vectorSize, @@ -283,7 +282,7 @@ private Uni> executeCollectionCreation( if (res.wasApplied()) { final List indexStatements = getIndexStatements( - commandContext.schemaObject().name().keyspace(), + commandContext.schemaObject().identifier().keyspace().asInternal(), name, lexicalConfig, collectionExisted); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/DeleteCollectionCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/DeleteCollectionCollectionOperation.java index daf45c5f7d..e0e6e72cf9 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/DeleteCollectionCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/DeleteCollectionCollectionOperation.java @@ -5,9 +5,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.request.RequestContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.QueryExecutor; import io.stargate.sgv2.jsonapi.service.operation.Operation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.function.Supplier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +29,7 @@ public record DeleteCollectionCollectionOperation( public Uni> execute( RequestContext dataApiRequestInfo, QueryExecutor queryExecutor) { logger.info("Executing DeleteCollectionCollectionOperation for {}", name); - String cql = DROP_TABLE_CQL.formatted(context.schemaObject().name().keyspace(), name); + String cql = DROP_TABLE_CQL.formatted(context.schemaObject().identifier().keyspace(), name); SimpleStatement query = SimpleStatement.newInstance(cql); // execute return queryExecutor diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/DeleteCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/DeleteCollectionOperation.java index 9fae39ac55..761ff2f3a6 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/DeleteCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/DeleteCollectionOperation.java @@ -178,8 +178,8 @@ private String buildDeleteQuery() { String delete = "DELETE FROM \"%s\".\"%s\" WHERE key = ? IF tx_id = ?"; return String.format( delete, - commandContext.schemaObject().name().keyspace(), - commandContext.schemaObject().name().table()); + commandContext.schemaObject().identifier().keyspace(), + commandContext.schemaObject().identifier().table()); } /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/EstimatedDocumentCountCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/EstimatedDocumentCountCollectionOperation.java index 48216c1906..c7fa40b65f 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/EstimatedDocumentCountCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/EstimatedDocumentCountCollectionOperation.java @@ -8,7 +8,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.request.RequestContext; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.QueryExecutor; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.function.Supplier; /** Operation that returns estimated count of documents. */ @@ -34,9 +34,9 @@ private SimpleStatement buildSelectQuery() { return selectFrom("system", "size_estimates") .all() .whereColumn("keyspace_name") - .isEqualTo(literal(commandContext.schemaObject().name().keyspace())) + .isEqualTo(literal(commandContext.schemaObject().identifier().keyspace())) .whereColumn("table_name") - .isEqualTo(literal(commandContext.schemaObject().name().table())) + .isEqualTo(literal(commandContext.schemaObject().identifier().table())) .build(); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionOperation.java index a47615ee42..3956876152 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionOperation.java @@ -369,7 +369,7 @@ public Uni> execute( return Uni.createFrom() .failure( ErrorCodeV1.VECTOR_SEARCH_NOT_SUPPORTED.toApiException( - "%s", commandContext().schemaObject().name().table())); + "%s", commandContext().schemaObject().identifier().table().asInternal())); } // get FindResponse @@ -517,8 +517,8 @@ private List buildSelectQueries(IDCollectionFilter additionalId ? documentColumns : documentKeyColumns) .from( - commandContext.schemaObject().name().keyspace(), - commandContext.schemaObject().name().table()) + commandContext.schemaObject().identifier().keyspace().toString(), + commandContext.schemaObject().identifier().table().toString()) .where(expression) .limit(limit); var bm25Expr = bm25SearchExpression(); @@ -551,8 +551,8 @@ private Query getVectorSearchQueryByExpression(Expression expres DocumentConstants.Columns.VECTOR_SEARCH_INDEX_COLUMN_NAME, commandContext().schemaObject().similarityFunction()) .from( - commandContext.schemaObject().name().keyspace(), - commandContext.schemaObject().name().table()) + commandContext.schemaObject().identifier().keyspace().asInternal(), + commandContext.schemaObject().identifier().table().asInternal()) .where(expression) .limit(limit) .vsearch(DocumentConstants.Columns.VECTOR_SEARCH_INDEX_COLUMN_NAME, vector()) @@ -562,8 +562,8 @@ private Query getVectorSearchQueryByExpression(Expression expres .select() .column(CollectionReadType.DOCUMENT == readType ? documentColumns : documentKeyColumns) .from( - commandContext.schemaObject().name().keyspace(), - commandContext.schemaObject().name().table()) + commandContext.schemaObject().identifier().keyspace().asInternal(), + commandContext.schemaObject().identifier().table().asInternal()) .where(expression) .limit(limit) .vsearch(DocumentConstants.Columns.VECTOR_SEARCH_INDEX_COLUMN_NAME, vector()) @@ -600,8 +600,8 @@ private List buildSortedSelectQueries(IDCollectionFilter additi .select() .column(columnsToAdd) .from( - commandContext.schemaObject().name().keyspace(), - commandContext.schemaObject().name().table()) + commandContext.schemaObject().identifier().keyspace().asInternal(), + commandContext.schemaObject().identifier().table().asInternal()) .where(expression) .limit(maxSortReadLimit()) .build(); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionsCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionsCollectionOperation.java index df64111ad5..12f8b8e7dd 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionsCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionsCollectionOperation.java @@ -14,9 +14,9 @@ import io.stargate.sgv2.jsonapi.api.request.RequestContext; import io.stargate.sgv2.jsonapi.exception.SchemaException; import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.QueryExecutor; import io.stargate.sgv2.jsonapi.service.operation.Operation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionTableMatcher; import java.util.List; @@ -64,7 +64,8 @@ public Uni> execute( .map( keyspaces -> keyspaces.get( - CqlIdentifier.fromInternal(commandContext.schemaObject().name().keyspace()))) + CqlIdentifier.fromInternal( + commandContext.schemaObject().identifier().keyspace().asInternal()))) .map( keyspaceMetadata -> { if (keyspaceMetadata == null) { @@ -76,7 +77,8 @@ public Uni> execute( .filter(tableMatcher) .map( table -> - CollectionSchemaObject.getCollectionSettings(table, objectMapper)) + CollectionSchemaObject.getCollectionSettings( + requestContext.tenant(), table, objectMapper)) .toList(); return new Result(explain, collections); }); @@ -98,7 +100,9 @@ public CommandResult get() { builder.addStatus(CommandStatus.EXISTING_COLLECTIONS, createCollectionCommands); } else { List tables = - collections.stream().map(schemaObject -> schemaObject.name().table()).toList(); + collections.stream() + .map(schemaObject -> schemaObject.identifier().table().asInternal()) + .toList(); builder.addStatus(CommandStatus.EXISTING_COLLECTIONS, tables); } return builder.build(); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/InsertCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/InsertCollectionOperation.java index 8bdc8b8164..305717dcf5 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/InsertCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/InsertCollectionOperation.java @@ -9,7 +9,6 @@ import io.stargate.sgv2.jsonapi.exception.DocumentException; import io.stargate.sgv2.jsonapi.exception.ErrorCodeV1; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.QueryExecutor; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObjectName; import io.stargate.sgv2.jsonapi.service.cqldriver.serializer.CQLBindValues; import io.stargate.sgv2.jsonapi.service.operation.InsertOperationPage; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; @@ -83,7 +82,7 @@ public Uni> execute( final boolean vectorEnabled = commandContext().schemaObject().vectorConfig().vectorEnabled(); if (!vectorEnabled && insertions.stream().anyMatch(insertion -> insertion.hasVectorValues())) { throw ErrorCodeV1.VECTOR_SEARCH_NOT_SUPPORTED.toApiException( - commandContext().schemaObject().name().table()); + commandContext().schemaObject().identifier().table().asInternal()); } // create json doc write metrics if (commandContext.jsonProcessingMetricsReporter() != null) { @@ -240,13 +239,12 @@ private Uni insertDocument( public String buildInsertQuery(boolean vectorEnabled) { final boolean lexicalEnabled = commandContext().schemaObject().lexicalConfig().enabled(); StringBuilder insertQuery = new StringBuilder(200); - final SchemaObjectName tableName = commandContext.schemaObject().name(); insertQuery .append("INSERT INTO \"") - .append(tableName.keyspace()) + .append(commandContext.schemaObject().identifier().keyspace().asInternal()) .append("\".\"") - .append(tableName.table()) + .append(commandContext.schemaObject().identifier().table().asInternal()) .append("\"") .append( " (key, tx_id, doc_json, exist_keys, array_size, array_contains, query_bool_values,") diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/ReadAndUpdateCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/ReadAndUpdateCollectionOperation.java index 4a3db0b409..21e29ba1fb 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/ReadAndUpdateCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/ReadAndUpdateCollectionOperation.java @@ -12,7 +12,6 @@ import io.stargate.sgv2.jsonapi.exception.DatabaseException; import io.stargate.sgv2.jsonapi.exception.unchecked.LWTFailureException; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.QueryExecutor; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObjectName; import io.stargate.sgv2.jsonapi.service.cqldriver.serializer.CQLBindValues; import io.stargate.sgv2.jsonapi.service.embedding.DataVectorizerService; import io.stargate.sgv2.jsonapi.service.operation.filters.collection.IDCollectionFilter; @@ -280,8 +279,12 @@ private Uni updatedDocument( } private String buildUpdateQuery(boolean vectorEnabled, boolean lexicalEnabled) { - final SchemaObjectName tableName = commandContext.schemaObject().name(); - return buildUpdateQuery(tableName.keyspace(), tableName.table(), vectorEnabled, lexicalEnabled); + var identifier = commandContext.schemaObject().identifier(); + return buildUpdateQuery( + identifier.keyspace().asInternal(), + identifier.table().asInternal(), + vectorEnabled, + lexicalEnabled); } // NOTE: This method is used in the test code (to avoid having to copy query Strings verbatim), diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/TruncateCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/TruncateCollectionOperation.java index f9e452740d..d449227fef 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/TruncateCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/collections/TruncateCollectionOperation.java @@ -25,10 +25,12 @@ public record TruncateCollectionOperation(CommandContext @Override public Uni> execute( RequestContext dataApiRequestInfo, QueryExecutor queryExecutor) { - logger.info("Executing TruncateCollectionOperation for {}", context.schemaObject().name()); + logger.info( + "Executing TruncateCollectionOperation for {}", context.schemaObject().identifier()); String cql = TRUNCATE_TABLE_CQL.formatted( - context.schemaObject().name().keyspace(), context.schemaObject().name().table()); + context.schemaObject().identifier().keyspace().asInternal(), + context.schemaObject().identifier().table().asInternal()); SimpleStatement query = SimpleStatement.newInstance(cql); // execute return queryExecutor diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingOperationFactory.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingOperationFactory.java index d6bc9bfdd7..4ebe03877a 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingOperationFactory.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingOperationFactory.java @@ -1,10 +1,10 @@ package io.stargate.sgv2.jsonapi.service.operation.embeddings; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProvider; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.tasks.*; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.Deferrable; import io.stargate.sgv2.jsonapi.service.shredding.DeferredAction; import org.slf4j.Logger; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTask.java index 1d045f9dc9..b21c7cce9d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTask.java @@ -3,10 +3,10 @@ import io.smallrye.mutiny.Uni; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.tracing.TraceMessage; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProvider; import io.stargate.sgv2.jsonapi.service.operation.tasks.BaseTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTaskBuilder.java index bb2a34b90a..0a39def305 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTaskBuilder.java @@ -1,11 +1,11 @@ package io.stargate.sgv2.jsonapi.service.operation.embeddings; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorizeDefinition; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProvider; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTaskGroupBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTaskGroupBuilder.java index 8260dfe4a9..33b7cb1022 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTaskGroupBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/embeddings/EmbeddingTaskGroupBuilder.java @@ -1,10 +1,10 @@ package io.stargate.sgv2.jsonapi.service.operation.embeddings; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProvider; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/InTableFilter.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/InTableFilter.java index 70b1a7e51b..cc21bfcc9f 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/InTableFilter.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/InTableFilter.java @@ -14,10 +14,10 @@ import io.stargate.sgv2.jsonapi.exception.checked.MissingJSONCodecException; import io.stargate.sgv2.jsonapi.exception.checked.ToCQLCodecException; import io.stargate.sgv2.jsonapi.exception.checked.UnknownColumnException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.builder.BuiltCondition; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistries; import io.stargate.sgv2.jsonapi.service.operation.query.TableFilter; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/MapSetListTableFilter.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/MapSetListTableFilter.java index a3c1e39274..9e6946c725 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/MapSetListTableFilter.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/MapSetListTableFilter.java @@ -15,13 +15,13 @@ import io.stargate.sgv2.jsonapi.exception.FilterException; import io.stargate.sgv2.jsonapi.exception.checked.MissingJSONCodecException; import io.stargate.sgv2.jsonapi.exception.checked.ToCQLCodecException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.override.DefaultSubConditionRelation; import io.stargate.sgv2.jsonapi.service.operation.builder.BuiltCondition; import io.stargate.sgv2.jsonapi.service.operation.builder.BuiltConditionPredicate; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistries; import io.stargate.sgv2.jsonapi.service.operation.query.TableFilter; import io.stargate.sgv2.jsonapi.service.schema.tables.*; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.List; /** Table filter against the map/set/list column. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/NativeTypeTableFilter.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/NativeTypeTableFilter.java index 919cf90366..da6eea0e97 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/NativeTypeTableFilter.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/filters/table/NativeTypeTableFilter.java @@ -10,12 +10,12 @@ import io.stargate.sgv2.jsonapi.exception.checked.MissingJSONCodecException; import io.stargate.sgv2.jsonapi.exception.checked.ToCQLCodecException; import io.stargate.sgv2.jsonapi.exception.checked.UnknownColumnException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.builder.BuiltCondition; import io.stargate.sgv2.jsonapi.service.operation.builder.BuiltConditionPredicate; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.*; import io.stargate.sgv2.jsonapi.service.operation.query.FilterBehaviour; import io.stargate.sgv2.jsonapi.service.operation.query.TableFilter; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/query/TableFilter.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/query/TableFilter.java index 69afdd6a97..92d4e256d1 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/query/TableFilter.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/query/TableFilter.java @@ -6,7 +6,7 @@ import com.datastax.oss.driver.api.querybuilder.relation.Relation; import com.datastax.oss.driver.api.querybuilder.select.Select; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.IndexUsage; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.List; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/query/WhereBehaviour.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/query/WhereBehaviour.java index bf9d723e5a..ce2a3267b3 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/query/WhereBehaviour.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/query/WhereBehaviour.java @@ -1,6 +1,6 @@ package io.stargate.sgv2.jsonapi.service.operation.query; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; /** * Interface that describes how a where clause behaves. diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/FindRerankingProvidersOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/FindRerankingProvidersOperation.java index 3a6dbab923..3ba2ed9728 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/FindRerankingProvidersOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/FindRerankingProvidersOperation.java @@ -6,12 +6,12 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.FindRerankingProvidersCommand; import io.stargate.sgv2.jsonapi.api.model.command.tracing.RequestTracing; import io.stargate.sgv2.jsonapi.api.request.RequestContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.QueryExecutor; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.provider.ApiModelSupport; import io.stargate.sgv2.jsonapi.service.reranking.configuration.RerankingProvidersConfig; import io.stargate.sgv2.jsonapi.service.reranking.configuration.RerankingProvidersConfigImpl; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import java.util.*; import java.util.function.Predicate; import java.util.function.Supplier; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/IntermediateCollectionReadTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/IntermediateCollectionReadTask.java index ef731fd812..4d0791b48c 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/IntermediateCollectionReadTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/IntermediateCollectionReadTask.java @@ -6,13 +6,13 @@ import io.stargate.sgv2.jsonapi.api.model.command.clause.sort.SortExpression; import io.stargate.sgv2.jsonapi.api.model.command.impl.FindCommand; import io.stargate.sgv2.jsonapi.api.model.command.tracing.TraceMessage; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.embeddings.EmbeddingTaskBuilder; import io.stargate.sgv2.jsonapi.service.operation.tasks.BaseTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; import io.stargate.sgv2.jsonapi.service.resolver.FindCommandResolver; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.Collections; import java.util.List; @@ -82,7 +82,8 @@ protected IntermediateReadResultSupplier buildResultSupplier( new TraceMessage( "Executing inner '%s' command for schema object '%s' " .formatted( - findCommand.commandName().getApiName(), schemaObject.name()), + findCommand.commandName().getApiName(), + schemaObject.identifier()), Recordable.copyOf(Map.of("command", findCommand)))); return findOperation.execute(commandContext); }, diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingMetrics.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingMetrics.java index f9bca51e2a..2993cf9467 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingMetrics.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingMetrics.java @@ -3,15 +3,17 @@ import static io.stargate.sgv2.jsonapi.metrics.MetricsConstants.MetricNames.*; import static io.stargate.sgv2.jsonapi.metrics.MetricsConstants.MetricTags.*; import static io.stargate.sgv2.jsonapi.util.ClassUtils.classSimpleName; +import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierToMessageString; +import com.datastax.oss.driver.api.core.CqlIdentifier; import io.micrometer.core.instrument.*; import io.micrometer.core.instrument.Timer; import io.stargate.sgv2.jsonapi.api.request.RequestContext; import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; import io.stargate.sgv2.jsonapi.metrics.MetricsConstants; import io.stargate.sgv2.jsonapi.metrics.MicrometerConfiguration; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.reranking.operation.RerankingProvider; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.*; import java.util.concurrent.TimeUnit; @@ -87,8 +89,8 @@ public void recordPassageCount(int passageCount) { Tags tenantTags = new RerankingTagsBuilder() .withTenant(requestContext.tenant()) - .withKeyspace(schemaObject.name().keyspace()) - .withTable(schemaObject.name().table()) + .withKeyspace(schemaObject.identifier().keyspace()) + .withTable(schemaObject.identifier().table()) .build(); meterRegistry.summary(RERANK_TENANT_PASSAGE_COUNT_METRIC, tenantTags).record(passageCount); @@ -139,8 +141,8 @@ public void recordCallLatency(Timer.Sample sample) { Tags tenantTags = new RerankingTagsBuilder() .withTenant(requestContext.tenant()) - .withKeyspace(schemaObject.name().keyspace()) - .withTable(schemaObject.name().table()) + .withKeyspace(schemaObject.identifier().keyspace()) + .withTable(schemaObject.identifier().table()) .build(); // Get the tenant timer instance Timer tenantTimer = meterRegistry.timer(RERANK_TENANT_CALL_DURATION_METRIC, tenantTags); @@ -181,13 +183,13 @@ public RerankingTagsBuilder withTenant(Tenant tenant) { return this; } - public RerankingTagsBuilder withKeyspace(String keyspace) { - putOrThrow(KEYSPACE_TAG, keyspace); + public RerankingTagsBuilder withKeyspace(CqlIdentifier keyspace) { + putOrThrow(KEYSPACE_TAG, cqlIdentifierToMessageString(keyspace)); return this; } - public RerankingTagsBuilder withTable(String table) { - putOrThrow(TABLE_TAG, table); + public RerankingTagsBuilder withTable(CqlIdentifier table) { + putOrThrow(TABLE_TAG, cqlIdentifierToMessageString(table)); return this; } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTask.java index 75961131be..abaa374d87 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTask.java @@ -9,11 +9,11 @@ import io.stargate.sgv2.jsonapi.api.model.command.tracing.RequestTracing; import io.stargate.sgv2.jsonapi.api.model.command.tracing.TraceMessage; import io.stargate.sgv2.jsonapi.api.request.RerankingCredentials; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.BaseTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; import io.stargate.sgv2.jsonapi.service.projection.DocumentProjector; import io.stargate.sgv2.jsonapi.service.reranking.operation.RerankingProvider; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.util.PathMatchLocator; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.*; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTaskBuilder.java index cf09dfd59e..a6abe11a90 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTaskBuilder.java @@ -1,8 +1,8 @@ package io.stargate.sgv2.jsonapi.service.operation.reranking; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; public class RerankingTaskBuilder extends TaskBuilder, SchemaT, RerankingTaskBuilder> { diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTaskPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTaskPage.java index ad3c89d47a..279dc8fd33 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTaskPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/reranking/RerankingTaskPage.java @@ -4,11 +4,11 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.CompositeTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskAccumulator; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskPage; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableDBTask.java index df8d1b9ea7..f005454165 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableDBTask.java @@ -8,10 +8,10 @@ import com.datastax.oss.driver.api.querybuilder.schema.AlterTableStart; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableExtensions; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDefContainer; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.List; import java.util.Map; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableDBTaskBuilder.java index 6fba093a87..4b29786f85 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableDBTaskBuilder.java @@ -1,10 +1,10 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; import com.datastax.oss.driver.api.core.CqlIdentifier; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDefContainer; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.List; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableExceptionHandler.java index a708a3adb8..02c8bebe4a 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTableExceptionHandler.java @@ -4,7 +4,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeDBTask.java index fd868d4a8b..7e4096a700 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeDBTask.java @@ -1,15 +1,14 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.*; -import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierFromUserInput; import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.querybuilder.schema.AlterTypeStart; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; import java.util.Objects; @@ -61,7 +60,7 @@ public static AlterTypeDBTaskBuilder builder(KeyspaceSchemaObject schemaObject) @Override protected SimpleStatement buildStatement() { - var keyspaceIdentifier = cqlIdentifierFromUserInput(schemaObject.name().keyspace()); + var keyspaceIdentifier = schemaObject.identifier().keyspace(); AlterTypeStart alterTypeStart = alterType(keyspaceIdentifier, udtName); return switch (alterTypeDBTaskType) { diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeDBTaskBuilder.java index 64bd4cf434..961e9f6a12 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeDBTaskBuilder.java @@ -3,9 +3,9 @@ import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierFromUserInput; import com.datastax.oss.driver.api.core.CqlIdentifier; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeExceptionHandler.java index d70c3d128a..7bfca4ed7d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/AlterTypeExceptionHandler.java @@ -7,7 +7,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.List; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexDBTask.java index 08515a5c01..7178a81573 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexDBTask.java @@ -6,12 +6,12 @@ import com.datastax.oss.driver.api.querybuilder.schema.CreateIndexOnTable; import com.datastax.oss.driver.internal.querybuilder.schema.DefaultCreateIndex; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.override.ExtendedCreateIndex; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOptions; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiIndexDef; import io.stargate.sgv2.jsonapi.service.schema.tables.CQLSAIIndex; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.Objects; /* diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexDBTaskBuilder.java index c1f5a60a9e..1c6183954b 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexDBTaskBuilder.java @@ -1,6 +1,5 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOption; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOptions; @@ -8,6 +7,7 @@ import io.stargate.sgv2.jsonapi.service.schema.tables.ApiRegularIndex; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTextIndex; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiVectorIndex; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.Objects; /** Builder for a {@link CreateIndexDBTask}. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexExceptionHandler.java index a0188a68fa..efb9c6988b 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateIndexExceptionHandler.java @@ -6,7 +6,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableDBTask.java index a38bca5a8e..af9ead08e0 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableDBTask.java @@ -1,16 +1,15 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createTable; -import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierFromUserInput; import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.querybuilder.schema.CreateTable; import com.datastax.oss.driver.api.querybuilder.schema.CreateTableStart; import com.datastax.oss.driver.api.querybuilder.schema.CreateTableWithOptions; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableExtensions; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTableDef; import java.util.Map; import java.util.Objects; @@ -45,7 +44,7 @@ public static CreateTableDBTaskBuilder builder(KeyspaceSchemaObject schemaObject protected SimpleStatement buildStatement() { - var keyspaceIdentifier = cqlIdentifierFromUserInput(schemaObject.name().keyspace()); + var keyspaceIdentifier = schemaObject.identifier().keyspace(); CreateTableStart create = createTable(keyspaceIdentifier, tableDef.name()); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableDBTaskBuilder.java index e2b5b614b3..71cc0fb2e3 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableDBTaskBuilder.java @@ -1,8 +1,8 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTableDef; import java.util.Map; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableExceptionHandler.java index de97a2b596..9236c23e42 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTableExceptionHandler.java @@ -7,7 +7,7 @@ import com.datastax.oss.driver.api.core.servererrors.AlreadyExistsException; import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeDBTask.java index 0c8d9cef0b..52d6e1c14e 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeDBTask.java @@ -1,14 +1,13 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createType; -import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierFromUserInput; import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.querybuilder.schema.*; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskRetryPolicy; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiUdtType; public class CreateTypeDBTask extends SchemaDBTask { @@ -43,7 +42,7 @@ public static CreateTypeDBTaskBuilder builder(KeyspaceSchemaObject schemaObject) @Override protected SimpleStatement buildStatement() { - var keyspaceIdentifier = cqlIdentifierFromUserInput(schemaObject.name().keyspace()); + var keyspaceIdentifier = schemaObject.identifier().keyspace(); CreateTypeStart createTypeStart = createType(keyspaceIdentifier, apiUdtType.udtName()); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeDBTaskBuilder.java index 1815e2bbd6..79afb0448f 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeDBTaskBuilder.java @@ -1,8 +1,8 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiUdtType; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeExceptionHandler.java index ba89e914b8..18fed5f3c4 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/CreateTypeExceptionHandler.java @@ -6,7 +6,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexDBTask.java index 60f306b97e..ddf7620b6a 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexDBTask.java @@ -5,9 +5,9 @@ import com.datastax.oss.driver.api.querybuilder.SchemaBuilder; import com.datastax.oss.driver.api.querybuilder.schema.Drop; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOptions; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.Objects; /* @@ -41,9 +41,7 @@ protected SimpleStatement buildStatement() { // The keyspace name always comes from the metadata, we need to add support to hold the // KeyspaceMetadata - Drop drop = - SchemaBuilder.dropIndex( - CqlIdentifier.fromInternal(schemaObject.name().keyspace()), indexName); + Drop drop = SchemaBuilder.dropIndex(schemaObject.identifier().keyspace(), indexName); // Apply any additional options drop = cqlOptions.applyBuilderOptions(drop); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexDBTaskBuilder.java index a0bbf008ca..290332d6da 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexDBTaskBuilder.java @@ -2,11 +2,11 @@ import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.querybuilder.schema.Drop; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOption; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOptions; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.Objects; /** Builds a {@link DropIndexDBTask}. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexExceptionHandler.java index 440723dc8c..efce4b85cb 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropIndexExceptionHandler.java @@ -6,7 +6,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableDBTask.java index 5ef57ee9cf..b6da96b4b8 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableDBTask.java @@ -1,15 +1,13 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; -import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierFromUserInput; - import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.querybuilder.SchemaBuilder; import com.datastax.oss.driver.api.querybuilder.schema.Drop; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOptions; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; /* An attempt to drop table in a keyspace. @@ -38,7 +36,7 @@ public static DropTableDBTaskBuilder builder(KeyspaceSchemaObject schemaObject) @Override protected SimpleStatement buildStatement() { - CqlIdentifier keyspaceIdentifier = cqlIdentifierFromUserInput(schemaObject.name().keyspace()); + CqlIdentifier keyspaceIdentifier = schemaObject.identifier().keyspace(); // Set as StorageAttachedIndex as default Drop drop = SchemaBuilder.dropTable(keyspaceIdentifier, name); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableDBTaskBuilder.java index ca15b785cd..3687c56ac2 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableDBTaskBuilder.java @@ -2,11 +2,11 @@ import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.querybuilder.schema.Drop; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOption; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOptions; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.Objects; /** Builds a {@link DropTableDBTask}. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableExceptionHandler.java index 1bf7bf90e7..ed1fb76e3e 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTableExceptionHandler.java @@ -6,7 +6,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeDBTask.java index a6bef90566..8a3e603502 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeDBTask.java @@ -1,15 +1,13 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; -import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierFromUserInput; - import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.querybuilder.SchemaBuilder; import com.datastax.oss.driver.api.querybuilder.schema.Drop; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOptions; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; /* An attempt to drop type in a keyspace. @@ -38,7 +36,7 @@ public static DropTypeDBTaskBuilder builder(KeyspaceSchemaObject schemaObject) { @Override protected SimpleStatement buildStatement() { - CqlIdentifier keyspaceIdentifier = cqlIdentifierFromUserInput(schemaObject.name().keyspace()); + CqlIdentifier keyspaceIdentifier = schemaObject.identifier().keyspace(); Drop drop = SchemaBuilder.dropType(keyspaceIdentifier, name); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeDBTaskBuilder.java index 4ac6c068b2..fe3011c419 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeDBTaskBuilder.java @@ -2,11 +2,11 @@ import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.querybuilder.schema.Drop; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOption; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOptions; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.Objects; /** Builds a {@link DropTypeDBTask}. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeExceptionHandler.java index 343308bdb5..3ab4c5825e 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/DropTypeExceptionHandler.java @@ -6,7 +6,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/KeyspaceDriverExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/KeyspaceDriverExceptionHandler.java index 4a04fdcb6c..8f7514392e 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/KeyspaceDriverExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/KeyspaceDriverExceptionHandler.java @@ -2,7 +2,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; /** * Subclass of {@link DefaultDriverExceptionHandler} for working with {@link KeyspaceSchemaObject}. diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableDeleteDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableDeleteDBTaskBuilder.java index 3fb9818b9f..0837b7a95f 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableDeleteDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableDeleteDBTaskBuilder.java @@ -2,10 +2,10 @@ import com.datastax.oss.driver.api.querybuilder.delete.Delete; import io.stargate.sgv2.jsonapi.exception.FilterException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.DeleteDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.WhereCQLClause; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableDriverExceptionHandler.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableDriverExceptionHandler.java index 38042fca9b..50dae88032 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableDriverExceptionHandler.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableDriverExceptionHandler.java @@ -2,8 +2,8 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; /** * Subclass of {@link DefaultDriverExceptionHandler} for working with {@link TableSchemaObject}. diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertDBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertDBTask.java index 58c3ef9910..d846841922 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertDBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertDBTask.java @@ -4,8 +4,8 @@ import io.stargate.sgv2.jsonapi.api.model.command.table.SchemaDescSource; import io.stargate.sgv2.jsonapi.api.model.command.table.definition.ColumnsDescContainer; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.InsertDBTask; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.DocRowIdentifer; import io.stargate.sgv2.jsonapi.service.shredding.tables.RowId; import io.stargate.sgv2.jsonapi.service.shredding.tables.WriteableTableRow; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertDBTaskBuilder.java index 7f7941006d..6e4abf4043 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertDBTaskBuilder.java @@ -2,11 +2,11 @@ import com.fasterxml.jackson.databind.JsonNode; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.InsertDBTask; import io.stargate.sgv2.jsonapi.service.operation.InsertDBTaskPage; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistries; import io.stargate.sgv2.jsonapi.service.operation.tasks.*; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.tables.JsonNamedValueContainerFactory; import io.stargate.sgv2.jsonapi.service.shredding.tables.WriteableTableRow; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertValuesCQLClause.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertValuesCQLClause.java index a5ac557bb4..08f78496ab 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertValuesCQLClause.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableInsertValuesCQLClause.java @@ -4,9 +4,9 @@ import com.datastax.oss.driver.api.querybuilder.insert.OngoingValues; import com.datastax.oss.driver.api.querybuilder.insert.RegularInsert; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.InsertValuesCQLClause; import io.stargate.sgv2.jsonapi.service.resolver.UnvalidatedClauseException; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.tables.WriteableTableRow; import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableMutationOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableMutationOperation.java index 812905caf3..18f5ff12c5 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableMutationOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableMutationOperation.java @@ -1,7 +1,7 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; /** * For now, a marker class / interface for operations that modify data in a table. 26 sept 2024 - diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableOperation.java index 0eaa64cd67..80c9eed83e 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableOperation.java @@ -1,8 +1,8 @@ package io.stargate.sgv2.jsonapi.service.operation.tables; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.Objects; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableProjection.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableProjection.java index c5b2d0f876..deca240e40 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableProjection.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableProjection.java @@ -18,11 +18,11 @@ import io.stargate.sgv2.jsonapi.exception.ProjectionException; import io.stargate.sgv2.jsonapi.exception.checked.MissingJSONCodecException; import io.stargate.sgv2.jsonapi.exception.checked.ToJSONCodecException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.OperationProjection; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.*; import io.stargate.sgv2.jsonapi.service.operation.query.SelectCQLClause; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiSupportDef; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.*; import java.util.function.Predicate; import org.slf4j.Logger; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableReadDBTaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableReadDBTaskBuilder.java index d124a7f1b1..1fe5169efe 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableReadDBTaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableReadDBTaskBuilder.java @@ -4,11 +4,11 @@ import io.stargate.sgv2.jsonapi.exception.FilterException; import io.stargate.sgv2.jsonapi.exception.WithWarnings; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CqlPagingState; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.OperationProjection; import io.stargate.sgv2.jsonapi.service.operation.ReadDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.*; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskBuilder; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableSimilarityFunction.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableSimilarityFunction.java index f963bf4407..9fd549ad81 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableSimilarityFunction.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableSimilarityFunction.java @@ -9,7 +9,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.Projectable; import io.stargate.sgv2.jsonapi.api.model.command.VectorSortable; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.CqlVectorUtil; import java.util.function.Function; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableWhereCQLClause.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableWhereCQLClause.java index c218104b04..ca8c5ae920 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableWhereCQLClause.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/TableWhereCQLClause.java @@ -7,9 +7,9 @@ import com.datastax.oss.driver.api.querybuilder.update.Update; import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.LogicalExpression; import io.stargate.sgv2.jsonapi.exception.WithWarnings; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.override.DefaultSubConditionRelation; import io.stargate.sgv2.jsonapi.service.operation.query.*; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.ArrayList; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/WhereCQLClauseAnalyzer.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/WhereCQLClauseAnalyzer.java index d74915eb2c..e1c6bd6619 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/WhereCQLClauseAnalyzer.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/WhereCQLClauseAnalyzer.java @@ -13,8 +13,6 @@ import io.stargate.sgv2.jsonapi.exception.FilterException; import io.stargate.sgv2.jsonapi.exception.WarningException; import io.stargate.sgv2.jsonapi.exception.WithWarnings; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.InTableFilter; import io.stargate.sgv2.jsonapi.service.operation.filters.table.MapSetListFilterComponent; import io.stargate.sgv2.jsonapi.service.operation.filters.table.MapSetListTableFilter; @@ -25,6 +23,8 @@ import io.stargate.sgv2.jsonapi.service.schema.tables.ApiIndexFunction; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiIndexType; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTableDef; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.*; import java.util.function.Consumer; import java.util.function.Function; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/WriteableTableRowBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/WriteableTableRowBuilder.java index 89eb6c2ec5..f8bbae246f 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/WriteableTableRowBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tables/WriteableTableRowBuilder.java @@ -8,9 +8,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.exception.DocumentException; import io.stargate.sgv2.jsonapi.exception.ErrorCode; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.*; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTableDef; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.*; import io.stargate.sgv2.jsonapi.service.shredding.tables.CqlNamedValueContainerFactory; import io.stargate.sgv2.jsonapi.service.shredding.tables.WriteableTableRow; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTask.java index 2f3ccd18a7..49c53777ee 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTask.java @@ -4,7 +4,7 @@ import io.smallrye.mutiny.Uni; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.exception.WarningException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.*; @@ -513,7 +513,7 @@ public Recordable.DataRecorder recordTo(Recordable.DataRecorder dataRecorder) { .append("status", status) .append("taskId", taskId) .append("schemaObject.type", schemaObject.type()) - .append("schemaObject.name", schemaObject.name()) + .append("schemaObject.name", schemaObject.identifier()) .append("retryPolicy", retryPolicy) .append("warnings", warnings) .append("suppressedWarnings", suppressedWarnings) diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTask.java index 15b5755565..b4ba0a1cd4 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTask.java @@ -3,7 +3,7 @@ import io.smallrye.mutiny.Uni; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.exception.WarningException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.ArrayList; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskInnerPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskInnerPage.java index 08b19d9a84..4e109894b8 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskInnerPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskInnerPage.java @@ -2,7 +2,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.Objects; import java.util.Optional; import java.util.function.Supplier; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskOperationBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskOperationBuilder.java index 8709f0c8bf..f95d90b305 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskOperationBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskOperationBuilder.java @@ -1,8 +1,8 @@ package io.stargate.sgv2.jsonapi.service.operation.tasks; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; /** * Helps build an {@link Operation} to run composite tasks of inner task groups. diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskOuterPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskOuterPage.java index 0237ee3ef0..389641c282 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskOuterPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/CompositeTaskOuterPage.java @@ -3,7 +3,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.function.Supplier; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DBTask.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DBTask.java index 5473bb7ebb..f52f69f616 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DBTask.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DBTask.java @@ -13,7 +13,7 @@ import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -186,7 +186,7 @@ protected CommandQueryExecutor getCommandQueryExecutor(CommandContext c // , improve later return new CommandQueryExecutor( commandContext.cqlSessionCache(), - new CommandQueryExecutor.DBRequestContext(commandContext), + commandContext.requestContext(), CommandQueryExecutor.QueryTarget.TABLE); } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DBTaskPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DBTaskPage.java index 367e34ab7f..8be28d2afe 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DBTaskPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DBTaskPage.java @@ -2,7 +2,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.Optional; public abstract class DBTaskPage, SchemaT extends SchemaObject> diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/Task.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/Task.java index dcb1f8bd79..11691b2b35 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/Task.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/Task.java @@ -3,7 +3,7 @@ import io.smallrye.mutiny.Uni; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.exception.WithWarnings; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.Optional; import java.util.UUID; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskAccumulator.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskAccumulator.java index 46b429f3bd..8a44987576 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskAccumulator.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskAccumulator.java @@ -4,7 +4,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.tracing.RequestTracing; import io.stargate.sgv2.jsonapi.config.OperationsConfig; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.Objects; import java.util.function.Supplier; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskAndDeferrables.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskAndDeferrables.java index 490b69d26c..b35f339dbc 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskAndDeferrables.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskAndDeferrables.java @@ -1,6 +1,6 @@ package io.stargate.sgv2.jsonapi.service.operation.tasks; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.Deferrable; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskBuilder.java index 28fc0cfbdf..ca235e1fd2 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskBuilder.java @@ -1,7 +1,7 @@ package io.stargate.sgv2.jsonapi.service.operation.tasks; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroup.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroup.java index fc15058144..e4b25b04a3 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroup.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroup.java @@ -1,6 +1,6 @@ package io.stargate.sgv2.jsonapi.service.operation.tasks; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.*; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroupAndDeferrables.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroupAndDeferrables.java index 02b7371969..d76b8ec3aa 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroupAndDeferrables.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroupAndDeferrables.java @@ -1,6 +1,6 @@ package io.stargate.sgv2.jsonapi.service.operation.tasks; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.Deferrable; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskOperation.java index b350cb5c95..764064a692 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskOperation.java @@ -5,8 +5,8 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.tracing.TraceMessage; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; import java.util.Objects; import java.util.function.Function; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskPage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskPage.java index 90b6c5f078..a75abfd768 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskPage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskPage.java @@ -2,8 +2,8 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; import io.stargate.sgv2.jsonapi.api.model.command.CommandResultBuilder; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.Collections; import java.util.Objects; import java.util.Optional; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/processor/CommandProcessor.java b/src/main/java/io/stargate/sgv2/jsonapi/service/processor/CommandProcessor.java index 580dd1ad61..535d16e0f0 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/processor/CommandProcessor.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/processor/CommandProcessor.java @@ -13,10 +13,10 @@ import io.stargate.sgv2.jsonapi.exception.ExceptionFlags; import io.stargate.sgv2.jsonapi.exception.JsonApiException; import io.stargate.sgv2.jsonapi.exception.mappers.ThrowableCommandResultSupplier; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.DataVectorizerService; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.resolver.CommandResolverService; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; @@ -66,7 +66,7 @@ public Uni Uni Uni { // Cleanup MDC after processing completes (success or failure) to prevent data from // leaking into the next request handled by the same thread. - commandContext.schemaObject().name().removeFromMDC(); + commandContext.schemaObject().identifier().removeFromMDC(); MDC.remove("tenantId"); }); } @@ -168,8 +168,10 @@ private String buildCommandLog( new CommandLog( command.getClass().getSimpleName(), commandContext.requestContext().tenant(), - commandContext.schemaObject().name().keyspace(), - commandContext.schemaObject().name().table(), + commandContext.schemaObject().identifier().keyspace().asInternal(), + commandContext.schemaObject().identifier().table() == null + ? "" + : commandContext.schemaObject().identifier().table().asInternal(), commandContext.schemaObject().type().name(), getIncomingDocumentsCount(command), getOutgoingDocumentsCount(result), diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/AlterTableCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/AlterTableCommandResolver.java index c241704079..273040368f 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/AlterTableCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/AlterTableCommandResolver.java @@ -14,7 +14,6 @@ import io.stargate.sgv2.jsonapi.exception.SchemaException; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableExtensions; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorizeDefinition; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; @@ -23,6 +22,7 @@ import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskOperation; import io.stargate.sgv2.jsonapi.service.schema.tables.*; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/AlterTypeCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/AlterTypeCommandResolver.java index 983931b991..b95aaeb0ad 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/AlterTypeCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/AlterTypeCommandResolver.java @@ -6,7 +6,6 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.AlterTypeCommand; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTaskPage; @@ -14,6 +13,7 @@ import io.stargate.sgv2.jsonapi.service.operation.tables.AlterTypeExceptionHandler; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiUdtType; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ClauseResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ClauseResolver.java index e531500e9a..0cd415f71e 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ClauseResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ClauseResolver.java @@ -5,7 +5,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.exception.WithWarnings; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; /** * Base for a class that can resolve a clause in a command for use by an Operation. diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CommandResolver.java index 6b69c45e31..45432d831e 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CommandResolver.java @@ -16,11 +16,14 @@ import io.stargate.sgv2.jsonapi.exception.RequestException; import io.stargate.sgv2.jsonapi.exception.ServerException; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.*; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.query.DBFilterBase; import io.stargate.sgv2.jsonapi.service.operation.query.DBLogicalExpression; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.Objects; /** @@ -165,7 +168,7 @@ default Operation resolveKeyspaceCommand( // throw error as a fallback to make sure method is implemented, commands are tested well throw ServerException.internalServerError( "%s Command does not support operating on Keyspaces, target was %s" - .formatted(command.getClass().getSimpleName(), ctx.schemaObject().name())); + .formatted(command.getClass().getSimpleName(), ctx.schemaObject().identifier())); } /** @@ -180,7 +183,7 @@ default Operation resolveDatabaseCommand( // throw error as a fallback to make sure method is implemented, commands are tested well throw ServerException.internalServerError( "%s Command does not support operating on Databases, target was %s" - .formatted(command.getClass().getSimpleName(), ctx.schemaObject().name())); + .formatted(command.getClass().getSimpleName(), ctx.schemaObject().identifier())); } /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateCollectionCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateCollectionCommandResolver.java index dcfacc0219..608f364adb 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateCollectionCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateCollectionCommandResolver.java @@ -13,11 +13,11 @@ import io.stargate.sgv2.jsonapi.exception.ErrorCodeV1; import io.stargate.sgv2.jsonapi.exception.JsonApiException; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.collections.CreateCollectionOperation; import io.stargate.sgv2.jsonapi.service.reranking.configuration.RerankingProvidersConfig; import io.stargate.sgv2.jsonapi.service.schema.EmbeddingSourceModel; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.SimilarityFunction; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionLexicalConfig; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionRerankDef; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateIndexCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateIndexCommandResolver.java index 5f0759c2c8..65083ec8d9 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateIndexCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateIndexCommandResolver.java @@ -9,7 +9,6 @@ import io.stargate.sgv2.jsonapi.config.constants.TableDescDefaults; import io.stargate.sgv2.jsonapi.exception.SchemaException; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTaskPage; @@ -20,6 +19,7 @@ import io.stargate.sgv2.jsonapi.service.schema.naming.NamingRules; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiIndexType; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiRegularIndex; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import jakarta.enterprise.context.ApplicationScoped; import java.time.Duration; import java.util.Map; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateKeyspaceCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateKeyspaceCommandResolver.java index f5132db2aa..ca013050e9 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateKeyspaceCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateKeyspaceCommandResolver.java @@ -2,9 +2,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateKeyspaceCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.keyspaces.CreateKeyspaceOperation; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.naming.NamingRules; import jakarta.enterprise.context.ApplicationScoped; import java.util.Map; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateNamespaceCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateNamespaceCommandResolver.java index 5d1952d378..cda5c7c16d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateNamespaceCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateNamespaceCommandResolver.java @@ -2,9 +2,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateNamespaceCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.keyspaces.CreateKeyspaceOperation; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.naming.NamingRules; import jakarta.enterprise.context.ApplicationScoped; import java.util.Map; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTableCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTableCommandResolver.java index 1762592138..d05432566a 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTableCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTableCommandResolver.java @@ -15,6 +15,7 @@ import io.stargate.sgv2.jsonapi.service.operation.tables.CreateTableExceptionHandler; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.naming.NamingRules; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiDataTypeDefs; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiSupportDef; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTextIndexCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTextIndexCommandResolver.java index e3d38e0174..32cb158d25 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTextIndexCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTextIndexCommandResolver.java @@ -9,7 +9,6 @@ import io.stargate.sgv2.jsonapi.config.constants.TableDescDefaults; import io.stargate.sgv2.jsonapi.exception.SchemaException; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTaskPage; @@ -21,6 +20,7 @@ import io.stargate.sgv2.jsonapi.service.schema.naming.NamingRules; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiIndexType; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTextIndex; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import jakarta.enterprise.context.ApplicationScoped; import java.time.Duration; import java.util.Map; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTypeCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTypeCommandResolver.java index 0f7430394e..8cbf33d3fd 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTypeCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateTypeCommandResolver.java @@ -7,13 +7,13 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateTypeCommand; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTaskPage; import io.stargate.sgv2.jsonapi.service.operation.tables.*; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiUdtType; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateVectorIndexCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateVectorIndexCommandResolver.java index 82b98e8e0a..87f24724b8 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateVectorIndexCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateVectorIndexCommandResolver.java @@ -9,7 +9,6 @@ import io.stargate.sgv2.jsonapi.config.constants.TableDescDefaults; import io.stargate.sgv2.jsonapi.exception.SchemaException; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.tables.CreateIndexDBTask; import io.stargate.sgv2.jsonapi.service.operation.tables.CreateIndexDBTaskBuilder; @@ -19,6 +18,7 @@ import io.stargate.sgv2.jsonapi.service.schema.naming.NamingRules; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiIndexType; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiVectorIndex; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import jakarta.enterprise.context.ApplicationScoped; import java.time.Duration; import java.util.Map; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteCollectionCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteCollectionCommandResolver.java index c0c486fd60..0a4188f14d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteCollectionCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteCollectionCommandResolver.java @@ -2,9 +2,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.DeleteCollectionCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.collections.DeleteCollectionCollectionOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import jakarta.enterprise.context.ApplicationScoped; /** Resolver for the {@link DeleteCollectionCommand}. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteManyCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteManyCommandResolver.java index 596a4e1b0e..c6e373a798 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteManyCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteManyCommandResolver.java @@ -7,7 +7,6 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.DeleteManyCommand; import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonApiMetricsConfig; import io.stargate.sgv2.jsonapi.config.OperationsConfig; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.collections.CollectionReadType; import io.stargate.sgv2.jsonapi.service.operation.collections.DeleteCollectionOperation; @@ -23,6 +22,7 @@ import io.stargate.sgv2.jsonapi.service.resolver.matcher.FilterResolver; import io.stargate.sgv2.jsonapi.service.resolver.matcher.TableFilterResolver; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteOneCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteOneCommandResolver.java index 353588b17c..0d76ad3d1b 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteOneCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteOneCommandResolver.java @@ -11,7 +11,6 @@ import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonApiMetricsConfig; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.exception.SortException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.collections.CollectionReadType; import io.stargate.sgv2.jsonapi.service.operation.collections.DeleteCollectionOperation; @@ -24,6 +23,7 @@ import io.stargate.sgv2.jsonapi.service.resolver.matcher.FilterResolver; import io.stargate.sgv2.jsonapi.service.resolver.matcher.TableFilterResolver; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.SortClauseUtil; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropIndexCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropIndexCommandResolver.java index 663007b63a..cf6ff8e511 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropIndexCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropIndexCommandResolver.java @@ -6,7 +6,6 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.DropIndexCommand; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTaskPage; @@ -14,6 +13,7 @@ import io.stargate.sgv2.jsonapi.service.operation.tables.DropIndexExceptionHandler; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.util.ApiOptionUtils; import jakarta.enterprise.context.ApplicationScoped; import java.time.Duration; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropKeyspaceCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropKeyspaceCommandResolver.java index b898dd2f23..b6943f5819 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropKeyspaceCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropKeyspaceCommandResolver.java @@ -2,9 +2,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.DropKeyspaceCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.keyspaces.DropKeyspaceOperation; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import jakarta.enterprise.context.ApplicationScoped; /** Command resolver for {@link DropKeyspaceCommand}. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropNamespaceCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropNamespaceCommandResolver.java index 503fad4409..ce0c886d2f 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropNamespaceCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropNamespaceCommandResolver.java @@ -2,9 +2,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.DropNamespaceCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.keyspaces.DropKeyspaceOperation; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import jakarta.enterprise.context.ApplicationScoped; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropTableCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropTableCommandResolver.java index de14d21556..e6cb842e63 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropTableCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropTableCommandResolver.java @@ -6,13 +6,13 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.DropTableCommand; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTaskPage; import io.stargate.sgv2.jsonapi.service.operation.tables.*; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.util.ApiOptionUtils; import jakarta.enterprise.context.ApplicationScoped; import java.time.Duration; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropTypeCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropTypeCommandResolver.java index f4d744ca7c..7404e17a8c 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropTypeCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/DropTypeCommandResolver.java @@ -6,7 +6,6 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.DropTypeCommand; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTask; import io.stargate.sgv2.jsonapi.service.operation.SchemaDBTaskPage; @@ -14,6 +13,7 @@ import io.stargate.sgv2.jsonapi.service.operation.tables.DropTypeExceptionHandler; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.util.ApiOptionUtils; import jakarta.enterprise.context.ApplicationScoped; import java.time.Duration; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindCollectionsCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindCollectionsCommandResolver.java index dc54ef1b66..23adf54fb8 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindCollectionsCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindCollectionsCommandResolver.java @@ -3,9 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.FindCollectionsCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.collections.FindCollectionsCollectionOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindCommandResolver.java index 78b011114d..db714bece1 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindCommandResolver.java @@ -11,13 +11,13 @@ import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.exception.SortException; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CqlPagingState; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.collections.CollectionReadType; import io.stargate.sgv2.jsonapi.service.operation.collections.FindCollectionOperation; import io.stargate.sgv2.jsonapi.service.resolver.matcher.CollectionFilterResolver; import io.stargate.sgv2.jsonapi.service.resolver.matcher.FilterResolver; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.SortClauseUtil; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindEmbeddingProvidersCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindEmbeddingProvidersCommandResolver.java index 791549bbac..b4b6a76046 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindEmbeddingProvidersCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindEmbeddingProvidersCommandResolver.java @@ -4,10 +4,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.FindEmbeddingProvidersCommand; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.exception.ErrorCodeV1; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.configuration.EmbeddingProvidersConfig; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.embeddings.FindEmbeddingProvidersOperation; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindKeyspacesCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindKeyspacesCommandResolver.java index ef9b937b0a..9f86622b91 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindKeyspacesCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindKeyspacesCommandResolver.java @@ -2,9 +2,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.FindKeyspacesCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.keyspaces.FindKeyspacesOperation; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import jakarta.enterprise.context.ApplicationScoped; /** Command resolver for {@link FindKeyspacesCommand}. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindNamespacesCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindNamespacesCommandResolver.java index cedc7929c4..814721ac4c 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindNamespacesCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindNamespacesCommandResolver.java @@ -2,9 +2,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.FindNamespacesCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.keyspaces.FindKeyspacesOperation; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import jakarta.enterprise.context.ApplicationScoped; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindOneCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindOneCommandResolver.java index 0ea66cc571..40bda02c50 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindOneCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindOneCommandResolver.java @@ -9,7 +9,6 @@ import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonApiMetricsConfig; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CqlPagingState; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.collections.CollectionReadType; import io.stargate.sgv2.jsonapi.service.operation.collections.FindCollectionOperation; @@ -17,6 +16,7 @@ import io.stargate.sgv2.jsonapi.service.resolver.matcher.CollectionFilterResolver; import io.stargate.sgv2.jsonapi.service.resolver.matcher.FilterResolver; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.SortClauseUtil; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindRerankingProvidersCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindRerankingProvidersCommandResolver.java index 7002bbf923..b4d03d92d4 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindRerankingProvidersCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/FindRerankingProvidersCommandResolver.java @@ -4,10 +4,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.FindRerankingProvidersCommand; import io.stargate.sgv2.jsonapi.config.feature.ApiFeature; import io.stargate.sgv2.jsonapi.exception.ErrorCodeV1; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.reranking.FindRerankingProvidersOperation; import io.stargate.sgv2.jsonapi.service.reranking.configuration.RerankingProvidersConfig; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/InsertManyCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/InsertManyCommandResolver.java index de5ae46e52..0ab26873b4 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/InsertManyCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/InsertManyCommandResolver.java @@ -2,7 +2,6 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.InsertManyCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.collections.CollectionInsertAttemptBuilder; import io.stargate.sgv2.jsonapi.service.operation.collections.InsertCollectionOperation; @@ -10,6 +9,7 @@ import io.stargate.sgv2.jsonapi.service.operation.tables.TableDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.operation.tables.TableInsertDBTask; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.JsonNodeDecoder; import io.stargate.sgv2.jsonapi.service.shredding.collections.DocumentShredder; import io.stargate.sgv2.jsonapi.service.shredding.tables.JsonNamedValueContainerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/InsertOneCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/InsertOneCommandResolver.java index 2877ba320d..1e24e92d30 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/InsertOneCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/InsertOneCommandResolver.java @@ -2,7 +2,6 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.InsertOneCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.collections.CollectionInsertAttemptBuilder; import io.stargate.sgv2.jsonapi.service.operation.collections.InsertCollectionOperation; @@ -10,6 +9,7 @@ import io.stargate.sgv2.jsonapi.service.operation.tables.TableDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.operation.tables.TableInsertDBTask; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.JsonNodeDecoder; import io.stargate.sgv2.jsonapi.service.shredding.collections.DocumentShredder; import io.stargate.sgv2.jsonapi.service.shredding.tables.JsonNamedValueContainerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListIndexesCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListIndexesCommandResolver.java index 5308b0fa1d..e27d72f69a 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListIndexesCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListIndexesCommandResolver.java @@ -3,11 +3,11 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; import io.stargate.sgv2.jsonapi.api.model.command.impl.ListIndexesCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.tables.TableDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskOperation; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import jakarta.enterprise.context.ApplicationScoped; /** Command resolver for the {@link ListIndexesCommand}. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListTablesCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListTablesCommandResolver.java index f1a70dd1cc..4ccb64db66 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListTablesCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListTablesCommandResolver.java @@ -4,11 +4,11 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; import io.stargate.sgv2.jsonapi.api.model.command.impl.ListTablesCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.tables.KeyspaceDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListTypesCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListTypesCommandResolver.java index a49bafc62a..e29d16e640 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListTypesCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/ListTypesCommandResolver.java @@ -4,13 +4,13 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; import io.stargate.sgv2.jsonapi.api.model.command.impl.ListTypesCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.ListTypesDBTask; import io.stargate.sgv2.jsonapi.service.operation.MetadataDBTaskPage; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.tables.KeyspaceDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskGroup; import io.stargate.sgv2.jsonapi.service.operation.tasks.TaskOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/TableReadDBOperationBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/TableReadDBOperationBuilder.java index 7b1553ba18..a036d9bc33 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/TableReadDBOperationBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/TableReadDBOperationBuilder.java @@ -5,7 +5,6 @@ import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.exception.WithWarnings; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CqlPagingState; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.embeddings.EmbeddingOperationFactory; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOption; @@ -16,6 +15,7 @@ import io.stargate.sgv2.jsonapi.service.resolver.matcher.TableFilterResolver; import io.stargate.sgv2.jsonapi.service.resolver.sort.TableCqlSortClauseResolver; import io.stargate.sgv2.jsonapi.service.resolver.sort.TableMemorySortClauseResolver; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/UpdateOneCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/UpdateOneCommandResolver.java index 3c9668e6c4..9c7f2134ac 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/UpdateOneCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/UpdateOneCommandResolver.java @@ -11,7 +11,6 @@ import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonApiMetricsConfig; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.exception.SortException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.DataVectorizerService; import io.stargate.sgv2.jsonapi.service.operation.*; import io.stargate.sgv2.jsonapi.service.operation.collections.CollectionReadType; @@ -28,6 +27,7 @@ import io.stargate.sgv2.jsonapi.service.resolver.matcher.TableFilterResolver; import io.stargate.sgv2.jsonapi.service.resolver.update.TableUpdateResolver; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.collections.DocumentShredder; import io.stargate.sgv2.jsonapi.service.updater.DocumentUpdater; import io.stargate.sgv2.jsonapi.util.SortClauseUtil; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/FilterResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/FilterResolver.java index affe37ecf4..5b1cd4e94c 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/FilterResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/FilterResolver.java @@ -4,9 +4,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.*; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.exception.WithWarnings; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.DBLogicalExpression; import io.stargate.sgv2.jsonapi.service.resolver.ClauseResolver; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.Objects; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/TableFilterResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/TableFilterResolver.java index 6840e3951c..217c730fbe 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/TableFilterResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/TableFilterResolver.java @@ -7,10 +7,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.JsonType; import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.ValueComparisonOperator; import io.stargate.sgv2.jsonapi.config.OperationsConfig; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.*; import io.stargate.sgv2.jsonapi.service.operation.filters.table.BinaryTableFilter; import io.stargate.sgv2.jsonapi.service.operation.query.DBLogicalExpression; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.collections.DocumentId; import java.math.BigDecimal; import java.util.EnumSet; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableCqlSortClauseResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableCqlSortClauseResolver.java index 2561e34720..c4dca7c4c2 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableCqlSortClauseResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableCqlSortClauseResolver.java @@ -17,7 +17,6 @@ import io.stargate.sgv2.jsonapi.exception.WarningException; import io.stargate.sgv2.jsonapi.exception.WithWarnings; import io.stargate.sgv2.jsonapi.service.cql.builder.QueryBuilder; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistries; import io.stargate.sgv2.jsonapi.service.operation.query.OrderByCqlClause; import io.stargate.sgv2.jsonapi.service.operation.query.WhereCQLClause; @@ -30,6 +29,7 @@ import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTableDef; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTypeName; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.*; import io.stargate.sgv2.jsonapi.service.shredding.collections.JsonPath; import io.stargate.sgv2.jsonapi.service.shredding.tables.CqlNamedValueContainerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableMemorySortClauseResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableMemorySortClauseResolver.java index faf417c056..6d21a76410 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableMemorySortClauseResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableMemorySortClauseResolver.java @@ -10,11 +10,11 @@ import io.stargate.sgv2.jsonapi.exception.SortException; import io.stargate.sgv2.jsonapi.exception.WithWarnings; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CqlPagingState; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.InMemorySortComparator; import io.stargate.sgv2.jsonapi.service.operation.query.OrderByCqlClause; import io.stargate.sgv2.jsonapi.service.operation.query.RowSorter; import io.stargate.sgv2.jsonapi.service.operation.tables.TableRowSorter; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.ArrayList; import java.util.List; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableSortClauseResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableSortClauseResolver.java index bbebbf223e..7f22cc9323 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableSortClauseResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/sort/TableSortClauseResolver.java @@ -5,8 +5,8 @@ import io.stargate.sgv2.jsonapi.api.model.command.Command; import io.stargate.sgv2.jsonapi.api.model.command.Sortable; import io.stargate.sgv2.jsonapi.config.OperationsConfig; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.resolver.ClauseResolver; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; /** * Common base for common code when resolving the sort clause for either CQL or in memory sorting diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateAnalyzer.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateAnalyzer.java index 6d3ffd701e..634a25c0f2 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateAnalyzer.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateAnalyzer.java @@ -8,8 +8,8 @@ import com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata; import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; import io.stargate.sgv2.jsonapi.exception.UpdateException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnAssignment; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import java.util.List; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateOperatorResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateOperatorResolver.java index 73792bec58..c8fef40c3f 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateOperatorResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateOperatorResolver.java @@ -6,10 +6,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import io.stargate.sgv2.jsonapi.api.model.command.clause.update.UpdateOperator; import io.stargate.sgv2.jsonapi.exception.UpdateException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistries; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistry; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnAssignment; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValue; import io.stargate.sgv2.jsonapi.service.shredding.JsonNodeDecoder; import io.stargate.sgv2.jsonapi.service.shredding.tables.CqlNamedValueContainerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdatePullAllResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdatePullAllResolver.java index d1ca2a1a4a..d23a13f370 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdatePullAllResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdatePullAllResolver.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import io.stargate.sgv2.jsonapi.api.model.command.clause.update.UpdateOperator; import io.stargate.sgv2.jsonapi.exception.UpdateException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistries; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnAssignment; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnRemoveToAssignment; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValue; import io.stargate.sgv2.jsonapi.service.shredding.JsonNodeDecoder; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdatePushResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdatePushResolver.java index 86df9e70c3..cef8d07547 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdatePushResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdatePushResolver.java @@ -11,10 +11,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.clause.update.UpdateOperator; import io.stargate.sgv2.jsonapi.api.model.command.clause.update.UpdateOperatorModifier; import io.stargate.sgv2.jsonapi.exception.UpdateException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnAppendToAssignment; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnAssignment; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValue; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateResolver.java index aa1b86ef79..e255d2be73 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateResolver.java @@ -14,10 +14,10 @@ import io.stargate.sgv2.jsonapi.exception.ErrorCode; import io.stargate.sgv2.jsonapi.exception.UpdateException; import io.stargate.sgv2.jsonapi.exception.WithWarnings; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnAssignment; import io.stargate.sgv2.jsonapi.service.operation.query.DefaultUpdateValuesCQLClause; import io.stargate.sgv2.jsonapi.service.operation.query.UpdateValuesCQLClause; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValue; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValueContainer; import io.stargate.sgv2.jsonapi.service.shredding.tables.CqlNamedValueContainerFactory; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateSetResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateSetResolver.java index aeb2d4d2c7..8caba3bff3 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateSetResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateSetResolver.java @@ -3,9 +3,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import io.stargate.sgv2.jsonapi.api.model.command.clause.update.UpdateOperator; import io.stargate.sgv2.jsonapi.exception.UpdateException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnAssignment; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnSetToAssignment; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValue; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateUnsetResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateUnsetResolver.java index 8b76bb01b4..ba6b7444ca 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateUnsetResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateUnsetResolver.java @@ -5,10 +5,10 @@ import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.JsonType; import io.stargate.sgv2.jsonapi.api.model.command.clause.update.UpdateOperator; import io.stargate.sgv2.jsonapi.exception.UpdateException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistries; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnAssignment; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnSetToAssignment; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValue; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/UpdateResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/UpdateResolver.java index 5825b852dd..fb209d87c4 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/UpdateResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/update/UpdateResolver.java @@ -3,9 +3,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.Command; import io.stargate.sgv2.jsonapi.api.model.command.Updatable; import io.stargate.sgv2.jsonapi.config.OperationsConfig; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.UpdateValuesCQLClause; import io.stargate.sgv2.jsonapi.service.resolver.ClauseResolver; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; /** * A {@link ClauseResolver} for the update clause in a command and creates a {@link diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/DatabaseSchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/DatabaseSchemaObject.java new file mode 100644 index 0000000000..c5476f7a2b --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/DatabaseSchemaObject.java @@ -0,0 +1,34 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.IndexUsage; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; + +/** + * A Database in the API. + * + *

While we don't do much with a database itself in the API, we do some commands like listing + * keyspaces that conceptually belong to the database. So we have a schema object for it. + * + *

Currently only identified by the tenant. + */ +public class DatabaseSchemaObject extends SchemaObject { + + public DatabaseSchemaObject(Tenant tenant) { + super(SchemaObjectType.DATABASE, SchemaObjectIdentifier.forDatabase(tenant)); + } + + public DatabaseSchemaObject(SchemaObjectIdentifier identifier) { + super(SchemaObjectType.DATABASE, identifier); + } + + @Override + public VectorConfig vectorConfig() { + return VectorConfig.NOT_ENABLED_CONFIG; + } + + @Override + public IndexUsage newIndexUsage() { + return IndexUsage.NO_OP; + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/KeyspaceSchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/KeyspaceSchemaObject.java new file mode 100644 index 0000000000..11bdef3f59 --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/KeyspaceSchemaObject.java @@ -0,0 +1,51 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata; +import com.google.common.annotations.VisibleForTesting; +import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.IndexUsage; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; +import java.util.Objects; + +/** + * A Keyspace in the API. + * + *

We currently do not hang things like Tables and Views of the KeyspaceSchemaObject, they can + * all be retrieved from {@link SchemaObjectCache} + * + *

We hae commands like list collections, list tables, etc. that run against as Keyspace so we + * have an object to represent that Keyspace. + */ +public class KeyspaceSchemaObject extends SchemaObject { + + private KeyspaceMetadata keyspaceMetadata; + + @VisibleForTesting + public KeyspaceSchemaObject(SchemaObjectIdentifier identifier) { + super(SchemaObjectType.KEYSPACE, identifier); + + // here for existing testing, where creating the KeyspaceMetadata was not common + this.keyspaceMetadata = null; + } + + public KeyspaceSchemaObject(Tenant tenant, KeyspaceMetadata keyspaceMetadata) { + super( + SchemaObjectType.KEYSPACE, + SchemaObjectIdentifier.forKeyspace(tenant, keyspaceMetadata.getName())); + + // keyspaceMetadata will prob be checked for null above, but for sanity, we ensure it's not null + // here + this.keyspaceMetadata = + Objects.requireNonNull(keyspaceMetadata, "keyspaceMetadata must not be null"); + } + + @Override + public VectorConfig vectorConfig() { + return VectorConfig.NOT_ENABLED_CONFIG; + } + + @Override + public IndexUsage newIndexUsage() { + return IndexUsage.NO_OP; + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObject.java new file mode 100644 index 0000000000..1d1820b9f8 --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObject.java @@ -0,0 +1,57 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.IndexUsage; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; +import io.stargate.sgv2.jsonapi.util.recordable.Recordable; +import java.util.Objects; + +/** + * Base for all Schema objects the API works with, such as Database, Keyspace, Table, Collection. + * + *

Schema Object are identified by a {@link SchemaObjectIdentifier} which is globally unique for + * all tenants. + */ +public abstract class SchemaObject implements Recordable { + + protected final SchemaObjectIdentifier identifier; + + protected SchemaObject(SchemaObjectType expectedType, SchemaObjectIdentifier identifier) { + + this.identifier = Objects.requireNonNull(identifier, "identifier must not be null"); + + if (identifier.type() != expectedType) { + throw new IllegalArgumentException( + String.format( + "Invalid SchemaObjectIdentifier, expected schemaType %s but got identifier: %s", + expectedType, identifier)); + } + } + + public SchemaObjectType type() { + return identifier.type(); + } + + public SchemaObjectIdentifier identifier() { + return identifier; + } + + /** + * Subclasses must always return VectorConfig, if there is no vector config they should return + * VectorConfig.notEnabledVectorConfig(). + * + *

aaron - 30 may 2025 - this is legacy from old code and should be moved in the future. + */ + public abstract VectorConfig vectorConfig(); + + /** + * Call to get an instance of the appropriate {@link IndexUsage} for this schema object + * + *

aaron - 30 may 2025 - this is legacy from old code and should be moved in the future. + */ + public abstract IndexUsage newIndexUsage(); + + @Override + public Recordable.DataRecorder recordTo(Recordable.DataRecorder dataRecorder) { + return dataRecorder.append("identifier", identifier); + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectCache.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectCache.java new file mode 100644 index 0000000000..39b3c9b1fc --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectCache.java @@ -0,0 +1,483 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata; +import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener; +import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListenerBase; +import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; +import com.datastax.oss.driver.api.core.session.Session; +import com.github.benmanes.caffeine.cache.Ticker; +import com.google.common.annotations.VisibleForTesting; +import io.micrometer.core.instrument.MeterRegistry; +import io.smallrye.mutiny.Uni; +import io.stargate.sgv2.jsonapi.api.request.RequestContext; +import io.stargate.sgv2.jsonapi.api.request.UserAgent; +import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; +import io.stargate.sgv2.jsonapi.api.request.tenant.TenantFactory; +import io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionFactory; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; +import io.stargate.sgv2.jsonapi.util.DynamicTTLCache; +import java.lang.ref.WeakReference; +import java.time.Duration; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.CompletionStage; +import org.jspecify.annotations.NonNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SchemaObjectCache + extends DynamicTTLCache { + + private static final Logger LOGGER = LoggerFactory.getLogger(SchemaObjectCache.class); + + private final DynamicTTLSupplier ttlSupplier; + + SchemaObjectCache( + long cacheMaxSize, + Duration cacheTTL, + UserAgent slaUserAgent, + Duration slaUserTTL, + SchemaObjectFactory schemaObjectFactory, + MeterRegistry meterRegistry) { + this( + cacheMaxSize, + cacheTTL, + slaUserAgent, + slaUserTTL, + schemaObjectFactory, + meterRegistry, + false, + null); + } + + @VisibleForTesting + SchemaObjectCache( + long cacheMaxSize, + Duration cacheTTL, + UserAgent slaUserAgent, + Duration slaUserTTL, + SchemaObjectFactory schemaObjectFactory, + MeterRegistry meterRegistry, + boolean asyncTaskOnCaller, + Ticker cacheTicker) { + super( + "schema_object_cache", + cacheMaxSize, + createOnLoad(schemaObjectFactory), + List.of(), + meterRegistry, + asyncTaskOnCaller, + cacheTicker); + + Objects.requireNonNull(schemaObjectFactory, "schemaObjectFactory must not be null"); + this.ttlSupplier = new DynamicTTLSupplier(cacheTTL, slaUserAgent, slaUserTTL); + + LOGGER.info( + "Initializing SchemaObjectCache with cacheMaxSize={}, ttlSupplier={}", + cacheMaxSize, + ttlSupplier); + } + + private static ValueFactory createOnLoad( + SchemaObjectFactory factory) { + + return (cacheKey) -> { + var requestContext = + cacheKey + .requestContext() + .orElseThrow( + () -> + new IllegalStateException( + "SchemaCacheKey.onLoad - requestContext is null, weak reference was cleared")); + + if (LOGGER.isTraceEnabled()) { + LOGGER.trace( + "SchemaCacheKey.onLoad - loading schema object with identifier: {}, forceRefresh: {}, userAgent: {}", + cacheKey.schemaIdentifier(), + cacheKey.forceRefresh(), + cacheKey.userAgent()); + } + + return factory.apply(requestContext, cacheKey.schemaIdentifier(), cacheKey.forceRefresh()); + }; + } + + /** + * Gets a listener to use with the {@link CqlSessionFactory} to remove the schema cache entries + * when the DB sends schema change events. + */ + public SchemaChangeListener getSchemaChangeListener() { + return new SchemaObjectCache.SchemaCacheSchemaChangeListener(this); + } + + public Uni getDatabase( + RequestContext requestContext, + SchemaObjectIdentifier identifier, + UserAgent userAgent, + boolean forceRefresh) { + return get(requestContext, identifier, userAgent, forceRefresh); + } + + public Uni getKeyspace( + RequestContext requestContext, + SchemaObjectIdentifier identifier, + UserAgent userAgent, + boolean forceRefresh) { + + return get(requestContext, identifier, userAgent, forceRefresh); + } + + public Uni getTableBased( + RequestContext requestContext, + UnscopedSchemaObjectIdentifier name, + UserAgent userAgent, + boolean forceRefresh) { + + var collectionKey = + createCacheKey( + requestContext, + SchemaObjectIdentifier.forCollection( + requestContext.tenant(), name.keyspace(), name.objectName()), + userAgent, + forceRefresh); + + var tableKey = + createCacheKey( + requestContext, + SchemaObjectIdentifier.forTable( + requestContext.tenant(), name.keyspace(), name.objectName()), + userAgent, + false); + + // we do not know if this is a collection or a table until we load it, and we + // cannot change the key once it is loaded, so we need to check both + + // As an optimization, we getifPresent incase the object is a table - we would get a cache miss + // for + // the collection key, then try to load, then discover it is a table, fail the load, then get + // again + // and potentially cache hit for the table. + + if (!forceRefresh) { + + var existingCollection = getIfPresent(collectionKey); + if (existingCollection.isPresent()) { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace( + "getTableBased() - found existing collection schema object collectionKey: {}", + collectionKey); + return Uni.createFrom().item((TableBasedSchemaObject) existingCollection.get()); + } + } + + var existingTable = getIfPresent(tableKey); + if (existingTable.isPresent()) { + // we have a cache hit for the table, return it + if (LOGGER.isTraceEnabled()) { + LOGGER.trace( + "getTableBased() - found existing table schema object tableKey: {}", tableKey); + } + return Uni.createFrom().item((TableBasedSchemaObject) existingTable.get()); + } + } + + // we do not have a cache hit, or we wanted to force refresh, so we need to load it + // force refresh on the collection cache key will cause the cache to load and replace the entry + // and if we will refresh the driver metadata. So no need to also do that on the table key. + return get(collectionKey) + .onFailure( + io.stargate.sgv2.jsonapi.service.schema.SchemaObjectFactory + .SchemaObjectTypeMismatchException.class) + .recoverWithUni( + () -> { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace( + "getTableBased() - collection key load resulted in SchemaObjectTypeMismatchException, retrying collectionKey.identifier: {}, tableKey.identifier: {}", + collectionKey.schemaIdentifier, + tableKey.schemaIdentifier); + } + return get(tableKey); + }) + .invoke( + schemaObject -> { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace( + "getTableBased() - loaded schema object with identifier: {}, collectionKey.identifier: {}, tableKey.identifier: {}", + schemaObject.identifier(), + collectionKey.schemaIdentifier, + tableKey.schemaIdentifier); + } + }) + .map(obj -> (TableBasedSchemaObject) obj); + } + + private Uni get( + RequestContext requestContext, + SchemaObjectIdentifier identifier, + UserAgent userAgent, + boolean forceRefresh) { + + // todo, check and cast somehow + return (Uni) get(createCacheKey(requestContext, identifier, userAgent, forceRefresh)); + } + + @VisibleForTesting + Optional getIfPresent( + RequestContext requestContext, SchemaObjectIdentifier identifier, UserAgent userAgent) { + + return (Optional) getIfPresent(createCacheKey(requestContext, identifier, userAgent, false)); + } + + protected void evictTable(Tenant tenant, CqlIdentifier keyspace, CqlIdentifier table) { + // no need to normalize the keyspace name, it is already normalized + // requestContext is only needed when creating/loading values + // Eviction with null requestContext works because SchemaCacheKey.equals() only compares + // schemaIdentifier + var evictKey = + createCacheKey(null, SchemaObjectIdentifier.forTable(tenant, keyspace, table), null, false); + + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("evictTable() - evictKey: {}", evictKey); + } + + evict(evictKey); + } + + protected void evictKeyspace(Tenant tenant, CqlIdentifier keyspace, boolean evictAll) { + // no need to normalize the keyspace name, it is already normalized + // requestContext is only needed when creating/loading values + // Eviction with null requestContext works because SchemaCacheKey.equals() only compares + // schemaIdentifier + var evictKey = + createCacheKey(null, SchemaObjectIdentifier.forKeyspace(tenant, keyspace), null, false); + + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("evictKeyspace() - evictKey: {}", evictKey); + } + + evict(evictKey); + if (evictAll) { + // we need to remove all the tables, collections, etc. All of those are in this keyspace. + evictIf(key -> evictKey.schemaIdentifier.isSameKeyspace(key.schemaIdentifier)); + } + } + + private SchemaCacheKey createCacheKey( + RequestContext requestContext, + SchemaObjectIdentifier schemaIdentifier, + UserAgent userAgent, + boolean forceRefresh) { + + // sanity check + // requestContext may be null when we are doing evictions + if (requestContext != null && (!requestContext.tenant().equals(schemaIdentifier.tenant()))) { + throw new IllegalArgumentException( + "RequestContext tenant does not match schemaIdentifier requestContext.tenant: " + + requestContext.tenant() + + ", schemaIdentifier.tenant: " + + schemaIdentifier.tenant()); + } + + return new SchemaCacheKey( + requestContext, + schemaIdentifier, + ttlSupplier.ttlForUsageAgent(userAgent), + forceRefresh, + userAgent); + } + + static class SchemaCacheKey implements DynamicTTLCache.CacheKey { + + private final SchemaObjectIdentifier schemaIdentifier; + // ttl is not part of the key identity + private final Duration ttl; + private final boolean forceRefresh; + // user agent only added for logging and debugging, not part of the key identity + private final UserAgent userAgent; + // held as weak because a cache key can be very long-lived, this is the context we loaded it in + private WeakReference requestContextWeakReference; + + SchemaCacheKey( + RequestContext requestContext, + SchemaObjectIdentifier schemaIdentifier, + Duration ttl, + boolean forceRefresh, + UserAgent userAgent) { + + this.schemaIdentifier = + Objects.requireNonNull(schemaIdentifier, "schemaIdentifier must not be null"); + this.ttl = Objects.requireNonNull(ttl, "ttl must not be null"); + this.forceRefresh = forceRefresh; + this.userAgent = userAgent; + // requestContext may be null, it is only used when we will need to load the schema object + this.requestContextWeakReference = new WeakReference<>(requestContext); + } + + SchemaObjectIdentifier schemaIdentifier() { + return schemaIdentifier; + } + + Optional requestContext() { + return Optional.ofNullable(requestContextWeakReference.get()); + } + + UserAgent userAgent() { + return userAgent; + } + + @Override + public Duration ttl() { + return ttl; + } + + @Override + public boolean forceRefresh() { + return forceRefresh; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof SchemaCacheKey that)) { + return false; + } + return schemaIdentifier.equals(that.schemaIdentifier); + } + + @Override + public int hashCode() { + return Objects.hash(schemaIdentifier); + } + + @Override + public String toString() { + return new StringBuilder() + .append("SchemaCacheKey{") + .append("schemaIdentifier=") + .append(schemaIdentifier) + .append(", ttl=") + .append(ttl) + .append(", userAgent='") + .append(userAgent) + .append("'}") + .toString(); + } + } + + /** + * SchemaChangeListener for the schema cache, this is used to evict the cache entries when we get + * messages from the DB that the schema has changed. + * + *

NOTE: This relies on the sessionName being set correctly which should be in {@link + * io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionFactory} + * + *

A new schema change listener should be created for each CQL {@link Session} when it is + * created because the listener will first listen for {@link SchemaChangeListener#onSessionReady} + * and get the tenantID from the session name via {@link Session#getName}. + * + *

If the tenant is not set, null or blank, we log at ERROR rather than throw because the + * callback methods are called on driver async threads and exceptions there are unlikely to be + * passed back in the request response. + * + *

This could be non-static inner, but static to make testing easier so we can pass in the + * cache it is working with. + */ + static class SchemaCacheSchemaChangeListener extends SchemaChangeListenerBase { + + private static final Logger LOGGER = + LoggerFactory.getLogger(SchemaCacheSchemaChangeListener.class); + + private final SchemaObjectCache schemaObjectCache; + + // tenantID is nullable when there is a regular C* database + private boolean sessionReady = false; + private Tenant tenant = null; + + public SchemaCacheSchemaChangeListener(SchemaObjectCache schemaObjectCache) { + this.schemaObjectCache = + Objects.requireNonNull(schemaObjectCache, "schemaObjectCache must not be null"); + } + + private boolean isSessionReady(String context) { + if (!sessionReady) { + LOGGER.error( + "SchemaCacheSchemaChangeListener sessionReady is false when expected true - {}", + context); + return false; + } + return true; + } + + private void evictTable(String context, TableMetadata tableMetadata) { + if (isSessionReady(context)) { + schemaObjectCache.evictTable(tenant, tableMetadata.getKeyspace(), tableMetadata.getName()); + } + } + + private void evictKeyspace( + String context, KeyspaceMetadata keyspaceMetadata, boolean evictAll) { + if (isSessionReady(context)) { + schemaObjectCache.evictKeyspace(tenant, keyspaceMetadata.getName(), evictAll); + } + } + + @Override + public void onSessionReady(@NonNull Session session) { + // This is called when the session is ready, we can get the tenant from the session name + // and set it in the listener so we can use it in the other methods. + tenant = TenantFactory.instance().create(session.getName()); + sessionReady = true; + } + + /** + * When a table is dropped, evict from cache to reduce the size and avoid stale if it is + * re-created + */ + @Override + public void onTableDropped(@NonNull TableMetadata table) { + evictTable("onTableDropped", table); + } + + /** When a table is created, evict from cache to avoid stale if it was re-created */ + @Override + public void onTableCreated(@NonNull TableMetadata table) { + evictTable("onTableCreated", table); + } + + /** When a table is updated, evict from cache to avoid stale entries */ + @Override + public void onTableUpdated(@NonNull TableMetadata current, @NonNull TableMetadata previous) { + // table name can never change + evictTable("onTableUpdated", current); + } + + /** When keyspace dropped, we dont need any more of the tables in the cache */ + @Override + public void onKeyspaceDropped(@NonNull KeyspaceMetadata keyspace) { + evictKeyspace("onKeyspaceDropped", keyspace, true); + } + + /** When keyspace created, evict KS and all other objects in case we missed the drop */ + @Override + public void onKeyspaceCreated(@NonNull KeyspaceMetadata keyspace) { + evictKeyspace("onKeyspaceCreated", keyspace, true); + } + + /** When keyspace updated, evict from cache in case stale keyspace or collections */ + @Override + public void onKeyspaceUpdated( + @NonNull KeyspaceMetadata current, @NonNull KeyspaceMetadata previous) { + evictKeyspace("onKeyspaceUpdated", current, false); + } + } + + /** Called to create a new schema object when one is needed. */ + interface SchemaObjectFactory { + CompletionStage apply( + RequestContext requestContext, SchemaObjectIdentifier identifier, boolean forceRefresh); + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectCacheSupplier.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectCacheSupplier.java new file mode 100644 index 0000000000..5bf59049b3 --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectCacheSupplier.java @@ -0,0 +1,41 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import io.micrometer.core.instrument.MeterRegistry; +import io.stargate.sgv2.jsonapi.api.request.UserAgent; +import io.stargate.sgv2.jsonapi.config.OperationsConfig; +import io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionCacheSupplier; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import java.time.Duration; +import java.util.function.Supplier; + +@ApplicationScoped +public class SchemaObjectCacheSupplier implements Supplier { + + private final SchemaObjectCache singleton; + + @Inject + public SchemaObjectCacheSupplier( + CqlSessionCacheSupplier cqlSessionCacheSupplier, + OperationsConfig operationsConfig, + MeterRegistry meterRegistry) { + + var dbConfig = operationsConfig.databaseConfig(); + + var factory = new SchemaObjectFactory(cqlSessionCacheSupplier.get()); + + this.singleton = + new SchemaObjectCache( + dbConfig.sessionCacheMaxSize(), + Duration.ofSeconds(dbConfig.sessionCacheTtlSeconds()), + operationsConfig.slaUserAgent().map(UserAgent::new).orElse(null), + Duration.ofSeconds(dbConfig.slaSessionCacheTtlSeconds()), + factory, + meterRegistry); + } + + @Override + public SchemaObjectCache get() { + return singleton; + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectFactory.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectFactory.java new file mode 100644 index 0000000000..da93f40747 --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectFactory.java @@ -0,0 +1,157 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import static io.stargate.sgv2.jsonapi.exception.ErrorFormatters.errFmtJoin; +import static io.stargate.sgv2.jsonapi.exception.ErrorFormatters.errVars; + +import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.smallrye.mutiny.Uni; +import io.stargate.sgv2.jsonapi.api.request.RequestContext; +import io.stargate.sgv2.jsonapi.exception.SchemaException; +import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.*; +import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionTableMatcher; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; +import io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil; +import java.util.Objects; +import java.util.concurrent.CompletionStage; + +public class SchemaObjectFactory implements SchemaObjectCache.SchemaObjectFactory { + + private static final CollectionTableMatcher IS_COLLECTION_PREDICATE = + new CollectionTableMatcher(); + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + private final CQLSessionCache sessionCache; + + public SchemaObjectFactory(CQLSessionCache sessionCache) { + this.sessionCache = Objects.requireNonNull(sessionCache, "sessionCache must not be null"); + } + + @Override + public CompletionStage apply( + RequestContext requestContext, SchemaObjectIdentifier identifier, boolean forceRefresh) { + + Objects.requireNonNull(requestContext, "requestContext must not be null"); + Objects.requireNonNull(identifier, "identifier must not be null"); + + // sanity check + if (!requestContext.tenant().equals(identifier.tenant())) { + throw new IllegalArgumentException( + "requestContext and identifier tenant mismatch, requestContext: %s, identifier: %s" + .formatted(requestContext, identifier.tenant())); + } + + Uni uni = + switch (identifier.type()) { + case DATABASE -> createDatabaseSchemaObject(requestContext, identifier, forceRefresh); + case KEYSPACE -> createKeyspaceSchemaObject(requestContext, identifier, forceRefresh); + case TABLE -> + createTableBasedSchemaObject(requestContext, identifier, forceRefresh) + .onItem() + .transformToUni( + tableBasedSchemaObject -> { + if (tableBasedSchemaObject.type() != SchemaObjectType.TABLE) { + return Uni.createFrom() + .failure( + new SchemaObjectTypeMismatchException( + SchemaObjectType.TABLE, tableBasedSchemaObject.type())); + } + return Uni.createFrom().item(tableBasedSchemaObject); + }); + case COLLECTION -> + createTableBasedSchemaObject(requestContext, identifier, forceRefresh) + .onItem() + .transformToUni( + tableBasedSchemaObject -> { + if (tableBasedSchemaObject.type() != SchemaObjectType.COLLECTION) { + return Uni.createFrom() + .failure( + new SchemaObjectTypeMismatchException( + SchemaObjectType.COLLECTION, tableBasedSchemaObject.type())); + } + return Uni.createFrom().item(tableBasedSchemaObject); + }); + default -> + throw new IllegalArgumentException( + "Unsupported schema object type: " + identifier.type()); + }; + return uni.map(obj -> (SchemaObject) obj).subscribeAsCompletionStage(); + } + + private Uni createDatabaseSchemaObject( + RequestContext requestContext, SchemaObjectIdentifier identifier, boolean forceRefresh) { + + // currently nothing to read for a database schema object + return Uni.createFrom().item(() -> new DatabaseSchemaObject(identifier)); + } + + private Uni createKeyspaceSchemaObject( + RequestContext requestContext, SchemaObjectIdentifier identifier, boolean forceRefresh) { + + // currently nothing to read for a keyspace schema object + return getKeyspaceMetadata(requestContext, identifier, forceRefresh) + .map( + keyspaceMetadata -> + new KeyspaceSchemaObject(requestContext.tenant(), keyspaceMetadata)); + } + + private Uni createTableBasedSchemaObject( + RequestContext requestContext, + UnscopedSchemaObjectIdentifier scopedName, + boolean forceRefresh) { + + return getKeyspaceMetadata(requestContext, scopedName, forceRefresh) + .map( + keyspaceMetadata -> { + var tableMetadata = + keyspaceMetadata + .getTable(scopedName.objectName()) + .orElseThrow( + () -> { + var allTables = + keyspaceMetadata.getTables().keySet().stream() + .sorted(CqlIdentifierUtil.CQL_IDENTIFIER_COMPARATOR) + .map(CqlIdentifierUtil::cqlIdentifierToMessageString) + .toList(); + return SchemaException.Code.UNKNOWN_COLLECTION_OR_TABLE.get( + errVars( + scopedName, + vars -> vars.put("allTables", errFmtJoin(allTables)))); + }); + return IS_COLLECTION_PREDICATE.test(tableMetadata) + ? CollectionSchemaObject.getCollectionSettings( + requestContext.tenant(), tableMetadata, OBJECT_MAPPER) + : TableSchemaObject.from(requestContext.tenant(), tableMetadata, OBJECT_MAPPER); + }); + } + + private Uni getKeyspaceMetadata( + RequestContext requestContext, + UnscopedSchemaObjectIdentifier scopedName, + boolean forceRefresh) { + + var queryExecutor = + new CommandQueryExecutor( + sessionCache, requestContext, CommandQueryExecutor.QueryTarget.SCHEMA); + + return queryExecutor + .getKeyspaceMetadata(scopedName.keyspace(), forceRefresh) + .map( + optKeyspace -> + optKeyspace.orElseThrow( + () -> SchemaException.Code.UNKNOWN_KEYSPACE.get(errVars(scopedName)))); + } + + static class SchemaObjectTypeMismatchException extends RuntimeException { + + SchemaObjectTypeMismatchException(SchemaObjectType expected, SchemaObjectType actual) { + super( + String.format( + "Expected schema object type %s but got %s", expected.apiName(), actual.apiName())); + } + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectIdentifier.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectIdentifier.java new file mode 100644 index 0000000000..7f479f1c49 --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectIdentifier.java @@ -0,0 +1,222 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierToMessageString; +import static io.stargate.sgv2.jsonapi.util.StringUtil.normalizeOptionalString; + +import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; +import com.google.common.base.Preconditions; +import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; +import io.stargate.sgv2.jsonapi.logging.LoggingMDCContext; +import io.stargate.sgv2.jsonapi.util.recordable.Recordable; +import java.util.Objects; +import javax.annotation.Nullable; +import org.slf4j.MDC; + +/** + * Identifies a {@link SchemaObject} in the API, which can be a database, keyspace, collection, etc. + * + *

Schema objects are identified by their type, name, and importantly, the tenant they belong to. + * So an identifier is unique and stable for all tenants in a single instance of the API. + * + *

Create using the factory methods, such as {@link #forDatabase(Tenant)} which validate the data + * that is needed. + * + *

use {@link #fullName()} or {@link #toString()} to get a human-readable representation of the + * identifier, such as keyspace_name.table_name Note: You should compare and + * manages the identifiers as objects using the {@link #equals(Object)} and {@link #hashCode()} + * methods, which include the tenant etc in the logic. Avoid comparing the individual fields, such + * as {@link #tenant()}, {@link #keyspace()} or {@link #table()}. + */ +public class SchemaObjectIdentifier + implements UnscopedSchemaObjectIdentifier, Recordable, LoggingMDCContext { + + private final SchemaObjectType type; + private final Tenant tenant; + private final CqlIdentifier keyspace; + private final CqlIdentifier table; + + private final String fullName; + + private SchemaObjectIdentifier( + SchemaObjectType type, Tenant tenant, CqlIdentifier keyspace, CqlIdentifier table) { + + this.type = type; + this.tenant = tenant; + this.keyspace = keyspace; + this.table = table; + + this.fullName = + switch (type) { + case DATABASE -> "db:" + tenant; + case KEYSPACE -> cqlIdentifierToMessageString(keyspace); + // Note, INDEX and UDT schemaType are not used currently + // Added for syntax completeness + case COLLECTION, TABLE, INDEX, UDT -> + cqlIdentifierToMessageString(keyspace) + "." + cqlIdentifierToMessageString(table); + }; + } + + /** Creates a {@link SchemaObjectIdentifier} for a database. */ + public static SchemaObjectIdentifier forDatabase(Tenant tenant) { + + checkTenantId(tenant); + return new SchemaObjectIdentifier(SchemaObjectType.DATABASE, tenant, null, null); + } + + /** Creates a {@link SchemaObjectIdentifier} for a keyspace. */ + public static SchemaObjectIdentifier forKeyspace(Tenant tenant, CqlIdentifier keyspace) { + + checkTenantId(tenant); + checkKeyspaceName(keyspace); + return new SchemaObjectIdentifier(SchemaObjectType.KEYSPACE, tenant, keyspace, null); + } + + /** Creates a {@link SchemaObjectIdentifier} for a collection. */ + public static SchemaObjectIdentifier forCollection( + Tenant tenant, CqlIdentifier keyspace, CqlIdentifier collection) { + + checkTenantId(tenant); + checkKeyspaceName(keyspace); + checkTableName("collection", collection); + return new SchemaObjectIdentifier(SchemaObjectType.COLLECTION, tenant, keyspace, collection); + } + + /** Creates a {@link SchemaObjectIdentifier} for a table. */ + public static SchemaObjectIdentifier forTable( + Tenant tenant, CqlIdentifier keyspace, CqlIdentifier table) { + + checkTenantId(tenant); + checkKeyspaceName(keyspace); + checkTableName("table", table); + return new SchemaObjectIdentifier(SchemaObjectType.TABLE, tenant, keyspace, table); + } + + /** Creates a {@link SchemaObjectIdentifier} using CQL TableMetadata to get the name parts. */ + public static SchemaObjectIdentifier fromTableMetadata( + SchemaObjectType type, Tenant tenant, TableMetadata tableMetadata) { + + checkTenantId(tenant); + Objects.requireNonNull(tableMetadata, "tableMetadata must not be null"); + + return switch (type) { + case TABLE -> forTable(tenant, tableMetadata.getKeyspace(), tableMetadata.getName()); + case COLLECTION -> + forCollection(tenant, tableMetadata.getKeyspace(), tableMetadata.getName()); + default -> + throw new IllegalArgumentException( + "fromTableMetadata() - Unsupported object type: " + type); + }; + } + + public SchemaObjectType type() { + return type; + } + + /** + * The full name of the schema object, this is also returned from {@link #toString()}.: + * + *

+ */ + public String fullName() { + return fullName; + } + + public Tenant tenant() { + return tenant; + } + + /** Gets the {@link SchemaObjectIdentifier} for the keyspace that contains this schema object. */ + public SchemaObjectIdentifier keyspaceIdentifier() { + return forKeyspace(tenant, keyspace); + } + + @Override + public CqlIdentifier keyspace() { + return keyspace; + } + + @Nullable + public CqlIdentifier table() { + return table; + } + + /** Same as {@link #table()} , part of the {@link UnscopedSchemaObjectIdentifier} interface. */ + @Override + public CqlIdentifier objectName() { + return table; + } + + /** Tests if this identifier is from the same tenant AND keyspace as another identifier. */ + public boolean isSameKeyspace(SchemaObjectIdentifier other) { + return Objects.equals(tenant, other.tenant) && Objects.equals(keyspace, other.keyspace); + } + + private static void checkTenantId(Tenant tenant) { + Objects.requireNonNull(tenant, "tenant name must not be null"); + } + + private static void checkKeyspaceName(CqlIdentifier keyspace) { + Objects.requireNonNull(keyspace, "keyspace name must not be null"); + Preconditions.checkArgument( + !keyspace.asInternal().isBlank(), "keyspace name must not be blank"); + } + + private static void checkTableName(String context, CqlIdentifier table) { + Objects.requireNonNull(table, context + " name must not be null"); + Preconditions.checkArgument(!table.asInternal().isBlank(), context + " name must not be blank"); + } + + @Override + public void addToMDC() { + // NOTE: MUST stay as namespace for logging analysis + MDC.put("namespace", keyspace.asInternal()); + + // NOTE: MUST stay as collection for logging analysis + MDC.put("collection", normalizeOptionalString(table == null ? null : table.asInternal())); + } + + @Override + public void removeFromMDC() { + MDC.remove("namespace"); + MDC.remove("collection"); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof SchemaObjectIdentifier that)) { + return false; + } + return Objects.equals(type, that.type) + && Objects.equals(tenant, that.tenant) + && Objects.equals(keyspace, that.keyspace) + && Objects.equals(table, that.table); + } + + @Override + public int hashCode() { + return Objects.hash(type, tenant, keyspace, table); + } + + /** Gets the {@link #fullName()} */ + @Override + public String toString() { + return fullName(); + } + + @Override + public DataRecorder recordTo(DataRecorder dataRecorder) { + return dataRecorder + .append("tenant", tenant) + .append("type", type) + .append("keyspace", keyspace) + .append("table", table); + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectType.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectType.java new file mode 100644 index 0000000000..72b7a82e8c --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectType.java @@ -0,0 +1,34 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import java.util.Objects; + +/** The types of schema object that are used in the API */ +public enum SchemaObjectType { + COLLECTION(Constants.COLLECTION), + DATABASE(Constants.DATABASE), + INDEX(Constants.INDEX), + KEYSPACE(Constants.KEYSPACE), + TABLE(Constants.TABLE), + UDT(Constants.UDT); + + /** Constants so the public HTTP API objects can use the same values. */ + public interface Constants { + String COLLECTION = "Collection"; + String DATABASE = "Database"; + String INDEX = "Index"; + String KEYSPACE = "Keyspace"; + String TABLE = "Table"; + String UDT = "Udt"; + } + + private final String apiName; + + SchemaObjectType(String apiName) { + this.apiName = Objects.requireNonNull(apiName, "apiName must not be null"); + } + + /** Gets the name to use when identifying this schema object type in the public API. */ + public String apiName() { + return apiName; + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/UnscopedSchemaObjectIdentifier.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/UnscopedSchemaObjectIdentifier.java new file mode 100644 index 0000000000..26619e8dae --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/UnscopedSchemaObjectIdentifier.java @@ -0,0 +1,33 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import com.datastax.oss.driver.api.core.CqlIdentifier; +import io.stargate.sgv2.jsonapi.api.request.RequestContext; +import io.stargate.sgv2.jsonapi.api.request.UserAgent; +import java.util.Objects; + +/** + * An identifier for a schema object that is not scoped to a {@link + * io.stargate.sgv2.jsonapi.api.request.tenant.Tenant}. + * + *

We only have the Keyspace and object name, such as the table name, we do now know who it + * belongs to. This is used by the SchemaObjectCache due to issues with not knowing if a CQL table + * is a API Collection or API Table. See {@link SchemaObjectCache#getTableBased(RequestContext, + * UnscopedSchemaObjectIdentifier, UserAgent, boolean)} + */ +public interface UnscopedSchemaObjectIdentifier { + + /** The keyspace that this object belongs to. */ + CqlIdentifier keyspace(); + + /** The name of the object, such as a table or index. */ + CqlIdentifier objectName(); + + record DefaultKeyspaceScopedName(CqlIdentifier keyspace, CqlIdentifier objectName) + implements UnscopedSchemaObjectIdentifier { + + public DefaultKeyspaceScopedName { + Objects.requireNonNull(keyspace, "keyspace must not be null"); + Objects.requireNonNull(objectName, "objectName must not be null"); + } + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSchemaObject.java index 5f3344171b..f138f77592 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSchemaObject.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSchemaObject.java @@ -1,6 +1,7 @@ package io.stargate.sgv2.jsonapi.service.schema.collections; import static io.stargate.sgv2.jsonapi.config.constants.DocumentConstants.Fields.VECTOR_EMBEDDING_TEXT_FIELD; +import static io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil.cqlIdentifierToMessageString; import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata; @@ -10,9 +11,11 @@ import com.fasterxml.jackson.core.JacksonException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateCollectionCommand; import io.stargate.sgv2.jsonapi.api.model.command.impl.VectorizeConfig; +import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; import io.stargate.sgv2.jsonapi.config.constants.DocumentConstants; import io.stargate.sgv2.jsonapi.config.constants.TableCommentConstants; import io.stargate.sgv2.jsonapi.config.constants.VectorConstants; @@ -20,8 +23,8 @@ import io.stargate.sgv2.jsonapi.exception.ServerException; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.*; import io.stargate.sgv2.jsonapi.service.projection.IndexingProjector; -import io.stargate.sgv2.jsonapi.service.schema.EmbeddingSourceModel; -import io.stargate.sgv2.jsonapi.service.schema.SimilarityFunction; +import io.stargate.sgv2.jsonapi.service.schema.*; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableBasedSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.List; import java.util.Map; @@ -35,20 +38,6 @@ */ public final class CollectionSchemaObject extends TableBasedSchemaObject { - public static final SchemaObjectType TYPE = SchemaObjectType.COLLECTION; - - // Collection Schema to use if all information missing: Vector not configured, - // no Lexical enabled - public static final CollectionSchemaObject MISSING = - new CollectionSchemaObject( - SchemaObjectName.MISSING, - null, - IdConfig.defaultIdConfig(), - VectorConfig.NOT_ENABLED_CONFIG, - null, - CollectionLexicalConfig.configForDisabled(), - CollectionRerankDef.configForDisabled()); - private final IdConfig idConfig; private final VectorConfig vectorConfig; private final CollectionIndexingConfig indexingConfig; @@ -56,60 +45,48 @@ public final class CollectionSchemaObject extends TableBasedSchemaObject { private final CollectionLexicalConfig lexicalConfig; private final CollectionRerankDef rerankDef; - /** - * @param vectorConfig - * @param indexingConfig - */ public CollectionSchemaObject( - String keypaceName, - String name, + Tenant tenant, TableMetadata tableMetadata, IdConfig idConfig, VectorConfig vectorConfig, CollectionIndexingConfig indexingConfig, CollectionLexicalConfig lexicalConfig, CollectionRerankDef rerankDef) { - this( - new SchemaObjectName(keypaceName, name), - tableMetadata, - idConfig, - vectorConfig, - indexingConfig, - lexicalConfig, - rerankDef); + + super(SchemaObjectType.COLLECTION, tenant, tableMetadata); + + this.idConfig = idConfig; + this.vectorConfig = vectorConfig; + this.indexingConfig = indexingConfig; + this.tableMetadata = tableMetadata; + this.lexicalConfig = Objects.requireNonNull(lexicalConfig); + this.rerankDef = Objects.requireNonNull(rerankDef); } + /** + * we have a lot of old tests that created a collection without having table metadata. Use the + * ctor with TableMetadata in prod code + */ + @VisibleForTesting public CollectionSchemaObject( - SchemaObjectName name, - TableMetadata tableMetadata, + SchemaObjectIdentifier identifier, IdConfig idConfig, VectorConfig vectorConfig, CollectionIndexingConfig indexingConfig, CollectionLexicalConfig lexicalConfig, CollectionRerankDef rerankDef) { - super(TYPE, name, tableMetadata); + + super(SchemaObjectType.COLLECTION, identifier); this.idConfig = idConfig; this.vectorConfig = vectorConfig; this.indexingConfig = indexingConfig; - this.tableMetadata = tableMetadata; + this.tableMetadata = null; this.lexicalConfig = Objects.requireNonNull(lexicalConfig); this.rerankDef = Objects.requireNonNull(rerankDef); } - // TODO: remove this, it is just here for testing and can be handled by creating test data - // effectively - public CollectionSchemaObject withIdType(CollectionIdType idType) { - return new CollectionSchemaObject( - name(), - tableMetadata, - new IdConfig(idType), - vectorConfig, - indexingConfig, - lexicalConfig, - rerankDef); - } - /** * Method for constructing a new CollectionSchemaObject with overrides for Lexical and Rerank * settings. @@ -117,7 +94,7 @@ public CollectionSchemaObject withIdType(CollectionIdType idType) { public CollectionSchemaObject withLexicalAndRerankOverrides( CollectionLexicalConfig lexicalOverride, CollectionRerankDef rerankOverride) { return new CollectionSchemaObject( - name(), + identifier().tenant(), tableMetadata, idConfig, vectorConfig, @@ -167,31 +144,9 @@ public IndexingProjector indexingProjector() { return indexingConfig.indexingProjector(); } - // TODO: AARON COMMENTED OUT TO SEE IF IT IS USED - // public enum AuthenticationType { - // NONE, - // HEADER, - // SHARED_SECRET, - // UNDEFINED; - // - // public static AuthenticationType fromString(String authenticationType) { - // if (authenticationType == null) return UNDEFINED; - // return switch (authenticationType.toLowerCase()) { - // case "none" -> NONE; - // case "header" -> HEADER; - // case "shared_secret" -> SHARED_SECRET; - // default -> - // throw ErrorCodeV1.VECTORIZE_INVALID_AUTHENTICATION_TYPE.toApiException( - // "'%s'", authenticationType); - // }; - // } - // } - public static CollectionSchemaObject getCollectionSettings( - TableMetadata table, ObjectMapper objectMapper) { - // [jsonapi#639]: get internal name to avoid quoting of case-sensitive names - String keyspaceName = table.getKeyspace().asInternal(); - String collectionName = table.getName().asInternal(); + Tenant tenant, TableMetadata table, ObjectMapper objectMapper) { + // get vector column final Optional vectorColumn = table.getColumn(DocumentConstants.Columns.VECTOR_SEARCH_INDEX_COLUMN_NAME); @@ -230,9 +185,9 @@ public static CollectionSchemaObject getCollectionSettings( () -> EmbeddingSourceModel.getUnknownSourceModelException(sourceModelName)); } } + return createCollectionSettings( - keyspaceName, - collectionName, + SchemaObjectIdentifier.forCollection(tenant, table.getKeyspace(), table.getName()), table, true, vectorSize, @@ -242,8 +197,7 @@ public static CollectionSchemaObject getCollectionSettings( objectMapper); } else { // if not vector collection return createCollectionSettings( - keyspaceName, - collectionName, + SchemaObjectIdentifier.forCollection(tenant, table.getKeyspace(), table.getName()), table, false, 0, @@ -254,31 +208,8 @@ public static CollectionSchemaObject getCollectionSettings( } } - public static CollectionSchemaObject getCollectionSettings( - String keyspaceName, - String collectionName, - TableMetadata tableMetadata, - boolean vectorEnabled, - int vectorSize, - SimilarityFunction similarityFunction, - EmbeddingSourceModel sourceModel, - String comment, - ObjectMapper objectMapper) { - return createCollectionSettings( - keyspaceName, - collectionName, - tableMetadata, - vectorEnabled, - vectorSize, - similarityFunction, - sourceModel, - comment, - objectMapper); - } - - private static CollectionSchemaObject createCollectionSettings( - String keyspaceName, - String collectionName, + public static CollectionSchemaObject createCollectionSettings( + SchemaObjectIdentifier identifier, TableMetadata tableMetadata, boolean vectorEnabled, int vectorSize, @@ -294,8 +225,7 @@ private static CollectionSchemaObject createCollectionSettings( CollectionRerankDef rerankingConfig = CollectionRerankDef.configForPreRerankingCollection(); if (vectorEnabled) { return new CollectionSchemaObject( - keyspaceName, - collectionName, + identifier.tenant(), tableMetadata, IdConfig.defaultIdConfig(), VectorConfig.fromColumnDefinitions( @@ -311,8 +241,7 @@ private static CollectionSchemaObject createCollectionSettings( rerankingConfig); } else { return new CollectionSchemaObject( - keyspaceName, - collectionName, + identifier.tenant(), tableMetadata, IdConfig.defaultIdConfig(), VectorConfig.NOT_ENABLED_CONFIG, @@ -340,8 +269,7 @@ private static CollectionSchemaObject createCollectionSettings( switch (collectionNode.get(TableCommentConstants.SCHEMA_VERSION_KEY).asInt()) { case 1: return new CollectionSettingsV1Reader() - .readCollectionSettings( - collectionNode, keyspaceName, collectionName, tableMetadata, objectMapper); + .readCollectionSettings(identifier, collectionNode, tableMetadata, objectMapper); default: throw ErrorCodeV1.INVALID_SCHEMA_VERSION.toApiException(); } @@ -350,9 +278,8 @@ private static CollectionSchemaObject createCollectionSettings( // sample comment : {"indexing":{"deny":["address"]}}} return new CollectionSettingsV0Reader() .readCollectionSettings( + identifier, commentConfigNode, - keyspaceName, - collectionName, tableMetadata, vectorEnabled, vectorSize, @@ -431,7 +358,8 @@ public static CreateCollectionCommand collectionSettingToCreateCollectionCommand // CreateCollectionCommand object is created for convenience to generate json // response. The code is not creating a collection here. - return new CreateCollectionCommand(collectionSetting.name.table(), options); + return new CreateCollectionCommand( + cqlIdentifierToMessageString(collectionSetting.identifier().table()), options); } public IdConfig idConfig() { @@ -466,7 +394,7 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (CollectionSchemaObject) obj; - return Objects.equals(this.name, that.name) + return Objects.equals(this.identifier(), that.identifier()) && Objects.equals(this.idConfig, that.idConfig) && Objects.equals(this.vectorConfig, that.vectorConfig) && Objects.equals(this.indexingConfig, that.indexingConfig) @@ -476,14 +404,14 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return Objects.hash(name, idConfig, vectorConfig, indexingConfig); + return Objects.hash(identifier(), idConfig, vectorConfig, indexingConfig); } @Override public String toString() { return "CollectionSchemaObject[" - + "name=" - + name + + "identifier=" + + identifier() + ", " + "idConfig=" + idConfig diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSettingsV0Reader.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSettingsV0Reader.java index 5dbb613938..6319eeb0c3 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSettingsV0Reader.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSettingsV0Reader.java @@ -7,6 +7,7 @@ import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorColumnDefinition; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; import io.stargate.sgv2.jsonapi.service.schema.EmbeddingSourceModel; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectIdentifier; import io.stargate.sgv2.jsonapi.service.schema.SimilarityFunction; import java.util.List; @@ -22,9 +23,8 @@ */ public class CollectionSettingsV0Reader { public CollectionSchemaObject readCollectionSettings( + SchemaObjectIdentifier identifier, JsonNode commentConfigNode, - String keyspaceName, - String collectionName, TableMetadata tableMetadata, boolean vectorEnabled, int vectorSize, @@ -48,8 +48,7 @@ public CollectionSchemaObject readCollectionSettings( indexingConfig = CollectionIndexingConfig.fromJson(indexing); } return new CollectionSchemaObject( - keyspaceName, - collectionName, + identifier.tenant(), tableMetadata, IdConfig.defaultIdConfig(), vectorConfig, diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSettingsV1Reader.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSettingsV1Reader.java index bb135102ea..1c620b51b2 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSettingsV1Reader.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSettingsV1Reader.java @@ -6,6 +6,7 @@ import io.stargate.sgv2.jsonapi.config.constants.TableCommentConstants; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorColumnDefinition; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectIdentifier; import java.util.List; /** @@ -17,9 +18,8 @@ */ public class CollectionSettingsV1Reader { public CollectionSchemaObject readCollectionSettings( + SchemaObjectIdentifier identifier, JsonNode collectionNode, - String keyspaceName, - String collectionName, TableMetadata tableMetadata, ObjectMapper objectMapper) { @@ -67,12 +67,15 @@ public CollectionSchemaObject readCollectionSettings( } else { rerankingConfig = CollectionRerankDef.fromCommentJson( - keyspaceName, collectionName, rerankingNode, objectMapper); + // [jsonapi#639]: get internal name to avoid quoting of case-sensitive names + identifier.keyspace().asInternal(), + identifier.table().asInternal(), + rerankingNode, + objectMapper); } return new CollectionSchemaObject( - keyspaceName, - collectionName, + identifier.tenant(), tableMetadata, idConfig, vectorConfig, diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/CollectionNamingRule.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/CollectionNamingRule.java index d71620cd5d..458ccf91f2 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/CollectionNamingRule.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/CollectionNamingRule.java @@ -1,10 +1,10 @@ package io.stargate.sgv2.jsonapi.service.schema.naming; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; /** The naming rule of the new Collection name. */ public class CollectionNamingRule extends SchemaObjectNamingRule { public CollectionNamingRule() { - super(SchemaObject.SchemaObjectType.COLLECTION); + super(SchemaObjectType.COLLECTION); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/IndexNamingRule.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/IndexNamingRule.java index c029d23abc..5287667652 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/IndexNamingRule.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/IndexNamingRule.java @@ -1,13 +1,13 @@ package io.stargate.sgv2.jsonapi.service.schema.naming; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; /** The naming rule of the new Index name. */ public class IndexNamingRule extends SchemaObjectNamingRule { private static final int MAX_INDEX_NAME_LENGTH = 100; public IndexNamingRule() { - super(SchemaObject.SchemaObjectType.INDEX); + super(SchemaObjectType.INDEX); } @Override diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/KeyspaceNamingRule.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/KeyspaceNamingRule.java index fe48883897..c51691cb74 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/KeyspaceNamingRule.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/KeyspaceNamingRule.java @@ -1,10 +1,10 @@ package io.stargate.sgv2.jsonapi.service.schema.naming; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; /** The naming rule of the new Keyspace name. */ public class KeyspaceNamingRule extends SchemaObjectNamingRule { public KeyspaceNamingRule() { - super(SchemaObject.SchemaObjectType.KEYSPACE); + super(SchemaObjectType.KEYSPACE); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/SchemaObjectNamingRule.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/SchemaObjectNamingRule.java index 0fe4bea2b1..0a4d9cea3d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/SchemaObjectNamingRule.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/SchemaObjectNamingRule.java @@ -2,7 +2,7 @@ import io.stargate.sgv2.jsonapi.exception.ErrorTemplate; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; import java.util.Map; import java.util.regex.Pattern; @@ -23,9 +23,9 @@ public abstract class SchemaObjectNamingRule extends NamingRule { private static final int MAX_NAME_LENGTH = 48; private static final Pattern PATTERN_WORD_CHARS = Pattern.compile("\\w+"); - private final SchemaObject.SchemaObjectType schemaType; + private final SchemaObjectType schemaType; - public SchemaObjectNamingRule(SchemaObject.SchemaObjectType schemaType) { + public SchemaObjectNamingRule(SchemaObjectType schemaType) { super(schemaType.name()); this.schemaType = schemaType; } @@ -33,7 +33,7 @@ public SchemaObjectNamingRule(SchemaObject.SchemaObjectType schemaType) { /** * @return the type of schema object that this rule is applied to */ - public SchemaObject.SchemaObjectType schemaType() { + public SchemaObjectType schemaType() { return schemaType; } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/TableNamingRule.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/TableNamingRule.java index 9c343e6ac8..6e8cb867ed 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/TableNamingRule.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/TableNamingRule.java @@ -1,10 +1,10 @@ package io.stargate.sgv2.jsonapi.service.schema.naming; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; /** The naming rule of the new Table name. */ public class TableNamingRule extends SchemaObjectNamingRule { public TableNamingRule() { - super(SchemaObject.SchemaObjectType.TABLE); + super(SchemaObjectType.TABLE); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/UdtNamingRule.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/UdtNamingRule.java index 0d4926749d..e8d7927e2a 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/UdtNamingRule.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/naming/UdtNamingRule.java @@ -1,10 +1,10 @@ package io.stargate.sgv2.jsonapi.service.schema.naming; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; public class UdtNamingRule extends SchemaObjectNamingRule { public UdtNamingRule() { - super(SchemaObject.SchemaObjectType.UDT); + super(SchemaObjectType.UDT); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiRegularIndex.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiRegularIndex.java index 1d83ac738d..14dc69a8ef 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiRegularIndex.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiRegularIndex.java @@ -14,7 +14,6 @@ import io.stargate.sgv2.jsonapi.config.constants.TableDescDefaults; import io.stargate.sgv2.jsonapi.exception.SchemaException; import io.stargate.sgv2.jsonapi.exception.checked.UnsupportedCqlIndexException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.factories.IndexFactoryFromCql; import io.stargate.sgv2.jsonapi.service.schema.tables.factories.IndexFactoryFromIndexDesc; import io.stargate.sgv2.jsonapi.util.ApiOptionUtils; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiTextIndex.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiTextIndex.java index b63bfcfd6a..531a3b9695 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiTextIndex.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiTextIndex.java @@ -18,7 +18,6 @@ import io.stargate.sgv2.jsonapi.config.constants.TableDescDefaults; import io.stargate.sgv2.jsonapi.exception.SchemaException; import io.stargate.sgv2.jsonapi.exception.checked.UnsupportedCqlIndexException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.factories.IndexFactoryFromCql; import io.stargate.sgv2.jsonapi.service.schema.tables.factories.IndexFactoryFromIndexDesc; import io.stargate.sgv2.jsonapi.util.JsonUtil; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiVectorIndex.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiVectorIndex.java index 11e1ee7ef1..0bcf7a85d8 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiVectorIndex.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiVectorIndex.java @@ -13,7 +13,6 @@ import io.stargate.sgv2.jsonapi.config.constants.VectorConstants; import io.stargate.sgv2.jsonapi.exception.SchemaException; import io.stargate.sgv2.jsonapi.exception.checked.UnsupportedCqlIndexException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.EmbeddingSourceModel; import io.stargate.sgv2.jsonapi.service.schema.SimilarityFunction; import io.stargate.sgv2.jsonapi.service.schema.tables.factories.IndexFactoryFromCql; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/TableBasedSchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/TableBasedSchemaObject.java new file mode 100644 index 0000000000..0d09df2323 --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/TableBasedSchemaObject.java @@ -0,0 +1,44 @@ +package io.stargate.sgv2.jsonapi.service.schema.tables; + +import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; +import com.google.common.annotations.VisibleForTesting; +import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectIdentifier; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; +import java.util.Objects; + +/** Common base for a Collection and Table, which are both a CQL Table. */ +public abstract class TableBasedSchemaObject extends SchemaObject { + + private final TableMetadata tableMetadata; + + protected TableBasedSchemaObject( + SchemaObjectType type, Tenant tenant, TableMetadata tableMetadata) { + super(type, SchemaObjectIdentifier.fromTableMetadata(type, tenant, tableMetadata)); + + this.tableMetadata = Objects.requireNonNull(tableMetadata, "tableMetadata must not be null"); + } + + /** For old tests that do not have the table metadata */ + @VisibleForTesting + protected TableBasedSchemaObject( + SchemaObjectType expectedType, SchemaObjectIdentifier schemaObjectIdentifier) { + super(expectedType, schemaObjectIdentifier); + + this.tableMetadata = null; + } + + public CqlIdentifier keyspaceName() { + return tableMetadata.getKeyspace(); + } + + public CqlIdentifier tableName() { + return tableMetadata.getName(); + } + + public TableMetadata tableMetadata() { + return tableMetadata; + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableSchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/TableSchemaObject.java similarity index 51% rename from src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableSchemaObject.java rename to src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/TableSchemaObject.java index 6fbf96d1d5..3d04424048 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableSchemaObject.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/TableSchemaObject.java @@ -1,8 +1,13 @@ -package io.stargate.sgv2.jsonapi.service.cqldriver.executor; +package io.stargate.sgv2.jsonapi.service.schema.tables; import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; import com.fasterxml.jackson.databind.ObjectMapper; -import io.stargate.sgv2.jsonapi.service.schema.tables.ApiTableDef; +import com.google.common.annotations.VisibleForTesting; +import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.IndexUsage; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectIdentifier; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,14 +15,15 @@ public class TableSchemaObject extends TableBasedSchemaObject { private static final Logger LOGGER = LoggerFactory.getLogger(TableSchemaObject.class); - public static final SchemaObjectType TYPE = SchemaObjectType.TABLE; - private final VectorConfig vectorConfig; private final ApiTableDef apiTableDef; private TableSchemaObject( - TableMetadata tableMetadata, VectorConfig vectorConfig, ApiTableDef apiTableDef) { - super(TYPE, tableMetadata); + Tenant tenant, + TableMetadata tableMetadata, + VectorConfig vectorConfig, + ApiTableDef apiTableDef) { + super(SchemaObjectType.TABLE, tenant, tableMetadata); this.vectorConfig = vectorConfig; this.apiTableDef = apiTableDef; } @@ -37,11 +43,23 @@ public ApiTableDef apiTableDef() { } /** Get table schema object from table metadata */ - public static TableSchemaObject from(TableMetadata tableMetadata, ObjectMapper objectMapper) { + public static TableSchemaObject from( + Tenant tenant, TableMetadata tableMetadata, ObjectMapper objectMapper) { var vectorConfig = VectorConfig.from(tableMetadata, objectMapper); var apiTableDef = ApiTableDef.FROM_CQL_FACTORY.create(tableMetadata, vectorConfig); - return new TableSchemaObject(tableMetadata, vectorConfig, apiTableDef); + return new TableSchemaObject(tenant, tableMetadata, vectorConfig, apiTableDef); + } + + /** + * we have tests that created a table without having table metadata. Use the ctor with + * TableMetadata in prod code + */ + @VisibleForTesting + public TableSchemaObject(SchemaObjectIdentifier identifier) { + super(SchemaObjectType.TABLE, identifier); + vectorConfig = null; + apiTableDef = null; } @Override diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/factories/IndexFactoryFromIndexDesc.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/factories/IndexFactoryFromIndexDesc.java index 41796c5e01..3b4d8fa36c 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/factories/IndexFactoryFromIndexDesc.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/factories/IndexFactoryFromIndexDesc.java @@ -6,9 +6,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.table.definition.indexes.IndexDefinitionDesc; import io.stargate.sgv2.jsonapi.exception.SchemaException; import io.stargate.sgv2.jsonapi.exception.checked.UnsupportedUserIndexException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiIndexDef; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; /** * Base for Factories that can create a {@link ApiIndexDef} subclass from the user description in a diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/CqlNamedValue.java b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/CqlNamedValue.java index 3b6e50faf4..3c21a24266 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/CqlNamedValue.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/CqlNamedValue.java @@ -12,12 +12,12 @@ import io.stargate.sgv2.jsonapi.exception.checked.MissingJSONCodecException; import io.stargate.sgv2.jsonapi.exception.checked.ToCQLCodecException; import io.stargate.sgv2.jsonapi.exception.checked.UnknownColumnException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.embeddings.EmbeddingDeferredAction; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodec; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistry; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiVectorType; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.*; /** diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/JsonNamedValue.java b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/JsonNamedValue.java index d7d2f0b9ea..737655acf0 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/JsonNamedValue.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/JsonNamedValue.java @@ -4,8 +4,8 @@ import com.fasterxml.jackson.databind.JsonNode; import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.JsonLiteral; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.collections.JsonPath; import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/NamedValue.java b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/NamedValue.java index 563d3dab1a..d75dd45728 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/NamedValue.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/NamedValue.java @@ -2,8 +2,8 @@ import io.stargate.sgv2.jsonapi.exception.ErrorCode; import io.stargate.sgv2.jsonapi.exception.RequestException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.tables.ApiColumnDef; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.Objects; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/CqlNamedValueContainerFactory.java b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/CqlNamedValueContainerFactory.java index dd914651a9..edab15bdef 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/CqlNamedValueContainerFactory.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/CqlNamedValueContainerFactory.java @@ -3,8 +3,8 @@ import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.internal.core.util.Strings; import io.stargate.sgv2.jsonapi.exception.RequestException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistry; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValue; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValueContainer; import io.stargate.sgv2.jsonapi.service.shredding.JsonNamedValueContainer; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/JsonNamedValueContainerFactory.java b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/JsonNamedValueContainerFactory.java index 260b000e34..b4bc884fd1 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/JsonNamedValueContainerFactory.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/JsonNamedValueContainerFactory.java @@ -1,7 +1,7 @@ package io.stargate.sgv2.jsonapi.service.shredding.tables; import com.fasterxml.jackson.databind.JsonNode; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.JsonNamedValue; import io.stargate.sgv2.jsonapi.service.shredding.JsonNamedValueContainer; import io.stargate.sgv2.jsonapi.service.shredding.JsonNodeDecoder; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/WriteableTableRow.java b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/WriteableTableRow.java index c320739322..7bf258e9a1 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/WriteableTableRow.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/shredding/tables/WriteableTableRow.java @@ -1,6 +1,6 @@ package io.stargate.sgv2.jsonapi.service.shredding.tables; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.*; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.List; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/util/CqlIdentifierUtil.java b/src/main/java/io/stargate/sgv2/jsonapi/util/CqlIdentifierUtil.java index 7a58f34d80..88843f59bf 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/util/CqlIdentifierUtil.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/util/CqlIdentifierUtil.java @@ -25,7 +25,7 @@ public static CqlIdentifier cqlIdentifierFromIndexTarget(String name) { } public static String cqlIdentifierToMessageString(CqlIdentifier identifier) { - return identifier.asCql(true); + return identifier == null ? "null" : identifier.asCql(true); } /** Returns the API representation of a CQL identifier. */ diff --git a/src/main/java/io/stargate/sgv2/jsonapi/util/DynamicTTLCache.java b/src/main/java/io/stargate/sgv2/jsonapi/util/DynamicTTLCache.java index 213002159f..961299f435 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/util/DynamicTTLCache.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/util/DynamicTTLCache.java @@ -17,6 +17,7 @@ import java.util.concurrent.CompletionStage; import java.util.concurrent.Executor; import java.util.function.Function; +import java.util.function.Predicate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -178,6 +179,10 @@ protected boolean evict(KeyT key) { return entryFound; } + protected void evictIf(Predicate predicate) { + cache.synchronous().asMap().keySet().removeIf(predicate); + } + /** * Process a key being removed from the cache for any reason. * diff --git a/src/main/java/io/stargate/sgv2/jsonapi/util/recordable/Recordable.java b/src/main/java/io/stargate/sgv2/jsonapi/util/recordable/Recordable.java index c51ec429a8..858478f3ff 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/util/recordable/Recordable.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/util/recordable/Recordable.java @@ -22,7 +22,7 @@ public interface Recordable { /** - * Called for the implementer to record its data to the {@link DataRecorder}, values should be + * Called for the implementer to record it's data to the {@link DataRecorder}, values should be * appended using {@link DataRecorder#append(String, Object)}. Values that implement {@link * Recordable} will be added as a sub object. * diff --git a/src/main/resources/errors.yaml b/src/main/resources/errors.yaml index 53690ba856..e1378a9d6c 100644 --- a/src/main/resources/errors.yaml +++ b/src/main/resources/errors.yaml @@ -1023,6 +1023,16 @@ request-errors: Resend the command using a Keyspace that exists. + - scope: SCHEMA + code: UNKNOWN_COLLECTION_OR_TABLE + title: Collection or Table does not exist in the Keyspace + body: |- + The command tried to get a Collection or Table ${table} that does not exist in the Keyspace ${keyspace}. + + The keyspace has the existing collections or tables: ${allTables}. + + Resend the command using a Collection or Table that exists. + - scope: SCHEMA code: UNKNOWN_PARTITION_SORT_COLUMNS title: Partition sort columns are not defined in the table schema diff --git a/src/test/java/io/stargate/sgv2/jsonapi/TestConstants.java b/src/test/java/io/stargate/sgv2/jsonapi/TestConstants.java index 7abfe895ef..b407512ac8 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/TestConstants.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/TestConstants.java @@ -19,12 +19,13 @@ import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProvider; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProviderFactory; import io.stargate.sgv2.jsonapi.service.reranking.operation.RerankingProviderFactory; -import io.stargate.sgv2.jsonapi.service.schema.EmbeddingSourceModel; -import io.stargate.sgv2.jsonapi.service.schema.SimilarityFunction; +import io.stargate.sgv2.jsonapi.service.schema.*; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionLexicalConfig; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionRerankDef; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.collections.IdConfig; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; +import io.stargate.sgv2.jsonapi.util.CqlIdentifierUtil; import java.util.List; import java.util.Optional; import org.apache.commons.lang3.RandomStringUtils; @@ -38,6 +39,7 @@ public class TestConstants { public final String APP_NAME; + public final DatabaseType DATABASE_TYPE; public final TenantFactory SINGLETON_TENANT_FACTORY; // ============================================================ @@ -55,8 +57,6 @@ public class TestConstants { public final String COLLECTION_NAME; public final String TABLE_NAME; - public final SchemaObjectName SCHEMA_OBJECT_NAME; - /** Raw SLA user agent, Use {@link #SLA_USER_AGENT} */ public final String SLA_USER_AGENT_NAME = "Datastax-SLA-Checker"; @@ -67,6 +67,18 @@ public class TestConstants { /** An astra database type TENANT used for test */ public final Tenant TENANT; + /** A database identifier for the test */ + public final SchemaObjectIdentifier DATABASE_IDENTIFIER; + + /** A keyspace identifier for the test */ + public final SchemaObjectIdentifier KEYSPACE_IDENTIFIER; + + /** A collection identifier for the test */ + public final SchemaObjectIdentifier COLLECTION_IDENTIFIER; + + /** A table identifier for the test */ + public final SchemaObjectIdentifier TABLE_IDENTIFIER; + /** A cassandra database type TENANT used for test */ public final Tenant CASSANDRA_TENANT; @@ -81,6 +93,11 @@ public class TestConstants { /** Embedding credentials */ public final EmbeddingCredentials EMBEDDING_CREDENTIALS; + /** + * Collection Schema to use if all information missing: Vector not configured, no Lexical enabled + */ + public final CollectionSchemaObject MISSING; + // ============================================================ // Schema Objects // ============================================================ @@ -88,6 +105,7 @@ public class TestConstants { public final CollectionSchemaObject COLLECTION_SCHEMA_OBJECT; public final CollectionSchemaObject COLLECTION_SCHEMA_OBJECT_LEGACY; public final CollectionSchemaObject VECTOR_COLLECTION_SCHEMA_OBJECT; + public final TableSchemaObject TABLE_SCHEMA_OBJECT; public final KeyspaceSchemaObject KEYSPACE_SCHEMA_OBJECT; public final DatabaseSchemaObject DATABASE_SCHEMA_OBJECT; @@ -99,20 +117,21 @@ public TestConstants() { COMMAND_NAME = "command-" + CORRELATION_ID; KEYSPACE_NAME = "keyspace-" + CORRELATION_ID; + var keyspaceCqlIdentifier = CqlIdentifierUtil.cqlIdentifierFromUserInput(KEYSPACE_NAME); COLLECTION_NAME = "collection-" + CORRELATION_ID; + var collectionCqlIdentifier = CqlIdentifierUtil.cqlIdentifierFromUserInput(COLLECTION_NAME); TABLE_NAME = "table-" + CORRELATION_ID; APP_NAME = "Stargate DATA API -" + CORRELATION_ID; - SCHEMA_OBJECT_NAME = new SchemaObjectName(KEYSPACE_NAME, COLLECTION_NAME); - // ============================================================ // Request Context // ============================================================ + DATABASE_TYPE = DatabaseType.ASTRA; var tenantId = "tenant-" + CORRELATION_ID; TenantFactory.reset(); - TenantFactory.initialize(DatabaseType.ASTRA); + TenantFactory.initialize(DATABASE_TYPE); TENANT = TenantFactory.instance().create(tenantId); SINGLETON_TENANT_FACTORY = TenantFactory.instance(); @@ -136,10 +155,20 @@ public TestConstants() { // Schema Objects // ============================================================ + DATABASE_IDENTIFIER = SchemaObjectIdentifier.forDatabase(TENANT); + KEYSPACE_IDENTIFIER = SchemaObjectIdentifier.forKeyspace(TENANT, keyspaceCqlIdentifier); + COLLECTION_IDENTIFIER = + SchemaObjectIdentifier.forCollection( + TENANT, keyspaceCqlIdentifier, collectionCqlIdentifier); + TABLE_IDENTIFIER = + SchemaObjectIdentifier.forTable( + TENANT, + keyspaceCqlIdentifier, + CqlIdentifierUtil.cqlIdentifierFromUserInput(TABLE_NAME)); + COLLECTION_SCHEMA_OBJECT = new CollectionSchemaObject( - SCHEMA_OBJECT_NAME, - null, + COLLECTION_IDENTIFIER, IdConfig.defaultIdConfig(), VectorConfig.NOT_ENABLED_CONFIG, null, @@ -153,8 +182,7 @@ public TestConstants() { // Schema object for testing with legacy (pre-lexical-config) defaults COLLECTION_SCHEMA_OBJECT_LEGACY = new CollectionSchemaObject( - SCHEMA_OBJECT_NAME, - null, + COLLECTION_IDENTIFIER, IdConfig.defaultIdConfig(), VectorConfig.NOT_ENABLED_CONFIG, null, @@ -163,8 +191,7 @@ public TestConstants() { VECTOR_COLLECTION_SCHEMA_OBJECT = new CollectionSchemaObject( - SCHEMA_OBJECT_NAME, - null, + COLLECTION_IDENTIFIER, IdConfig.defaultIdConfig(), VectorConfig.fromColumnDefinitions( List.of( @@ -178,8 +205,19 @@ public TestConstants() { CollectionLexicalConfig.configForDisabled(), CollectionRerankDef.configForPreRerankingCollection()); - KEYSPACE_SCHEMA_OBJECT = KeyspaceSchemaObject.fromSchemaObject(COLLECTION_SCHEMA_OBJECT); - DATABASE_SCHEMA_OBJECT = new DatabaseSchemaObject(); + TABLE_SCHEMA_OBJECT = new TableSchemaObject(TABLE_IDENTIFIER); + + KEYSPACE_SCHEMA_OBJECT = new KeyspaceSchemaObject(KEYSPACE_IDENTIFIER); + DATABASE_SCHEMA_OBJECT = new DatabaseSchemaObject(TENANT); + + MISSING = + new CollectionSchemaObject( + COLLECTION_IDENTIFIER, + IdConfig.defaultIdConfig(), + VectorConfig.NOT_ENABLED_CONFIG, + null, + CollectionLexicalConfig.configForDisabled(), + CollectionRerankDef.configForDisabled()); } // CommandContext for working on the schema objects above diff --git a/src/test/java/io/stargate/sgv2/jsonapi/api/configuration/CollectionSchemaObjectTest.java b/src/test/java/io/stargate/sgv2/jsonapi/api/configuration/CollectionSchemaObjectTest.java index 3c729e6cce..5b7a30b54b 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/api/configuration/CollectionSchemaObjectTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/api/configuration/CollectionSchemaObjectTest.java @@ -4,6 +4,7 @@ import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; +import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; import io.stargate.sgv2.jsonapi.service.projection.IndexingProjector; import io.stargate.sgv2.jsonapi.service.schema.collections.*; @@ -15,21 +16,26 @@ @QuarkusTest @TestProfile(NoGlobalResourcesTestProfile.Impl.class) public class CollectionSchemaObjectTest { + + private final TestConstants TEST_CONSTANTS = new TestConstants(); + @Test public void ensureSingleProjectorCreation() { + CollectionIndexingConfig indexingConfig = new CollectionIndexingConfig(new HashSet<>(Arrays.asList("abc")), null); + CollectionSchemaObject settings = new CollectionSchemaObject( - "namespace", - "collectionName", - null, + TEST_CONSTANTS.COLLECTION_SCHEMA_OBJECT.identifier(), IdConfig.defaultIdConfig(), VectorConfig.NOT_ENABLED_CONFIG, indexingConfig, CollectionLexicalConfig.configForDisabled(), CollectionRerankDef.configForPreRerankingCollection()); + IndexingProjector indexingProj = settings.indexingProjector(); + assertThat(indexingProj) .isNotNull() // Should get the same instance second time due to memoization diff --git a/src/test/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableFilterClauseBuilderTest.java b/src/test/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableFilterClauseBuilderTest.java index 232a7fc087..e9e89682e5 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableFilterClauseBuilderTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/api/model/command/builders/TableFilterClauseBuilderTest.java @@ -10,8 +10,8 @@ import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.exception.FilterException; import io.stargate.sgv2.jsonapi.fixtures.testdata.TestData; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.MapSetListFilterComponent; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; import jakarta.inject.Inject; import java.io.IOException; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/CqlFixture.java b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/CqlFixture.java index 6a267769ec..f66a082cfc 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/CqlFixture.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/CqlFixture.java @@ -2,12 +2,13 @@ import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; import com.fasterxml.jackson.databind.ObjectMapper; +import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.fixtures.data.DefaultData; import io.stargate.sgv2.jsonapi.fixtures.data.FixtureData; import io.stargate.sgv2.jsonapi.fixtures.identifiers.BaseFixtureIdentifiers; import io.stargate.sgv2.jsonapi.fixtures.identifiers.FixtureIdentifiers; import io.stargate.sgv2.jsonapi.fixtures.tables.TableFixture; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.ArrayList; import java.util.List; @@ -63,7 +64,9 @@ public CqlFixture( this.cqlData = cqlData; this.tableFixture = tableFixture; this.tableMetadata = tableFixture.tableMetadata(identifiers); - this.tableSchemaObject = TableSchemaObject.from(tableMetadata, new ObjectMapper()); + var TEST_CONSTANT = new TestConstants(); + this.tableSchemaObject = + TableSchemaObject.from(TEST_CONSTANT.TENANT, tableMetadata, new ObjectMapper()); } public FixtureIdentifiers identifiers() { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/SchemaObjectTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/SchemaObjectTestData.java index 53052200f7..217b89fbb0 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/SchemaObjectTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/SchemaObjectTestData.java @@ -1,7 +1,7 @@ package io.stargate.sgv2.jsonapi.fixtures.testdata; import com.fasterxml.jackson.databind.ObjectMapper; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; public class SchemaObjectTestData extends TestDataSuplier { @@ -9,12 +9,10 @@ public SchemaObjectTestData(TestData testData) { super(testData); } - public TableSchemaObject emptyTableSchemaObject() { - return TableSchemaObject.from(testData.tableMetadata().empty(), new ObjectMapper()); - } - public TableSchemaObject tableWithMapSetList() { return TableSchemaObject.from( - testData.tableMetadata().tableAllDatatypesIndexed(), new ObjectMapper()); + testData.tenant().defaultTenant(), + testData.tableMetadata().tableAllDatatypesIndexed(), + new ObjectMapper()); } } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TableUpdateAnalyzerTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TableUpdateAnalyzerTestData.java index bbb64b4c4d..b037b7c81e 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TableUpdateAnalyzerTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TableUpdateAnalyzerTestData.java @@ -6,10 +6,11 @@ import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; import com.fasterxml.jackson.databind.ObjectMapper; +import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.exception.FilterException; import io.stargate.sgv2.jsonapi.exception.UpdateException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.resolver.update.TableUpdateAnalyzer; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import org.slf4j.Logger; @@ -40,9 +41,12 @@ public static class TableUpdateAnalyzerFixture implements Recordable { public TableUpdateAnalyzerFixture(String message, TableMetadata tableMetadata) { this.message = message; this.tableMetadata = tableMetadata; + var TEST_CONSTANT = new TestConstants(); this.analyzer = - new TableUpdateAnalyzer(TableSchemaObject.from(tableMetadata, new ObjectMapper())); - this.tableSchemaObject = TableSchemaObject.from(tableMetadata, new ObjectMapper()); + new TableUpdateAnalyzer( + TableSchemaObject.from(TEST_CONSTANT.TENANT, tableMetadata, new ObjectMapper())); + this.tableSchemaObject = + TableSchemaObject.from(TEST_CONSTANT.TENANT, tableMetadata, new ObjectMapper()); this.columnAssignments = new UpdateClauseTestData.ColumnAssignmentsBuilder<>(this, tableMetadata); } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TableWhereCQLClauseTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TableWhereCQLClauseTestData.java index 5cd28e6ccd..ff5f2576ba 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TableWhereCQLClauseTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TableWhereCQLClauseTestData.java @@ -9,10 +9,11 @@ import com.datastax.oss.driver.api.querybuilder.select.Select; import com.datastax.oss.driver.internal.querybuilder.select.DefaultSelect; import com.fasterxml.jackson.databind.ObjectMapper; +import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.exception.WithWarnings; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.DBLogicalExpression; import io.stargate.sgv2.jsonapi.service.operation.tables.TableWhereCQLClause; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.ArrayList; import java.util.List; @@ -56,7 +57,8 @@ public TableWhereCQLClauseFixture( String message, TableMetadata tableMetadata, DBLogicalExpression expressionBuilder) { this.message = message; this.tableMetadata = tableMetadata; - this.tableSchemaObject = TableSchemaObject.from(tableMetadata, new ObjectMapper()); + this.tableSchemaObject = + TableSchemaObject.from(new TestConstants().TENANT, tableMetadata, new ObjectMapper()); this.expressionBuilder = new LogicalExpressionTestData.ExpressionBuilder<>(this, expressionBuilder, tableMetadata); } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TenantTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TenantTestData.java new file mode 100644 index 0000000000..e81dafe0e5 --- /dev/null +++ b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TenantTestData.java @@ -0,0 +1,17 @@ +package io.stargate.sgv2.jsonapi.fixtures.testdata; + +import io.stargate.sgv2.jsonapi.TestConstants; +import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; + +public class TenantTestData extends TestDataSuplier { + + private final TestConstants TEST_CONSTANTS = new TestConstants(); + + public TenantTestData(TestData testData) { + super(testData); + } + + public Tenant defaultTenant() { + return TEST_CONSTANTS.TENANT; + } +} diff --git a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TestData.java b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TestData.java index 538da34f21..fa6def490d 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/TestData.java @@ -41,6 +41,10 @@ private T getOrCache(Class clazz) { }); } + public TenantTestData tenant() { + return getOrCache(TenantTestData.class); + } + public SchemaObjectTestData schemaObject() { return getOrCache(SchemaObjectTestData.class); } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/UpdateClauseTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/UpdateClauseTestData.java index 7de29e3961..84ee683c5d 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/UpdateClauseTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/UpdateClauseTestData.java @@ -11,11 +11,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.stargate.sgv2.jsonapi.exception.ErrorCode; import io.stargate.sgv2.jsonapi.exception.UpdateException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.JSONCodecRegistries; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnAssignment; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnSetToAssignment; import io.stargate.sgv2.jsonapi.service.operation.query.DBLogicalExpression; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValue; import io.stargate.sgv2.jsonapi.service.shredding.CqlNamedValueContainer; import io.stargate.sgv2.jsonapi.service.shredding.JsonNodeDecoder; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/WhereAnalyzerTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/WhereAnalyzerTestData.java index 5ce2b43479..88c761eca6 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/WhereAnalyzerTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/WhereAnalyzerTestData.java @@ -11,13 +11,14 @@ import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; import com.fasterxml.jackson.databind.ObjectMapper; +import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.exception.FilterException; import io.stargate.sgv2.jsonapi.exception.WarningException; import io.stargate.sgv2.jsonapi.exception.WithWarnings; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.DBLogicalExpression; import io.stargate.sgv2.jsonapi.service.operation.tables.TableWhereCQLClause; import io.stargate.sgv2.jsonapi.service.operation.tables.WhereCQLClauseAnalyzer; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.Arrays; @@ -91,10 +92,13 @@ public WhereAnalyzerFixture( this.message = message; this.tableMetadata = tableMetadata; + var TEST_CONSTANT = new TestConstants(); this.analyzer = new WhereCQLClauseAnalyzer( - TableSchemaObject.from(tableMetadata, new ObjectMapper()), statementType); - this.tableSchemaObject = TableSchemaObject.from(tableMetadata, new ObjectMapper()); + TableSchemaObject.from(TEST_CONSTANT.TENANT, tableMetadata, new ObjectMapper()), + statementType); + this.tableSchemaObject = + TableSchemaObject.from(TEST_CONSTANT.TENANT, tableMetadata, new ObjectMapper()); this.expression = new LogicalExpressionTestData.ExpressionBuilder<>(this, expression, tableMetadata); } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/WhereCQLClauseTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/WhereCQLClauseTestData.java index b3e65f1fe3..de2f52443e 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/WhereCQLClauseTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/fixtures/testdata/WhereCQLClauseTestData.java @@ -1,9 +1,9 @@ package io.stargate.sgv2.jsonapi.fixtures.testdata; import com.datastax.oss.driver.api.querybuilder.select.Select; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.DBLogicalExpression; import io.stargate.sgv2.jsonapi.service.operation.query.WhereCQLClause; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.List; public class WhereCQLClauseTestData extends TestDataSuplier { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/CqlSessionCacheSupplierTests.java b/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/CqlSessionCacheSupplierTests.java index 33bffb19f7..d86cef2c25 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/CqlSessionCacheSupplierTests.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/CqlSessionCacheSupplierTests.java @@ -4,12 +4,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.config.DatabaseType; import io.stargate.sgv2.jsonapi.config.OperationsConfig; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaCache; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectCacheSupplier; import java.util.List; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -37,12 +36,7 @@ public void testSingleton() { when(operationsConfig.slaUserAgent()) .thenReturn(Optional.of(TEST_CONSTANTS.SLA_USER_AGENT_NAME)); - // aaron - changes to the schema cache come later - var mockSchemaCache = mock(SchemaCache.class); - when(mockSchemaCache.getSchemaChangeListener()).thenReturn(mock(SchemaChangeListener.class)); - - when(mockSchemaCache.getDeactivatedTenantConsumer()) - .thenReturn(mock(CQLSessionCache.DeactivatedTenantListener.class)); + var mockSchemaCache = mock(SchemaObjectCacheSupplier.class); var factory = new CqlSessionCacheSupplier( diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandlerTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandlerTest.java index d23d050fce..e96659a4d7 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandlerTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandlerTest.java @@ -1,6 +1,5 @@ package io.stargate.sgv2.jsonapi.service.cqldriver.executor; -import static io.stargate.sgv2.jsonapi.exception.ErrorFormatters.errFmt; import static io.stargate.sgv2.jsonapi.exception.ErrorFormatters.errFmtJoin; import static io.stargate.sgv2.jsonapi.exception.ExceptionFlags.UNRELIABLE_DB_SESSION; import static org.assertj.core.api.Assertions.assertThat; @@ -155,8 +154,8 @@ public void runAssertions( if (assertSchemaNames) { assertThat(handledException) .as("Handled error message has the schema names") - .hasMessageContaining(errFmt(TEST_DATA.KEYSPACE_NAME)) - .hasMessageContaining(errFmt(TEST_DATA.TABLE_NAME)); + .hasMessageContaining(TEST_DATA.testConstants.KEYSPACE_NAME) + .hasMessageContaining(TEST_DATA.testConstants.TABLE_NAME); } if (assertOrigError) { @@ -237,7 +236,7 @@ private static Stream tableDriverErrorHandledData() { false, false, false, - TEST_DATA.KEYSPACE_NAME.asCql(true), + TEST_DATA.testConstants.KEYSPACE_NAME, null)), new TestArguments( new NodeUnavailableException(mockNode("node: monkeys")), @@ -282,8 +281,8 @@ private static Stream tableDriverErrorHandledData() { new TestArguments( new AlreadyExistsException( mockNode("node: monkeys"), - TEST_DATA.KEYSPACE_NAME.asCql(true), - TEST_DATA.TABLE_NAME.asCql(true)), + TEST_DATA.testConstants.KEYSPACE_NAME, + TEST_DATA.testConstants.TABLE_NAME), Assertions.isUnexpectedDriverException()), // InvalidConfigurationInQueryException will happen if we send wrong DDL command // not expected diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandlerTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandlerTestData.java index ac5239c6df..10a7b0a352 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandlerTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DefaultDriverExceptionHandlerTestData.java @@ -1,45 +1,21 @@ package io.stargate.sgv2.jsonapi.service.cqldriver.executor; -import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.cql.SimpleStatement; -import com.datastax.oss.driver.internal.core.metadata.schema.DefaultTableMetadata; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import io.stargate.sgv2.jsonapi.TestConstants; public class DefaultDriverExceptionHandlerTestData { public final DriverExceptionHandler DRIVER_HANDLER; - public final TableSchemaObject TABLE_SCHEMA_OBJECT; - - public final CqlIdentifier KEYSPACE_NAME = - CqlIdentifier.fromInternal("keyspace-" + System.currentTimeMillis()); - - public final CqlIdentifier TABLE_NAME = - CqlIdentifier.fromInternal("table-" + System.currentTimeMillis()); + public TestConstants testConstants = new TestConstants(); public final SimpleStatement STATEMENT = - SimpleStatement.newInstance("SELECT * FROM " + TABLE_NAME.asCql(true) + " WHERE x=?;", 1); + SimpleStatement.newInstance( + "SELECT * FROM " + testConstants.TABLE_IDENTIFIER.table().asCql(true) + " WHERE x=?;", 1); public DefaultDriverExceptionHandlerTestData() { - // Its just as easy to create the table metadata from the driver. - var tableMetadata = - new DefaultTableMetadata( - KEYSPACE_NAME, - TABLE_NAME, - UUID.randomUUID(), - false, - false, - List.of(), - Map.of(), - Map.of(), - Map.of(), - Map.of()); - TABLE_SCHEMA_OBJECT = TableSchemaObject.from(tableMetadata, new ObjectMapper()); - - DRIVER_HANDLER = new DefaultDriverExceptionHandler<>(TABLE_SCHEMA_OBJECT, STATEMENT); + DRIVER_HANDLER = + new DefaultDriverExceptionHandler<>(testConstants.TABLE_SCHEMA_OBJECT, STATEMENT); } } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/NamespaceCacheTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/NamespaceCacheTest.java deleted file mode 100644 index f8b064ddfe..0000000000 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/NamespaceCacheTest.java +++ /dev/null @@ -1,366 +0,0 @@ -package io.stargate.sgv2.jsonapi.service.cqldriver.executor; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.datastax.oss.driver.api.core.CqlIdentifier; -import com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata; -import com.datastax.oss.driver.api.core.type.DataTypes; -import com.datastax.oss.driver.internal.core.metadata.schema.DefaultColumnMetadata; -import com.datastax.oss.driver.internal.core.metadata.schema.DefaultTableMetadata; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.Lists; -import io.quarkus.test.InjectMock; -import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.TestProfile; -import io.smallrye.mutiny.Uni; -import io.smallrye.mutiny.helpers.test.UniAssertSubscriber; -import io.stargate.sgv2.jsonapi.api.request.RequestContext; -import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; -import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; -import jakarta.inject.Inject; -import java.util.*; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - -@QuarkusTest -@TestProfile(NoGlobalResourcesTestProfile.Impl.class) -public class NamespaceCacheTest { - - @Inject ObjectMapper objectMapper; - - @InjectMock protected RequestContext dataApiRequestInfo; - - @Nested - class Execute { - - @Test - public void checkValidJsonApiTable() { - QueryExecutor queryExecutor = mock(QueryExecutor.class); - when(queryExecutor.getTableMetadata(any(), any(), any())) - .then( - i -> { - List partitionColumn = - Lists.newArrayList( - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("key"), - DataTypes.tupleOf(DataTypes.TINYINT, DataTypes.TEXT), - false)); - Map columns = new HashMap<>(); - columns.put( - CqlIdentifier.fromInternal("tx_id"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("tx_id"), - DataTypes.TIMEUUID, - false)); - columns.put( - CqlIdentifier.fromInternal("doc_json"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("doc_json"), - DataTypes.TEXT, - false)); - columns.put( - CqlIdentifier.fromInternal("exist_keys"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("exist_keys"), - DataTypes.setOf(DataTypes.TEXT), - false)); - columns.put( - CqlIdentifier.fromInternal("array_size"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("array_size"), - DataTypes.mapOf(DataTypes.TEXT, DataTypes.INT), - false)); - columns.put( - CqlIdentifier.fromInternal("array_contains"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("array_contains"), - DataTypes.setOf(DataTypes.TEXT), - false)); - columns.put( - CqlIdentifier.fromInternal("query_bool_values"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("query_bool_values"), - DataTypes.mapOf(DataTypes.TEXT, DataTypes.TINYINT), - false)); - columns.put( - CqlIdentifier.fromInternal("query_dbl_values"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("query_dbl_values"), - DataTypes.mapOf(DataTypes.TEXT, DataTypes.DECIMAL), - false)); - columns.put( - CqlIdentifier.fromInternal("query_text_values"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("query_text_values"), - DataTypes.mapOf(DataTypes.TEXT, DataTypes.TEXT), - false)); - columns.put( - CqlIdentifier.fromInternal("query_timestamp_values"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("query_timestamp_values"), - DataTypes.mapOf(DataTypes.TEXT, DataTypes.TIMESTAMP), - false)); - columns.put( - CqlIdentifier.fromInternal("query_null_values"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("query_null_values"), - DataTypes.setOf(DataTypes.TEXT), - false)); - - return Uni.createFrom() - .item( - Optional.of( - new DefaultTableMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - UUID.randomUUID(), - false, - false, - partitionColumn, - new HashMap<>(), - columns, - new HashMap<>(), - new HashMap<>()))); - }); - TableBasedSchemaCache namespaceCache = createNamespaceCache(queryExecutor); - var schemaObject = - namespaceCache - .getSchemaObject(dataApiRequestInfo, "table", false) - .subscribe() - .withSubscriber(UniAssertSubscriber.create()) - .awaitItem() - .getItem(); - - assertThat(schemaObject instanceof CollectionSchemaObject); - assertThat(schemaObject) - .satisfies( - s -> { - assertThat(s.vectorConfig().vectorEnabled()).isFalse(); - assertThat(s.name.table()).isEqualTo("table"); - }); - } - - @Test - public void checkValidJsonApiTableWithIndexing() { - QueryExecutor queryExecutor = mock(QueryExecutor.class); - when(queryExecutor.getTableMetadata(any(), any(), any())) - .then( - i -> { - List partitionColumn = - Lists.newArrayList( - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("key"), - DataTypes.tupleOf(DataTypes.TINYINT, DataTypes.TEXT), - false)); - Map columns = new HashMap<>(); - columns.put( - CqlIdentifier.fromInternal("tx_id"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("tx_id"), - DataTypes.TIMEUUID, - false)); - columns.put( - CqlIdentifier.fromInternal("doc_json"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("doc_json"), - DataTypes.TEXT, - false)); - columns.put( - CqlIdentifier.fromInternal("exist_keys"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("exist_keys"), - DataTypes.setOf(DataTypes.TEXT), - false)); - columns.put( - CqlIdentifier.fromInternal("array_size"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("array_size"), - DataTypes.mapOf(DataTypes.TEXT, DataTypes.INT), - false)); - columns.put( - CqlIdentifier.fromInternal("array_contains"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("array_contains"), - DataTypes.setOf(DataTypes.TEXT), - false)); - columns.put( - CqlIdentifier.fromInternal("query_bool_values"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("query_bool_values"), - DataTypes.mapOf(DataTypes.TEXT, DataTypes.TINYINT), - false)); - columns.put( - CqlIdentifier.fromInternal("query_dbl_values"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("query_dbl_values"), - DataTypes.mapOf(DataTypes.TEXT, DataTypes.DECIMAL), - false)); - columns.put( - CqlIdentifier.fromInternal("query_text_values"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("query_text_values"), - DataTypes.mapOf(DataTypes.TEXT, DataTypes.TEXT), - false)); - columns.put( - CqlIdentifier.fromInternal("query_timestamp_values"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("query_timestamp_values"), - DataTypes.mapOf(DataTypes.TEXT, DataTypes.TIMESTAMP), - false)); - columns.put( - CqlIdentifier.fromInternal("query_null_values"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("query_null_values"), - DataTypes.setOf(DataTypes.TEXT), - false)); - - return Uni.createFrom() - .item( - Optional.of( - new DefaultTableMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - UUID.randomUUID(), - false, - false, - partitionColumn, - new HashMap<>(), - columns, - Map.of( - CqlIdentifier.fromInternal("comment"), - "{\"indexing\":{\"deny\":[\"comment\"]}}"), - new HashMap<>()))); - }); - TableBasedSchemaCache namespaceCache = createNamespaceCache(queryExecutor); - var schemaObject = - namespaceCache - .getSchemaObject(dataApiRequestInfo, "table", false) - .subscribe() - .withSubscriber(UniAssertSubscriber.create()) - .awaitItem() - .getItem(); - - assertThat(schemaObject).isInstanceOf(CollectionSchemaObject.class); - var collectionSchemaObject = (CollectionSchemaObject) schemaObject; - assertThat(collectionSchemaObject) - .satisfies( - s -> { - assertThat(s.vectorConfig().vectorEnabled()).isFalse(); - assertThat(s.name.table()).isEqualTo("table"); - assertThat(s.indexingConfig().denied()).containsExactly("comment"); - }); - } - - @Test - public void checkNonCollectionJsonApiTable() { - QueryExecutor queryExecutor = mock(QueryExecutor.class); - when(queryExecutor.getTableMetadata(any(), any(), any())) - .then( - i -> { - List partitionColumn = - Lists.newArrayList( - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("key"), - DataTypes.tupleOf(DataTypes.TINYINT, DataTypes.TEXT), - false)); - // aaron - 25 oct 2024, use linked to preserve order and must have all columns in - // the col map - Map columns = new LinkedHashMap<>(); - columns.put(partitionColumn.getFirst().getName(), partitionColumn.getFirst()); - columns.put( - CqlIdentifier.fromInternal("tx_id"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("tx_id"), - DataTypes.TIMEUUID, - false)); - columns.put( - CqlIdentifier.fromInternal("doc"), - new DefaultColumnMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - CqlIdentifier.fromInternal("doc"), - DataTypes.TEXT, - false)); - return Uni.createFrom() - .item( - Optional.of( - new DefaultTableMetadata( - CqlIdentifier.fromInternal("ks"), - CqlIdentifier.fromInternal("table"), - UUID.randomUUID(), - false, - false, - partitionColumn, - new HashMap<>(), - columns, - new HashMap<>(), - new HashMap<>()))); - }); - TableBasedSchemaCache namespaceCache = createNamespaceCache(queryExecutor); - var schemaObject = - namespaceCache - .getSchemaObject(dataApiRequestInfo, "table", false) - .subscribe() - .withSubscriber(UniAssertSubscriber.create()) - .awaitItem() - .getItem(); - - assertThat(schemaObject).isInstanceOf(TableSchemaObject.class); - } - } - - private TableBasedSchemaCache createNamespaceCache(QueryExecutor qe) { - return new TableBasedSchemaCache("ks", qe, objectMapper); - } -} diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaCacheTests.java b/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaCacheTests.java deleted file mode 100644 index 129c3021a6..0000000000 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaCacheTests.java +++ /dev/null @@ -1,256 +0,0 @@ -package io.stargate.sgv2.jsonapi.service.cqldriver.executor; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.*; - -import com.datastax.oss.driver.api.core.CqlIdentifier; -import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata; -import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener; -import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; -import com.datastax.oss.driver.api.core.session.Session; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.smallrye.mutiny.Uni; -import io.stargate.sgv2.jsonapi.TestConstants; -import io.stargate.sgv2.jsonapi.api.request.RequestContext; -import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; -import io.stargate.sgv2.jsonapi.config.DatabaseType; -import io.stargate.sgv2.jsonapi.config.OperationsConfig; -import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; -import io.stargate.sgv2.jsonapi.service.cqldriver.CqlSessionCacheSupplier; -import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; -import org.junit.Test; - -public class SchemaCacheTests { - - private final TestConstants testConstants = new TestConstants(); - - @Test - public void deactivatedTenantRemovesAllKeyspaces() { - var fixture = newFixture(); - - // put two tables in from two keyspaces - var table1 = addTable(fixture, testConstants.TENANT, "keyspace1", "table1"); - var table2 = addTable(fixture, testConstants.TENANT, "keyspace2", "table2"); - var table3 = addTable(fixture, testConstants.TENANT, "keyspace3", "table3"); - - var deactivatedListener = fixture.schemaCache.getDeactivatedTenantConsumer(); - - deactivatedListener.accept(testConstants.TENANT); - - // all of TENANT_ID should be removed, and the non TENANT_ID can stay - assertThat(fixture.schemaCache.peekSchemaObject(testConstants.TENANT, "keyspace1", "table1")) - .as("TENANT_ID keyspace1 removed") - .isEmpty(); - assertThat(fixture.schemaCache.peekSchemaObject(testConstants.TENANT, "keyspace2", "table2")) - .as("TENANT_ID keyspace2 removed") - .isEmpty(); - assertThat(fixture.schemaCache.peekSchemaObject(testConstants.TENANT, "keyspace3", "table3")) - .as("notTenantId keyspace3 not removed") - .contains(table3); - } - - @Test - public void schemasChangeListenerNotInitialized() { - - var fixture = newFixture(); - var table1 = addTable(fixture, testConstants.TENANT, "keyspace1", "table1"); - - var listener = fixture.schemaCache.getSchemaChangeListener(); - - // if the listener is called before onSessionReady is called it should not error - var tableMetadata = mock(TableMetadata.class); - listener.onTableDropped(tableMetadata); - listener.onTableCreated(tableMetadata); - listener.onTableUpdated(tableMetadata, tableMetadata); - - var keyspaceMetadata = mock(KeyspaceMetadata.class); - listener.onKeyspaceDropped(keyspaceMetadata); - - // table1 should still be in the cache even because listener does not know what tenant - // the session was for - assertThat(fixture.schemaCache.peekSchemaObject(testConstants.TENANT, "keyspace1", "table1")) - .as("TENANT_ID keyspace1 not removed") - .contains(table1); - } - - @Test - public void tableChangesEvictTabe() { - - var removedTableMetadata = tableMetadata("keyspace1", "table1"); - - List> calls = - List.of( - (cb) -> { - cb.onTableCreated(removedTableMetadata); - return "onTableCreated"; - }, - (cb) -> { - cb.onTableUpdated(removedTableMetadata, removedTableMetadata); - return "onTableUpdated"; - }, - (cb) -> { - cb.onTableDropped(removedTableMetadata); - return "onTableDropped"; - }); - var notTenantId = "not-tenant-id"; - - for (var cb : calls) { - var fixture = newFixture(); - - // put two tables in from two keyspaces for the tenant we are removing - var table1 = addTable(fixture, testConstants.TENANT, "keyspace1", "table1"); - var table2 = addTable(fixture, testConstants.TENANT, "keyspace2", "table2"); - var table3 = addTable(fixture, testConstants.TENANT, "keyspace3", "table3"); - - var listener = fixture.schemaCache.getSchemaChangeListener(); - listener.onSessionReady(fixture.session); - var operation = cb.apply(listener); - - // all of TENANT_ID should be removed, and the non TENANT_ID can stay - assertThat(fixture.schemaCache.peekSchemaObject(testConstants.TENANT, "keyspace1", "table1")) - .as("TENANT_ID keyspace1 removed on table event operation=%s", operation) - .isEmpty(); - assertThat(fixture.schemaCache.peekSchemaObject(testConstants.TENANT, "keyspace2", "table2")) - .as("TENANT_ID keyspace2 not removed on table event operation=%s", operation) - .contains(table2); - assertThat(fixture.schemaCache.peekSchemaObject(testConstants.TENANT, "keyspace3", "table3")) - .as("notTenantId keyspace3 not removed on table event operation=%s", operation) - .contains(table3); - } - } - - @Test - public void keyspaceDroppedEvictsAllTables() { - - var notTenantId = "not-tenant-id"; - var fixture = newFixture(); - - var table1 = addTable(fixture, testConstants.TENANT, "keyspace1", "table1"); - var table2 = addTable(fixture, testConstants.TENANT, "keyspace2", "table2"); - var table3 = addTable(fixture, testConstants.TENANT, "keyspace3", "table3"); - - var listener = fixture.schemaCache.getSchemaChangeListener(); - listener.onSessionReady(fixture.session); - listener.onKeyspaceDropped(keyspaceMetadata("keyspace1")); - - assertThat(fixture.schemaCache.peekSchemaObject(testConstants.TENANT, "keyspace1", "table1")) - .as("TENANT_ID keyspace1 removed") - .isEmpty(); - assertThat(fixture.schemaCache.peekSchemaObject(testConstants.TENANT, "keyspace2", "table2")) - .as("TENANT_ID keyspace2 not removed") - .contains(table2); - assertThat(fixture.schemaCache.peekSchemaObject(testConstants.TENANT, "keyspace3", "table3")) - .as("notTenantId keyspace3 not removed") - .contains(table3); - } - - /** Add a keyspace and cache item to the schema cache. */ - private SchemaObject addTable( - Fixture fixture, Tenant tenant, String keyspaceName, String tableName) { - - // setup to return a mocked table schema object - var tableSchemaCache = mock(TableBasedSchemaCache.class); - var expectedSchemaObject = mock(CollectionSchemaObject.class); - - when(tableSchemaCache.getSchemaObject(any(RequestContext.class), eq(tableName), anyBoolean())) - .thenReturn(Uni.createFrom().item(() -> expectedSchemaObject)); - when(tableSchemaCache.peekSchemaObject(eq(tableName))) - .thenReturn(Optional.of(expectedSchemaObject)); - - // override so that we return an empty schema object after it was evicted - doAnswer( - invocation -> { - when(tableSchemaCache.peekSchemaObject(eq(tableName))).thenReturn(Optional.empty()); - return null; - }) - .when(tableSchemaCache) - .evictCollectionSettingCacheEntry(tableName); - - when(fixture.tableCacheFactory.create(eq(keyspaceName), any(), any())) - .thenReturn(tableSchemaCache); - - // request context only needs the few things the SchemaCache uses - var requestContext = mock(RequestContext.class); - when(requestContext.tenant()).thenReturn(testConstants.TENANT); - - // setup so we return the TableBasedSchemaCache for the keyspace - reset(fixture.tableCacheFactory); - when(fixture.tableCacheFactory.create(eq(keyspaceName), any(), any())) - .thenReturn(tableSchemaCache); - - var actualUni = - fixture.schemaCache.getSchemaObject(requestContext, keyspaceName, tableName, false); - - assertThat(actualUni).as("getSchemaObject returns non null").isNotNull(); - var actualSchemaObject = actualUni.await().indefinitely(); - assertThat(actualSchemaObject) - .as("getSchemaObject returns the schema object from table cache") - .isSameAs(expectedSchemaObject); - - assertThat(fixture.schemaCache.peekSchemaObject(tenant, keyspaceName, tableName)) - .as("peekSchemaObject returns the schema object from table cache") - .contains(expectedSchemaObject); - - return actualSchemaObject; - } - - private TableMetadata tableMetadata(String keyspaceName, String tableName) { - - var tableMetadata = mock(TableMetadata.class); - - var keyspaceIdentifier = mock(CqlIdentifier.class); - when(keyspaceIdentifier.asInternal()).thenReturn(keyspaceName); - when(tableMetadata.getKeyspace()).thenReturn(keyspaceIdentifier); - - var tableIdentifier = mock(CqlIdentifier.class); - when(tableIdentifier.asInternal()).thenReturn(tableName); - when(tableMetadata.getName()).thenReturn(tableIdentifier); - - return tableMetadata; - } - - private KeyspaceMetadata keyspaceMetadata(String keyspaceName) { - - var keyspaceMetadata = mock(KeyspaceMetadata.class); - - var keyspaceIdentifier = mock(CqlIdentifier.class); - when(keyspaceIdentifier.asInternal()).thenReturn(keyspaceName); - when(keyspaceMetadata.getName()).thenReturn(keyspaceIdentifier); - - return keyspaceMetadata; - } - - record Fixture( - Session session, SchemaCache.TableCacheFactory tableCacheFactory, SchemaCache schemaCache) {} - - private Fixture newFixture() { - return newFixture(DatabaseType.ASTRA); - } - - private Fixture newFixture(DatabaseType databaseType) { - - var session = mock(Session.class); - when(session.getName()).thenReturn(testConstants.TENANT.toString()); - - var tableCacheFactory = mock(SchemaCache.TableCacheFactory.class); - - var sessionCacheSupplier = mock(CqlSessionCacheSupplier.class); - when(sessionCacheSupplier.get()).thenReturn(mock(CQLSessionCache.class)); - - var objectMapper = mock(ObjectMapper.class); - - var databaseConfig = mock(OperationsConfig.DatabaseConfig.class); - var operationsConfig = mock(OperationsConfig.class); - when(operationsConfig.databaseConfig()).thenReturn(databaseConfig); - when(databaseConfig.type()).thenReturn(databaseType); - - SchemaCache schemaCache = - new SchemaCache(sessionCacheSupplier, objectMapper, operationsConfig, tableCacheFactory); - return new Fixture(session, tableCacheFactory, schemaCache); - } -} diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/embedding/operation/DataVectorizerTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/embedding/operation/DataVectorizerTest.java index dc2d4f5c71..fe68998620 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/embedding/operation/DataVectorizerTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/embedding/operation/DataVectorizerTest.java @@ -257,8 +257,7 @@ public void testWithUnmatchedVectorSize() { // new collection settings with different expected vector size CollectionSchemaObject collectionSettings = new CollectionSchemaObject( - "namespace", - "collections", + testConstants.TENANT, null, IdConfig.defaultIdConfig(), VectorConfig.fromColumnDefinitions( diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/embedding/operation/TestEmbeddingProvider.java b/src/test/java/io/stargate/sgv2/jsonapi/service/embedding/operation/TestEmbeddingProvider.java index 38b3b9081c..d13c317903 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/embedding/operation/TestEmbeddingProvider.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/embedding/operation/TestEmbeddingProvider.java @@ -83,7 +83,7 @@ public CommandContext commandContextWithVectorize() { return TEST_CONSTANTS.collectionContext( "testCommand", new CollectionSchemaObject( - TEST_CONSTANTS.SCHEMA_OBJECT_NAME, + TEST_CONSTANTS.TENANT, null, IdConfig.defaultIdConfig(), VectorConfig.fromColumnDefinitions( diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionOperationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionOperationTest.java index b8d59bbf00..c29073cd77 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionOperationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/FindCollectionOperationTest.java @@ -87,7 +87,7 @@ public void beforeEach() { testConstants.collectionContext( "testCommand", new CollectionSchemaObject( - SCHEMA_OBJECT_NAME, + testConstants.TENANT, null, IdConfig.defaultIdConfig(), VectorConfig.fromColumnDefinitions( diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/InsertCollectionOperationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/InsertCollectionOperationTest.java index ffc38b783a..affce14356 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/InsertCollectionOperationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/InsertCollectionOperationTest.java @@ -108,7 +108,7 @@ public void beforeEach() { testConstants.collectionContext( "testCommand", new CollectionSchemaObject( - SCHEMA_OBJECT_NAME, + testConstants.TENANT, null, IdConfig.defaultIdConfig(), VectorConfig.fromColumnDefinitions( diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/OperationTestBase.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/OperationTestBase.java index 6152378074..c33fd2e87d 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/OperationTestBase.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/OperationTestBase.java @@ -20,10 +20,9 @@ import io.stargate.sgv2.jsonapi.api.request.RequestContext; import io.stargate.sgv2.jsonapi.config.constants.DocumentConstants; import io.stargate.sgv2.jsonapi.metrics.JsonProcessingMetricsReporter; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObjectName; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; import io.stargate.sgv2.jsonapi.service.cqldriver.serializer.CQLBindValues; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionLexicalConfig; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionRerankDef; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; @@ -48,8 +47,6 @@ public class OperationTestBase { protected final String KEYSPACE_NAME = RandomStringUtils.insecure().nextAlphanumeric(16); protected final String COLLECTION_NAME = RandomStringUtils.insecure().nextAlphanumeric(16); - protected final SchemaObjectName SCHEMA_OBJECT_NAME = - new SchemaObjectName(KEYSPACE_NAME, COLLECTION_NAME); protected CollectionSchemaObject COLLECTION_SCHEMA_OBJECT; protected KeyspaceSchemaObject KEYSPACE_SCHEMA_OBJECT; @@ -65,7 +62,7 @@ public void beforeEach() { // must do this here to avoid touching quarkus config before it is initialized COLLECTION_SCHEMA_OBJECT = new CollectionSchemaObject( - SCHEMA_OBJECT_NAME, + testConstants.TENANT, null, IdConfig.defaultIdConfig(), VectorConfig.NOT_ENABLED_CONFIG, @@ -73,7 +70,7 @@ public void beforeEach() { CollectionLexicalConfig.configForDisabled(), CollectionRerankDef.configForPreRerankingCollection()); - KEYSPACE_SCHEMA_OBJECT = KeyspaceSchemaObject.fromSchemaObject(COLLECTION_SCHEMA_OBJECT); + KEYSPACE_SCHEMA_OBJECT = new KeyspaceSchemaObject(COLLECTION_SCHEMA_OBJECT.identifier()); COLLECTION_CONTEXT = testConstants.collectionContext( diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/ReadAndUpdateCollectionOperationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/ReadAndUpdateCollectionOperationTest.java index 4cdc9e2518..1e783ab8e7 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/ReadAndUpdateCollectionOperationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/collections/ReadAndUpdateCollectionOperationTest.java @@ -72,7 +72,7 @@ public class ReadAndUpdateCollectionOperationTest extends OperationTestBase { @Inject DocumentShredder documentShredder; @Inject ObjectMapper objectMapper; @Inject DataVectorizerService dataVectorizerService; - private TestConstants testConstants = new TestConstants(); + private final TestConstants testConstants = new TestConstants(); private final ColumnDefinitions KEY_TXID_JSON_COLUMNS = buildColumnDefs( @@ -87,7 +87,7 @@ public void beforeEach() { testConstants.collectionContext( "testCommand", new CollectionSchemaObject( - SCHEMA_OBJECT_NAME, + testConstants.TENANT, null, IdConfig.defaultIdConfig(), VectorConfig.fromColumnDefinitions( diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskAssertions.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskAssertions.java index 43a1636f87..658d5f2b82 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskAssertions.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskAssertions.java @@ -10,9 +10,9 @@ import io.smallrye.mutiny.helpers.test.UniAssertSubscriber; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.exception.WarningException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObjectName; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObjectType; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; import java.time.Duration; import java.util.Objects; @@ -43,8 +43,7 @@ public static TableSchemaObject mockTable(String keyspaceName, String tableName) when(mockTable.keyspaceName()).thenReturn(CqlIdentifier.fromInternal(keyspaceName)); when(mockTable.tableName()).thenReturn(CqlIdentifier.fromInternal(tableName)); - when(mockTable.type()).thenReturn(SchemaObject.SchemaObjectType.TABLE); - when(mockTable.name()).thenReturn(new SchemaObjectName(keyspaceName, tableName)); + when(mockTable.type()).thenReturn(SchemaObjectType.TABLE); return mockTable; } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskTestData.java index 01f813efea..3982dabf0e 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskTestData.java @@ -3,7 +3,7 @@ import static org.mockito.Mockito.*; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.time.Duration; public class BaseTaskTestData { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskTestTask.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskTestTask.java index 412c0c1d37..d92c539e1a 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskTestTask.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/BaseTaskTestTask.java @@ -2,7 +2,7 @@ import io.smallrye.mutiny.Uni; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; /** * Test task for testing the core functionality of the {@link BaseTask} - not testing any of the diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DriverExceptionHandlerAssertions.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DriverExceptionHandlerAssertions.java index 6a1fd51434..4297cc5919 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DriverExceptionHandlerAssertions.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/DriverExceptionHandlerAssertions.java @@ -6,7 +6,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.SchemaObject; import java.util.ArrayList; import java.util.List; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskAssertions.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskAssertions.java index 5dd1d154cb..e7e6cb9ae0 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskAssertions.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskAssertions.java @@ -11,7 +11,7 @@ import io.smallrye.mutiny.Uni; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CommandQueryExecutor; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.List; import java.util.Objects; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskTestData.java index a66dbd5779..ddbe776076 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskTestData.java @@ -10,13 +10,13 @@ import io.stargate.sgv2.jsonapi.api.model.command.tracing.RequestTracing; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CqlPagingState; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.CQLOptions; import io.stargate.sgv2.jsonapi.service.operation.query.DBLogicalExpression; import io.stargate.sgv2.jsonapi.service.operation.query.OrderByCqlClause; import io.stargate.sgv2.jsonapi.service.operation.query.WhereCQLClause; import io.stargate.sgv2.jsonapi.service.operation.tables.TableDriverExceptionHandler; import io.stargate.sgv2.jsonapi.service.operation.tables.TableProjection; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.List; public class ReadDBTaskTestData { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskTestTask.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskTestTask.java index 1bc8e695f0..63b9845b50 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskTestTask.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/ReadDBTaskTestTask.java @@ -4,11 +4,11 @@ import com.datastax.oss.driver.api.querybuilder.select.Select; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CqlPagingState; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DefaultDriverExceptionHandler; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.OperationProjection; import io.stargate.sgv2.jsonapi.service.operation.ReadDBTask; import io.stargate.sgv2.jsonapi.service.operation.query.*; import io.stargate.sgv2.jsonapi.service.operation.tables.TableDriverExceptionHandler; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; /** * A test the mocks reading from the database, using the {@link ReadDBTask} to read from the diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroupTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroupTest.java index 37d5b0064c..25bf2ca91e 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroupTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/tasks/TaskGroupTest.java @@ -2,7 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/processor/CommandContextTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/service/processor/CommandContextTestData.java index 73f49bd500..413c64192c 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/processor/CommandContextTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/processor/CommandContextTestData.java @@ -12,9 +12,9 @@ import io.stargate.sgv2.jsonapi.metrics.JsonProcessingMetricsReporter; import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.*; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProviderFactory; import io.stargate.sgv2.jsonapi.service.reranking.operation.RerankingProviderFactory; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; /** tests data and mocks for working with {@link CommandContext} */ public class CommandContextTestData extends TestDataSuplier { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/processor/SchemaObjectTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/service/processor/SchemaObjectTestData.java deleted file mode 100644 index 0797ed4991..0000000000 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/processor/SchemaObjectTestData.java +++ /dev/null @@ -1,67 +0,0 @@ -package io.stargate.sgv2.jsonapi.service.processor; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.*; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject.SchemaObjectType; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; -import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; - -/** Tests data and mocks for working with {@link SchemaObject} */ -public class SchemaObjectTestData { - - public final String DATABASE_NAME = "database-" + System.currentTimeMillis(); - public final String KEYSPACE_NAME = "keyspace-" + System.currentTimeMillis(); - public final String COLLECTION_NAME = "collection-" + System.currentTimeMillis(); - public final String TABLE_NAME = "table-" + System.currentTimeMillis(); - - public final DatabaseSchemaObject MOCK_DATABASE = - mockSchemaObject( - DatabaseSchemaObject.class, SchemaObjectType.DATABASE, SchemaObjectName.MISSING); - public final KeyspaceSchemaObject MOCK_KEYSPACE = - mockSchemaObject( - KeyspaceSchemaObject.class, - SchemaObjectType.KEYSPACE, - new SchemaObjectName(KEYSPACE_NAME, SchemaObjectName.MISSING_NAME)); - public final CollectionSchemaObject MOCK_COLLECTION = - mockSchemaObject( - CollectionSchemaObject.class, - SchemaObjectType.COLLECTION, - new SchemaObjectName(KEYSPACE_NAME, COLLECTION_NAME)); - public final TableSchemaObject MOCK_TABLE = - mockSchemaObject( - TableSchemaObject.class, - SchemaObjectType.TABLE, - new SchemaObjectName(KEYSPACE_NAME, TABLE_NAME)); - - /** helper to get the prebuilt mock instance on this class by the class of the schema object */ - @SuppressWarnings("unchecked") - public T prebuiltMock(Class schemaType) { - // cannot use new switch :( - if (schemaType == DatabaseSchemaObject.class) { - return (T) MOCK_DATABASE; - } else if (schemaType == KeyspaceSchemaObject.class) { - return (T) MOCK_KEYSPACE; - } else if (schemaType == CollectionSchemaObject.class) { - return (T) MOCK_COLLECTION; - } else if (schemaType == TableSchemaObject.class) { - return (T) MOCK_TABLE; - } else { - throw new IllegalArgumentException("Unknown schema object type: " + schemaType); - } - } - - /** - * Create get mock and setup the type and name, used for internal. Call {@link - * #prebuiltMock(Class)} to get the prebuilt mock on this instnace by the schema object class. - */ - public T mockSchemaObject( - Class schemaType, SchemaObjectType type, SchemaObjectName name) { - - T schema = mock(schemaType); - when(schema.type()).thenReturn(type); - when(schema.name()).thenReturn(name); - return schema; - } -} diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CommandResolverWithVectorizerTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CommandResolverWithVectorizerTest.java index 3c758a8657..93870c5d26 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CommandResolverWithVectorizerTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CommandResolverWithVectorizerTest.java @@ -23,7 +23,6 @@ import io.stargate.sgv2.jsonapi.config.constants.DocumentConstants; import io.stargate.sgv2.jsonapi.exception.ErrorCodeV1; import io.stargate.sgv2.jsonapi.exception.JsonApiException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObjectName; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorColumnDefinition; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; import io.stargate.sgv2.jsonapi.service.embedding.DataVectorizerService; @@ -84,7 +83,7 @@ public void beforeEach() { testConstants.collectionContext( "testCommand", new CollectionSchemaObject( - new SchemaObjectName(KEYSPACE_NAME, COLLECTION_NAME), + testConstants.TENANT, null, IdConfig.defaultIdConfig(), VectorConfig.fromColumnDefinitions( @@ -173,7 +172,7 @@ public void findNonVectorize() throws Exception { assertThat(exception.getMessage()) .isEqualTo( "Unable to vectorize data, embedding service not configured for the collection : " - + VECTOR_COMMAND_CONTEXT.schemaObject().name().table()); + + VECTOR_COMMAND_CONTEXT.schemaObject().identifier().table()); assertThat(exception.getErrorCode()) .isEqualTo(ErrorCodeV1.EMBEDDING_SERVICE_NOT_CONFIGURED); }); @@ -332,7 +331,7 @@ public void updateNonVectorize() throws Exception { assertThat(exception.getMessage()) .isEqualTo( "Unable to vectorize data, embedding service not configured for the collection : " - + VECTOR_COMMAND_CONTEXT.schemaObject().name().table()); + + VECTOR_COMMAND_CONTEXT.schemaObject().identifier().table()); assertThat(exception.getErrorCode()) .isEqualTo(ErrorCodeV1.EMBEDDING_SERVICE_NOT_CONFIGURED); }); @@ -527,7 +526,7 @@ public void insertManyNonVectorize() throws Exception { assertThat(exception.getMessage()) .isEqualTo( "Unable to vectorize data, embedding service not configured for the collection : " - + VECTOR_COMMAND_CONTEXT.schemaObject().name().table()); + + VECTOR_COMMAND_CONTEXT.schemaObject().identifier().table()); assertThat(exception.getErrorCode()) .isEqualTo(ErrorCodeV1.EMBEDDING_SERVICE_NOT_CONFIGURED); }); diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CreateCollectionCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CreateCollectionCommandResolverTest.java index f878785b71..f772a074dd 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CreateCollectionCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CreateCollectionCommandResolverTest.java @@ -13,9 +13,9 @@ import io.stargate.sgv2.jsonapi.exception.ErrorCodeV1; import io.stargate.sgv2.jsonapi.exception.JsonApiException; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.collections.CreateCollectionOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import jakarta.inject.Inject; import org.apache.commons.lang3.RandomStringUtils; import org.junit.jupiter.api.BeforeEach; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CreateKeyspaceCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CreateKeyspaceCommandResolverTest.java index 477bc51b8c..2c9b860b82 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CreateKeyspaceCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/CreateKeyspaceCommandResolverTest.java @@ -10,9 +10,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateNamespaceCommand; import io.stargate.sgv2.jsonapi.exception.SchemaException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.keyspaces.CreateKeyspaceOperation; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; import jakarta.inject.Inject; import org.apache.commons.lang3.RandomStringUtils; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteCollectionCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteCollectionCommandResolverTest.java index ee0903a277..244dd1b9bb 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteCollectionCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/DeleteCollectionCommandResolverTest.java @@ -8,9 +8,9 @@ import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.DeleteCollectionCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.collections.DeleteCollectionCollectionOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/DropKeyspaceCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/DropKeyspaceCommandResolverTest.java index ab821b1bb0..a1b6ab8dbd 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/DropKeyspaceCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/DropKeyspaceCommandResolverTest.java @@ -8,9 +8,9 @@ import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.DropNamespaceCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.keyspaces.DropKeyspaceOperation; +import io.stargate.sgv2.jsonapi.service.schema.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/FindCollectionCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/FindCollectionCommandResolverTest.java index 76b9542812..7d0d61e049 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/FindCollectionCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/FindCollectionCommandResolverTest.java @@ -8,9 +8,9 @@ import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.FindCollectionsCommand; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.Operation; import io.stargate.sgv2.jsonapi.service.operation.collections.FindCollectionsCollectionOperation; +import io.stargate.sgv2.jsonapi.service.schema.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/FilterInversionTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/FilterInversionTest.java index ceda79fd10..b48a21f96d 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/FilterInversionTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/matcher/FilterInversionTest.java @@ -13,9 +13,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.FindCommand; import io.stargate.sgv2.jsonapi.api.model.command.table.definition.datatype.MapComponentDesc; import io.stargate.sgv2.jsonapi.fixtures.testdata.TestData; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.filters.table.MapSetListFilterComponent; import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; import jakarta.inject.Inject; import java.math.BigDecimal; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateOperatorTestData.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateOperatorTestData.java index 8e82f4380d..fa62f84aeb 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateOperatorTestData.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/update/TableUpdateOperatorTestData.java @@ -12,8 +12,8 @@ import io.stargate.sgv2.jsonapi.exception.UpdateException; import io.stargate.sgv2.jsonapi.fixtures.testdata.TestData; import io.stargate.sgv2.jsonapi.fixtures.testdata.TestDataSuplier; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.query.ColumnAssignment; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; import io.stargate.sgv2.jsonapi.util.recordable.Recordable; import java.util.List; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectCacheChangeListenerTests.java b/src/test/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectCacheChangeListenerTests.java new file mode 100644 index 0000000000..99a5cb7467 --- /dev/null +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectCacheChangeListenerTests.java @@ -0,0 +1,492 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.CqlSession; +import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata; +import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener; +import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; +import com.github.benmanes.caffeine.cache.Ticker; +import io.micrometer.core.instrument.simple.SimpleMeterRegistry; +import io.stargate.sgv2.jsonapi.api.request.RequestContext; +import io.stargate.sgv2.jsonapi.api.request.UserAgent; +import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; +import io.stargate.sgv2.jsonapi.api.request.tenant.TenantFactory; +import io.stargate.sgv2.jsonapi.config.DatabaseType; +import io.stargate.sgv2.jsonapi.service.schema.tables.TableSchemaObject; +import io.stargate.sgv2.jsonapi.util.CacheTestsBase; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Function; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Tests for the {@link SchemaObjectCache.SchemaCacheSchemaChangeListener} to evict and clear items + * see XXX for tests on the cache directly. + */ +public class SchemaObjectCacheChangeListenerTests extends CacheTestsBase { + private static final Logger LOGGER = + LoggerFactory.getLogger(SchemaObjectCacheChangeListenerTests.class); + + private final UserAgent SLA_USER_AGENT = + new UserAgent("user-agent/" + TEST_CONSTANTS.CORRELATION_ID); + + private final Tenant OTHER_TENANT = + Tenant.create(DatabaseType.ASTRA, "other-tenantFixture-" + TEST_CONSTANTS.CORRELATION_ID); + + private final SchemaObjectIdentifier TABLE_1_IDENTIFIER = TEST_CONSTANTS.TABLE_IDENTIFIER; + + private final SchemaObjectIdentifier TABLE_2_IDENTIFIER = + SchemaObjectIdentifier.forTable( + TEST_CONSTANTS.TENANT, + TABLE_1_IDENTIFIER.keyspace(), + CqlIdentifier.fromInternal("table2")); + + // NOTE: actual table name is the same as TABLE_1_IDENTIFIER, but in a different tenant! + private final SchemaObjectIdentifier TABLE_OTHER_IDENTIFIER = + SchemaObjectIdentifier.forTable( + OTHER_TENANT, TABLE_1_IDENTIFIER.keyspace(), TABLE_1_IDENTIFIER.table()); + + private final SchemaObjectIdentifier KEYSPACE_1_IDENTIFIER = + TABLE_1_IDENTIFIER.keyspaceIdentifier(); + + private final SchemaObjectIdentifier KEYSPACE_OTHER_IDENTIFIER = + TABLE_OTHER_IDENTIFIER.keyspaceIdentifier(); + + @BeforeEach + public void setUp() { + // the listener needs to create tenants, and it uses this factory + TenantFactory.initialize(DatabaseType.ASTRA); + } + + @AfterEach + public void reset() { + TenantFactory.reset(); + } + + @Test + public void silentFailWhenOnSessionReadyNotCalled() { + + var fixture = newFixture(); + var expectedTable = + fixture.mockTable( + fixture.tenantFixture, TEST_CONSTANTS.TABLE_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + + var tableMetadata = fixture.tableMetadataForIdentifier(TEST_CONSTANTS.TABLE_IDENTIFIER); + var keyspaceMetadata = fixture.keyspaceMetadataForIdentifier(TEST_CONSTANTS.TABLE_IDENTIFIER); + + // if the listener is called before onSessionReady is called it should not error + fixture.listener.onTableDropped(tableMetadata); + fixture.listener.onTableCreated(tableMetadata); + fixture.listener.onTableUpdated(tableMetadata, tableMetadata); + + fixture.listener.onKeyspaceDropped(keyspaceMetadata); + fixture.listener.onKeyspaceCreated(keyspaceMetadata); + fixture.listener.onKeyspaceUpdated(keyspaceMetadata, keyspaceMetadata); + + // and the table should still be there + var actualTableAfter = + fixture + .cache() + .getIfPresent( + fixture.tenantFixture.requestContext, + TEST_CONSTANTS.TABLE_IDENTIFIER, + TEST_CONSTANTS.USER_AGENT); + + assertThat(actualTableAfter) + .as("Table is still in schema cache after listener called before onSessionReady") + .isPresent() + .get() + .isSameAs(expectedTable); + } + + @Test + public void tableChangesEvictTable() { + + var tableMetadata = newFixture().tableMetadataForIdentifier(TABLE_1_IDENTIFIER); + + List> calls = + List.of( + (cb) -> { + cb.onTableCreated(tableMetadata); + return "onTableCreated"; + }, + (cb) -> { + cb.onTableUpdated(tableMetadata, tableMetadata); + return "onTableUpdated"; + }, + (cb) -> { + cb.onTableDropped(tableMetadata); + return "onTableDropped"; + }); + + for (var cb : calls) { + var fixture = newFixture(); + + // put two tables in from two keyspaces for the tenantFixture we are removing + // and one from a different tenantFixture + // table 1 is the one we remove + var expectedTable1 = + fixture.mockTable(fixture.tenantFixture, TABLE_1_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedTable2 = + fixture.mockTable(fixture.tenantFixture, TABLE_2_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedTableOther = + fixture.mockTable( + fixture.otherTenantFixture, TABLE_OTHER_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + + fixture.listener.onSessionReady(fixture.tenantFixture().cqlSession); + var operation = cb.apply(fixture.listener); + + // only table1 should be removed, the others should still be there + assertSchemaObjectRemoved(operation, fixture.tenantFixture, fixture, TABLE_1_IDENTIFIER); + assertSchemaObjectPresent( + operation, fixture.tenantFixture, fixture, TABLE_2_IDENTIFIER, expectedTable2); + assertSchemaObjectPresent( + operation, + fixture.otherTenantFixture, + fixture, + TABLE_OTHER_IDENTIFIER, + expectedTableOther); + } + } + + @Test + public void keyspaceDroppedEvictsAllForKS() { + + var fixture = newFixture(); + + // put two tables in from two keyspaces for the tenantFixture we are removing + // and one from a different tenantFixture + // table 1 and 2 is the ones we remove + var expectedTable1 = + fixture.mockTable(fixture.tenantFixture, TABLE_1_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedTable2 = + fixture.mockTable(fixture.tenantFixture, TABLE_2_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedTableOther = + fixture.mockTable( + fixture.otherTenantFixture, TABLE_OTHER_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + + var expectedKS = + fixture.mockKeyspace( + fixture.tenantFixture, KEYSPACE_1_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedKSOther = + fixture.mockKeyspace( + fixture.otherTenantFixture, KEYSPACE_OTHER_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + + var ksMetadata1 = fixture.keyspaceMetadataForIdentifier(KEYSPACE_1_IDENTIFIER); + + // the cql session name is set for to use the TEST_CONSTANTS.TENANT + fixture.listener.onSessionReady(fixture.tenantFixture.cqlSession); + // drop keyspace 1, from the TENANT + fixture.listener.onKeyspaceDropped(ksMetadata1); + + // table1 and 2 should be removed because from same keyspace + tenantFixture, table other still + // there + // keyspace 1 should be removed, but not the other keyspace + var operation = "onKeyspaceDropped"; + assertSchemaObjectRemoved(operation, fixture.tenantFixture, fixture, TABLE_1_IDENTIFIER); + assertSchemaObjectRemoved(operation, fixture.tenantFixture, fixture, TABLE_2_IDENTIFIER); + assertSchemaObjectPresent( + operation, fixture.otherTenantFixture, fixture, TABLE_OTHER_IDENTIFIER, expectedTableOther); + + assertSchemaObjectRemoved(operation, fixture.tenantFixture, fixture, KEYSPACE_1_IDENTIFIER); + assertSchemaObjectPresent( + operation, fixture.otherTenantFixture, fixture, KEYSPACE_OTHER_IDENTIFIER, expectedKSOther); + } + + @Test + public void keyspaceUpdatedEvictsOnlyKs() { + + var fixture = newFixture(); + + // put two tables in from two keyspaces for the tenantFixture we are removing + // and one from a different tenantFixture + var expectedTable1 = + fixture.mockTable(fixture.tenantFixture, TABLE_1_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedTable2 = + fixture.mockTable(fixture.tenantFixture, TABLE_2_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedTableOther = + fixture.mockTable( + fixture.otherTenantFixture, TABLE_OTHER_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + + var expectedKS = + fixture.mockKeyspace( + fixture.tenantFixture, KEYSPACE_1_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedKSOther = + fixture.mockKeyspace( + fixture.otherTenantFixture, KEYSPACE_OTHER_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + + var ksMetadata1 = fixture.keyspaceMetadataForIdentifier(KEYSPACE_1_IDENTIFIER); + + // the cql session name is set for to use the TEST_CONSTANTS.TENANT + fixture.listener.onSessionReady(fixture.tenantFixture.cqlSession); + // drop keyspace 1, from the TENANT + fixture.listener.onKeyspaceUpdated(ksMetadata1, ksMetadata1); + + // only ks for the tenant should be removed, other tables and ks should still be there + var operation = "onKeyspaceUpdated"; + assertSchemaObjectPresent( + operation, fixture.tenantFixture, fixture, TABLE_1_IDENTIFIER, expectedTable1); + assertSchemaObjectPresent( + operation, fixture.tenantFixture, fixture, TABLE_2_IDENTIFIER, expectedTable2); + assertSchemaObjectPresent( + operation, fixture.otherTenantFixture, fixture, TABLE_OTHER_IDENTIFIER, expectedTableOther); + + assertSchemaObjectRemoved(operation, fixture.tenantFixture, fixture, KEYSPACE_1_IDENTIFIER); + assertSchemaObjectPresent( + operation, fixture.otherTenantFixture, fixture, KEYSPACE_OTHER_IDENTIFIER, expectedKSOther); + } + + @Test + public void keyspaceCreatedEvictsAllForKS() { + + var fixture = newFixture(); + + var expectedTable1 = + fixture.mockTable(fixture.tenantFixture, TABLE_1_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedTable2 = + fixture.mockTable(fixture.tenantFixture, TABLE_2_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedTableOther = + fixture.mockTable( + fixture.otherTenantFixture, TABLE_OTHER_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + + var expectedKS = + fixture.mockKeyspace( + fixture.tenantFixture, KEYSPACE_1_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + var expectedKSOther = + fixture.mockKeyspace( + fixture.otherTenantFixture, KEYSPACE_OTHER_IDENTIFIER, TEST_CONSTANTS.USER_AGENT); + + var ksMetadata1 = fixture.keyspaceMetadataForIdentifier(KEYSPACE_1_IDENTIFIER); + + // the cql session name is set for to use the TEST_CONSTANTS.TENANT + fixture.listener.onSessionReady(fixture.tenantFixture.cqlSession); + // drop keyspace 1, from the TENANT + fixture.listener.onKeyspaceCreated(ksMetadata1); + + // only ks for the tenant should be removed, other tables and ks should still be there + var operation = "onKeyspaceCreated"; + assertSchemaObjectRemoved(operation, fixture.tenantFixture, fixture, TABLE_1_IDENTIFIER); + assertSchemaObjectRemoved(operation, fixture.tenantFixture, fixture, TABLE_2_IDENTIFIER); + assertSchemaObjectPresent( + operation, fixture.otherTenantFixture, fixture, TABLE_OTHER_IDENTIFIER, expectedTableOther); + + assertSchemaObjectRemoved(operation, fixture.tenantFixture, fixture, KEYSPACE_1_IDENTIFIER); + assertSchemaObjectPresent( + operation, fixture.otherTenantFixture, fixture, KEYSPACE_OTHER_IDENTIFIER, expectedKSOther); + } + + // ========================================================================================================= + // Helper methods to create mock objects for testing + // ========================================================================================================= + + private void assertSchemaObjectRemoved( + String operation, + FixtureTenant thisFixtureTenant, + Fixture fixture, + SchemaObjectIdentifier identifier) { + + assertThat( + fixture.cache.getIfPresent( + thisFixtureTenant.requestContext, identifier, TEST_CONSTANTS.USER_AGENT)) + .as("%s removed on after operation=%s", identifier, operation) + .isEmpty(); + } + + private void assertSchemaObjectPresent( + String operation, + FixtureTenant thisFixtureTenant, + Fixture fixture, + SchemaObjectIdentifier identifier, + SchemaObject expectedSchemaObject) { + assertThat( + fixture.cache.getIfPresent( + thisFixtureTenant.requestContext, identifier, TEST_CONSTANTS.USER_AGENT)) + .as("%s present on after operation=%s", identifier, operation) + .isPresent() + .get() + .isSameAs(expectedSchemaObject); + } + + private TableMetadata tableMetadata(String keyspaceName, String tableName) { + + var tableMetadata = mock(TableMetadata.class); + + var keyspaceIdentifier = mock(CqlIdentifier.class); + when(keyspaceIdentifier.asInternal()).thenReturn(keyspaceName); + when(tableMetadata.getKeyspace()).thenReturn(keyspaceIdentifier); + + var tableIdentifier = mock(CqlIdentifier.class); + when(tableIdentifier.asInternal()).thenReturn(tableName); + when(tableMetadata.getName()).thenReturn(tableIdentifier); + + return tableMetadata; + } + + private KeyspaceMetadata keyspaceMetadata(String keyspaceName) { + + var keyspaceMetadata = mock(KeyspaceMetadata.class); + + var keyspaceIdentifier = mock(CqlIdentifier.class); + when(keyspaceIdentifier.asInternal()).thenReturn(keyspaceName); + when(keyspaceMetadata.getName()).thenReturn(keyspaceIdentifier); + + return keyspaceMetadata; + } + + private Fixture newFixture() { + + var schemaObjectFactory = mock(SchemaObjectCache.SchemaObjectFactory.class); + var ticker = new CacheTestsBase.FakeTicker(); + + var cache = + new SchemaObjectCache( + CACHE_MAX_SIZE, + LONG_TTL, + SLA_USER_AGENT, + SHORT_TTL, + schemaObjectFactory, + new SimpleMeterRegistry(), + true, + ticker); + + return new Fixture( + schemaObjectFactory, + cache.getSchemaChangeListener(), + cache, + ticker, + newFixtureTenant(TEST_CONSTANTS.TENANT), + newFixtureTenant(OTHER_TENANT)); + } + + private FixtureTenant newFixtureTenant(Tenant tenant) { + + var requestContext = mock(RequestContext.class); + when(requestContext.tenant()).thenReturn(tenant); + + var cqlSession = mock(CqlSession.class); + when(cqlSession.getName()).thenReturn(tenant.toString()); + + return new FixtureTenant(tenant, requestContext, cqlSession); + } + + record Fixture( + SchemaObjectCache.SchemaObjectFactory factory, + SchemaChangeListener listener, + SchemaObjectCache cache, + Ticker ticker, + FixtureTenant tenantFixture, + FixtureTenant otherTenantFixture) { + + public TableSchemaObject mockTable( + FixtureTenant thisFixtureTenant, SchemaObjectIdentifier identifier, UserAgent userAgent) { + + var tableSchemaObject = mock(TableSchemaObject.class); + when(tableSchemaObject.identifier()).thenReturn(identifier); + + addToCache(thisFixtureTenant, identifier, userAgent, tableSchemaObject); + return tableSchemaObject; + } + + public KeyspaceSchemaObject mockKeyspace( + FixtureTenant thisFixtureTenant, SchemaObjectIdentifier identifier, UserAgent userAgent) { + + var keyspaceSchemaObject = mock(KeyspaceSchemaObject.class); + + when(keyspaceSchemaObject.identifier()).thenReturn(identifier); + + addToCache(thisFixtureTenant, identifier, userAgent, keyspaceSchemaObject); + return keyspaceSchemaObject; + } + + public void addToCache( + FixtureTenant thisFixtureTenant, + SchemaObjectIdentifier identifier, + UserAgent userAgent, + TableSchemaObject tableSchemaObject) { + + LOGGER.info( + "Setting up factories for identifier: {}, thisFixtureTenant: {}", + identifier, + thisFixtureTenant); + + // the getTableBased function may need to make two calls to get the schema object, the first + // is to try if it is a collection, the second is to get it as a table + // so we need ot make sure to throw an exception when called + + // this is the success call + when(factory.apply(any(), eq(identifier), anyBoolean())) + .thenReturn(CompletableFuture.completedFuture(tableSchemaObject)); + + // now the failure call + var otherIdentifier = + identifier.type() == SchemaObjectType.COLLECTION + ? SchemaObjectIdentifier.forTable( + identifier.tenant(), identifier.keyspace(), identifier.table()) + : SchemaObjectIdentifier.forCollection( + identifier.tenant(), identifier.keyspace(), identifier.table()); + when(factory.apply(any(), eq(otherIdentifier), anyBoolean())) + .thenReturn( + CompletableFuture.failedFuture( + new SchemaObjectFactory.SchemaObjectTypeMismatchException( + identifier.type(), otherIdentifier.type()))); + + LOGGER.info("Calling cache to get table for identifier: {}", identifier); + + var actualTable = + cache() + .getTableBased(thisFixtureTenant.requestContext, identifier, userAgent, false) + .await() + .indefinitely(); + + assertThat(actualTable) + .as( + "Table is one returned by the factory, expected:%s actual:%s", + identifier, actualTable.identifier()) + .isEqualTo(tableSchemaObject); + } + + public void addToCache( + FixtureTenant thisFixtureTenant, + SchemaObjectIdentifier identifier, + UserAgent userAgent, + KeyspaceSchemaObject keyspaceSchemaObject) { + + when(factory.apply(any(), eq(identifier), anyBoolean())) + .thenReturn(CompletableFuture.completedFuture(keyspaceSchemaObject)); + + var actual = + cache() + .getKeyspace(thisFixtureTenant.requestContext, identifier, userAgent, false) + .await() + .indefinitely(); + + assertThat(actual) + .as("Keyspace is one returned by the factory") + .isEqualTo(keyspaceSchemaObject); + } + + public TableMetadata tableMetadataForIdentifier(SchemaObjectIdentifier identifier) { + + var tableMetaData = mock(TableMetadata.class); + when(tableMetaData.getKeyspace()).thenReturn(identifier.keyspace()); + when(tableMetaData.getName()).thenReturn(identifier.table()); + return tableMetaData; + } + + public KeyspaceMetadata keyspaceMetadataForIdentifier(SchemaObjectIdentifier identifier) { + + var keyspaceMetaData = mock(KeyspaceMetadata.class); + when(keyspaceMetaData.getName()).thenReturn(identifier.keyspace()); + return keyspaceMetaData; + } + } + + record FixtureTenant(Tenant tenant, RequestContext requestContext, CqlSession cqlSession) {} +} diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectIdentifierTests.java b/src/test/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectIdentifierTests.java new file mode 100644 index 0000000000..7f0865487c --- /dev/null +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/schema/SchemaObjectIdentifierTests.java @@ -0,0 +1,401 @@ +package io.stargate.sgv2.jsonapi.service.schema; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import io.stargate.sgv2.jsonapi.TestConstants; +import io.stargate.sgv2.jsonapi.api.request.tenant.Tenant; +import io.stargate.sgv2.jsonapi.util.recordable.Jsonable; +import io.stargate.sgv2.jsonapi.util.recordable.PrettyPrintable; +import org.junit.jupiter.api.Test; +import org.slf4j.MDC; + +public class SchemaObjectIdentifierTests { + + protected final TestConstants TEST_CONSTANTS = new TestConstants(); + private final Tenant OTHER_TENANT = + Tenant.create(TEST_CONSTANTS.DATABASE_TYPE, "other-tenant-" + TEST_CONSTANTS.CORRELATION_ID); + + @Test + public void forDatabaseFactory() { + + assertThatThrownBy(() -> SchemaObjectIdentifier.forDatabase(null)) + .as("throws if tenant is null") + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("tenant"); + + var tenant = TEST_CONSTANTS.TENANT; + var identifier = SchemaObjectIdentifier.forDatabase(tenant); + assertThat(identifier.fullName()) + .as("fullName should be db:") + .isEqualTo("db:" + tenant); + + assertThat(identifier.type()) + .as("type should be DATABASE") + .isEqualTo(SchemaObjectType.DATABASE); + + assertThat(identifier.tenant()) + .as("tenant should match the one used to create the identifier") + .isEqualTo(tenant); + } + + @Test + public void forKeyspaceFactory() { + var tenant = TEST_CONSTANTS.TENANT; + + assertThatThrownBy(() -> SchemaObjectIdentifier.forKeyspace(null, CqlIdentifier.fromCql("ks"))) + .as("throws if tenant is null") + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("tenant"); + + assertThatThrownBy(() -> SchemaObjectIdentifier.forKeyspace(tenant, null)) + .as("throws if keyspace is null") + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("keyspace"); + + // need fromInternal to create a blank CqlIdentifier + assertThatThrownBy( + () -> SchemaObjectIdentifier.forKeyspace(tenant, CqlIdentifier.fromInternal(""))) + .as("throws if keyspace is blank") + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("keyspace name must not be blank"); + + var keyspace = CqlIdentifier.fromCql("ks"); + var identifier = SchemaObjectIdentifier.forKeyspace(tenant, keyspace); + assertThat(identifier.fullName()).as("fullName should equal keyspace name").isEqualTo("ks"); + + assertThat(identifier.type()) + .as("type should be KEYSPACE") + .isEqualTo(SchemaObjectType.KEYSPACE); + + assertThat(identifier.tenant()) + .as("tenant should match the one used to create the identifier") + .isEqualTo(tenant); + } + + @Test + public void forCollectionFactory() { + var tenant = TEST_CONSTANTS.TENANT; + var keyspace = CqlIdentifier.fromCql("ks"); + + assertThatThrownBy( + () -> + SchemaObjectIdentifier.forCollection(null, keyspace, CqlIdentifier.fromCql("col"))) + .as("throws if tenant is null") + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("tenant"); + + assertThatThrownBy( + () -> SchemaObjectIdentifier.forCollection(tenant, null, CqlIdentifier.fromCql("col"))) + .as("throws if keyspace is null") + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("keyspace"); + + assertThatThrownBy(() -> SchemaObjectIdentifier.forCollection(tenant, keyspace, null)) + .as("throws if collection is null") + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("collection"); + + // need fromInternal to create a blank CqlIdentifier + assertThatThrownBy( + () -> + SchemaObjectIdentifier.forCollection( + tenant, keyspace, CqlIdentifier.fromInternal(""))) + .as("throws if collection is blank") + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("collection name must not be blank"); + + var collection = CqlIdentifier.fromCql("col"); + var identifier = SchemaObjectIdentifier.forCollection(tenant, keyspace, collection); + assertThat(identifier.fullName()) + .as("fullName should be keyspace.collection") + .isEqualTo("ks.col"); + + assertThat(identifier.type()) + .as("type should be COLLECTION") + .isEqualTo(SchemaObjectType.COLLECTION); + + assertThat(identifier.tenant()) + .as("tenant should match the one used to create the identifier") + .isEqualTo(tenant); + } + + @Test + public void forTableFactory() { + var tenant = TEST_CONSTANTS.TENANT; + var keyspace = CqlIdentifier.fromCql("ks"); + + assertThatThrownBy( + () -> SchemaObjectIdentifier.forTable(null, keyspace, CqlIdentifier.fromCql("tbl"))) + .as("throws if tenant is null") + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("tenant"); + + assertThatThrownBy( + () -> SchemaObjectIdentifier.forTable(tenant, null, CqlIdentifier.fromCql("tbl"))) + .as("throws if keyspace is null") + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("keyspace"); + + assertThatThrownBy(() -> SchemaObjectIdentifier.forTable(tenant, keyspace, null)) + .as("throws if table is null") + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("table"); + + // need fromInternal to create a blank CqlIdentifier + assertThatThrownBy( + () -> SchemaObjectIdentifier.forTable(tenant, keyspace, CqlIdentifier.fromInternal(""))) + .as("throws if table is blank") + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("table name must not be blank"); + + var table = CqlIdentifier.fromCql("tbl"); + var identifier = SchemaObjectIdentifier.forTable(tenant, keyspace, table); + assertThat(identifier.fullName()).as("fullName should be keyspace.table").isEqualTo("ks.tbl"); + + assertThat(identifier.type()).as("type should be TABLE").isEqualTo(SchemaObjectType.TABLE); + + assertThat(identifier.tenant()) + .as("tenant should match the one used to create the identifier") + .isEqualTo(tenant); + } + + @Test + public void fromTableMetadata() { + var tenant = TEST_CONSTANTS.TENANT; + var keyspace = CqlIdentifier.fromCql("ks"); + var table = CqlIdentifier.fromCql("tbl"); + + var metadata = mock(TableMetadata.class); + when(metadata.getKeyspace()).thenReturn(keyspace); + when(metadata.getName()).thenReturn(table); + + var fromTable = + SchemaObjectIdentifier.fromTableMetadata(SchemaObjectType.TABLE, tenant, metadata); + assertThat(fromTable.type()) + .as("should return SchemaObjectType.TABLE") + .isEqualTo(SchemaObjectType.TABLE); + assertThat(fromTable.fullName()) + .as("should extract fullName from metadata for TABLE") + .isEqualTo("ks.tbl"); + + var fromCollection = + SchemaObjectIdentifier.fromTableMetadata(SchemaObjectType.COLLECTION, tenant, metadata); + assertThat(fromCollection.type()) + .as("should return SchemaObjectType.COLLECTION") + .isEqualTo(SchemaObjectType.COLLECTION); + assertThat(fromCollection.fullName()) + .as("should extract fullName from metadata for COLLECTION") + .isEqualTo("ks.tbl"); + + assertThatThrownBy( + () -> + SchemaObjectIdentifier.fromTableMetadata( + SchemaObjectType.KEYSPACE, tenant, metadata)) + .as("should throw for unsupported SchemaObjectType") + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Unsupported object type"); + + assertThatThrownBy( + () -> SchemaObjectIdentifier.fromTableMetadata(SchemaObjectType.TABLE, tenant, null)) + .as("should throw if TableMetadata is null") + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("tableMetadata must not be null"); + } + + @Test + public void keyspaceIdentifierIsExpected() { + var tenant = TEST_CONSTANTS.TENANT; + var keyspace = CqlIdentifier.fromCql("ks"); + var table = CqlIdentifier.fromCql("tbl"); + + var tableIdentifier = SchemaObjectIdentifier.forTable(tenant, keyspace, table); + var keyspaceIdentifier = tableIdentifier.keyspaceIdentifier(); + + assertThat(keyspaceIdentifier.type()) + .as("should return type KEYSPACE") + .isEqualTo(SchemaObjectType.KEYSPACE); + + assertThat(keyspaceIdentifier.keyspace()) + .as("keyspaceIdentifier has same keyspace as the table identifier") + .isEqualTo(tableIdentifier.keyspace()); + assertThat(keyspaceIdentifier.tenant()) + .as("keyspaceIdentifier has same tenant as the table identifier") + .isEqualTo(tableIdentifier.tenant()); + } + + @Test + public void unscopedIdentifierInterface() { + var tenant = TEST_CONSTANTS.TENANT; + var keyspace = CqlIdentifier.fromCql("ks"); + var table = CqlIdentifier.fromCql("tbl"); + + var tableIdentifier = SchemaObjectIdentifier.forTable(tenant, keyspace, table); + var unscoped = (UnscopedSchemaObjectIdentifier) tableIdentifier; + + assertThat(unscoped.keyspace()) + .as("unscoped keyspace should match the table identifier's keyspace") + .isEqualTo(tableIdentifier.keyspace()); + + assertThat(unscoped.objectName()) + .as("unscoped object name should match the table identifier's table name") + .isEqualTo(tableIdentifier.table()); + } + + @Test + public void toStringIsFullName() { + var tenant = TEST_CONSTANTS.TENANT; + var keyspace = CqlIdentifier.fromCql("ks"); + var table = CqlIdentifier.fromCql("tbl"); + + var tableIdentifier = SchemaObjectIdentifier.forTable(tenant, keyspace, table); + + assertThat(tableIdentifier.toString()) + .as("toString should return fullName") + .isEqualTo(tableIdentifier.fullName()); + } + + @Test + public void isSameKeyspace() { + var tenant = TEST_CONSTANTS.TENANT; + var keyspace = CqlIdentifier.fromCql("ks"); + + var table1 = CqlIdentifier.fromCql("t1"); + var table2 = CqlIdentifier.fromCql("t2"); + + var id1 = SchemaObjectIdentifier.forTable(tenant, keyspace, table1); + var id2 = SchemaObjectIdentifier.forTable(tenant, keyspace, table2); + + assertThat(id1.isSameKeyspace(id2)) + .as("should return true when tenant and keyspace match") + .isTrue(); + + var id3 = SchemaObjectIdentifier.forTable(OTHER_TENANT, keyspace, table1); + + assertThat(id1.isSameKeyspace(id3)).as("should return false when tenant differs").isFalse(); + + var otherKeyspace = CqlIdentifier.fromCql("otherks"); + var id4 = SchemaObjectIdentifier.forTable(tenant, otherKeyspace, table1); + + assertThat(id1.isSameKeyspace(id4)).as("should return false when keyspace differs").isFalse(); + } + + @Test + public void testAddAndRemoveFromMDC() { + var tenant = TEST_CONSTANTS.TENANT; + var keyspace = CqlIdentifier.fromCql("ks"); + var table = CqlIdentifier.fromCql("tbl"); + + var identifier = SchemaObjectIdentifier.forTable(tenant, keyspace, table); + + identifier.addToMDC(); + + assertThat(MDC.get("namespace")) + .as("MDC should contain keyspace as 'namespace'") + .isEqualTo("ks"); + + assertThat(MDC.get("collection")) + .as("MDC should contain table as 'collection'") + .isEqualTo("tbl"); + + identifier.removeFromMDC(); + + assertThat(MDC.get("namespace")).as("MDC 'namespace' should be removed").isNull(); + + assertThat(MDC.get("collection")).as("MDC 'collection' should be removed").isNull(); + } + + @Test + public void recordTo() { + var tenant = TEST_CONSTANTS.TENANT; + var keyspace = CqlIdentifier.fromCql("ks"); + var table = CqlIdentifier.fromCql("tbl"); + + var identifier = SchemaObjectIdentifier.forTable(tenant, keyspace, table); + + var pretty = PrettyPrintable.pprint(identifier); + assertThat(pretty) + .as("recordTo output for SchemaObjectIdentifier") + .contains("tenant", tenant.toString()) + .contains("databaseType", TEST_CONSTANTS.DATABASE_TYPE.name()) + .contains("type", "TABLE") + .contains("keyspace", "ks") + .contains("table", "tbl"); + + var identifierJson = Jsonable.toJson(identifier); + var expected = JsonNodeFactory.instance.objectNode(); + // there is a top level "SchemaObjectIdentifier" field + var contents = expected.withObjectProperty("SchemaObjectIdentifier"); + contents.put("tenant", Jsonable.toJson(tenant)); + contents.put("type", "TABLE"); + contents.put("keyspace", keyspace.asInternal()); + contents.put("table", table.asInternal()); + + assertThat(identifierJson).as("JSON output for Tenant").isEqualTo(expected); + } + + @Test + public void equalityAndHashCodeReflexive() { + var db = TEST_CONSTANTS.DATABASE_IDENTIFIER; + var ks = TEST_CONSTANTS.KEYSPACE_IDENTIFIER; + var coll = TEST_CONSTANTS.COLLECTION_IDENTIFIER; + var table = TEST_CONSTANTS.TABLE_IDENTIFIER; + + assertThat(db).isEqualTo(db).hasSameHashCodeAs(db); + assertThat(ks).isEqualTo(ks).hasSameHashCodeAs(ks); + assertThat(coll).isEqualTo(coll).hasSameHashCodeAs(coll); + assertThat(table).isEqualTo(table).hasSameHashCodeAs(table); + } + + @Test + public void equalityAndHashCodeTransitive() { + var id1 = + SchemaObjectIdentifier.forCollection( + TEST_CONSTANTS.TENANT, + TEST_CONSTANTS.KEYSPACE_IDENTIFIER.keyspace(), + TEST_CONSTANTS.COLLECTION_IDENTIFIER.table()); + + var id2 = + SchemaObjectIdentifier.forCollection( + TEST_CONSTANTS.TENANT, + TEST_CONSTANTS.KEYSPACE_IDENTIFIER.keyspace(), + TEST_CONSTANTS.COLLECTION_IDENTIFIER.table()); + + var id3 = + SchemaObjectIdentifier.forCollection( + TEST_CONSTANTS.TENANT, + TEST_CONSTANTS.KEYSPACE_IDENTIFIER.keyspace(), + TEST_CONSTANTS.COLLECTION_IDENTIFIER.table()); + + assertThat(id1).isEqualTo(id2); + assertThat(id2).isEqualTo(id3); + assertThat(id1).isEqualTo(id3); + + assertThat(id1.hashCode()).isEqualTo(id2.hashCode()); + assertThat(id2.hashCode()).isEqualTo(id3.hashCode()); + } + + @Test + public void differentTenant() { + var id1 = + SchemaObjectIdentifier.forCollection( + TEST_CONSTANTS.TENANT, + TEST_CONSTANTS.KEYSPACE_SCHEMA_OBJECT.identifier.keyspace(), + TEST_CONSTANTS.COLLECTION_SCHEMA_OBJECT.identifier.table()); + + var id2 = + SchemaObjectIdentifier.forCollection( + OTHER_TENANT, + TEST_CONSTANTS.KEYSPACE_SCHEMA_OBJECT.identifier.keyspace(), + TEST_CONSTANTS.COLLECTION_SCHEMA_OBJECT.identifier.table()); + + assertThat(id1).isNotEqualTo(id2); + + assertThat(id1.hashCode()).isNotEqualTo(id2.hashCode()); + } +} diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderDocLimitsTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderDocLimitsTest.java index 3927785f10..6b5283f1de 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderDocLimitsTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderDocLimitsTest.java @@ -142,7 +142,7 @@ public void allowDocWithHugeObjectNoIndex() { IndexingProjector.createForIndexing(null, Collections.singleton("no_index")); assertThat( documentShredder.shred( - doc, null, indexProjector, "testCommand", CollectionSchemaObject.MISSING, null)) + doc, null, indexProjector, "testCommand", testConstants.MISSING, null)) .isNotNull(); } @@ -223,7 +223,7 @@ public void allowDocWithHugeArrayNoIndex() { IndexingProjector.createForIndexing(null, Collections.singleton("no_index")); assertThat( documentShredder.shred( - doc, null, indexProjector, "testCommand", CollectionSchemaObject.MISSING, null)) + doc, null, indexProjector, "testCommand", testConstants.MISSING, null)) .isNotNull(); } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderTest.java index 5b95ff0092..9b8a135d91 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderTest.java @@ -607,7 +607,7 @@ public void shredWithIndexAllowSome() throws Exception { new HashSet<>(Arrays.asList("name", "metadata")), null); WritableShreddedDocument doc = documentShredder.shred( - inputDoc, null, indexProjector, "testCommand", CollectionSchemaObject.MISSING, null); + inputDoc, null, indexProjector, "testCommand", testConstants.MISSING, null); assertThat(doc.id()).isEqualTo(DocumentId.fromNumber(BigDecimal.valueOf(123))); List expPaths = Arrays.asList( @@ -676,7 +676,7 @@ public void shredVectorize9K() throws Exception { new HashSet<>(Arrays.asList("name", "metadata")), null); WritableShreddedDocument doc = documentShredder.shred( - inputDoc, null, indexProjector, "testCommand", CollectionSchemaObject.MISSING, null); + inputDoc, null, indexProjector, "testCommand", testConstants.MISSING, null); assertThat(doc.id()).isEqualTo(DocumentId.fromNumber(BigDecimal.valueOf(123))); List expPaths = Arrays.asList( @@ -739,7 +739,7 @@ public void shredWithIndexAllowAll() throws Exception { new HashSet<>(Arrays.asList("name", "metadata")), null); WritableShreddedDocument doc = documentShredder.shred( - inputDoc, null, indexProjector, "testCommand", CollectionSchemaObject.MISSING, null); + inputDoc, null, indexProjector, "testCommand", testConstants.MISSING, null); assertThat(doc.id()).isEqualTo(DocumentId.fromNumber(BigDecimal.valueOf(123))); List expPaths = Arrays.asList( @@ -797,7 +797,7 @@ public void shredWithIndexDenySome() throws Exception { IndexingProjector.createForIndexing(null, new HashSet<>(Arrays.asList("name", "values"))); WritableShreddedDocument doc = documentShredder.shred( - inputDoc, null, indexProjector, "testCommand", CollectionSchemaObject.MISSING, null); + inputDoc, null, indexProjector, "testCommand", testConstants.MISSING, null); assertThat(doc.id()).isEqualTo(DocumentId.fromNumber(BigDecimal.valueOf(123))); List expPaths = Arrays.asList( @@ -860,7 +860,7 @@ public void shredWithIndexDenyAll() throws Exception { IndexingProjector.createForIndexing(null, new HashSet<>(Arrays.asList("*"))); WritableShreddedDocument doc = documentShredder.shred( - inputDoc, null, indexProjector, "testCommand", CollectionSchemaObject.MISSING, null); + inputDoc, null, indexProjector, "testCommand", testConstants.MISSING, null); assertThat(doc.id()).isEqualTo(DocumentId.fromNumber(BigDecimal.valueOf(123))); List expPaths = @@ -904,7 +904,7 @@ public void shredWithHugeNonIndexedString() throws Exception { IndexingProjector.createForIndexing(null, new HashSet<>(Arrays.asList("blob"))); WritableShreddedDocument doc = documentShredder.shred( - inputDoc, null, indexProjector, "testCommand", CollectionSchemaObject.MISSING, null); + inputDoc, null, indexProjector, "testCommand", testConstants.MISSING, null); assertThat(doc.id()).isEqualTo(DocumentId.fromNumber(BigDecimal.valueOf(1))); List expPaths = Arrays.asList(JsonPath.from("_id"), JsonPath.from("name")); assertThat(doc.existKeys()).isEqualTo(new HashSet<>(expPaths)); @@ -944,7 +944,7 @@ public void validateJsonBytesWriteMetrics() throws Exception { null, IndexingProjector.identityProjector(), "jsonBytesWriteCommand", - CollectionSchemaObject.MISSING, + testConstants.MISSING, null); // verify metrics diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderWithExtendedTypesTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderWithExtendedTypesTest.java index b541fef763..82adc64b5a 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderWithExtendedTypesTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/shredding/DocumentShredderWithExtendedTypesTest.java @@ -14,9 +14,9 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.request.RequestContext; import io.stargate.sgv2.jsonapi.exception.DocumentException; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; import io.stargate.sgv2.jsonapi.service.projection.IndexingProjector; -import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionIdType; -import io.stargate.sgv2.jsonapi.service.schema.collections.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.schema.collections.*; import io.stargate.sgv2.jsonapi.service.shredding.collections.*; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; import jakarta.inject.Inject; @@ -198,15 +198,23 @@ class OkCasesGeneratedId { public void shredSimpleWithoutIdGenLegacyUUID() throws Exception { final String inputJson = "{\"value\": 42}"; final JsonNode inputDoc = objectMapper.readTree(inputJson); + var collectionSchemaObject = + new CollectionSchemaObject( + testConstants.TENANT, + null, + new IdConfig(CollectionIdType.UNDEFINED), + VectorConfig.NOT_ENABLED_CONFIG, + null, + CollectionLexicalConfig.configForDisabled(), + CollectionRerankDef.configForDisabled()); WritableShreddedDocument doc = documentShredder.shred( inputDoc, null, IndexingProjector.identityProjector(), "test", - CollectionSchemaObject.MISSING.withIdType(CollectionIdType.UNDEFINED), + collectionSchemaObject, null); - DocumentId docId = doc.id(); // Legacy UUID generated as "plain" String id assertThat(docId).isInstanceOf(DocumentId.StringId.class); @@ -244,7 +252,7 @@ public void shredSimpleWithoutIdGenObjectId() throws Exception { null, IndexingProjector.identityProjector(), "test", - CollectionSchemaObject.MISSING.withIdType(CollectionIdType.OBJECT_ID), + testConstants.MISSING, null); DocumentId docId = doc.id(); @@ -294,13 +302,23 @@ private void _testShredUUIDAutoGeneration(CollectionIdType idType, int uuidVersi throws Exception { final String inputJson = "{\"value\": 42}"; final JsonNode inputDoc = objectMapper.readTree(inputJson); + + var collectionSchemaObject = + new CollectionSchemaObject( + testConstants.TENANT, + null, + new IdConfig(idType), + VectorConfig.NOT_ENABLED_CONFIG, + null, + CollectionLexicalConfig.configForDisabled(), + CollectionRerankDef.configForDisabled()); WritableShreddedDocument doc = documentShredder.shred( inputDoc, null, IndexingProjector.identityProjector(), "test", - CollectionSchemaObject.MISSING.withIdType(idType), + collectionSchemaObject, null); DocumentId docId = doc.id();