Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #898: improve error message for "multiple _id filters" case #913

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
tatu-at-datastax marked this conversation as resolved.
Show resolved Hide resolved

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
Loading