From 680a795c93b69dcc73dfc9eb9c3938e62fd9e21b Mon Sep 17 00:00:00 2001 From: Aaron Morton Date: Tue, 16 Jul 2024 15:58:59 +1200 Subject: [PATCH] Fix failing tests. This commit fixes failing unit and integration tests. It cherry picks multiple commits from the ajm/tables branch below. -> SKIPPED - did not cherry pick the original see below <- commit 0b53fbafe90685a58f24c0372c0cb370fd870c1a Author: Tatu Saloranta Date: Tue Jul 9 17:34:14 2024 -0700 Revert UT->IT cherry-picked merge commit 951a0922bb5e4ab7b638fe40315e77926b914457 Author: Tatu Saloranta Date: Tue Jul 9 17:32:20 2024 -0700 Minor clean up of test contexts, javadocs commit 28c9ebbce5e684011b55e9775dca44c9c7c15068 Author: Tatu Saloranta Date: Tue Jul 9 17:21:20 2024 -0700 Minor clean up commit 980156604416d67d75e325128221217e3a4b5930 Author: Tatu Saloranta Date: Tue Jul 9 17:09:18 2024 -0700 Fix import stmt -> merge commit - not cherry picked <- commit b14dfa23922a9154a9b39bb57572c7d64ad92e45 Merge: 13678a59 a9cb4360 Author: Tatu Saloranta Date: Tue Jul 9 16:49:10 2024 -0700 Merge branch 'main' into ajm/tables -> came from merge, not cherry picked <- commit a9cb4360f78a83521d3c02714f9c268cac2a3fec Author: Tatu Saloranta Date: Tue Jul 9 16:47:00 2024 -0700 Update Quarkus Data API uses to 3.9.5 (from parent 3.6.x) (#1246) -> merge commit - not cherry picked <- commit 13678a5991b321a9cd995f6d0933013cdb5b2268 Merge: c7eccc06 dd424850 Author: Tatu Saloranta Date: Tue Jul 9 12:29:49 2024 -0700 Merge branch 'main' into ajm/tables -> came from merge, not cherry picked <- commit dd4248507fc901c0f172e0e669f48e4d322764bd Author: Tatu Saloranta Date: Tue Jul 9 11:40:21 2024 -0700 Fix a problem that would prevent Quarkus 3.12 upgrade (due to change in Smallrye lib) (#1248) -> came from merge, not cherry picked <- commit 15cd3f6502e8d99bfa899b6372c8d14a74fd8eed Author: YuqiDu Date: Tue Jul 9 10:31:03 2024 -0700 fix http port to 8181, refactor application.yaml as alphabetic order (#1247) -> came from merge, not cherry picked <- commit ce2b3373cab783cf007941a46e403a3e38a559d6 Author: YuqiDu Date: Tue Jul 9 09:19:11 2024 -0700 Bridge-Removal - Detach the quarkus-common-module dependency (OFF WE GO!) (#1191) Co-authored-by: Tatu Saloranta commit c7eccc0658451a325284221cea33e664bd58bfa2 Author: Aaron Morton Date: Tue Jul 9 19:31:31 2024 +1200 fmt fix commit 64930f5f266df57a0ca5836ab5480a7a782584d8 Author: Aaron Morton Date: Tue Jul 9 19:28:42 2024 +1200 Unit test fixes for Namespace commands -> merge commit - not cherry picked <- commit e7a6d159aabcbbcbe8ae6bb659de1085278593b7 Merge: baa6ea5c 5796eca9 Author: Aaron Morton Date: Tue Jul 9 19:18:55 2024 +1200 Merge branch 'main' into ajm/tables commit baa6ea5c62af991dbeae2a46cacd88454e11b3c5 Author: Aaron Morton Date: Tue Jul 9 19:14:03 2024 +1200 Fixes for Namespace Commands so they work on DatabaseSchemaObject commit cfbbc8c2aed5988f45cc4f91722a1bb646ca79b0 Author: Aaron Morton Date: Tue Jul 9 14:57:20 2024 +1200 fix CreateCollectionResolverVectorizeDisabledTest -> SKIPPED - later reverted , broke IT's <- commit c50d7fd05a5f1069d95c4dbbe702d03a7ff0fada Author: Tatu Saloranta Date: Mon Jul 8 19:30:57 2024 -0700 Fixes #1245: change 3 unit tests to integration tests to speed up unit test runtime git cherry-pick 19966978842dbe1e9aa96c7b8e5768e89b5ce706 -> came from merge, not cherry picked <- commit 5796eca9b623ca62bc29a215bced5e432165f4db Author: Tatu Saloranta Date: Mon Jul 8 19:08:23 2024 -0700 Refactor unit test profiles, try to speed things up (#1244) -> came from merge, not cherry picked <- commit 30c7ae055815377e23492fe258114e3ec0f66d48 Author: Tatu Saloranta Date: Mon Jul 8 18:36:41 2024 -0700 Fix accidental dependencies to shaded packages (#1243) -> merge commit, not cherry picked <- commit 18a804b2ac8027ce30c113deb5b9ee831785aaf2 Merge: 7ee94cdc 35ecb003 Author: Tatu Saloranta Date: Mon Jul 8 18:33:51 2024 -0700 Merge branch 'main' into ajm/tables commit 7ee94cdc4f4f2c914d03f42561a2a753a75941b4 Author: Aaron Morton Date: Tue Jul 9 13:13:47 2024 +1200 fix CreateCollectionResolverVectorDisabledTest commit b12c4844959fd07d882350e6cbb8b9d7559c1346 Author: Aaron Morton Date: Tue Jul 9 12:45:23 2024 +1200 Fix for failing Collection based tests -> came from merge, not cherry picked <- commit 35ecb003df15677239bfa51870bc7633d2dcbee0 Author: YuqiDu Date: Mon Jul 8 17:32:05 2024 -0700 Bridge-Removal - miscellaneous cleanups (#1149) Co-authored-by: Tatu Saloranta commit 4681ccdd2c00ab4a5715330ebb781e6d8b09cfa8 Author: Aaron Morton Date: Tue Jul 9 11:52:31 2024 +1200 fix for createCollection and other commands that run against the namespace FindIntegrationTest works, waiting to find out about others --- .../api/model/command/CommandContext.java | 64 ++++++++++++------- .../sgv2/jsonapi/api/v1/GeneralResource.java | 10 ++- .../jsonapi/api/v1/NamespaceResource.java | 2 +- .../executor/DatabaseSchemaObject.java | 20 ++++++ .../cqldriver/executor/IndexUsage.java | 7 +- .../executor/KeyspaceSchemaObject.java | 33 +++++++++- .../cqldriver/executor/SchemaObject.java | 1 + .../cqldriver/executor/SchemaObjectName.java | 5 +- .../collections/CollectionReadOperation.java | 1 + .../CreateCollectionOperation.java | 8 ++- .../DeleteCollectionOperation.java | 4 +- .../collections/FindCollectionsOperation.java | 7 +- .../model/collections/FindOperation.java | 2 + .../model/tables/TableReadOperation.java | 9 ++- .../resolver/model/CommandResolver.java | 25 ++++++-- .../impl/CreateCollectionCommandResolver.java | 6 +- .../impl/CreateNamespaceCommandResolver.java | 7 +- .../impl/DeleteCollectionCommandResolver.java | 6 +- .../impl/DropNamespaceCommandResolver.java | 7 +- .../impl/FindCollectionsCommandResolver.java | 7 +- ...FindEmbeddingProvidersCommandResolver.java | 6 +- .../impl/FindNamespacesCommandResolver.java | 6 +- .../schema/model/JsonapiTableMatcher.java | 2 + .../impl/BeginOfflineSessionCommand.java | 16 +++-- .../stargate/sgv2/jsonapi/TestConstants.java | 30 +++++++-- .../model/impl/CountOperationTest.java | 18 +++--- .../impl/CreateCollectionOperationTest.java | 10 +-- .../model/impl/OperationTestBase.java | 10 ++- .../MeteredCommandProcessorTest.java | 6 +- .../CountDocumentsCommandResolverTest.java | 2 +- .../CreateCollectionCommandResolverTest.java | 4 +- ...llectionResolverVectorizeDisabledTest.java | 15 +++-- .../CreateNamespaceCommandResolverTest.java | 4 +- .../DeleteCollectionCommandResolverTest.java | 4 +- .../impl/DeleteManyCommandResolverTest.java | 2 +- .../impl/DeleteOneCommandResolverTest.java | 2 +- .../DropNamespaceCommandResolverTest.java | 4 +- .../FindCollectionCommandResolverTest.java | 4 +- .../model/impl/FindCommandResolverTest.java | 8 +-- .../FindOneAndDeleteCommandResolverTest.java | 2 +- .../FindOneAndReplaceCommandResolverTest.java | 2 +- .../FindOneAndUpdateCommandResolverTest.java | 2 +- .../impl/FindOneCommandResolverTest.java | 2 +- .../impl/InsertManyCommandResolverTest.java | 2 +- .../impl/InsertOneCommandResolverTest.java | 2 +- .../impl/UpdateManyCommandResolverTest.java | 2 +- .../impl/UpdateOneCommandResolverTest.java | 2 +- .../impl/matcher/FilterMatchRuleTest.java | 6 +- .../impl/matcher/FilterMatchRulesTest.java | 5 +- ...eginOfflineSessionCommandResolverTest.java | 4 +- .../EndOfflineSessionCommandResolverTest.java | 4 +- .../OfflineGetStatusCommandResolverTest.java | 4 +- .../OfflineInsertManyCommandResolverTest.java | 6 +- 53 files changed, 283 insertions(+), 146 deletions(-) create mode 100644 src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DatabaseSchemaObject.java 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 2a998b0638..c74d1d560e 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 @@ -2,10 +2,7 @@ import com.google.common.base.Preconditions; import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonProcessingMetricsReporter; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaObject; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.TableSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.*; import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingProvider; /** @@ -25,12 +22,6 @@ public record CommandContext( // private static final CommandContext EMPTY = // new CommandContext(null, null, CollectionSettings.empty(), null, "testCommand", null); - public static final CommandContext EMPTY_COLLECTION = - new CommandContext<>(CollectionSchemaObject.MISSING, null, "testCommand", null); - - public static final CommandContext EMPTY_TABLE = - new CommandContext<>(TableSchemaObject.MISSING, null, "testCommand", null); - /** * Factory method to create a new instance of {@link CommandContext} based on the schema object we * are working with. @@ -65,6 +56,10 @@ public static CommandContext forSchemaObject( return (CommandContext) forSchemaObject(kso, embeddingProvider, commandName, jsonProcessingMetricsReporter); } + if (schemaObject instanceof DatabaseSchemaObject dso) { + return (CommandContext) + forSchemaObject(dso, embeddingProvider, commandName, jsonProcessingMetricsReporter); + } throw new IllegalArgumentException("Unknown schema object type: " + schemaObject.getClass()); } @@ -125,34 +120,55 @@ public static CommandContext forSchemaObject( schemaObject, embeddingProvider, commandName, jsonProcessingMetricsReporter); } + /** + * Factory method to create a new instance of {@link CommandContext} based on the schema object we + * are working with + * + * @param schemaObject + * @param embeddingProvider + * @param commandName + * @param jsonProcessingMetricsReporter + * @return + */ + public static CommandContext forSchemaObject( + DatabaseSchemaObject schemaObject, + EmbeddingProvider embeddingProvider, + String commandName, + JsonProcessingMetricsReporter jsonProcessingMetricsReporter) { + return new CommandContext<>( + schemaObject, embeddingProvider, commandName, jsonProcessingMetricsReporter); + } + @SuppressWarnings("unchecked") public CommandContext asCollectionContext() { - Preconditions.checkArgument( - schemaObject().type == CollectionSchemaObject.TYPE, - "SchemaObject type is actual was %s expected was %s ", - schemaObject().type, - CollectionSchemaObject.TYPE); + checkSchemaObjectType(CollectionSchemaObject.TYPE); return (CommandContext) this; } @SuppressWarnings("unchecked") public CommandContext asTableContext() { - Preconditions.checkArgument( - schemaObject().type == TableSchemaObject.TYPE, - "SchemaObject type is actual was %s expected was %s ", - schemaObject().type, - TableSchemaObject.TYPE); + checkSchemaObjectType(TableSchemaObject.TYPE); return (CommandContext) this; } @SuppressWarnings("unchecked") public CommandContext asKeyspaceContext() { + checkSchemaObjectType(KeyspaceSchemaObject.TYPE); + return (CommandContext) this; + } + + @SuppressWarnings("unchecked") + public CommandContext asDatabaseContext() { + checkSchemaObjectType(DatabaseSchemaObject.TYPE); + return (CommandContext) this; + } + + private void checkSchemaObjectType(SchemaObject.SchemaObjectType expectedType) { Preconditions.checkArgument( - schemaObject().type == KeyspaceSchemaObject.TYPE, - "SchemaObject type is actual was %s expected was %s ", + schemaObject().type == expectedType, + "SchemaObject type actual was %s expected was %s ", schemaObject().type, - KeyspaceSchemaObject.TYPE); - return (CommandContext) this; + expectedType); } // TODO: why do we have these public ctors, and a static factor, and this is a record ?? 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 35b6db1c9a..6bec37ca36 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 @@ -7,6 +7,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateNamespaceCommand; import io.stargate.sgv2.jsonapi.api.request.DataApiRequestInfo; import io.stargate.sgv2.jsonapi.config.constants.OpenApiConstants; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.processor.MeteredCommandProcessor; import jakarta.inject.Inject; import jakarta.validation.Valid; @@ -45,6 +46,7 @@ public GeneralResource(MeteredCommandProcessor meteredCommandProcessor) { this.meteredCommandProcessor = meteredCommandProcessor; } + // TODO: add example for findEmbeddingProviders @Operation(summary = "Execute command", description = "Executes a single general command.") @RequestBody( content = @@ -73,9 +75,13 @@ public GeneralResource(MeteredCommandProcessor meteredCommandProcessor) { }))) @POST public Uni> postCommand(@NotNull @Valid GeneralCommand command) { - // call processor + + var commandContext = + CommandContext.forSchemaObject( + new DatabaseSchemaObject(), null, command.getClass().getSimpleName(), null); + return meteredCommandProcessor - .processCommand(dataApiRequestInfo, CommandContext.EMPTY_COLLECTION, command) + .processCommand(dataApiRequestInfo, commandContext, command) // map to 2xx unless overridden by error .map(commandResult -> commandResult.map()); } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/v1/NamespaceResource.java b/src/main/java/io/stargate/sgv2/jsonapi/api/v1/NamespaceResource.java index a2f485aff9..c40eb732d0 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/v1/NamespaceResource.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/v1/NamespaceResource.java @@ -90,7 +90,7 @@ public Uni> postCommand( String namespace) { // create context - // TODO: Aaron , left here to see what CTOR was used, there was a lot of different onces. + // TODO: Aaron , left here to see what CTOR was used, there was a lot of different ones. // CommandContext commandContext = new CommandContext(namespace, null); // HACK TODO: The above did not set a command name on the command context, how did that work ? CommandContext commandContext = 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 new file mode 100644 index 0000000000..600f6106a4 --- /dev/null +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/DatabaseSchemaObject.java @@ -0,0 +1,20 @@ +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.notEnabledVectorConfig(); + } + + @Override + public IndexUsage newIndexUsage() { + return IndexUsage.NO_OP; + } +} diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/IndexUsage.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/IndexUsage.java index b846b37318..215112e513 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/IndexUsage.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/IndexUsage.java @@ -26,9 +26,10 @@ public void merge(IndexUsage indexUsage) { Tags getTags(); /** - * This method is used to merge the index usage of two different types for filters used in a query + * Method used to merge the index usage of two different types for filters used in a query; tags + * from {@code otherIndexUsage} are merged into {@code this} instance. * - * @param indexUsage + * @param otherIndexUsage the other index usage to merge into this instance */ - void merge(IndexUsage indexUsage); + void merge(IndexUsage otherIndexUsage); } 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 index 45ff57c2fd..e0eccb7482 100644 --- 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 @@ -9,13 +9,33 @@ public class KeyspaceSchemaObject extends SchemaObject { new KeyspaceSchemaObject(SchemaObjectName.MISSING); public KeyspaceSchemaObject(String keyspace) { - this(new SchemaObjectName(keyspace, SchemaObjectName.MISSING_NAME)); + 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.notEnabledVectorConfig(); @@ -25,4 +45,15 @@ public VectorConfig vectorConfig() { 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/SchemaObject.java b/src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/SchemaObject.java index c27c9637b8..7bee450192 100644 --- 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 @@ -9,6 +9,7 @@ public enum SchemaObjectType { TABLE, COLLECTION, KEYSPACE, + DATABASE } public final SchemaObjectType type; 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 index d68690d04c..e6df0fda62 100644 --- 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 @@ -13,9 +13,8 @@ public record SchemaObjectName(String keyspace, String table) { @SuppressWarnings("StringEquality") public SchemaObjectName(String keyspace, String table) { - // Check using reference equality for the missing value marker object, so we only allow emptry - // string if that - // object is used. + // 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( diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/CollectionReadOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/CollectionReadOperation.java index 44e16161e7..acff9c25d7 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/CollectionReadOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/CollectionReadOperation.java @@ -113,6 +113,7 @@ default Uni findDocument( Row row = rowIterator.next(); ReadDocument document = null; try { + // TODO: Use the field name, not the ordinal for the field this is too brittle JsonNode root = readDocument ? objectMapper.readTree(row.getString(2)) : null; if (root != null) { // create metrics diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/CreateCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/CreateCollectionOperation.java index cd58050e1d..2e9998279d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/CreateCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/CreateCollectionOperation.java @@ -17,6 +17,7 @@ import io.stargate.sgv2.jsonapi.exception.JsonApiException; import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +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.model.Operation; import io.stargate.sgv2.jsonapi.service.schema.model.JsonapiTableMatcher; @@ -31,7 +32,7 @@ import org.slf4j.LoggerFactory; public record CreateCollectionOperation( - CommandContext commandContext, + CommandContext commandContext, DatabaseLimitsConfig dbLimitsConfig, ObjectMapper objectMapper, CQLSessionCache cqlSessionCache, @@ -51,7 +52,7 @@ public record CreateCollectionOperation( private static final JsonapiTableMatcher COLLECTION_MATCHER = new JsonapiTableMatcher(); public static CreateCollectionOperation withVectorSearch( - CommandContext commandContext, + CommandContext commandContext, DatabaseLimitsConfig dbLimitsConfig, ObjectMapper objectMapper, CQLSessionCache cqlSessionCache, @@ -78,7 +79,7 @@ public static CreateCollectionOperation withVectorSearch( } public static CreateCollectionOperation withoutVectorSearch( - CommandContext commandContext, + CommandContext commandContext, DatabaseLimitsConfig dbLimitsConfig, ObjectMapper objectMapper, CQLSessionCache cqlSessionCache, @@ -308,6 +309,7 @@ private Multi createIndexParallel( public Uni cleanUpCollectionFailedWithTooManyIndex( DataApiRequestInfo dataApiRequestInfo, QueryExecutor queryExecutor) { + DeleteCollectionOperation deleteCollectionOperation = new DeleteCollectionOperation(commandContext, name); return deleteCollectionOperation diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/DeleteCollectionOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/DeleteCollectionOperation.java index 72c10cf625..dbfd71f7d9 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/DeleteCollectionOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/DeleteCollectionOperation.java @@ -5,7 +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.api.request.DataApiRequestInfo; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +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.model.Operation; import java.util.function.Supplier; @@ -18,7 +18,7 @@ * @param context Command context, carries namespace of the collection. * @param name Collection name. */ -public record DeleteCollectionOperation(CommandContext context, String name) +public record DeleteCollectionOperation(CommandContext context, String name) implements Operation { private static final Logger logger = LoggerFactory.getLogger(DeleteCollectionOperation.class); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/FindCollectionsOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/FindCollectionsOperation.java index 5e2f80abd7..b1f1674d8a 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/FindCollectionsOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/FindCollectionsOperation.java @@ -13,6 +13,7 @@ import io.stargate.sgv2.jsonapi.exception.JsonApiException; import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +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.model.Operation; import io.stargate.sgv2.jsonapi.service.schema.model.JsonapiTableMatcher; @@ -35,17 +36,19 @@ public record FindCollectionsOperation( ObjectMapper objectMapper, CQLSessionCache cqlSessionCache, JsonapiTableMatcher tableMatcher, - CommandContext commandContext) + CommandContext commandContext) implements Operation { // shared table matcher instance + // TODO: if this is static why does the record that have an instance variable passed by the ctor + // below ? private static final JsonapiTableMatcher TABLE_MATCHER = new JsonapiTableMatcher(); public FindCollectionsOperation( boolean explain, ObjectMapper objectMapper, CQLSessionCache cqlSessionCache, - CommandContext commandContext) { + CommandContext commandContext) { this(explain, objectMapper, cqlSessionCache, TABLE_MATCHER, commandContext); } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/FindOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/FindOperation.java index f26f83d750..91bbf201fd 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/FindOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/collections/FindOperation.java @@ -316,6 +316,8 @@ public Uni> execute( // map the response to result .map( docs -> { + // TODO: why is this here and not higher up where it can happen for any command result + // ? commandContext .jsonProcessingMetricsReporter() .reportJsonReadDocsMetrics(commandContext().commandName(), docs.docs().size()); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/tables/TableReadOperation.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/tables/TableReadOperation.java index cf9235c636..7662dcafaf 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/tables/TableReadOperation.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/tables/TableReadOperation.java @@ -1,9 +1,9 @@ package io.stargate.sgv2.jsonapi.service.operation.model.tables; -import com.google.common.base.Preconditions; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.LogicalExpression; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +import java.util.Objects; /** For now, a marker class / interface for operations that read data in a table. */ abstract class TableReadOperation extends TableOperation { @@ -13,9 +13,8 @@ abstract class TableReadOperation extends TableOperation { public TableReadOperation( CommandContext commandContext, LogicalExpression logicalExpression) { - Preconditions.checkNotNull(commandContext, "commandContext cannot be null"); - Preconditions.checkNotNull(logicalExpression, "logicalExpression cannot be null"); - this.commandContext = commandContext; - this.logicalExpression = logicalExpression; + this.commandContext = Objects.requireNonNull(commandContext, "commandContext cannot be null"); + this.logicalExpression = + Objects.requireNonNull(logicalExpression, "logicalExpression cannot be null"); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/CommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/CommandResolver.java index 36224eedcf..a982fbbeb4 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/CommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/CommandResolver.java @@ -1,6 +1,5 @@ package io.stargate.sgv2.jsonapi.service.resolver.model; -import com.google.common.base.Preconditions; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tags; @@ -13,6 +12,7 @@ import io.stargate.sgv2.jsonapi.service.cqldriver.executor.*; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.filters.DBFilterBase; +import java.util.Objects; /** * Resolver looks at a valid {@link Command} and determines the best {@link Operation} to implement @@ -57,13 +57,14 @@ public interface CommandResolver { @SuppressWarnings("unchecked") default Operation resolveCommand( CommandContext commandContext, C command) { - Preconditions.checkNotNull(commandContext, "commandContext must not be null"); - Preconditions.checkNotNull(command, "command must not be null"); + Objects.requireNonNull(commandContext, "commandContext must not be null"); + Objects.requireNonNull(command, "command must not be null"); return switch (commandContext.schemaObject().type) { case COLLECTION -> resolveCollectionCommand(commandContext.asCollectionContext(), command); case TABLE -> resolveTableCommand(commandContext.asTableContext(), command); case KEYSPACE -> resolveKeyspaceCommand(commandContext.asKeyspaceContext(), command); + case DATABASE -> resolveDatabaseCommand(commandContext.asDatabaseContext(), command); }; } @@ -80,7 +81,7 @@ default Operation resolveCollectionCommand( // commands are tested well throw new UnsupportedOperationException( String.format( - "%s Command does not support operating on Collectons, target was %s", + "%s Command does not support operating on Collections, target was %s", command.getClass().getSimpleName(), ctx.schemaObject().name)); } ; @@ -117,6 +118,22 @@ default Operation resolveKeyspaceCommand(CommandContext ct command.getClass().getSimpleName(), ctx.schemaObject().name)); } + /** + * Implementors should use this method when they can resolve commands for a databse. + * + * @param ctx + * @param command + * @return + */ + default Operation resolveDatabaseCommand(CommandContext ctx, C command) { + // there error is a fallback to make sure it is implemented if it should be + // commands are tested well + throw new UnsupportedOperationException( + String.format( + "%s Command does not support operating on Databases, target was %s", + command.getClass().getSimpleName(), ctx.schemaObject().name)); + } + static final String UNKNOWN_VALUE = "unknown"; static final String TENANT_TAG = "tenant"; diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionCommandResolver.java index 3c0fef0dc9..29cc5ee0eb 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionCommandResolver.java @@ -11,7 +11,7 @@ import io.stargate.sgv2.jsonapi.exception.ErrorCode; import io.stargate.sgv2.jsonapi.exception.JsonApiException; import io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.embedding.configuration.EmbeddingProvidersConfig; import io.stargate.sgv2.jsonapi.service.embedding.configuration.ProviderConstants; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; @@ -61,8 +61,8 @@ public Class getCommandClass() { } @Override - public Operation resolveCollectionCommand( - CommandContext ctx, CreateCollectionCommand command) { + public Operation resolveKeyspaceCommand( + CommandContext ctx, CreateCollectionCommand command) { if (command.options() == null) { return CreateCollectionOperation.withoutVectorSearch( ctx, diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateNamespaceCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateNamespaceCommandResolver.java index f1d6fa9454..ede0a17a98 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateNamespaceCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateNamespaceCommandResolver.java @@ -2,7 +2,7 @@ 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.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.CreateNamespaceOperation; import io.stargate.sgv2.jsonapi.service.resolver.model.CommandResolver; @@ -28,9 +28,8 @@ public Class getCommandClass() { /** {@inheritDoc} */ @Override - public Operation resolveCollectionCommand( - CommandContext ctx, CreateNamespaceCommand command) { - // TODO:Need a new Schema Object for this ! + public Operation resolveDatabaseCommand( + CommandContext ctx, CreateNamespaceCommand command) { String replicationMap = getReplicationMap(command.options()); return new CreateNamespaceOperation(command.name(), replicationMap); } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteCollectionCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteCollectionCommandResolver.java index 6b08bb9f17..25b67df1df 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteCollectionCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteCollectionCommandResolver.java @@ -2,7 +2,7 @@ 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.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.DeleteCollectionOperation; import io.stargate.sgv2.jsonapi.service.resolver.model.CommandResolver; @@ -17,8 +17,8 @@ public Class getCommandClass() { } @Override - public Operation resolveCollectionCommand( - CommandContext ctx, DeleteCollectionCommand command) { + public Operation resolveKeyspaceCommand( + CommandContext ctx, DeleteCollectionCommand command) { return new DeleteCollectionOperation(ctx, command.name()); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DropNamespaceCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DropNamespaceCommandResolver.java index b8f107b6ca..13fd410e05 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DropNamespaceCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DropNamespaceCommandResolver.java @@ -2,7 +2,7 @@ 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.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.DropNamespaceOperation; import io.stargate.sgv2.jsonapi.service.resolver.model.CommandResolver; @@ -20,9 +20,8 @@ public Class getCommandClass() { /** {@inheritDoc} */ @Override - public Operation resolveCollectionCommand( - CommandContext ctx, DropNamespaceCommand command) { - // TODO: Need a new schema object here + public Operation resolveDatabaseCommand( + CommandContext ctx, DropNamespaceCommand command) { return new DropNamespaceOperation(command.name()); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCollectionsCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCollectionsCommandResolver.java index d568594567..c24e2ffb0e 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCollectionsCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCollectionsCommandResolver.java @@ -4,7 +4,7 @@ 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.CQLSessionCache; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.FindCollectionsOperation; import io.stargate.sgv2.jsonapi.service.resolver.model.CommandResolver; @@ -32,8 +32,9 @@ public Class getCommandClass() { /** {@inheritDoc} */ @Override - public Operation resolveCollectionCommand( - CommandContext ctx, FindCollectionsCommand command) { + public Operation resolveKeyspaceCommand( + CommandContext ctx, FindCollectionsCommand command) { + boolean explain = command.options() != null ? command.options().explain() : false; return new FindCollectionsOperation(explain, objectMapper, cqlSessionCache, ctx); } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindEmbeddingProvidersCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindEmbeddingProvidersCommandResolver.java index c05917e684..f07fd6c150 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindEmbeddingProvidersCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindEmbeddingProvidersCommandResolver.java @@ -4,7 +4,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.impl.FindEmbeddingProvidersCommand; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.exception.ErrorCode; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +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.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.FindEmbeddingProvidersOperation; @@ -28,8 +28,8 @@ public Class getCommandClass() { } @Override - public Operation resolveCollectionCommand( - CommandContext ctx, FindEmbeddingProvidersCommand command) { + public Operation resolveDatabaseCommand( + CommandContext ctx, FindEmbeddingProvidersCommand command) { if (!operationsConfig.vectorizeEnabled()) { throw ErrorCode.VECTORIZE_FEATURE_NOT_AVAILABLE.toApiException(); } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindNamespacesCommandResolver.java b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindNamespacesCommandResolver.java index b22ac2e230..1dfa877018 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindNamespacesCommandResolver.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindNamespacesCommandResolver.java @@ -3,7 +3,7 @@ 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.CQLSessionCache; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.FindNamespacesOperations; import io.stargate.sgv2.jsonapi.service.resolver.model.CommandResolver; @@ -26,8 +26,8 @@ public Class getCommandClass() { /** {@inheritDoc} */ @Override - public Operation resolveCollectionCommand( - CommandContext ctx, FindNamespacesCommand command) { + public Operation resolveDatabaseCommand( + CommandContext ctx, FindNamespacesCommand command) { return new FindNamespacesOperations(cqlSessionCache); } } diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/model/JsonapiTableMatcher.java b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/model/JsonapiTableMatcher.java index 0b6442cd1e..d2a1bc08e9 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/schema/model/JsonapiTableMatcher.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/schema/model/JsonapiTableMatcher.java @@ -77,6 +77,8 @@ public JsonapiTableMatcher() { CqlIdentifier.fromInternal("query_null_values"), new PrimitiveType(ProtocolConstants.DataType.VARCHAR))); + // TODO: do not duplicate all of the code above below here, just add one extra predicate if we + // need to test for a vector. columnsPredicateVector = new CqlColumnMatcher.BasicType( CqlIdentifier.fromInternal("tx_id"), diff --git a/src/main/offline/io/stargate/sgv2/jsonapi/api/model/command/impl/BeginOfflineSessionCommand.java b/src/main/offline/io/stargate/sgv2/jsonapi/api/model/command/impl/BeginOfflineSessionCommand.java index eeb42212ae..0a2b4216cf 100644 --- a/src/main/offline/io/stargate/sgv2/jsonapi/api/model/command/impl/BeginOfflineSessionCommand.java +++ b/src/main/offline/io/stargate/sgv2/jsonapi/api/model/command/impl/BeginOfflineSessionCommand.java @@ -9,6 +9,7 @@ import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.request.FileWriterParams; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.VectorConfig; import io.stargate.sgv2.jsonapi.service.operation.model.collections.CreateCollectionOperation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.InsertOperation; @@ -153,9 +154,16 @@ private FileWriterParams buildFileWriterParams(CollectionSchemaObject collection boolean hasIndexing = indexingConfig != null; boolean hasVector = vectorSearchConfig != null; - var commandContext = + var tableCommandContext = CommandContext.forSchemaObject(collectionObject, null, this.createCollection.name(), null); + var keyspaceCommandContext = + CommandContext.forSchemaObject( + KeyspaceSchemaObject.fromSchemaObject(collectionObject), + null, + this.createCollection.name(), + null); + String comment = CreateCollectionCommandResolver.generateComment( new ObjectMapper(), @@ -168,7 +176,7 @@ private FileWriterParams buildFileWriterParams(CollectionSchemaObject collection CreateCollectionOperation createCollectionOperation = hasVector ? CreateCollectionOperation.withVectorSearch( - commandContext, + keyspaceCommandContext, null, new ObjectMapper(), null, @@ -182,7 +190,7 @@ private FileWriterParams buildFileWriterParams(CollectionSchemaObject collection false, false) : CreateCollectionOperation.withoutVectorSearch( - commandContext, + keyspaceCommandContext, null, new ObjectMapper(), null, @@ -202,7 +210,7 @@ private FileWriterParams buildFileWriterParams(CollectionSchemaObject collection .map(SimpleStatement::getQuery) .toList(); InsertOperation insertOperation = - InsertOperation.create(commandContext, List.of(), true, true, false); + InsertOperation.create(tableCommandContext, List.of(), true, true, false); String insertStatementCQL = insertOperation.buildInsertQuery(hasVector); return new FileWriterParams( this.namespace, diff --git a/src/test/java/io/stargate/sgv2/jsonapi/TestConstants.java b/src/test/java/io/stargate/sgv2/jsonapi/TestConstants.java index 27da8bda2f..4f5d30b6c2 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/TestConstants.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/TestConstants.java @@ -1,19 +1,22 @@ package io.stargate.sgv2.jsonapi; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; -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.executor.*; import org.apache.commons.lang3.RandomStringUtils; -/** Re-usable values for tests */ +/** + * Re-usable values for tests TODO: move this from static to instance so that the keyspace and + * collections names get generated for each test + */ public final class TestConstants { + // Random keyspace and collection names, NOTE: these are static for all tests public static final String KEYSPACE_NAME = RandomStringUtils.randomAlphanumeric(16); public static final String COLLECTION_NAME = RandomStringUtils.randomAlphanumeric(16); public static final SchemaObjectName SCHEMA_OBJECT_NAME = new SchemaObjectName(KEYSPACE_NAME, COLLECTION_NAME); + // Schema objects for testing public static final CollectionSchemaObject COLLECTION_SCHEMA_OBJECT = new CollectionSchemaObject( SCHEMA_OBJECT_NAME, @@ -21,8 +24,21 @@ public final class TestConstants { VectorConfig.notEnabledVectorConfig(), null); - public static final String COMMAND_NAME = "testCommand"; + public static final KeyspaceSchemaObject KEYSPACE_SCHEMA_OBJECT = + KeyspaceSchemaObject.fromSchemaObject(COLLECTION_SCHEMA_OBJECT); - public static final CommandContext CONTEXT = - new CommandContext<>(COLLECTION_SCHEMA_OBJECT, null, COMMAND_NAME, null); + public static final DatabaseSchemaObject DATABASE_SCHEMA_OBJECT = new DatabaseSchemaObject(); + + public static final String TEST_COMMAND_NAME = "testCommand"; + + // CommandContext for working on the schema objects above + + public static final CommandContext COLLECTION_CONTEXT = + new CommandContext<>(COLLECTION_SCHEMA_OBJECT, null, TEST_COMMAND_NAME, null); + + public static final CommandContext KEYSPACE_CONTEXT = + new CommandContext<>(KEYSPACE_SCHEMA_OBJECT, null, TEST_COMMAND_NAME, null); + + public static final CommandContext DATABASE_CONTEXT = + new CommandContext<>(DATABASE_SCHEMA_OBJECT, null, TEST_COMMAND_NAME, null); } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/CountOperationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/CountOperationTest.java index 06dca14c75..61344e3615 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/CountOperationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/CountOperationTest.java @@ -64,7 +64,8 @@ public void countWithNoFilter() { return CompletableFuture.supplyAsync(() -> mockResults).minimalCompletionStage(); }); - CountOperation countOperation = new CountOperation(CONTEXT, LogicalExpression.and(), 100, -1); + CountOperation countOperation = + new CountOperation(COLLECTION_CONTEXT, LogicalExpression.and(), 100, -1); Supplier execute = countOperation .execute(dataApiRequestInfo, queryExecutor) @@ -113,7 +114,7 @@ public void countWithDynamic() { .setDBFilters( List.of( new TextCollectionFilter("username", MapCollectionFilter.Operator.EQ, "user1"))); - CountOperation countOperation = new CountOperation(CONTEXT, implicitAnd, 100, -1); + CountOperation countOperation = new CountOperation(COLLECTION_CONTEXT, implicitAnd, 100, -1); Supplier execute = countOperation .execute(dataApiRequestInfo, queryExecutor) @@ -164,7 +165,7 @@ public void countWithDynamicNoMatch() { new TextCollectionFilter( "username", MapCollectionFilter.Operator.EQ, "user_all"))); - CountOperation countOperation = new CountOperation(CONTEXT, implicitAnd, 100, -1); + CountOperation countOperation = new CountOperation(COLLECTION_CONTEXT, implicitAnd, 100, -1); Supplier execute = countOperation .execute(dataApiRequestInfo, queryExecutor) @@ -203,7 +204,7 @@ public void error() { }); LogicalExpression implicitAnd = LogicalExpression.and(); - CountOperation countOperation = new CountOperation(CONTEXT, implicitAnd, 100, -1); + CountOperation countOperation = new CountOperation(COLLECTION_CONTEXT, implicitAnd, 100, -1); Throwable result = countOperation .execute(dataApiRequestInfo, queryExecutor) @@ -247,7 +248,8 @@ public void countWithNoFilter() { return CompletableFuture.supplyAsync(() -> mockResults).minimalCompletionStage(); }); - CountOperation countOperation = new CountOperation(CONTEXT, LogicalExpression.and(), 100, 10); + CountOperation countOperation = + new CountOperation(COLLECTION_CONTEXT, LogicalExpression.and(), 100, 10); Supplier execute = countOperation .execute(dataApiRequestInfo, queryExecutor) @@ -295,7 +297,7 @@ public void countWithDynamic() { .setDBFilters( List.of( new TextCollectionFilter("username", MapCollectionFilter.Operator.EQ, "user2"))); - CountOperation countOperation = new CountOperation(CONTEXT, implicitAnd, 100, 10); + CountOperation countOperation = new CountOperation(COLLECTION_CONTEXT, implicitAnd, 100, 10); Supplier execute = countOperation .execute(dataApiRequestInfo, queryExecutor) @@ -345,7 +347,7 @@ public void countWithDynamicNoMatch() { new TextCollectionFilter( "username", MapCollectionFilter.Operator.EQ, "user_all"))); - CountOperation countOperation = new CountOperation(CONTEXT, implicitAnd, 100, 10); + CountOperation countOperation = new CountOperation(COLLECTION_CONTEXT, implicitAnd, 100, 10); Supplier execute = countOperation .execute(dataApiRequestInfo, queryExecutor) @@ -384,7 +386,7 @@ public void error() { }); LogicalExpression implicitAnd = LogicalExpression.and(); - CountOperation countOperation = new CountOperation(CONTEXT, implicitAnd, 100, 10); + CountOperation countOperation = new CountOperation(COLLECTION_CONTEXT, implicitAnd, 100, 10); Throwable result = countOperation .execute(dataApiRequestInfo, queryExecutor) diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/CreateCollectionOperationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/CreateCollectionOperationTest.java index df95052cb0..30e1183e09 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/CreateCollectionOperationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/CreateCollectionOperationTest.java @@ -103,7 +103,7 @@ public void createCollectionNoVector() { CreateCollectionOperation operation = CreateCollectionOperation.withoutVectorSearch( - COMMAND_CONTEXT, + KEYSPACE_CONTEXT, databaseLimitsConfig, objectMapper, sessionCache, @@ -161,7 +161,7 @@ public void createCollectionVector() { CreateCollectionOperation operation = CreateCollectionOperation.withVectorSearch( - COMMAND_CONTEXT, + KEYSPACE_CONTEXT, databaseLimitsConfig, objectMapper, sessionCache, @@ -221,7 +221,7 @@ public void denyAllCollectionNoVector() { CreateCollectionOperation operation = CreateCollectionOperation.withoutVectorSearch( - COMMAND_CONTEXT, + KEYSPACE_CONTEXT, databaseLimitsConfig, objectMapper, sessionCache, @@ -279,7 +279,7 @@ public void denyAllCollectionVector() { CreateCollectionOperation operation = CreateCollectionOperation.withVectorSearch( - COMMAND_CONTEXT, + KEYSPACE_CONTEXT, databaseLimitsConfig, objectMapper, sessionCache, @@ -364,7 +364,7 @@ public void indexAlreadyDropTable() { CreateCollectionOperation operation = CreateCollectionOperation.withoutVectorSearch( - COMMAND_CONTEXT, + KEYSPACE_CONTEXT, databaseLimitsConfig, objectMapper, sessionCache, diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/OperationTestBase.java b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/OperationTestBase.java index 9aa823bbfb..bd5dcdeabb 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/OperationTestBase.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/OperationTestBase.java @@ -20,6 +20,7 @@ import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonProcessingMetricsReporter; import io.stargate.sgv2.jsonapi.config.constants.DocumentConstants; import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +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; @@ -36,17 +37,24 @@ public class OperationTestBase { protected final String COLLECTION_NAME = RandomStringUtils.randomAlphanumeric(16); protected final SchemaObjectName SCHEMA_OBJECT_NAME = new SchemaObjectName(KEYSPACE_NAME, COLLECTION_NAME); + protected final CollectionSchemaObject COLLECTION_SCHEMA_OBJECT = new CollectionSchemaObject( SCHEMA_OBJECT_NAME, CollectionSchemaObject.IdConfig.defaultIdConfig(), VectorConfig.notEnabledVectorConfig(), null); + protected final KeyspaceSchemaObject KEYSPACE_SCHEMA_OBJECT = + KeyspaceSchemaObject.fromSchemaObject(COLLECTION_SCHEMA_OBJECT); + protected final String COMMAND_NAME = "testCommand"; - protected final CommandContext CONTEXT = + protected final CommandContext COLLECTION_CONTEXT = new CommandContext<>( COLLECTION_SCHEMA_OBJECT, null, COMMAND_NAME, jsonProcessingMetricsReporter); + protected final CommandContext KEYSPACE_CONTEXT = + new CommandContext<>( + KEYSPACE_SCHEMA_OBJECT, null, COMMAND_NAME, jsonProcessingMetricsReporter); @InjectMock protected DataApiRequestInfo dataApiRequestInfo; diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/processor/MeteredCommandProcessorTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/processor/MeteredCommandProcessorTest.java index d7b2bbefb5..5c4437b75d 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/processor/MeteredCommandProcessorTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/processor/MeteredCommandProcessorTest.java @@ -51,7 +51,7 @@ public void metrics() throws Exception { CountDocumentsCommand countCommand = objectMapper.readValue(json, CountDocumentsCommand.class); - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; CommandResult commandResult = new CommandResult(Collections.emptyList()); Mockito.when( @@ -102,7 +102,7 @@ public void errorMetricsWithNoErrorCode() throws Exception { """; FindCommand countCommand = objectMapper.readValue(json, FindCommand.class); - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; Map fields = new HashMap<>(); fields.put("exceptionClass", "TestExceptionClass"); CommandResult.Error error = @@ -159,7 +159,7 @@ public void errorMetrics() throws Exception { CountDocumentsCommand countCommand = objectMapper.readValue(json, CountDocumentsCommand.class); - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; Map fields = new HashMap<>(); fields.put("exceptionClass", "TestExceptionClass"); fields.put("errorCode", "TestErrorCode"); diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CountDocumentsCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CountDocumentsCommandResolverTest.java index fb1646b2fe..a4ab01d51d 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CountDocumentsCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CountDocumentsCommandResolverTest.java @@ -34,7 +34,7 @@ class CountDocumentsCommandResolverTest { @Nested class ResolveCommand { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void noFilter() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionCommandResolverTest.java index 1f18a83c56..0ed7b75c6f 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionCommandResolverTest.java @@ -12,7 +12,7 @@ import io.stargate.sgv2.jsonapi.config.constants.TableCommentConstants; import io.stargate.sgv2.jsonapi.exception.ErrorCode; import io.stargate.sgv2.jsonapi.exception.JsonApiException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.CreateCollectionOperation; import jakarta.inject.Inject; @@ -29,7 +29,7 @@ class CreateCollectionCommandResolverTest { @Nested class ResolveCommand { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.KEYSPACE_CONTEXT; @Test public void happyPath() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionResolverVectorizeDisabledTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionResolverVectorizeDisabledTest.java index 62c3cb86c5..619cece8ea 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionResolverVectorizeDisabledTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateCollectionResolverVectorizeDisabledTest.java @@ -7,12 +7,10 @@ import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; import io.stargate.sgv2.jsonapi.TestConstants; -import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateCollectionCommand; import io.stargate.sgv2.jsonapi.api.model.command.impl.FindEmbeddingProvidersCommand; import io.stargate.sgv2.jsonapi.exception.ErrorCode; import io.stargate.sgv2.jsonapi.exception.JsonApiException; -import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSchemaObject; import jakarta.inject.Inject; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -27,8 +25,6 @@ public class CreateCollectionResolverVectorizeDisabledTest { @Nested class ResolveCommand { - CommandContext commandContext = TestConstants.CONTEXT; - @Test public void vectorizeSearchDisabled() throws Exception { String json = @@ -53,7 +49,9 @@ public void vectorizeSearchDisabled() throws Exception { CreateCollectionCommand command = objectMapper.readValue(json, CreateCollectionCommand.class); Exception e = catchException( - () -> createCollectionCommandResolver.resolveCommand(commandContext, command)); + () -> + createCollectionCommandResolver.resolveCommand( + TestConstants.KEYSPACE_CONTEXT, command)); assertThat(e) .isInstanceOf(JsonApiException.class) .hasMessageStartingWith(ErrorCode.VECTORIZE_FEATURE_NOT_AVAILABLE.getMessage()); @@ -61,6 +59,9 @@ public void vectorizeSearchDisabled() throws Exception { @Test public void findEmbeddingProvidersWithVectorizeSearchDisabled() throws Exception { + // TODO: This test should be moved, these are rests for create collection NOT for + // findEmbeddingProviders. + String json = """ { @@ -71,7 +72,9 @@ public void findEmbeddingProvidersWithVectorizeSearchDisabled() throws Exception objectMapper.readValue(json, FindEmbeddingProvidersCommand.class); Exception e = catchException( - () -> findEmbeddingProvidersCommandResolver.resolveCommand(commandContext, command)); + () -> + findEmbeddingProvidersCommandResolver.resolveCommand( + TestConstants.DATABASE_CONTEXT, command)); assertThat(e) .isInstanceOf(JsonApiException.class) .hasMessageStartingWith(ErrorCode.VECTORIZE_FEATURE_NOT_AVAILABLE.getMessage()); diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateNamespaceCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateNamespaceCommandResolverTest.java index fbe8ff6341..4d086a8f05 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateNamespaceCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CreateNamespaceCommandResolverTest.java @@ -8,7 +8,7 @@ import io.stargate.sgv2.jsonapi.TestConstants; 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.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.CreateNamespaceOperation; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; @@ -23,7 +23,7 @@ class CreateNamespaceCommandResolverTest { @Inject ObjectMapper objectMapper; @Inject CreateNamespaceCommandResolver resolver; - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.DATABASE_CONTEXT; @Nested class ResolveCommand { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteCollectionCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteCollectionCommandResolverTest.java index 2dbe952033..1d4ff7a801 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteCollectionCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteCollectionCommandResolverTest.java @@ -8,7 +8,7 @@ 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.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.DeleteCollectionOperation; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; @@ -26,7 +26,7 @@ class DeleteCollectionCommandResolverTest { @Nested class ResolveCommand { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.KEYSPACE_CONTEXT; @Test public void happyPath() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteManyCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteManyCommandResolverTest.java index 7a4da3f058..e38d0d40db 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteManyCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteManyCommandResolverTest.java @@ -37,7 +37,7 @@ public class DeleteManyCommandResolverTest { @Nested class ResolveCommand { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void idFilterCondition() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteOneCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteOneCommandResolverTest.java index 56cdd4187c..f877dcdad8 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteOneCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DeleteOneCommandResolverTest.java @@ -36,7 +36,7 @@ public class DeleteOneCommandResolverTest { @Nested class DeleteOneCommandResolveCommand { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void idFilterCondition() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DropNamespaceCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DropNamespaceCommandResolverTest.java index f1cd10adbb..517f4c2302 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DropNamespaceCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/DropNamespaceCommandResolverTest.java @@ -8,7 +8,7 @@ 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.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.DatabaseSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.DropNamespaceOperation; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; @@ -23,7 +23,7 @@ class DropNamespaceCommandResolverTest { @Inject ObjectMapper objectMapper; @Inject DropNamespaceCommandResolver resolver; - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.DATABASE_CONTEXT; @Nested class ResolveCommand { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCollectionCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCollectionCommandResolverTest.java index a57a75690d..e5927eaae8 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCollectionCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCollectionCommandResolverTest.java @@ -8,7 +8,7 @@ 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.CollectionSchemaObject; +import io.stargate.sgv2.jsonapi.service.cqldriver.executor.KeyspaceSchemaObject; import io.stargate.sgv2.jsonapi.service.operation.model.Operation; import io.stargate.sgv2.jsonapi.service.operation.model.collections.FindCollectionsOperation; import io.stargate.sgv2.jsonapi.testresource.NoGlobalResourcesTestProfile; @@ -26,7 +26,7 @@ public class FindCollectionCommandResolverTest { @Nested class FindCollectionCommandResolveCommand { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.KEYSPACE_CONTEXT; @Test public void findCollection() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCommandResolverTest.java index 6d1e9b5e3d..a2aa454d6b 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindCommandResolverTest.java @@ -40,7 +40,7 @@ public class FindCommandResolverTest { @Nested class FindCommandResolveCommand { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void idFilterCondition() throws Exception { @@ -996,7 +996,7 @@ public void emptyOr() throws Exception { @Nested class FindCommandResolveWithProjection { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void idFilterConditionAndProjection() throws Exception { @@ -1098,7 +1098,7 @@ public void noFilterConditionWithProjection() throws Exception { @Nested class FindCommandResolveWithINOperator { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void NonIdIn() throws Exception { @@ -1424,7 +1424,7 @@ public void ascendingSortNonIdInIdIn() throws Exception { @Nested class FindCommandResolveWithRangeOperator { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void gt() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndDeleteCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndDeleteCommandResolverTest.java index 2f493a3302..40ae438833 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndDeleteCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndDeleteCommandResolverTest.java @@ -39,7 +39,7 @@ public class FindOneAndDeleteCommandResolverTest { @Nested class Resolve { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void idFilterCondition() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndReplaceCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndReplaceCommandResolverTest.java index d5e11798a4..f1e8e23b46 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndReplaceCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndReplaceCommandResolverTest.java @@ -44,7 +44,7 @@ public class FindOneAndReplaceCommandResolverTest { @Nested class Resolve { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void idFilterCondition() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndUpdateCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndUpdateCommandResolverTest.java index 560c4b2247..f7b83fbcc8 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndUpdateCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneAndUpdateCommandResolverTest.java @@ -45,7 +45,7 @@ public class FindOneAndUpdateCommandResolverTest { @Nested class Resolve { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void idFilterCondition() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneCommandResolverTest.java index eeeed01fb5..b25ef095fe 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/FindOneCommandResolverTest.java @@ -35,7 +35,7 @@ public class FindOneCommandResolverTest { @Nested class Resolve { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void idFilterCondition() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/InsertManyCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/InsertManyCommandResolverTest.java index ba6b311205..98c6111af3 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/InsertManyCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/InsertManyCommandResolverTest.java @@ -31,7 +31,7 @@ public class InsertManyCommandResolverTest { @Nested class ResolveCommand { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void happyPath() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/InsertOneCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/InsertOneCommandResolverTest.java index d0c09e7bda..367731b331 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/InsertOneCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/InsertOneCommandResolverTest.java @@ -34,7 +34,7 @@ class InsertOneCommandResolverTest { @Nested class ResolveCommand { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void happyPath() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/UpdateManyCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/UpdateManyCommandResolverTest.java index 843578b884..1cd73c3684 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/UpdateManyCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/UpdateManyCommandResolverTest.java @@ -46,7 +46,7 @@ public class UpdateManyCommandResolverTest { @Nested class Resolve { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void idFilterCondition() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/UpdateOneCommandResolverTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/UpdateOneCommandResolverTest.java index 4b4c4f86aa..74f3bf4d51 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/UpdateOneCommandResolverTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/UpdateOneCommandResolverTest.java @@ -43,7 +43,7 @@ public class UpdateOneCommandResolverTest { @Nested class Resolve { - CommandContext commandContext = TestConstants.CONTEXT; + CommandContext commandContext = TestConstants.COLLECTION_CONTEXT; @Test public void idFilterCondition() throws Exception { diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/matcher/FilterMatchRuleTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/matcher/FilterMatchRuleTest.java index 9633f801b5..26fe712550 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/matcher/FilterMatchRuleTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/matcher/FilterMatchRuleTest.java @@ -51,7 +51,7 @@ public void apply() throws Exception { FilterMatchRule filterMatchRule = new FilterMatchRule(matcher); Optional response = - filterMatchRule.apply(TestConstants.CONTEXT, findOneCommand); + filterMatchRule.apply(TestConstants.COLLECTION_CONTEXT, findOneCommand); assertThat(response).isPresent(); matcher = new FilterMatcher<>(FilterMatcher.MatchStrategy.GREEDY, resolveFunction); @@ -59,7 +59,7 @@ public void apply() throws Exception { .capture("CAPTURE 1") .compareValues("*", EnumSet.of(ValueComparisonOperator.EQ), JsonType.NULL); filterMatchRule = new FilterMatchRule(matcher); - response = filterMatchRule.apply(TestConstants.CONTEXT, findOneCommand); + response = filterMatchRule.apply(TestConstants.COLLECTION_CONTEXT, findOneCommand); assertThat(response).isEmpty(); } @@ -87,7 +87,7 @@ public void testDynamicIn() throws Exception { .compareValues("*", EnumSet.of(ValueComparisonOperator.IN), JsonType.ARRAY); Optional response = - filterMatchRule.apply(TestConstants.CONTEXT, findOneCommand); + filterMatchRule.apply(TestConstants.COLLECTION_CONTEXT, findOneCommand); assertThat(response).isPresent(); } } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/matcher/FilterMatchRulesTest.java b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/matcher/FilterMatchRulesTest.java index 7b9ad094fb..6175455fea 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/matcher/FilterMatchRulesTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/matcher/FilterMatchRulesTest.java @@ -56,7 +56,8 @@ public void apply() throws Exception { .capture("TEST1") .compareValues("*", EnumSet.of(ValueComparisonOperator.EQ), JsonType.STRING); - LogicalExpression response = filterMatchRules.apply(TestConstants.CONTEXT, findOneCommand); + LogicalExpression response = + filterMatchRules.apply(TestConstants.COLLECTION_CONTEXT, findOneCommand); assertThat(response).isNotNull(); json = @@ -69,7 +70,7 @@ public void apply() throws Exception { """; findOneCommand = objectMapper.readValue(json, FindOneCommand.class); - response = filterMatchRules.apply(TestConstants.CONTEXT, findOneCommand); + response = filterMatchRules.apply(TestConstants.COLLECTION_CONTEXT, findOneCommand); assertThat(response).isNotNull(); } diff --git a/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/BeginOfflineSessionCommandResolverTest.java b/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/BeginOfflineSessionCommandResolverTest.java index 843f233426..e1df868503 100644 --- a/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/BeginOfflineSessionCommandResolverTest.java +++ b/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/BeginOfflineSessionCommandResolverTest.java @@ -4,7 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertInstanceOf; import com.fasterxml.jackson.databind.ObjectMapper; -import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; +import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.api.model.command.impl.BeginOfflineSessionCommand; import io.stargate.sgv2.jsonapi.api.model.command.impl.CreateCollectionCommand; import io.stargate.sgv2.jsonapi.service.operation.model.impl.BeginOfflineSessionOperation; @@ -24,7 +24,7 @@ public void verifyOperation() { assertInstanceOf( BeginOfflineSessionOperation.class, beginOfflineSessionCommandResolver.resolveCommand( - CommandContext.EMPTY_COLLECTION, + TestConstants.COLLECTION_CONTEXT, new BeginOfflineSessionCommand( "namespace1", createCollectionCommand, "ssTableOutputDirectory", 20))); assertEquals( diff --git a/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/EndOfflineSessionCommandResolverTest.java b/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/EndOfflineSessionCommandResolverTest.java index b135b5f00c..072dcfddd3 100644 --- a/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/EndOfflineSessionCommandResolverTest.java +++ b/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/EndOfflineSessionCommandResolverTest.java @@ -3,7 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; +import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.api.model.command.impl.EndOfflineSessionCommand; import io.stargate.sgv2.jsonapi.service.operation.model.impl.EndOfflineSessionOperation; import java.util.UUID; @@ -20,7 +20,7 @@ public void verifyOperation() { assertInstanceOf( EndOfflineSessionOperation.class, endOfflineSessionCommandResolver.resolveCommand( - CommandContext.EMPTY_COLLECTION, endOfflineSessionCommand)); + TestConstants.COLLECTION_CONTEXT, endOfflineSessionCommand)); assertEquals( EndOfflineSessionCommand.class, endOfflineSessionCommandResolver.getCommandClass()); } diff --git a/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/OfflineGetStatusCommandResolverTest.java b/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/OfflineGetStatusCommandResolverTest.java index 20ea29e566..de77107a76 100644 --- a/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/OfflineGetStatusCommandResolverTest.java +++ b/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/OfflineGetStatusCommandResolverTest.java @@ -4,7 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertInstanceOf; import com.fasterxml.jackson.databind.ObjectMapper; -import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; +import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.api.model.command.impl.OfflineGetStatusCommand; import io.stargate.sgv2.jsonapi.service.operation.model.impl.OfflineGetStatusOperation; import io.stargate.sgv2.jsonapi.service.shredding.Shredder; @@ -24,7 +24,7 @@ public void verifyOperation() { assertInstanceOf( OfflineGetStatusOperation.class, offlineGetStatusCommandResolver.resolveCommand( - CommandContext.EMPTY_COLLECTION, offlineGetStatusCommand)); + TestConstants.COLLECTION_CONTEXT, offlineGetStatusCommand)); assertEquals(OfflineGetStatusCommand.class, offlineGetStatusCommandResolver.getCommandClass()); } } diff --git a/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/OfflineInsertManyCommandResolverTest.java b/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/OfflineInsertManyCommandResolverTest.java index e02412a48a..c8a949854e 100644 --- a/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/OfflineInsertManyCommandResolverTest.java +++ b/src/test/offline/io/stargate/sgv2/jsonapi/service/resolver/model/impl/OfflineInsertManyCommandResolverTest.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; +import io.stargate.sgv2.jsonapi.TestConstants; import io.stargate.sgv2.jsonapi.api.model.command.impl.OfflineInsertManyCommand; import io.stargate.sgv2.jsonapi.config.OperationsConfig; import io.stargate.sgv2.jsonapi.service.operation.model.collections.InsertOperation; @@ -34,7 +34,7 @@ public void verifyOperation() { assertInstanceOf( InsertOperation.class, offlineInsertManyCommandResolver.resolveCommand( - CommandContext.EMPTY_COLLECTION, offlineInsertManyCommand)); + TestConstants.COLLECTION_CONTEXT, offlineInsertManyCommand)); assertEquals( OfflineInsertManyCommand.class, offlineInsertManyCommandResolver.getCommandClass()); } @@ -59,7 +59,7 @@ public void verifyOperationWhenMaxDocsExceeded() { IllegalArgumentException.class, () -> offlineInsertManyCommandResolver.resolveCommand( - CommandContext.EMPTY_COLLECTION, offlineInsertManyCommand), + TestConstants.COLLECTION_CONTEXT, offlineInsertManyCommand), "Exceeded max document insert count"); } }