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

invalid $ operator use case, INVALID_REQUEST typo fix #803

Merged
merged 5 commits into from
Jan 17, 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 @@ -377,6 +377,12 @@ private static Object jsonNodeValue(JsonNode node) {
throw new JsonApiException(
ErrorCode.INVALID_FILTER_EXPRESSION, "Date value has to be sent as epoch time");
}
} else {
// handle an invalid filter use case:
// { "address": { "street": { "$xx": xxx } } }
throw new JsonApiException(
ErrorCode.INVALID_FILTER_EXPRESSION,
String.format("Invalid use of %s operator", node.fields().next().getKey()));
}
} else {
ObjectNode objectNode = (ObjectNode) node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum ErrorCode {

FILTER_FIELDS_LIMIT_VIOLATION("Filter fields size limitation violated"),

INVALID_REQUST("Request not supported by the data store"),
INVALID_REQUEST("Request not supported by the data store"),
Yuqi-Du marked this conversation as resolved.
Show resolved Hide resolved

INVALID_INDEXING_DEFINITION("Invalid indexing definition"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public final class ThrowableToErrorMapper {
if (message.contains("vector<float,")) { // TODO is there a better way?
message = "Mismatched vector dimension";
}
fields = Map.of("errorCode", ErrorCode.INVALID_REQUST.name());
fields = Map.of("errorCode", ErrorCode.INVALID_REQUEST.name());
return new CommandResult.Error(message, fieldsForMetricsTag, fields, Response.Status.OK);
} else if (throwable instanceof DriverTimeoutException
|| throwable instanceof WriteTimeoutException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,27 @@ void dollarOperatorInFilterPathExpression() {
.body("errors[0].exceptionClass", is("JsonApiException"));
}

@Test
void invalidDollarOperatorPathExpression() {
String json =
"""
{ "find": { "filter" : {"address" : {"city" : {"$eq" : "Beijing"}}}}}
""";
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(json)
.when()
.post(CollectionResource.BASE_PATH, namespaceName, collectionName)
.then()
.statusCode(200)
.body("status", is(nullValue()))
.body("data", is(nullValue()))
.body("errors[0].message", endsWith("Invalid use of $eq operator"))
.body("errors[0].errorCode", is("INVALID_FILTER_EXPRESSION"))
.body("errors[0].exceptionClass", is("JsonApiException"));
}

@Test
public void exceedMaxFieldInFilter() {
// Max allowed 64, so fail with 65
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ public void failWithZerosVector() {
.statusCode(200)
.body("errors", is(notNullValue()))
.body("errors", hasSize(1))
.body("errors[0].errorCode", is("INVALID_REQUST"))
.body("errors[0].errorCode", is("INVALID_REQUEST"))
.body(
"errors[0].message",
endsWith("Zero vectors cannot be indexed or queried with cosine similarity"));
Expand Down