mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): refuse an ordering comparison or BETWEEN operand with no ordering (#7841)
* fix(dynamodb): refuse an ordering comparison or BETWEEN operand with no ordering * test(dynamodb): pin the SearchVectors ordering operand error before the comparator error
This commit is contained in:
1 parent
2a3dbb1aa4
commit
7748d2b51f
6 files changed
+90
-5
No files matched your search
@@ -897,6 +897,24 @@ class DynamoDbAccessPathIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(30)
|
||||
void queryRefusesAnOrderingOperandWithNoOrderingBeforeTheTableLookup() {
|
||||
String operandError = "Invalid KeyConditionExpression: Incorrect operand type for operator or function; "
|
||||
+ "operator or function: <, operand type: BOOL";
|
||||
for (String table : List.of(TABLE, "access-path-validation-missing")) {
|
||||
request("DynamoDB_20120810.Query", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"KeyConditionExpression":"pk = :pk AND sk < :sk",
|
||||
"ExpressionAttributeValues":{":pk":{"S":"p1"},":sk":{"BOOL":true}}
|
||||
}
|
||||
""".formatted(table))
|
||||
.statusCode(400)
|
||||
.body("message", equalTo(operandError));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void deleteTable() {
|
||||
|
||||
@@ -512,6 +512,18 @@ class DynamoDbVectorSearchIntegrationTest {
|
||||
+ "SearchConditionExpression");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
void searchVectorsChecksAnOrderingOperandTypeBeforeTheComparator() {
|
||||
expectValidation("SearchVectors", search(SCHEMA, "schema", 4, """
|
||||
,
|
||||
"SearchConditionExpression": "tenant < :t",
|
||||
"ExpressionAttributeValues": {":t": {"BOOL": true}}
|
||||
"""),
|
||||
"Invalid SearchConditionExpression: Incorrect operand type for operator or function; "
|
||||
+ "operator or function: <, operand type: BOOL");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void searchVectorsRejectsADimensionMismatch() {
|
||||
|
||||
@@ -772,6 +772,39 @@ class ExpressionEvaluatorTest {
|
||||
"ConditionExpression", null, values));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
|
||||
n < :v | {":v":{"BOOL":true}} | <, operand type: BOOL
|
||||
:v >= n | {":v":{"NULL":true}} | >=, operand type: NULL
|
||||
size(n) > :v | {":v":{"SS":["a"]}} | >, operand type: SS
|
||||
NOT n <= :v | {":v":{"L":[]}} | <=, operand type: L
|
||||
n BETWEEN :lo AND :hi | {":lo":{"N":"1"},":hi":{"BOOL":true}} | BETWEEN, operand type: BOOL
|
||||
n BETWEEN :lo AND :hi | {":lo":{"M":{}},":hi":{"BOOL":true}} | BETWEEN, operand type: M
|
||||
n BETWEEN :lo AND :hi | {":lo":{"N":"5"},":hi":{"NS":["1"]}} | BETWEEN, operand type: NS
|
||||
""")
|
||||
void anOrderingOperatorRefusesAnOperandTypeWithNoOrdering(String expression, String values, String error)
|
||||
throws Exception {
|
||||
JsonNode parsed = mapper.readTree(values);
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () ->
|
||||
ExpressionEvaluator.validateExpression(expression, "FilterExpression", null, parsed));
|
||||
assertEquals("Invalid FilterExpression: Incorrect operand type for operator or function; "
|
||||
+ "operator or function: " + error, e.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', quoteCharacter = '`', textBlock = """
|
||||
n < :v | {":v":{"B":"AQ=="}}
|
||||
n = :v | {":v":{"BOOL":true}}
|
||||
n <> :v | {":v":{"NULL":true}}
|
||||
""")
|
||||
void orderedTypesAndOtherComparisonsAreAccepted(String expression, String values) throws Exception {
|
||||
JsonNode parsed = mapper.readTree(values);
|
||||
|
||||
assertDoesNotThrow(() ->
|
||||
ExpressionEvaluator.validateExpression(expression, "FilterExpression", null, parsed));
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingOperandThrowsSyntaxError() {
|
||||
AwsException e = assertThrows(AwsException.class, () ->
|
||||
|
||||
@@ -2407,6 +2407,7 @@ class NativeDynamoDbJsonHandlerTest {
|
||||
PutItem | {"TableName":"Missing","Item":{"pk":{"S":"a"}},"ConditionExpression":"","ExpressionAttributeValues":{":v":{"S":"x"}}} | 1 validation error detected: Invalid ConditionExpression: The expression can not be empty;
|
||||
DeleteItem | {"TableName":"Missing","Key":{"pk":{"S":"a"}},"ConditionExpression":"a = :v"} | 1 validation error detected: Invalid ConditionExpression: An expression attribute value used in expression is not defined; attribute value: :v
|
||||
PutItem | {"TableName":"Missing","Item":{"pk":{"S":"a"}},"ConditionExpression":"a BETWEEN :b AND :a","ExpressionAttributeValues":{":a":{"N":"1"},":b":{"N":"5"}}} | 1 validation error detected: Invalid ConditionExpression: The BETWEEN operator requires upper bound to be greater than or equal to lower bound; lower bound operand: AttributeValue: {N:5}, upper bound operand: AttributeValue: {N:1}
|
||||
DeleteItem | {"TableName":"Missing","Key":{"pk":{"S":"a"}},"ConditionExpression":"a < :v","ExpressionAttributeValues":{":v":{"BOOL":true}}} | 1 validation error detected: Invalid ConditionExpression: Incorrect operand type for operator or function; operator or function: <, operand type: BOOL
|
||||
""")
|
||||
void aPutOrDeleteChecksItsConditionMembersInOrderInsideTheEnvelope(String operation, String request,
|
||||
String message) throws Exception {
|
||||
|
||||
Reference in new issue
Block a user