mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(dynamodb): drop the table name from the PartiQL missing table error, and treat a CREATING table as missing (#7158)
This commit is contained in:
1 parent
e77823feed
commit
89ecb594e1
5 files changed
+77
-13
No files matched your search
+6
-6
@@ -46,7 +46,7 @@ class DynamoDbPartiQLHandler {
|
||||
// --- SELECT ---
|
||||
|
||||
private Result executeSelect(Stmt.Select stmt, PartiQLExecuteContext ctx, String region) {
|
||||
TableDefinition table = service.describeTable(stmt.table(), region);
|
||||
TableDefinition table = service.requireTableForItemCall(stmt.table(), region);
|
||||
// A vector index is reachable through SearchVectors alone, and PartiQL says so
|
||||
// rather than reporting the index as missing.
|
||||
if (table.findVectorIndex(stmt.index()).isPresent()) {
|
||||
@@ -544,7 +544,7 @@ class DynamoDbPartiQLHandler {
|
||||
// --- INSERT ---
|
||||
|
||||
private Result executeInsert(Stmt.Insert stmt, String region) {
|
||||
TableDefinition table = service.describeTable(stmt.table(), region);
|
||||
TableDefinition table = service.requireTableForItemCall(stmt.table(), region);
|
||||
String pkName = table.getPartitionKeyName();
|
||||
|
||||
ObjectNode item = mapper.createObjectNode();
|
||||
@@ -564,7 +564,7 @@ class DynamoDbPartiQLHandler {
|
||||
|
||||
private Result executeUpdate(Stmt.Update stmt, String returnValuesOnConditionCheckFailure, String region) {
|
||||
requireNoIndexQualifier(stmt.index());
|
||||
TableDefinition table = service.describeTable(stmt.table(), region);
|
||||
TableDefinition table = service.requireTableForItemCall(stmt.table(), region);
|
||||
requireOneValuePerKey(table, stmt.where());
|
||||
ObjectNode key = buildKey(table, stmt.where());
|
||||
|
||||
@@ -619,7 +619,7 @@ class DynamoDbPartiQLHandler {
|
||||
|
||||
private Result executeDelete(Stmt.Delete stmt, String returnValuesOnConditionCheckFailure, String region) {
|
||||
requireNoIndexQualifier(stmt.index());
|
||||
TableDefinition table = service.describeTable(stmt.table(), region);
|
||||
TableDefinition table = service.requireTableForItemCall(stmt.table(), region);
|
||||
requireOneValuePerKey(table, stmt.where());
|
||||
ObjectNode key = buildKey(table, stmt.where());
|
||||
|
||||
@@ -652,7 +652,7 @@ class DynamoDbPartiQLHandler {
|
||||
case Stmt.Delete del -> del.index();
|
||||
default -> null;
|
||||
});
|
||||
Optional<TableDefinition> found = service.findTable(stmt.table(), region);
|
||||
Optional<TableDefinition> found = service.findTableForItemCall(stmt.table(), region);
|
||||
if (found.isEmpty()) {
|
||||
return TransactMember.TABLE_NOT_FOUND;
|
||||
}
|
||||
@@ -767,7 +767,7 @@ class DynamoDbPartiQLHandler {
|
||||
}
|
||||
|
||||
TransactMember toTransactGetItem(Stmt.Select stmt, String region) {
|
||||
Optional<TableDefinition> found = service.findTable(stmt.table(), region);
|
||||
Optional<TableDefinition> found = service.findTableForItemCall(stmt.table(), region);
|
||||
if (found.isEmpty()) {
|
||||
return TransactMember.TABLE_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -4928,12 +4928,11 @@ public class DynamoDbService {
|
||||
}
|
||||
|
||||
private TableDefinition requireActiveTable(String storageKey) {
|
||||
TableDefinition table = tableStore.get(storageKey)
|
||||
.orElseThrow(DynamoDbService::itemCallResourceNotFound);
|
||||
if ("CREATING".equals(table.getTableStatus())) {
|
||||
throw itemCallResourceNotFound();
|
||||
}
|
||||
return table;
|
||||
return findActiveTable(storageKey).orElseThrow(DynamoDbService::itemCallResourceNotFound);
|
||||
}
|
||||
|
||||
private Optional<TableDefinition> findActiveTable(String storageKey) {
|
||||
return tableStore.get(storageKey).filter(table -> !"CREATING".equals(table.getTableStatus()));
|
||||
}
|
||||
|
||||
/** Resolves a table for an item call, so a miss reports the message AWS uses there. */
|
||||
@@ -4942,6 +4941,11 @@ public class DynamoDbService {
|
||||
return requireActiveTable(regionKey(region, canonicalTableName));
|
||||
}
|
||||
|
||||
/** Finds a table for an item call, which treats a CREATING table as absent. */
|
||||
public Optional<TableDefinition> findTableForItemCall(String tableName, String region) {
|
||||
return findActiveTable(regionKey(region, canonicalTableName(region, tableName)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the table for an item call and validates the key it names, without reading the
|
||||
* stored item, so a caller can report table and key errors before its own validation.
|
||||
|
||||
+1
-1
@@ -3841,10 +3841,10 @@ public class NativeDynamoDbJsonHandler {
|
||||
// WHERE clauses are rejected per statement (characterised on real AWS,
|
||||
// eu-west-1, 2026-09-02).
|
||||
private void requireBatchSelectReadsByKey(DynamoDbPartiQLParser.Stmt.Select select, String region) {
|
||||
TableDefinition table = dynamoDbService.requireTableForItemCall(select.table(), region);
|
||||
if (select.index() != null) {
|
||||
throw batchSelectNeedsKey();
|
||||
}
|
||||
TableDefinition table = dynamoDbService.requireTableForItemCall(select.table(), region);
|
||||
DynamoDbPartiQLHandler.requireReadsWithinLimit(table, select.where());
|
||||
if (!DynamoDbPartiQLHandler.namesOnlyTheKey(table, select.where())) {
|
||||
throw batchSelectNeedsKey();
|
||||
|
||||
+25
@@ -8,6 +8,8 @@ import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
@@ -599,6 +601,29 @@ class DynamoDbPartiQLIntegrationTest {
|
||||
.body("Responses[0].Error.Message", equalTo(notWellFormed));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@Order(29)
|
||||
@ValueSource(strings = {
|
||||
"SELECT * FROM \"%s\" WHERE pk = 'x'",
|
||||
"SELECT * FROM \"%s\".\"gsi\" WHERE pk = 'x'",
|
||||
"INSERT INTO \"%s\" VALUE {'pk': 'x'}",
|
||||
"UPDATE \"%s\" SET a = 1 WHERE pk = 'x'",
|
||||
"DELETE FROM \"%s\" WHERE pk = 'x'",
|
||||
"FROM \"%s\" WHERE pk = 'x' SET c = 1"})
|
||||
void aStatementOnAMissingTableIsRefusedWithoutTheTableName(String statement) {
|
||||
String partiql = statement.formatted(TABLE + "-never-created");
|
||||
|
||||
statement(partiql)
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"))
|
||||
.body("message", equalTo("Requested resource not found"));
|
||||
request("DynamoDB_20120810.BatchExecuteStatement",
|
||||
"{\"Statements\":[{\"Statement\":\"" + partiql.replace("\"", "\\\"") + "\"}]}")
|
||||
.statusCode(200)
|
||||
.body("Responses[0].Error.Code", equalTo("ResourceNotFound"))
|
||||
.body("Responses[0].Error.Message", equalTo("Requested resource not found"));
|
||||
}
|
||||
|
||||
private static void putItem(String pk, String attributes) {
|
||||
request("DynamoDB_20120810.PutItem", """
|
||||
{"TableName":"%s","Item":{"pk":{"S":"%s"},%s}}
|
||||
|
||||
+35
@@ -16,6 +16,8 @@ import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
@@ -2533,6 +2535,39 @@ class NativeDynamoDbJsonHandlerTest {
|
||||
assertEquals("Requested resource not found", ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"SELECT * FROM \"Users\".\"TitleIndex\" WHERE userId = 'u1'",
|
||||
"INSERT INTO \"Users\" VALUE {'userId': 1}",
|
||||
"UPDATE \"Users\" SET a = 1 WHERE userId = 1",
|
||||
"DELETE FROM \"Users\" WHERE nope = 'u1'"})
|
||||
void executeStatementAnswersResourceNotFoundForACreatingTableBeforeTheKeyCheck(String statement) {
|
||||
createUsersTable("eu-west-1").setTableStatus("CREATING");
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("Statement", statement);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> handler.handle("ExecuteStatement", request, "eu-west-1"));
|
||||
assertEquals("ResourceNotFoundException", ex.getErrorCode());
|
||||
assertEquals("Requested resource not found", ex.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"SELECT * FROM \"Users\" WHERE userId = 'u1'",
|
||||
"UPDATE \"Users\" SET a = 1 WHERE userId = 'u1'"})
|
||||
void executeTransactionCancelsOnACreatingTable(String statement) throws Exception {
|
||||
createUsersTable("eu-west-1").setTableStatus("CREATING");
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.putArray("TransactStatements").addObject().put("Statement", statement);
|
||||
|
||||
Response response = handler.handle("ExecuteTransaction", request, "eu-west-1");
|
||||
assertEquals(400, response.getStatus());
|
||||
JsonNode reason = mapper.convertValue(response.getEntity(), JsonNode.class).get("CancellationReasons").get(0);
|
||||
assertEquals("ResourceNotFound", reason.get("Code").asText());
|
||||
assertEquals("Requested resource not found", reason.get("Message").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void transactWriteItemsFailsTheRequestOnAnEmptyKeyAheadOfAKeyMismatch() {
|
||||
createUsersTable("eu-west-1");
|
||||
|
||||
Reference in new issue
Block a user