fix(dynamodb): resume a Query after the ExclusiveStartKey position, whether or not an item has that key (#8021)

Closes #7970
This commit is contained in:
Niels Kootstra authored and GitHub committed 2026-11-11 11:43:29 -04:00
1 parent d0d0e0eef8
commit 29253ff7f8
2 files changed
+96 -44

No files matched your search

@@ -879,6 +879,62 @@ class DynamoDbServiceTest {
.toList());
}
@Test
void queryResumesAfterTheStartKeyOfAnItemDeletedSinceThePreviousPage() {
createPagingTable();
service.deleteItem("Paging", item("PK", "p", "SK", "s2"), "us-east-1");
assertEquals(List.of("s3", "s4", "s5"),
pagingQuery(null, true, item("PK", "p", "SK", "s2")));
}
@Test
void queryResumesAfterAStartKeyThatNeverExisted() {
createPagingTable();
assertEquals(List.of("s4", "s5"), pagingQuery(null, true, item("PK", "p", "SK", "s3x")));
}
@Test
void descendingQueryResumesBeforeAStartKeyThatNeverExisted() {
createPagingTable();
assertEquals(List.of("s3", "s2", "s1"), pagingQuery(null, false, item("PK", "p", "SK", "s3x")));
}
@Test
void indexQueryResumesAfterTheStartKeyOfAnItemReKeyedSinceThePreviousPage() {
createPagingTable();
service.putItem("Paging", item("PK", "p", "SK", "s3", "G", "live", "GS", "t9"), "us-east-1");
assertEquals(List.of("s4", "s5", "s3"),
pagingQuery("gsi1", true, item("PK", "p", "SK", "s3", "G", "live", "GS", "t3")));
}
private void createPagingTable() {
GlobalSecondaryIndex gsi = new GlobalSecondaryIndex("gsi1",
List.of(new KeySchemaElement("G", "HASH"), new KeySchemaElement("GS", "RANGE")),
null, "ALL", null);
service.createTable("Paging",
List.of(new KeySchemaElement("PK", "HASH"), new KeySchemaElement("SK", "RANGE")),
List.of(new AttributeDefinition("PK", "S"), new AttributeDefinition("SK", "S"),
new AttributeDefinition("G", "S"), new AttributeDefinition("GS", "S")),
5L, 5L, List.of(gsi), "us-east-1");
for (int i = 1; i <= 5; i++) {
service.putItem("Paging", item("PK", "p", "SK", "s" + i, "G", "live", "GS", "t" + i), "us-east-1");
}
}
private List<String> pagingQuery(String indexName, boolean forward, ObjectNode exclusiveStartKey) {
ObjectNode exprValues = mapper.createObjectNode();
exprValues.set(":v", attributeValue("S", indexName == null ? "p" : "live"));
String keyCondition = indexName == null ? "PK = :v" : "G = :v";
return service.query("Paging", null, exprValues, keyCondition, null, null, forward, indexName,
exclusiveStartKey, null, "us-east-1").items().stream()
.map(result -> result.get("SK").get("S").asText())
.toList();
}
private void createRequestsTableWithCompositeSortKeyGsi(String region) {
GlobalSecondaryIndex gsi = new GlobalSecondaryIndex(
"memberIndex",