diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/DynamoDbPartiQLTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/DynamoDbPartiQLTest.java index 516275d987..1147b3b236 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/DynamoDbPartiQLTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/DynamoDbPartiQLTest.java @@ -349,4 +349,20 @@ class DynamoDbPartiQLTest { .isEqualTo("NextToken does not match request"); }); } + + @Test + @Order(20) + void executeStatementReadsEveryAttributeThroughAllProjectionIndex() { + // status-index projects ALL, so a qualified read returns attributes that + // belong to no key, and naming one explicitly stays legal. + ExecuteStatementResponse all = ddb.executeStatement(r -> r + .statement("SELECT * FROM \"" + INDEX_TABLE + "\".\"status-index\" WHERE status = 'active'")); + assertThat(all.items()).hasSize(2); + assertThat(all.items().get(0)).containsKey("alternate"); + + ExecuteStatementResponse explicit = ddb.executeStatement(r -> r + .statement("SELECT alternate FROM \"" + INDEX_TABLE + "\".\"status-index\" WHERE status = 'active'")); + assertThat(explicit.items()).hasSize(2); + assertThat(explicit.items().get(0).get("alternate").s()).startsWith("alt-"); + } } diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbPartiQLHandler.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbPartiQLHandler.java index a4ffff4e32..032b79acbb 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbPartiQLHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbPartiQLHandler.java @@ -56,7 +56,7 @@ class DynamoDbPartiQLHandler { // 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()) { + if (accessPath.isGlobalSecondaryIndex() && !"ALL".equals(accessPath.projectionType())) { Set projected = accessPath.projectedAttributeNames(table); List unprojected = stmt.columns().stream() .filter(c -> !"*".equals(c)) @@ -151,8 +151,10 @@ class DynamoDbPartiQLHandler { .toList(); } - // SELECT * over an index reads the projection, not the whole item. - if (stmt.columns().isEmpty() && accessPath.isIndex()) { + // SELECT * over an index reads the projection, not the whole item. An + // ALL projection stores every base attribute, so nothing is trimmed. + if (stmt.columns().isEmpty() && accessPath.isIndex() + && !"ALL".equals(accessPath.projectionType())) { Set projected = accessPath.projectedAttributeNames(table); items = items.stream() .map(item -> (JsonNode) ProjectionEvaluator.trimToAttributes((ObjectNode) item, projected)) diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathIntegrationTest.java index 629f9d27b1..aabb2329cb 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathIntegrationTest.java @@ -23,6 +23,7 @@ class DynamoDbAccessPathIntegrationTest { private static final String CONTENT_TYPE = "application/x-amz-json-1.0"; private static final String TABLE = "access-path-validation"; private static final String SIBLING_TABLE = "access-path-validation-sibling"; + private static final String ALL_PROJECTION_TABLE = "access-path-validation-all-projection"; @BeforeAll static void configureRestAssured() { @@ -755,6 +756,85 @@ class DynamoDbAccessPathIntegrationTest { } } + @Test + @Order(29) + void executeStatementReadsEveryAttributeThroughAllProjectionIndex() { + // An ALL projection stores every base attribute, so a qualified read + // returns them all and an explicit non-key column stays legal. Query + // and Scan already skip the projection trim for ALL; ExecuteStatement + // kept only the key attributes, so a caller reading its own data + // through an ALL-projection index silently lost every non-key + // attribute. + given() + .header("X-Amz-Target", "DynamoDB_20120810.CreateTable") + .contentType(CONTENT_TYPE) + .body(""" + { + "TableName":"%s", + "AttributeDefinitions":[ + {"AttributeName":"pk","AttributeType":"S"}, + {"AttributeName":"runId","AttributeType":"S"} + ], + "KeySchema":[{"AttributeName":"pk","KeyType":"HASH"}], + "GlobalSecondaryIndexes":[{ + "IndexName":"all-projection-index", + "KeySchema":[{"AttributeName":"runId","KeyType":"HASH"}], + "Projection":{"ProjectionType":"ALL"} + }], + "BillingMode":"PAY_PER_REQUEST" + } + """.formatted(ALL_PROJECTION_TABLE)) + .when() + .post("/") + .then() + .statusCode(200); + try { + request("DynamoDB_20120810.PutItem", """ + { + "TableName":"%s", + "Item":{"pk":{"S":"p1"},"runId":{"S":"run-1"},"rowsInserted":{"N":"7"}} + } + """.formatted(ALL_PROJECTION_TABLE)) + .statusCode(200); + + request("DynamoDB_20120810.ExecuteStatement", """ + {"Statement":"SELECT * FROM \\"%s\\".\\"all-projection-index\\" WHERE runId = 'run-1'"} + """.formatted(ALL_PROJECTION_TABLE)) + .statusCode(200) + .body("Items.size()", equalTo(1)) + .body("Items[0].rowsInserted.N", equalTo("7")); + + request("DynamoDB_20120810.ExecuteStatement", """ + {"Statement":"SELECT rowsInserted FROM \\"%s\\".\\"all-projection-index\\" WHERE runId = 'run-1'"} + """.formatted(ALL_PROJECTION_TABLE)) + .statusCode(200) + .body("Items.size()", equalTo(1)) + .body("Items[0].rowsInserted.N", equalTo("7")); + + // Query over the same index is the behaviour ExecuteStatement must match. + request("DynamoDB_20120810.Query", """ + { + "TableName":"%s", + "IndexName":"all-projection-index", + "KeyConditionExpression":"runId = :r", + "ExpressionAttributeValues":{":r":{"S":"run-1"}} + } + """.formatted(ALL_PROJECTION_TABLE)) + .statusCode(200) + .body("Items.size()", equalTo(1)) + .body("Items[0].rowsInserted.N", equalTo("7")); + } finally { + given() + .header("X-Amz-Target", "DynamoDB_20120810.DeleteTable") + .contentType(CONTENT_TYPE) + .body("{\"TableName\":\"" + ALL_PROJECTION_TABLE + "\"}") + .when() + .post("/") + .then() + .statusCode(200); + } + } + @Test @Order(99) void deleteTable() {