diff --git a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/deserializers/FilterClauseDeserializer.java b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/deserializers/FilterClauseDeserializer.java index 38be684d1e..5435b7d4a5 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/deserializers/FilterClauseDeserializer.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/api/model/command/deserializers/FilterClauseDeserializer.java @@ -135,8 +135,7 @@ private void populateExpression( private void validate(LogicalExpression logicalExpression) { if (logicalExpression.getTotalIdComparisonExpressionCount() > 1) { - throw new JsonApiException( - ErrorCode.FILTER_MULTIPLE_ID_FILTER, ErrorCode.FILTER_MULTIPLE_ID_FILTER.getMessage()); + throw ErrorCode.FILTER_MULTIPLE_ID_FILTER.toApiException(); } for (LogicalExpression subLogicalExpression : logicalExpression.logicalExpressions) { validate(subLogicalExpression); diff --git a/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java b/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java index 61655d353a..d50a151c16 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java @@ -29,7 +29,7 @@ public enum ErrorCode { FILTER_UNRESOLVABLE("Unable to resolve the filter"), FILTER_MULTIPLE_ID_FILTER( - "Should only have one _id filter, document id cannot be restricted by more than one relation if it includes an Equal"), + "Cannot have more than one _id equals filter clause: use $in operator instead"), FILTER_FIELDS_LIMIT_VIOLATION("Filter fields size limitation violated"), diff --git a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/ExpressionBuilder.java b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/ExpressionBuilder.java index 525784d9f9..92ae3806e6 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/ExpressionBuilder.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/ExpressionBuilder.java @@ -7,7 +7,6 @@ import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.ComparisonExpression; import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.LogicalExpression; import io.stargate.sgv2.jsonapi.exception.ErrorCode; -import io.stargate.sgv2.jsonapi.exception.JsonApiException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -40,8 +39,7 @@ private static List> buildExpressionWithId( Expression expressionWithoutId, List idFilters) { if (idFilters.size() > 1) { - throw new JsonApiException( - ErrorCode.FILTER_MULTIPLE_ID_FILTER, ErrorCode.FILTER_MULTIPLE_ID_FILTER.getMessage()); + throw ErrorCode.FILTER_MULTIPLE_ID_FILTER.toApiException(); } if (idFilters.isEmpty() && additionalIdFilter == null) { // no idFilters in filter clause and no additionalIdFilter diff --git a/src/test/java/io/stargate/sgv2/jsonapi/api/model/command/deserializers/FilterClauseDeserializerTest.java b/src/test/java/io/stargate/sgv2/jsonapi/api/model/command/deserializers/FilterClauseDeserializerTest.java index 6b14784e24..e83ef161ed 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/api/model/command/deserializers/FilterClauseDeserializerTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/api/model/command/deserializers/FilterClauseDeserializerTest.java @@ -9,6 +9,7 @@ import io.stargate.sgv2.common.testprofiles.NoGlobalResourcesTestProfile; import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.*; import io.stargate.sgv2.jsonapi.config.OperationsConfig; +import io.stargate.sgv2.jsonapi.exception.ErrorCode; import io.stargate.sgv2.jsonapi.exception.JsonApiException; import io.stargate.sgv2.jsonapi.service.shredding.model.DocumentId; import jakarta.inject.Inject; @@ -1493,8 +1494,7 @@ public void multipleIdFilterAndOr() throws Exception { .satisfies( t -> { assertThat(t.getMessage()) - .isEqualTo( - "Should only have one _id filter, document id cannot be restricted by more than one relation if it includes an Equal"); + .isEqualTo(ErrorCode.FILTER_MULTIPLE_ID_FILTER.getMessage()); }); }