fix(dynamodb): prefix the Select conflict errors of Query and Scan (#5562)

This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-13 11:39:27 -04:00
1 parent 2a04cd78c7
commit 9c9e5a1464
3 files changed
+50 -6

No files matched your search

@@ -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");
@@ -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());
}
@@ -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");