mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(dynamodb): read PartiQL's FROM-first form of UPDATE (#6648)
* feat(dynamodb): read PartiQL's FROM-first form of UPDATE DynamoDB accepts FROM "T" WHERE key SET ... REMOVE ..., the clauses in PartiQL's order, and runs it as the same update as UPDATE "T" SET ... WHERE key, under the same dynamodb:PartiQLUpdate action. Without a SET or REMOVE the statement is not well formed, and a WHERE after them is a token left over. Floci refused the form as not well formed. * fix(dynamodb): refuse an UPDATE whose SET or REMOVE does not follow the table DynamoDB answers UPDATE "T" WHERE pk = 'x' and UPDATE "T" WHERE pk = 'x' SET c = 1 with "Statement wasn't well formed, can't be processed: Expected data manipulation", the same as the FROM-first form with no SET or REMOVE. The shared clause parser now makes that check for both forms.
This commit is contained in:
1 parent
a1ebc10bd1
commit
d42b83ceac
3 files changed
+173
-6
No files matched your search
+27
-6
@@ -128,7 +128,7 @@ public class DynamoDbPartiQLParser {
|
||||
return switch (tokens.getFirst().type()) {
|
||||
case SELECT -> "dynamodb:PartiQLSelect";
|
||||
case INSERT -> "dynamodb:PartiQLInsert";
|
||||
case UPDATE -> "dynamodb:PartiQLUpdate";
|
||||
case UPDATE, FROM -> "dynamodb:PartiQLUpdate";
|
||||
case DELETE -> "dynamodb:PartiQLDelete";
|
||||
default -> null;
|
||||
};
|
||||
@@ -471,9 +471,9 @@ public class DynamoDbPartiQLParser {
|
||||
case SELECT -> parseSelect();
|
||||
case INSERT -> parseInsert();
|
||||
case UPDATE -> parseUpdate();
|
||||
case FROM -> parseFromFirstUpdate();
|
||||
case DELETE -> parseDelete();
|
||||
default -> throw validationEx(
|
||||
"Statement wasn't well formed, can't be processed: Expected data manipulation");
|
||||
default -> throw validationEx(NOT_WELL_FORMED + "Expected data manipulation");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -548,6 +548,29 @@ public class DynamoDbPartiQLParser {
|
||||
consume(TType.UPDATE);
|
||||
String table = expectTableName();
|
||||
String index = parseIndexQualifier();
|
||||
Edits edits = parseEdits();
|
||||
consume(TType.WHERE);
|
||||
List<Cond> where = parseConditions();
|
||||
return new Stmt.Update(table, index, edits.sets(), edits.removes(), where, parseReturning());
|
||||
}
|
||||
|
||||
// FROM "Table" [WHERE …] SET attr=val [, …] [REMOVE attr [, …]], an UPDATE with the clauses in PartiQL's order
|
||||
private Stmt.Update parseFromFirstUpdate() {
|
||||
consume(TType.FROM);
|
||||
String table = expectTableName();
|
||||
String index = parseIndexQualifier();
|
||||
List<Cond> where = List.of();
|
||||
if (peek().type() == TType.WHERE) { advance(); where = parseConditions(); }
|
||||
Edits edits = parseEdits();
|
||||
return new Stmt.Update(table, index, edits.sets(), edits.removes(), where, parseReturning());
|
||||
}
|
||||
|
||||
private record Edits(List<SetClause> sets, List<Path> removes) {}
|
||||
|
||||
private Edits parseEdits() {
|
||||
if (peek().type() != TType.SET && peek().type() != TType.REMOVE) {
|
||||
throw validationEx(NOT_WELL_FORMED + "Expected data manipulation");
|
||||
}
|
||||
List<SetClause> sets = new ArrayList<>();
|
||||
List<Path> removes = new ArrayList<>();
|
||||
while (peek().type() == TType.SET || peek().type() == TType.REMOVE) {
|
||||
@@ -561,9 +584,7 @@ public class DynamoDbPartiQLParser {
|
||||
while (peek().type() == TType.COMMA) { advance(); removes.add(parsePath()); }
|
||||
}
|
||||
}
|
||||
consume(TType.WHERE);
|
||||
List<Cond> where = parseConditions();
|
||||
return new Stmt.Update(table, index, sets, removes, where, parseReturning());
|
||||
return new Edits(sets, removes);
|
||||
}
|
||||
|
||||
private Stmt.Delete parseDelete() {
|
||||
|
||||
Reference in new issue
Block a user