From 0a88dbd260110ed3d3c445cab3c5abd2533a1cce Mon Sep 17 00:00:00 2001 From: Yuqi Du Date: Tue, 16 Jan 2024 16:11:19 -0800 Subject: [PATCH 1/4] Fix --- .../command/deserializers/FilterClauseDeserializer.java | 6 ++++++ .../java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java | 2 +- .../jsonapi/exception/mappers/ThrowableToErrorMapper.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) 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 03387fe166..c35e56cba2 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 @@ -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; 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 afca17a9dd..bbae514ca6 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/exception/ErrorCode.java @@ -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"), INVALID_INDEXING_DEFINITION("Invalid indexing definition"), diff --git a/src/main/java/io/stargate/sgv2/jsonapi/exception/mappers/ThrowableToErrorMapper.java b/src/main/java/io/stargate/sgv2/jsonapi/exception/mappers/ThrowableToErrorMapper.java index 6c970c0f93..0f695bc62f 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/exception/mappers/ThrowableToErrorMapper.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/exception/mappers/ThrowableToErrorMapper.java @@ -72,7 +72,7 @@ public final class ThrowableToErrorMapper { if (message.contains("vector Date: Tue, 16 Jan 2024 16:20:18 -0800 Subject: [PATCH 2/4] add test --- .../jsonapi/api/v1/FindIntegrationTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/FindIntegrationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/FindIntegrationTest.java index ed60666397..9bb4675fd6 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/FindIntegrationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/FindIntegrationTest.java @@ -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 From 671abac68c0043bfab5f80949e75d0137b0f972e Mon Sep 17 00:00:00 2001 From: Yuqi Du Date: Tue, 16 Jan 2024 16:24:02 -0800 Subject: [PATCH 3/4] typo --- .../model/command/deserializers/FilterClauseDeserializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c35e56cba2..38be684d1e 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 @@ -378,7 +378,7 @@ private static Object jsonNodeValue(JsonNode node) { ErrorCode.INVALID_FILTER_EXPRESSION, "Date value has to be sent as epoch time"); } } else { - // handle an Invalid filter use case: + // handle an invalid filter use case: // { "address": { "street": { "$xx": xxx } } } throw new JsonApiException( ErrorCode.INVALID_FILTER_EXPRESSION, From 49721a9bc6841943dfd7d885de60807604f041c3 Mon Sep 17 00:00:00 2001 From: Yuqi Du Date: Tue, 16 Jan 2024 16:55:09 -0800 Subject: [PATCH 4/4] IT typo --- .../sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java index 765e923644..3184702119 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java @@ -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"));