mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(dynamodb): use the AWS wording when Query or Scan rejects AttributesToGet with a Select (#5599)
* fix(dynamodb): use the AWS wording when Query or Scan rejects AttributesToGet with a Select * refactor(dynamodb): share the Select conflict check for ProjectionExpression and AttributesToGet
This commit is contained in:
1 parent
ddc0e0257b
commit
dd0f40fcbb
2 files changed
+34
-8
No files matched your search
+10
-8
@@ -55,18 +55,12 @@ final class DynamoDbAccessPathValidator {
|
||||
static void validateSelection(TableDefinition table, DynamoDbAccessPath accessPath,
|
||||
String select, String projectionExpression,
|
||||
JsonNode attributesToGet, JsonNode expressionAttributeNames) {
|
||||
if (projectionExpression != null && select != null && !"SPECIFIC_ATTRIBUTES".equals(select)) {
|
||||
throw validationException("1 validation error detected: "
|
||||
+ "Cannot specify the ProjectionExpression when choosing to get "
|
||||
+ ("COUNT".equals(select) ? "only the Count" : select));
|
||||
}
|
||||
rejectWithSelect("ProjectionExpression", projectionExpression != null, select);
|
||||
rejectWithSelect("AttributesToGet", attributesToGet != null, select);
|
||||
if ("ALL_PROJECTED_ATTRIBUTES".equals(select) && !accessPath.isIndex()) {
|
||||
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");
|
||||
}
|
||||
if (!accessPath.isGlobalSecondaryIndex() || "ALL".equals(accessPath.projectionType())) {
|
||||
return;
|
||||
}
|
||||
@@ -93,6 +87,14 @@ final class DynamoDbAccessPathValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void rejectWithSelect(String parameter, boolean present, String select) {
|
||||
if (present && select != null && !"SPECIFIC_ATTRIBUTES".equals(select)) {
|
||||
throw validationException("1 validation error detected: "
|
||||
+ "Cannot specify the " + parameter + " when choosing to get "
|
||||
+ ("COUNT".equals(select) ? "only the Count" : select));
|
||||
}
|
||||
}
|
||||
|
||||
private static String validateKeyConditionExpression(TableDefinition table,
|
||||
DynamoDbAccessPath accessPath,
|
||||
String expression, JsonNode names,
|
||||
|
||||
+24
@@ -1159,6 +1159,30 @@ class NativeDynamoDbJsonHandlerTest {
|
||||
+ "when Querying using an IndexName", allProjected.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanNamesTheSelectWhenRejectingAttributesToGet() {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
AwsException ex = expectValidationException("Scan", json("""
|
||||
{"TableName": "Users", "Select": "COUNT", "AttributesToGet": ["userId"]}
|
||||
"""));
|
||||
assertEquals("1 validation error detected: Cannot specify the AttributesToGet "
|
||||
+ "when choosing to get only the Count", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryReportsTheAttributesToGetConflictBeforeTheMissingIndex() {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
AwsException ex = expectValidationException("Query", json("""
|
||||
{"TableName": "Users",
|
||||
"KeyConditions": {"userId": {"ComparisonOperator": "EQ", "AttributeValueList": [{"S": "a"}]}},
|
||||
"Select": "ALL_PROJECTED_ATTRIBUTES", "AttributesToGet": ["userId"]}
|
||||
"""));
|
||||
assertEquals("1 validation error detected: Cannot specify the AttributesToGet "
|
||||
+ "when choosing to get ALL_PROJECTED_ATTRIBUTES", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanAcceptsSegmentsAtTheBounds() throws Exception {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
Reference in new issue
Block a user