fix(dynamodb): match AWS for unprojected GSI attributes in Query, Scan and PartiQL (#5911)

* fix(dynamodb): use the AWS wording for unprojected GSI attributes in Query and Scan

* refactor(dynamodb): share the unprojected GSI attribute error with PartiQL

* fix(dynamodb): check PartiQL GSI columns after the WHERE clause

AWS reports a key type mismatch, overlapping ranges, too many reads and an
unprojected filter attribute before an unprojected column. It also lists
each column root once.

* fix(dynamodb): keep rejecting a projection path that starts with a list index
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-18 00:55:47 -04:00
1 parent b55014ddef
commit 61102a7c4e
7 files changed
+111 -36

No files matched your search

@@ -19,6 +19,7 @@ import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
@@ -71,11 +72,12 @@ final class DynamoDbAccessPathValidator {
return;
}
if ("ALL_ATTRIBUTES".equals(select)) {
throw validationException("Select type ALL_ATTRIBUTES is not supported for global secondary index "
throw validationException("One or more parameter values were invalid: "
+ "Select type ALL_ATTRIBUTES is not supported for global secondary index "
+ accessPath.indexName() + " because its projection type is not ALL");
}
Set<String> requestedAttributes = new HashSet<>();
Set<String> requestedAttributes = new LinkedHashSet<>();
if (projectionExpression != null) {
requestedAttributes.addAll(ProjectionEvaluator.topLevelAttributes(
projectionExpression, expressionAttributeNames));
@@ -87,12 +89,15 @@ final class DynamoDbAccessPathValidator {
Set<String> projectedAttributes = accessPath.projectedAttributeNames(table);
requestedAttributes.removeAll(projectedAttributes);
if (!requestedAttributes.isEmpty()) {
throw validationException("One or more parameter values were invalid: Global secondary index "
+ accessPath.indexName() + " does not project "
+ String.join(", ", requestedAttributes.stream().sorted().toList()));
throw unprojectedGsiAttributes(accessPath.indexName(), requestedAttributes);
}
}
static AwsException unprojectedGsiAttributes(String indexName, Collection<String> attributes) {
return validationException("One or more parameter values were invalid: Global secondary index "
+ indexName + " does not project [" + String.join(", ", attributes) + "]");
}
private static void rejectWithSelect(String parameter, boolean present, String select) {
if (present && select != null && !"SPECIFIC_ATTRIBUTES".equals(select)) {
throw validationException("1 validation error detected: "
@@ -66,31 +66,12 @@ class DynamoDbPartiQLHandler {
"Strongly consistent read is not supported on Global Secondary Indexes", 400);
}
// A GSI-qualified statement can only select attributes the index
// projects; the message preserves statement order (characterised on
// real AWS, eu-west-1, 2026-09-02). An LSI read reaches the co-located
// base item, so non-projected columns stay legal there.
if (accessPath.isGlobalSecondaryIndex() && !"ALL".equals(accessPath.projectionType())
&& !stmt.columns().isEmpty()) {
Set<String> projected = accessPath.projectedAttributeNames(table);
List<String> unprojected = stmt.columns().stream()
.map(Path::root)
.filter(c -> !"*".equals(c))
.filter(c -> !projected.contains(c))
.toList();
if (!unprojected.isEmpty()) {
throw new AwsException("ValidationException",
"One or more parameter values were invalid: Global secondary index "
+ accessPath.indexName() + " does not project ["
+ String.join(", ", unprojected) + "]", 400);
}
}
DynamoDbPartiQLKeyPlan keys = new DynamoDbPartiQLKeyPlan(stmt.where(), accessPath, table);
keys.requireKeyTypesMatchSchema();
keys.requireNoOverlap();
keys.requireReadsWithinLimit();
requireFilterAttributesProjected(keys, accessPath, table);
requireColumnsProjected(stmt, accessPath, table);
Routing routing = routingOf(stmt.where(), keys, accessPath.partitionKeyName(), accessPath.sortKeyName());
Supplier<JsonNode> startKey = () -> decodeNextToken(ctx.nextToken(), ctx.tokenBinding());
@@ -503,6 +484,25 @@ class DynamoDbPartiQLHandler {
}
}
// An LSI read reaches the co-located base item, so non-projected columns stay legal there.
// AWS lists each root once, in an order of its own that is not the statement order.
private static void requireColumnsProjected(Stmt.Select stmt, DynamoDbAccessPath accessPath,
TableDefinition table) {
if (!accessPath.isGlobalSecondaryIndex() || "ALL".equals(accessPath.projectionType())) {
return;
}
Set<String> projected = accessPath.projectedAttributeNames(table);
List<String> unprojected = stmt.columns().stream()
.map(Path::root)
.filter(c -> !"*".equals(c))
.filter(c -> !projected.contains(c))
.distinct()
.toList();
if (!unprojected.isEmpty()) {
throw DynamoDbAccessPathValidator.unprojectedGsiAttributes(accessPath.indexName(), unprojected);
}
}
private static boolean isKeyCondition(Cond cond, String keyName) {
return cond.bareAttribute().filter(keyName::equals).isPresent();
}
@@ -7,8 +7,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -65,14 +66,19 @@ final class ProjectionEvaluator {
}
static Set<String> topLevelAttributes(String projectionExpression, JsonNode exprAttrNames) {
HashSet<String> attributes = new HashSet<>();
Set<String> attributes = new LinkedHashSet<>();
for (String rawPath : splitProjectionPaths(projectionExpression)) {
List<PathSegment> segments = resolvePath(rawPath.trim(), exprAttrNames);
if (!segments.isEmpty()) {
attributes.add(segments.getFirst().name());
if (segments.isEmpty()) {
continue;
}
PathSegment root = segments.getFirst();
if (root.isIndex()) {
throw new IllegalArgumentException("Projection path starts with a list index: " + rawPath.trim());
}
attributes.add(root.name());
}
return Set.copyOf(attributes);
return Collections.unmodifiableSet(attributes);
}
static void validateSyntax(String expression, String expressionType) {