mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(dynamodb): prefix the Select conflict errors of Query and Scan (#5562)
This commit is contained in:
1 parent
2a04cd78c7
commit
9c9e5a1464
3 files changed
+50
-6
No files matched your search
+4
-2
@@ -56,11 +56,13 @@ final class DynamoDbAccessPathValidator {
|
||||
String select, String projectionExpression,
|
||||
JsonNode attributesToGet, JsonNode expressionAttributeNames) {
|
||||
if (projectionExpression != null && select != null && !"SPECIFIC_ATTRIBUTES".equals(select)) {
|
||||
throw validationException("Cannot specify the ProjectionExpression when choosing to get "
|
||||
throw validationException("1 validation error detected: "
|
||||
+ "Cannot specify the ProjectionExpression when choosing to get "
|
||||
+ ("COUNT".equals(select) ? "only the Count" : select));
|
||||
}
|
||||
if ("ALL_PROJECTED_ATTRIBUTES".equals(select) && !accessPath.isIndex()) {
|
||||
throw validationException("ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName");
|
||||
throw validationException("1 validation error detected: "
|
||||
+ "ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName");
|
||||
}
|
||||
if (attributesToGet != null && select != null && !"SPECIFIC_ATTRIBUTES".equals(select)) {
|
||||
throw validationException("Cannot use both Select and AttributesToGet unless Select is SPECIFIC_ATTRIBUTES");
|
||||
|
||||
+8
-4
@@ -392,13 +392,15 @@ class DynamoDbAccessPathValidatorTest {
|
||||
AwsException allAttributes = assertThrows(AwsException.class,
|
||||
() -> DynamoDbAccessPathValidator.validateSelection(
|
||||
table, tablePath, "ALL_ATTRIBUTES", "sk", null, null));
|
||||
assertEquals("Cannot specify the ProjectionExpression when choosing to get ALL_ATTRIBUTES",
|
||||
assertEquals("1 validation error detected: "
|
||||
+ "Cannot specify the ProjectionExpression when choosing to get ALL_ATTRIBUTES",
|
||||
allAttributes.getMessage());
|
||||
|
||||
AwsException count = assertThrows(AwsException.class,
|
||||
() -> DynamoDbAccessPathValidator.validateSelection(
|
||||
table, tablePath, "COUNT", "sk", null, null));
|
||||
assertEquals("Cannot specify the ProjectionExpression when choosing to get only the Count",
|
||||
assertEquals("1 validation error detected: "
|
||||
+ "Cannot specify the ProjectionExpression when choosing to get only the Count",
|
||||
count.getMessage());
|
||||
}
|
||||
|
||||
@@ -407,13 +409,15 @@ class DynamoDbAccessPathValidatorTest {
|
||||
AwsException both = assertThrows(AwsException.class,
|
||||
() -> DynamoDbAccessPathValidator.validateSelection(
|
||||
table, tablePath, "ALL_PROJECTED_ATTRIBUTES", "sk", null, null));
|
||||
assertEquals("Cannot specify the ProjectionExpression when choosing to get ALL_PROJECTED_ATTRIBUTES",
|
||||
assertEquals("1 validation error detected: "
|
||||
+ "Cannot specify the ProjectionExpression when choosing to get ALL_PROJECTED_ATTRIBUTES",
|
||||
both.getMessage());
|
||||
|
||||
AwsException indexOnly = assertThrows(AwsException.class,
|
||||
() -> DynamoDbAccessPathValidator.validateSelection(
|
||||
table, tablePath, "ALL_PROJECTED_ATTRIBUTES", null, null, null));
|
||||
assertEquals("ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName",
|
||||
assertEquals("1 validation error detected: "
|
||||
+ "ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName",
|
||||
indexOnly.getMessage());
|
||||
}
|
||||
|
||||
|
||||
+38
@@ -1121,6 +1121,44 @@ class NativeDynamoDbJsonHandlerTest {
|
||||
+ "when choosing to get SPECIFIC_ATTRIBUTES", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanPrefixesTheSelectConflicts() {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
AwsException count = expectValidationException("Scan", json("""
|
||||
{"TableName": "Users", "Select": "COUNT", "ProjectionExpression": "userId"}
|
||||
"""));
|
||||
assertEquals("1 validation error detected: Cannot specify the ProjectionExpression "
|
||||
+ "when choosing to get only the Count", count.getMessage());
|
||||
|
||||
AwsException allProjected = expectValidationException("Scan", json("""
|
||||
{"TableName": "Users", "Select": "ALL_PROJECTED_ATTRIBUTES"}
|
||||
"""));
|
||||
assertEquals("1 validation error detected: ALL_PROJECTED_ATTRIBUTES can be used only "
|
||||
+ "when Querying using an IndexName", allProjected.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryPrefixesTheSelectConflicts() {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
AwsException allAttributes = expectValidationException("Query", json("""
|
||||
{"TableName": "Users", "KeyConditionExpression": "userId = :u",
|
||||
"ExpressionAttributeValues": {":u": {"S": "a"}},
|
||||
"Select": "ALL_ATTRIBUTES", "ProjectionExpression": "userId"}
|
||||
"""));
|
||||
assertEquals("1 validation error detected: Cannot specify the ProjectionExpression "
|
||||
+ "when choosing to get ALL_ATTRIBUTES", allAttributes.getMessage());
|
||||
|
||||
AwsException allProjected = expectValidationException("Query", json("""
|
||||
{"TableName": "Users", "KeyConditionExpression": "userId = :u",
|
||||
"ExpressionAttributeValues": {":u": {"S": "a"}},
|
||||
"Select": "ALL_PROJECTED_ATTRIBUTES"}
|
||||
"""));
|
||||
assertEquals("1 validation error detected: ALL_PROJECTED_ATTRIBUTES can be used only "
|
||||
+ "when Querying using an IndexName", allProjected.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanAcceptsSegmentsAtTheBounds() throws Exception {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
Reference in new issue
Block a user