From c160e3cc0d7327bb2b605962d03c5cc2496fbd0a Mon Sep 17 00:00:00 2001 From: YuqiDu Date: Mon, 4 Nov 2024 17:40:17 -0800 Subject: [PATCH] Can not sort table update delete (#1638) Co-authored-by: Aaron Morton --- .../sgv2/jsonapi/exception/SortException.java | 2 ++ .../resolver/DeleteOneCommandResolver.java | 9 +++++++++ .../resolver/UpdateOneCommandResolver.java | 9 +++++++++ src/main/resources/errors.yaml | 20 +++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/main/java/io/stargate/sgv2/jsonapi/exception/SortException.java b/src/main/java/io/stargate/sgv2/jsonapi/exception/SortException.java index 0fc7b1e8c..e5ff36a2d 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/exception/SortException.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/exception/SortException.java @@ -15,6 +15,8 @@ public SortException(ErrorInstance errorInstance) { public enum Code implements ErrorCode { CANNOT_MIX_VECTOR_AND_NON_VECTOR_SORT, + CANNOT_SORT_TABLE_DELETE_COMMAND, + CANNOT_SORT_TABLE_UPDATE_COMMAND, CANNOT_SORT_UNKNOWN_COLUMNS, CANNOT_VECTOR_SORT_NON_INDEXED_VECTOR_COLUMNS, CANNOT_VECTOR_SORT_NON_VECTOR_COLUMNS, 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 2ff31a3c0..d8365f534 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 @@ -1,5 +1,7 @@ package io.stargate.sgv2.jsonapi.service.resolver; +import static io.stargate.sgv2.jsonapi.exception.ErrorFormatters.errVars; + import com.fasterxml.jackson.databind.ObjectMapper; import io.micrometer.core.instrument.MeterRegistry; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; @@ -9,6 +11,7 @@ import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonApiMetricsConfig; import io.stargate.sgv2.jsonapi.config.DebugModeConfig; 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; @@ -65,6 +68,12 @@ public DeleteOneCommandResolver( public Operation resolveTableCommand( CommandContext ctx, DeleteOneCommand command) { + // Sort clause is not supported for table deleteOne command. + if (command.sortClause() != null && !command.sortClause().isEmpty()) { + throw SortException.Code.CANNOT_SORT_TABLE_DELETE_COMMAND.get( + errVars(ctx.schemaObject(), map -> {})); + } + var builder = new DeleteAttemptBuilder<>(ctx.schemaObject(), true); // need to update so we use WithWarnings correctly 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 a269845be..9938f6613 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 @@ -1,5 +1,7 @@ package io.stargate.sgv2.jsonapi.service.resolver; +import static io.stargate.sgv2.jsonapi.exception.ErrorFormatters.errVars; + import com.fasterxml.jackson.databind.ObjectMapper; import io.micrometer.core.instrument.MeterRegistry; import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; @@ -9,6 +11,7 @@ import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonApiMetricsConfig; import io.stargate.sgv2.jsonapi.config.DebugModeConfig; 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.*; @@ -79,6 +82,12 @@ public Class getCommandClass() { public Operation resolveTableCommand( CommandContext ctx, UpdateOneCommand command) { + // Sort clause is not supported for table updateOne command. + if (command.sortClause() != null && !command.sortClause().isEmpty()) { + throw SortException.Code.CANNOT_SORT_TABLE_UPDATE_COMMAND.get( + errVars(ctx.schemaObject(), map -> {})); + } + var builder = new UpdateAttemptBuilder<>(ctx.schemaObject()); // need to update so we use WithWarnings correctly diff --git a/src/main/resources/errors.yaml b/src/main/resources/errors.yaml index 78ab64282..b00dffce9 100644 --- a/src/main/resources/errors.yaml +++ b/src/main/resources/errors.yaml @@ -778,6 +778,26 @@ request-errors: Resend the command using only vector columns that have been indexed. + - scope: SORT + code: CANNOT_SORT_TABLE_DELETE_COMMAND + title: Sort supplied for non sortable delete Table command + body: |- + The command attempted to sort a delete command running against a table. + + Deleting rows in a table does not support sorting, rows can only be deleted by specifying the partition key(s) and optionally the clustering key(s) for the row(s) to be deleted. + + Resend the command without the sort clause. + + - scope: SORT + code: CANNOT_SORT_TABLE_UPDATE_COMMAND + title: Sort supplied for non sortable update Table command + body: |- + The command attempted to sort a update command running against a table. + + Updating row in a table does not support sorting, a row can only be updated by specifying full primary key(s). + + Resend the command without the sort clause. + # ================================================================================================================ # ================================================================================================================ # Server Errors