fix(glue): return partitions in deterministic order from GetPartitions (#1335)

GlueService.getPartitions returned partitions in storage-scan order, which is
not stable across runs because partition keys embed the table name. Sort by
partition values so GetPartitions is deterministic, matching the existing
sorted-list convention in GlueService and the moto reference, which preserves a
stable partition order.

De-flakes the sdk-test-awscli "Glue catalog: table and partition lifecycle"
compatibility test, whose assertions assume a stable partition order.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-06-14 00:45:33 -05:00
1 parent f70709a70f
commit 08797954d9
2 files changed
+35

No files matched your search

@@ -391,9 +391,25 @@ public class GlueService {
String prefix = tableKey(databaseName, tableName) + ":";
return partitionStore.scan(k -> k.startsWith(prefix)).stream()
.filter(partition -> matchesPartitionExpression(table, partition, expression))
.sorted(GlueService::comparePartitionValues)
.toList();
}
// The partition store scan returns values in storage iteration order, which is not stable.
// Return partitions ordered by their values so GetPartitions is deterministic across calls.
private static int comparePartitionValues(Partition a, Partition b) {
List<String> aValues = a.getValues() == null ? List.of() : a.getValues();
List<String> bValues = b.getValues() == null ? List.of() : b.getValues();
int shared = Math.min(aValues.size(), bValues.size());
for (int i = 0; i < shared; i++) {
int comparison = Comparator.nullsFirst(String::compareTo).compare(aValues.get(i), bValues.get(i));
if (comparison != 0) {
return comparison;
}
}
return Integer.compare(aValues.size(), bValues.size());
}
public void deletePartition(String databaseName, String tableName, List<String> partitionValues) {
getPartition(databaseName, tableName, partitionValues);
String key = partitionKey(databaseName, tableName, partitionValues);