mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(dynamodb): check the Scan segment pairing after the Select checks (#5857)
* fix(dynamodb): check the Scan segment pairing after the Select checks * fix(dynamodb): check the Scan Select conflicts before the segment pairing
This commit is contained in:
1 parent
2a012cf9a4
commit
5b12c620aa
4 files changed
+72
-29
No files matched your search
+8
-4
@@ -52,15 +52,19 @@ final class DynamoDbAccessPathValidator {
|
||||
return partitionKeyValuePlaceholder;
|
||||
}
|
||||
|
||||
static void validateSelection(TableDefinition table, DynamoDbAccessPath accessPath,
|
||||
String select, String projectionExpression,
|
||||
JsonNode attributesToGet, JsonNode expressionAttributeNames) {
|
||||
static void validateSelection(String select, String indexName,
|
||||
String projectionExpression, JsonNode attributesToGet) {
|
||||
rejectWithSelect("ProjectionExpression", projectionExpression != null, select);
|
||||
rejectWithSelect("AttributesToGet", attributesToGet != null, select);
|
||||
if ("ALL_PROJECTED_ATTRIBUTES".equals(select) && !accessPath.isIndex()) {
|
||||
if ("ALL_PROJECTED_ATTRIBUTES".equals(select) && indexName == null) {
|
||||
throw validationException("1 validation error detected: "
|
||||
+ "ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName");
|
||||
}
|
||||
}
|
||||
|
||||
static void validateGsiProjection(TableDefinition table, DynamoDbAccessPath accessPath,
|
||||
String select, String projectionExpression,
|
||||
JsonNode attributesToGet, JsonNode expressionAttributeNames) {
|
||||
if (!accessPath.isGlobalSecondaryIndex() || "ALL".equals(accessPath.projectionType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
+17
-15
@@ -1139,7 +1139,8 @@ public class NativeDynamoDbJsonHandler {
|
||||
DynamoDbAccessPath queryAccessPath = DynamoDbAccessPath.resolve(queryTable, indexName);
|
||||
DynamoDbAccessPathValidator.validateQuery(queryTable, queryAccessPath, keyConditions,
|
||||
keyConditionExpr, filterExpr, queryFilter, exprAttrNames, exprAttrValues);
|
||||
DynamoDbAccessPathValidator.validateSelection(queryTable, queryAccessPath, select,
|
||||
DynamoDbAccessPathValidator.validateSelection(select, indexName, projectionExpression, attributesToGet);
|
||||
DynamoDbAccessPathValidator.validateGsiProjection(queryTable, queryAccessPath, select,
|
||||
projectionExpression, attributesToGet, exprAttrNames);
|
||||
rejectConsistentReadOnGsi(request, queryAccessPath);
|
||||
|
||||
@@ -1257,19 +1258,6 @@ public class NativeDynamoDbJsonHandler {
|
||||
List.of("AttributesToGet", "ScanFilter", "ConditionalOperator"),
|
||||
List.of("ProjectionExpression", "FilterExpression"));
|
||||
|
||||
if (segment != null && totalSegments == null) {
|
||||
throw new AwsException("ValidationException",
|
||||
"The TotalSegments parameter is required but was not present in the request when Segment parameter is present", 400);
|
||||
}
|
||||
if (totalSegments != null && segment == null) {
|
||||
throw new AwsException("ValidationException",
|
||||
"The Segment parameter is required but was not present in the request when parameter TotalSegments is present", 400);
|
||||
}
|
||||
if (segment != null && totalSegments != null && segment >= totalSegments) {
|
||||
throw new AwsException("ValidationException",
|
||||
"The Segment parameter is zero-based and must be less than parameter TotalSegments", 400);
|
||||
}
|
||||
|
||||
DynamoDbExpressionSize.checkReadWithSize(filterExpr, "FilterExpression");
|
||||
DynamoDbExpressionSize.checkRead(projectionExpressionScan, "ProjectionExpression");
|
||||
DynamoDbAttributeValueValidator.requireNestingWithinLimit(exprAttrValues);
|
||||
@@ -1295,10 +1283,24 @@ public class NativeDynamoDbJsonHandler {
|
||||
throw new AwsException("ValidationException",
|
||||
"1 validation error detected: " + SELECT_NEEDS_PROJECTION, 400);
|
||||
}
|
||||
DynamoDbAccessPathValidator.validateSelection(select, indexNameScan,
|
||||
projectionExpressionScan, attributesToGetScan);
|
||||
if (segment != null && totalSegments == null) {
|
||||
throw new AwsException("ValidationException",
|
||||
"The TotalSegments parameter is required but was not present in the request when Segment parameter is present", 400);
|
||||
}
|
||||
if (totalSegments != null && segment == null) {
|
||||
throw new AwsException("ValidationException",
|
||||
"The Segment parameter is required but was not present in the request when parameter TotalSegments is present", 400);
|
||||
}
|
||||
if (segment != null && totalSegments != null && segment >= totalSegments) {
|
||||
throw new AwsException("ValidationException",
|
||||
"The Segment parameter is zero-based and must be less than parameter TotalSegments", 400);
|
||||
}
|
||||
|
||||
TableDefinition scanTable = dynamoDbService.requireTableForItemCall(tableName, region);
|
||||
DynamoDbAccessPath scanAccessPath = DynamoDbAccessPath.resolve(scanTable, indexNameScan);
|
||||
DynamoDbAccessPathValidator.validateSelection(scanTable, scanAccessPath, select,
|
||||
DynamoDbAccessPathValidator.validateGsiProjection(scanTable, scanAccessPath, select,
|
||||
projectionExpressionScan, attributesToGetScan, exprAttrNames);
|
||||
rejectConsistentReadOnGsi(request, scanAccessPath);
|
||||
|
||||
|
||||
Reference in new issue
Block a user