Skip to content

Commit

Permalink
Can not sort table update delete (#1638)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Morton <aaron.morton@datastax.com>
  • Loading branch information
Yuqi-Du and amorton authored Nov 5, 2024
1 parent 6533223 commit c160e3c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public SortException(ErrorInstance errorInstance) {

public enum Code implements ErrorCode<SortException> {
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -65,6 +68,12 @@ public DeleteOneCommandResolver(
public Operation resolveTableCommand(
CommandContext<TableSchemaObject> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -79,6 +82,12 @@ public Class<UpdateOneCommand> getCommandClass() {
public Operation resolveTableCommand(
CommandContext<TableSchemaObject> 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
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/errors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c160e3c

Please sign in to comment.