Skip to content

Commit

Permalink
Fixes #898: improve error message for "multiple _id filters" case (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatu-at-datastax authored Mar 4, 2024
1 parent f06db87 commit 1492d0f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,8 +39,7 @@ private static List<Expression<BuiltCondition>> buildExpressionWithId(
Expression<BuiltCondition> expressionWithoutId,
List<DBFilterBase.IDFilter> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
});
}

Expand Down

0 comments on commit 1492d0f

Please sign in to comment.