mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): order unprojected PartiQL columns by name hash (#8867)
* fix(dynamodb): order unprojected PartiQL columns by name hash
This commit is contained in:
1 parent
10824e6701
commit
0aa5ecd1de
2 files changed
+29
-2
No files matched your search
@@ -584,7 +584,6 @@ 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())) {
|
||||
@@ -595,7 +594,10 @@ class DynamoDbPartiQLHandler {
|
||||
.map(Path::root)
|
||||
.filter(c -> !"*".equals(c))
|
||||
.filter(c -> !projected.contains(c))
|
||||
.distinct()
|
||||
.map(Utf8Name::new)
|
||||
.collect(Collectors.toCollection(HashSet::new))
|
||||
.stream()
|
||||
.map(Utf8Name::name)
|
||||
.toList();
|
||||
if (!unprojected.isEmpty()) {
|
||||
throw DynamoDbAccessPathValidator.unprojectedGsiAttributes(accessPath.indexName(), unprojected);
|
||||
@@ -606,6 +608,14 @@ class DynamoDbPartiQLHandler {
|
||||
return cond.bareAttribute().filter(keyName::equals).isPresent();
|
||||
}
|
||||
|
||||
// DynamoDB lists the unprojected columns in the order of a HashSet that hashes their UTF-8 bytes.
|
||||
private record Utf8Name(String name) {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(name.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
private record SelectedColumn(Path path, String reportedName) {}
|
||||
|
||||
private static List<SelectedColumn> selectedColumns(Stmt.Select stmt) {
|
||||
|
||||
+17
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@@ -1012,6 +1013,22 @@ class DynamoDbPartiQLEdgeCaseIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(37)
|
||||
void listsUnprojectedColumnsInTheSameOrderWhateverTheStatementOrder() {
|
||||
String refused = "One or more parameter values were invalid: Global secondary index gsi-inc does not project ";
|
||||
Map<List<String>, String> lists = Map.of(
|
||||
List.of("nonproj", "lsiSk"), "[nonproj, lsiSk]",
|
||||
List.of("lsiSk", "nonproj"), "[nonproj, lsiSk]",
|
||||
List.of("alpha", "beta", "gamma", "delta"), "[delta, alpha, gamma, beta]",
|
||||
List.of("x1", "x2", "x3", "x10", "x20"), "[x10, x20, x1, x2, x3]");
|
||||
|
||||
lists.forEach((columns, list) -> statement("SELECT " + String.join(", ", columns)
|
||||
+ " FROM \"partiql-edge-cases-index\".\"gsi-inc\" WHERE gsiPk = 'y'")
|
||||
.statusCode(400)
|
||||
.body("message", equalTo(refused + list)));
|
||||
}
|
||||
|
||||
private static void putItem(String pk, String attributes) {
|
||||
putItem(pk, "1", attributes);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user