From 429b5d3e649b310d3646a0e44b78d60c2834fd26 Mon Sep 17 00:00:00 2001 From: John Ed Quinn Date: Thu, 5 Dec 2024 16:14:27 -0800 Subject: [PATCH] Renames AST FromSubquery to FromExpr Removes InsertColumnList AST node Fixes the passing of some AST children Updates Javadocs Adds tests for explicit use of ROW --- partiql-ast/api/partiql-ast.api | 41 ++++++------------- .../main/java/org/partiql/ast/AstVisitor.java | 6 +-- .../java/org/partiql/ast/ConflictAction.java | 6 --- .../java/org/partiql/ast/ConflictTarget.java | 5 --- .../src/main/java/org/partiql/ast/Delete.java | 9 ++-- .../java/org/partiql/ast/DoReplaceAction.java | 2 - .../java/org/partiql/ast/DoUpdateAction.java | 2 - .../src/main/java/org/partiql/ast/Insert.java | 3 -- .../org/partiql/ast/InsertColumnList.java | 37 ----------------- .../java/org/partiql/ast/InsertSource.java | 13 +++--- .../main/java/org/partiql/ast/OnConflict.java | 2 - .../main/java/org/partiql/ast/Replace.java | 2 - .../main/java/org/partiql/ast/SetClause.java | 6 +-- .../src/main/java/org/partiql/ast/Update.java | 9 ++-- .../java/org/partiql/ast/UpdateTarget.java | 2 - .../org/partiql/ast/UpdateTargetStep.java | 3 -- .../src/main/java/org/partiql/ast/Upsert.java | 2 - .../org/partiql/ast/expr/ExprRowValue.java | 2 - .../java/org/partiql/ast/expr/ExprValues.java | 1 - .../src/main/kotlin/org/partiql/ast/Ast.kt | 7 ++-- .../src/main/antlr/PartiQLParser.g4 | 7 +++- .../parser/internal/InsertStatementTests.kt | 2 + 22 files changed, 39 insertions(+), 130 deletions(-) delete mode 100644 partiql-ast/src/main/java/org/partiql/ast/InsertColumnList.java diff --git a/partiql-ast/api/partiql-ast.api b/partiql-ast/api/partiql-ast.api index be3f16a50..c8e7348ca 100644 --- a/partiql-ast/api/partiql-ast.api +++ b/partiql-ast/api/partiql-ast.api @@ -81,7 +81,7 @@ public final class org/partiql/ast/Ast { public static final fun identifierChain (Lorg/partiql/ast/Identifier;Lorg/partiql/ast/IdentifierChain;)Lorg/partiql/ast/IdentifierChain; public static final fun insert (Lorg/partiql/ast/IdentifierChain;Lorg/partiql/ast/Identifier;Lorg/partiql/ast/InsertSource;Lorg/partiql/ast/OnConflict;)Lorg/partiql/ast/Insert; public static final fun insertSourceDefault ()Lorg/partiql/ast/InsertSource$FromDefault; - public static final fun insertSourceExpr (Ljava/util/List;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/InsertSource$FromSubquery; + public static final fun insertSourceExpr (Ljava/util/List;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/InsertSource$FromExpr; public static final fun let (Ljava/util/List;)Lorg/partiql/ast/Let; public static final fun letBinding (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/Identifier;)Lorg/partiql/ast/Let$Binding; public static final fun onConflict (Lorg/partiql/ast/ConflictAction;Lorg/partiql/ast/ConflictTarget;)Lorg/partiql/ast/OnConflict; @@ -96,7 +96,7 @@ public final class org/partiql/ast/Ast { public static final fun selectPivot (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/SelectPivot; public static final fun selectStar (Lorg/partiql/ast/SetQuantifier;)Lorg/partiql/ast/SelectStar; public static final fun selectValue (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/SetQuantifier;)Lorg/partiql/ast/SelectValue; - public static final fun setClause (Lorg/partiql/ast/AstNode;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/SetClause; + public static final fun setClause (Lorg/partiql/ast/UpdateTarget;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/SetClause; public static final fun setOp (Lorg/partiql/ast/SetOpType;Lorg/partiql/ast/SetQuantifier;)Lorg/partiql/ast/SetOp; public static final fun sort (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/Order;Lorg/partiql/ast/Nulls;)Lorg/partiql/ast/Sort; public static final fun update (Lorg/partiql/ast/IdentifierChain;Ljava/util/List;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/Update; @@ -365,10 +365,9 @@ public abstract class org/partiql/ast/AstVisitor { public fun visitIdentifier (Lorg/partiql/ast/Identifier;Ljava/lang/Object;)Ljava/lang/Object; public fun visitIdentifierChain (Lorg/partiql/ast/IdentifierChain;Ljava/lang/Object;)Ljava/lang/Object; public fun visitInsert (Lorg/partiql/ast/Insert;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitInsertColumnList (Lorg/partiql/ast/InsertColumnList;Ljava/lang/Object;)Ljava/lang/Object; public fun visitInsertSource (Lorg/partiql/ast/InsertSource;Ljava/lang/Object;)Ljava/lang/Object; public fun visitInsertSourceFromDefault (Lorg/partiql/ast/InsertSource$FromDefault;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitInsertSourceFromSubquery (Lorg/partiql/ast/InsertSource$FromSubquery;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitInsertSourceFromExpr (Lorg/partiql/ast/InsertSource$FromExpr;Ljava/lang/Object;)Ljava/lang/Object; public fun visitLet (Lorg/partiql/ast/Let;Ljava/lang/Object;)Ljava/lang/Object; public fun visitLetBinding (Lorg/partiql/ast/Let$Binding;Ljava/lang/Object;)Ljava/lang/Object; public fun visitOnConflict (Lorg/partiql/ast/OnConflict;Ljava/lang/Object;)Ljava/lang/Object; @@ -1032,22 +1031,6 @@ public class org/partiql/ast/Insert$Builder { public fun toString ()Ljava/lang/String; } -public final class org/partiql/ast/InsertColumnList : org/partiql/ast/Statement { - public final field columns Ljava/util/List; - public fun (Ljava/util/List;)V - public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/InsertColumnList$Builder; - public fun children ()Ljava/util/Collection; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I -} - -public class org/partiql/ast/InsertColumnList$Builder { - public fun build ()Lorg/partiql/ast/InsertColumnList; - public fun columns (Ljava/util/List;)Lorg/partiql/ast/InsertColumnList$Builder; - public fun toString ()Ljava/lang/String; -} - public abstract class org/partiql/ast/InsertSource : org/partiql/ast/AstNode { public fun ()V } @@ -1065,21 +1048,21 @@ public class org/partiql/ast/InsertSource$FromDefault$Builder { public fun toString ()Ljava/lang/String; } -public final class org/partiql/ast/InsertSource$FromSubquery : org/partiql/ast/InsertSource { +public final class org/partiql/ast/InsertSource$FromExpr : org/partiql/ast/InsertSource { public final field columns Ljava/util/List; public final field expr Lorg/partiql/ast/expr/Expr; public fun (Ljava/util/List;Lorg/partiql/ast/expr/Expr;)V public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/InsertSource$FromSubquery$Builder; + public static fun builder ()Lorg/partiql/ast/InsertSource$FromExpr$Builder; public fun children ()Ljava/util/Collection; public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I } -public class org/partiql/ast/InsertSource$FromSubquery$Builder { - public fun build ()Lorg/partiql/ast/InsertSource$FromSubquery; - public fun columns (Ljava/util/List;)Lorg/partiql/ast/InsertSource$FromSubquery$Builder; - public fun expr (Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/InsertSource$FromSubquery$Builder; +public class org/partiql/ast/InsertSource$FromExpr$Builder { + public fun build ()Lorg/partiql/ast/InsertSource$FromExpr; + public fun columns (Ljava/util/List;)Lorg/partiql/ast/InsertSource$FromExpr$Builder; + public fun expr (Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/InsertSource$FromExpr$Builder; public fun toString ()Ljava/lang/String; } @@ -1432,8 +1415,8 @@ public class org/partiql/ast/SelectValue$Builder { public final class org/partiql/ast/SetClause : org/partiql/ast/AstNode { public final field expr Lorg/partiql/ast/expr/Expr; - public final field target Lorg/partiql/ast/AstNode; - public fun (Lorg/partiql/ast/AstNode;Lorg/partiql/ast/expr/Expr;)V + public final field target Lorg/partiql/ast/UpdateTarget; + public fun (Lorg/partiql/ast/UpdateTarget;Lorg/partiql/ast/expr/Expr;)V public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun builder ()Lorg/partiql/ast/SetClause$Builder; public fun children ()Ljava/util/Collection; @@ -1444,7 +1427,7 @@ public final class org/partiql/ast/SetClause : org/partiql/ast/AstNode { public class org/partiql/ast/SetClause$Builder { public fun build ()Lorg/partiql/ast/SetClause; public fun expr (Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/SetClause$Builder; - public fun target (Lorg/partiql/ast/AstNode;)Lorg/partiql/ast/SetClause$Builder; + public fun target (Lorg/partiql/ast/UpdateTarget;)Lorg/partiql/ast/SetClause$Builder; public fun toString ()Ljava/lang/String; } diff --git a/partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java b/partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java index 04a9d22e7..abd8780fc 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java +++ b/partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java @@ -105,15 +105,11 @@ public R visitSetClause(SetClause node, C ctx) { return defaultVisit(node, ctx); } - public R visitInsertColumnList(InsertColumnList node, C ctx) { - return defaultVisit(node, ctx); - } - public R visitInsertSource(InsertSource node, C ctx) { return node.accept(this, ctx); } - public R visitInsertSourceFromSubquery(InsertSource.FromSubquery node, C ctx) { + public R visitInsertSourceFromExpr(InsertSource.FromExpr node, C ctx) { return defaultVisit(node, ctx); } diff --git a/partiql-ast/src/main/java/org/partiql/ast/ConflictAction.java b/partiql-ast/src/main/java/org/partiql/ast/ConflictAction.java index 6430428f1..134a62e31 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/ConflictAction.java +++ b/partiql-ast/src/main/java/org/partiql/ast/ConflictAction.java @@ -26,8 +26,6 @@ public abstract class ConflictAction extends AstNode { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static final class DoNothing extends ConflictAction { - // TODO: Equals and hashcode - @NotNull @Override public Collection children() { @@ -49,8 +47,6 @@ public R accept(@NotNull AstVisitor visitor, C ctx) { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static final class DoReplace extends ConflictAction { - // TODO: Equals and hashcode - /** * TODO */ @@ -99,8 +95,6 @@ public R accept(@NotNull AstVisitor visitor, C ctx) { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static final class DoUpdate extends ConflictAction { - // TODO: Equals and hashcode - /** * TODO */ diff --git a/partiql-ast/src/main/java/org/partiql/ast/ConflictTarget.java b/partiql-ast/src/main/java/org/partiql/ast/ConflictTarget.java index b1b14b4dd..7ace100ee 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/ConflictTarget.java +++ b/partiql-ast/src/main/java/org/partiql/ast/ConflictTarget.java @@ -23,9 +23,6 @@ public abstract class ConflictTarget extends AstNode { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static final class Index extends ConflictTarget { - // TODO: Do we like this name? - // TODO: Equals and hashcode - /** * TODO */ @@ -61,8 +58,6 @@ public R accept(@NotNull AstVisitor visitor, C ctx) { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static final class Constraint extends ConflictTarget { - // TODO: Equals and hashcode - /** * TODO */ diff --git a/partiql-ast/src/main/java/org/partiql/ast/Delete.java b/partiql-ast/src/main/java/org/partiql/ast/Delete.java index ac4448bae..3903df964 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/Delete.java +++ b/partiql-ast/src/main/java/org/partiql/ast/Delete.java @@ -11,15 +11,11 @@ import java.util.List; /** - * This is the update searched statement. - * @see InsertColumnList - * @see InsertSource + * This is the delete searched statement. */ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public final class Delete extends Statement { - // TODO: Equals and hashcode - /** * TODO */ @@ -47,6 +43,9 @@ public Delete(@NotNull IdentifierChain tableName, @Nullable Expr condition) { public Collection children() { List kids = new ArrayList<>(); kids.add(tableName); + if (condition != null) { + kids.add(condition); + } return kids; } diff --git a/partiql-ast/src/main/java/org/partiql/ast/DoReplaceAction.java b/partiql-ast/src/main/java/org/partiql/ast/DoReplaceAction.java index 16707085b..404e5d29a 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/DoReplaceAction.java +++ b/partiql-ast/src/main/java/org/partiql/ast/DoReplaceAction.java @@ -21,8 +21,6 @@ public abstract class DoReplaceAction extends AstNode { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static final class Excluded extends DoReplaceAction { - // TODO: Equals and hashcode - @NotNull @Override public Collection children() { diff --git a/partiql-ast/src/main/java/org/partiql/ast/DoUpdateAction.java b/partiql-ast/src/main/java/org/partiql/ast/DoUpdateAction.java index 4ab67e5d2..c145dd64b 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/DoUpdateAction.java +++ b/partiql-ast/src/main/java/org/partiql/ast/DoUpdateAction.java @@ -21,8 +21,6 @@ public abstract class DoUpdateAction extends AstNode { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static final class Excluded extends DoUpdateAction { - // TODO: Equals and hashcode - @NotNull @Override public Collection children() { diff --git a/partiql-ast/src/main/java/org/partiql/ast/Insert.java b/partiql-ast/src/main/java/org/partiql/ast/Insert.java index 61c4d5ac6..8a7b062fc 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/Insert.java +++ b/partiql-ast/src/main/java/org/partiql/ast/Insert.java @@ -11,14 +11,11 @@ /** * This is the insert statement. - * @see InsertColumnList * @see InsertSource */ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public final class Insert extends Statement { - // TODO: Equals and hashcode - /** * TODO */ diff --git a/partiql-ast/src/main/java/org/partiql/ast/InsertColumnList.java b/partiql-ast/src/main/java/org/partiql/ast/InsertColumnList.java deleted file mode 100644 index 548d8e858..000000000 --- a/partiql-ast/src/main/java/org/partiql/ast/InsertColumnList.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.partiql.ast; - -import lombok.Builder; -import lombok.EqualsAndHashCode; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * This specifies the list of columns to insert into. - * @see Insert - */ -@Builder(builderClassName = "Builder") -@EqualsAndHashCode(callSuper = false) -public final class InsertColumnList extends Statement { - // TODO: Equals and hashcode - - @NotNull - public final List columns; - - public InsertColumnList(@NotNull List columns) { - this.columns = columns; - } - - @NotNull - @Override - public Collection children() { - return new ArrayList<>(columns); - } - - @Override - public R accept(@NotNull AstVisitor visitor, C ctx) { - return visitor.visitInsertColumnList(this, ctx); - } -} diff --git a/partiql-ast/src/main/java/org/partiql/ast/InsertSource.java b/partiql-ast/src/main/java/org/partiql/ast/InsertSource.java index ae9e63f07..04fb6242c 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/InsertSource.java +++ b/partiql-ast/src/main/java/org/partiql/ast/InsertSource.java @@ -17,15 +17,14 @@ public abstract class InsertSource extends AstNode { /** - * This specifies the data to be inserted from a subquery or expression. + * This specifies the data to be inserted from a subquery or expression. This represents (and generalizes) + * SQL:1999's <from subquery> EBNF rule. * @see Insert * @see InsertSource */ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) - public static final class FromSubquery extends InsertSource { - // TODO: Equals and hashcode - + public static final class FromExpr extends InsertSource { /** * TODO */ @@ -43,7 +42,7 @@ public static final class FromSubquery extends InsertSource { * @param columns TODO * @param expr TODO */ - public FromSubquery(@Nullable List columns, @NotNull Expr expr) { + public FromExpr(@Nullable List columns, @NotNull Expr expr) { this.columns = columns; this.expr = expr; } @@ -61,7 +60,7 @@ public Collection children() { @Override public R accept(@NotNull AstVisitor visitor, C ctx) { - return visitor.visitInsertSourceFromSubquery(this, ctx); + return visitor.visitInsertSourceFromExpr(this, ctx); } } @@ -73,8 +72,6 @@ public R accept(@NotNull AstVisitor visitor, C ctx) { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static final class FromDefault extends InsertSource { - // TODO: Equals and hashcode - @NotNull @Override public Collection children() { diff --git a/partiql-ast/src/main/java/org/partiql/ast/OnConflict.java b/partiql-ast/src/main/java/org/partiql/ast/OnConflict.java index ebd3205d9..f65f379d6 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/OnConflict.java +++ b/partiql-ast/src/main/java/org/partiql/ast/OnConflict.java @@ -17,8 +17,6 @@ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public final class OnConflict extends AstNode { - // TODO: Equals and hashcode - /** * TODO */ diff --git a/partiql-ast/src/main/java/org/partiql/ast/Replace.java b/partiql-ast/src/main/java/org/partiql/ast/Replace.java index 7c9e6a115..3297b2621 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/Replace.java +++ b/partiql-ast/src/main/java/org/partiql/ast/Replace.java @@ -16,8 +16,6 @@ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public final class Replace extends Statement { - // TODO: Equals and hashcode - /** * TODO */ diff --git a/partiql-ast/src/main/java/org/partiql/ast/SetClause.java b/partiql-ast/src/main/java/org/partiql/ast/SetClause.java index 4175b8e66..76f20daa3 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/SetClause.java +++ b/partiql-ast/src/main/java/org/partiql/ast/SetClause.java @@ -16,13 +16,11 @@ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public final class SetClause extends AstNode { - // TODO: Equals and hashcode - /** * TODO */ @NotNull - public final AstNode target; + public final UpdateTarget target; /** * TODO @@ -35,7 +33,7 @@ public final class SetClause extends AstNode { * @param target TODO * @param expr TODO */ - public SetClause(@NotNull AstNode target, @NotNull Expr expr) { + public SetClause(@NotNull UpdateTarget target, @NotNull Expr expr) { this.target = target; this.expr = expr; } diff --git a/partiql-ast/src/main/java/org/partiql/ast/Update.java b/partiql-ast/src/main/java/org/partiql/ast/Update.java index d9465549a..8d71becdb 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/Update.java +++ b/partiql-ast/src/main/java/org/partiql/ast/Update.java @@ -12,14 +12,11 @@ /** * This is the update searched statement. - * @see InsertColumnList - * @see InsertSource + * @see SetClause */ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public final class Update extends Statement { - // TODO: Equals and hashcode - /** * TODO */ @@ -55,6 +52,10 @@ public Update(@NotNull IdentifierChain tableName, @NotNull List setCl public Collection children() { List kids = new ArrayList<>(); kids.add(tableName); + kids.addAll(setClauses); + if (condition != null) { + kids.add(condition); + } return kids; } diff --git a/partiql-ast/src/main/java/org/partiql/ast/UpdateTarget.java b/partiql-ast/src/main/java/org/partiql/ast/UpdateTarget.java index 784bbeeb7..f1a6ad834 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/UpdateTarget.java +++ b/partiql-ast/src/main/java/org/partiql/ast/UpdateTarget.java @@ -18,8 +18,6 @@ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public final class UpdateTarget extends AstNode { - // TODO: Equals and hashcode - /** * TODO */ diff --git a/partiql-ast/src/main/java/org/partiql/ast/UpdateTargetStep.java b/partiql-ast/src/main/java/org/partiql/ast/UpdateTargetStep.java index cd09d5ab4..13a4391ba 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/UpdateTargetStep.java +++ b/partiql-ast/src/main/java/org/partiql/ast/UpdateTargetStep.java @@ -26,7 +26,6 @@ public abstract class UpdateTargetStep extends AstNode { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static final class Element extends UpdateTargetStep { - // TODO: Equals and hashcode // TODO: Should we explicitly have an ElementInt and ElementString? Especially once PartiQLValue is removed. /** @@ -82,8 +81,6 @@ public R accept(@NotNull AstVisitor visitor, C ctx) { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static final class Field extends UpdateTargetStep { - // TODO: Equals and hashcode - /** * TODO */ diff --git a/partiql-ast/src/main/java/org/partiql/ast/Upsert.java b/partiql-ast/src/main/java/org/partiql/ast/Upsert.java index c04b42b19..067d91080 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/Upsert.java +++ b/partiql-ast/src/main/java/org/partiql/ast/Upsert.java @@ -16,8 +16,6 @@ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public final class Upsert extends Statement { - // TODO: Equals and hashcode - /** * TODO */ diff --git a/partiql-ast/src/main/java/org/partiql/ast/expr/ExprRowValue.java b/partiql-ast/src/main/java/org/partiql/ast/expr/ExprRowValue.java index 0e75dafec..612ff066f 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/expr/ExprRowValue.java +++ b/partiql-ast/src/main/java/org/partiql/ast/expr/ExprRowValue.java @@ -22,8 +22,6 @@ @lombok.Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public class ExprRowValue extends Expr { - // TODO: Equals and hashcode - /** * Specifies whether the ROW keyword explicitly precedes the elements in the textual representation. For example, * {@code ROW (1, 2, 3)} versus {@code (1, 2, 3)}. In the first example, {@code isExplicit} is true. diff --git a/partiql-ast/src/main/java/org/partiql/ast/expr/ExprValues.java b/partiql-ast/src/main/java/org/partiql/ast/expr/ExprValues.java index 093093fb8..1af83eac0 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/expr/ExprValues.java +++ b/partiql-ast/src/main/java/org/partiql/ast/expr/ExprValues.java @@ -19,7 +19,6 @@ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public class ExprValues extends Expr { - // TODO: Equals and hashcode // TODO: May not be an expr? // TODO: Tracking issue for VALUES and subqueries -- https://github.com/partiql/partiql-lang-kotlin/issues/1641. diff --git a/partiql-ast/src/main/kotlin/org/partiql/ast/Ast.kt b/partiql-ast/src/main/kotlin/org/partiql/ast/Ast.kt index 3faa124cb..68075803d 100644 --- a/partiql-ast/src/main/kotlin/org/partiql/ast/Ast.kt +++ b/partiql-ast/src/main/kotlin/org/partiql/ast/Ast.kt @@ -480,15 +480,14 @@ public object Ast { return Delete(tableName, condition) } - // TODO: Target @JvmStatic - public fun setClause(target: AstNode, value: Expr): SetClause { + public fun setClause(target: UpdateTarget, value: Expr): SetClause { return SetClause(target, value) } @JvmStatic - public fun insertSourceExpr(columns: List?, expr: Expr): InsertSource.FromSubquery { - return InsertSource.FromSubquery(columns, expr) + public fun insertSourceExpr(columns: List?, expr: Expr): InsertSource.FromExpr { + return InsertSource.FromExpr(columns, expr) } @JvmStatic diff --git a/partiql-parser/src/main/antlr/PartiQLParser.g4 b/partiql-parser/src/main/antlr/PartiQLParser.g4 index c95fabb6e..943a8d2b5 100644 --- a/partiql-parser/src/main/antlr/PartiQLParser.g4 +++ b/partiql-parser/src/main/antlr/PartiQLParser.g4 @@ -210,16 +210,19 @@ setClauseList: setClause ( COMMA setClause )*; /** * @see https://ronsavage.github.io/SQL/sql-99.bnf.html#set%20clause - * TODO: The above reference set clause doesn't exactly allow for the flexibility provided by pathSimple. + * The above referenced set clause doesn't exactly allow for the flexibility provided by updateTarget (previously + * named pathSimple). The SQL:1999 EBNF states that can either be a column name or a column name + * followed by square brackets and a literal (or other simple value). Since PartiQL allows for setting a nested attribute + * the updateTarget here provides for a superset of SQL's */ setClause: updateTarget EQ expr; updateTarget: symbolPrimitive updateTargetStep*; +// TODO: https://github.com/partiql/partiql-lang-kotlin/issues/1671 updateTargetStep : updateTargetStepElement | updateTargetStepField - // TODO: Do we need this? Seems wrong. | BRACKET_LEFT key=symbolPrimitive BRACKET_RIGHT # PathSimpleSymbol ; updateTargetStepElement: BRACKET_LEFT key=literal BRACKET_RIGHT; diff --git a/partiql-parser/src/test/kotlin/org/partiql/parser/internal/InsertStatementTests.kt b/partiql-parser/src/test/kotlin/org/partiql/parser/internal/InsertStatementTests.kt index 06ece2a09..52d27e03d 100644 --- a/partiql-parser/src/test/kotlin/org/partiql/parser/internal/InsertStatementTests.kt +++ b/partiql-parser/src/test/kotlin/org/partiql/parser/internal/InsertStatementTests.kt @@ -23,6 +23,8 @@ class InsertStatementTests { "Simplest insert of a row" to "INSERT INTO tbl VALUES (1, 2, 3)", "Column definitions" to "INSERT INTO tbl (a, b, c) VALUES (1, 2, 3)", "Multiple rows" to "INSERT INTO tbl VALUES (1, 2, 3), (4, 5, 6), (7, 8, 8)", + "Multiple explicit rows" to "INSERT INTO tbl VALUES ROW (1, 2, 3), (4, 5, 6), ROW (7, 8, 8)", + "Multiple explicit rows to disambiguate a single parenthesized expression" to "INSERT INTO tbl VALUES ROW (1), 2, ROW (3)", "Multiple non-row values" to "INSERT INTO tbl VALUES 1, 2, 3", "Using DEFAULT VALUES" to "INSERT INTO tbl DEFAULT VALUES", "Explicit bag" to "INSERT INTO tbl << 1, 2, 3 >>",