mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(dynamodb): read every attribute through an ALL-projection index in PartiQL (#3309)
A PartiQL read qualified with a secondary index trimmed each item to the attributes the index projects, but projectedAttributeNames returns only key attributes for an ALL projection, because "all attributes" cannot be enumerated from a schemaless table. Query, Scan and the selection validator each guard that case with "ALL".equals(projectionType); the PartiQL read path did not. Against an index that stores the whole item, a qualified SELECT * therefore dropped every non-key attribute, and naming one explicitly was rejected with "does not project". Both are wrong data rather than an error, and both disappear on the same statement against the base table. The existing coverage used only INCLUDE and KEYS_ONLY indexes, so neither case surfaced. The integration test adds an ALL-projection index and asserts SELECT *, an explicit non-key column, and Query over the same index agreeing; the INCLUDE and KEYS_ONLY expectations are unchanged.
This commit is contained in:
1 parent
2fbe2b7c64
commit
4cb9314a2d
3 files changed
+101
-3
No files matched your search
+16
@@ -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-");
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -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<String> projected = accessPath.projectedAttributeNames(table);
|
||||
List<String> 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<String> projected = accessPath.projectedAttributeNames(table);
|
||||
items = items.stream()
|
||||
.map(item -> (JsonNode) ProjectionEvaluator.trimToAttributes((ObjectNode) item, projected))
|
||||
|
||||
+80
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user