-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1666 from johnedquinn/v1-dml
Adds DML (INSERT, DELETE, UPDATE, UPSERT, REPLACE)
- Loading branch information
Showing
32 changed files
with
2,591 additions
and
255 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
partiql-ast/src/main/java/org/partiql/ast/dml/ConflictAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package org.partiql.ast.dml; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.partiql.ast.AstNode; | ||
import org.partiql.ast.AstVisitor; | ||
import org.partiql.ast.expr.Expr; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* This is the mandatory action of the ON CONFLICT clause. | ||
* @see Insert#onConflict | ||
* @see OnConflict#action | ||
*/ | ||
public abstract class ConflictAction extends AstNode { | ||
|
||
/** | ||
* This is the DO NOTHING variant of the conflict action. | ||
* @see ConflictAction | ||
* @see OnConflict#action | ||
* @see Insert#onConflict | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public static final class DoNothing extends ConflictAction { | ||
|
||
/** | ||
* TODO | ||
*/ | ||
public DoNothing() {} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<AstNode> children() { | ||
return new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitConflictActionDoNothing(this, ctx); | ||
} | ||
} | ||
|
||
/** | ||
* This is the DO REPLACE variant of the conflict action. | ||
* @see ConflictAction | ||
* @see OnConflict#action | ||
* @see Insert#onConflict | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public static final class DoReplace extends ConflictAction { | ||
/** | ||
* TODO | ||
*/ | ||
@NotNull | ||
public final DoReplaceAction action; | ||
|
||
/** | ||
* TODO | ||
*/ | ||
@Nullable | ||
public final Expr condition; | ||
|
||
/** | ||
* TODO | ||
* @param action TODO | ||
* @param condition TODO | ||
*/ | ||
public DoReplace(@NotNull DoReplaceAction action, @Nullable Expr condition) { | ||
this.action = action; | ||
this.condition = condition; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<AstNode> children() { | ||
List<AstNode> children = new ArrayList<>(); | ||
children.add(action); | ||
if (condition != null) { | ||
children.add(condition); | ||
} | ||
return children; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitConflictActionDoReplace(this, ctx); | ||
} | ||
} | ||
|
||
/** | ||
* This is the DO UPDATE variant of the conflict action. | ||
* @see ConflictAction | ||
* @see OnConflict#action | ||
* @see Insert#onConflict | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public static final class DoUpdate extends ConflictAction { | ||
/** | ||
* TODO | ||
*/ | ||
@NotNull | ||
public final DoUpdateAction action; | ||
|
||
/** | ||
* TODO | ||
*/ | ||
@Nullable | ||
public final Expr condition; | ||
|
||
/** | ||
* TODO | ||
* @param action TODO | ||
* @param condition TODO | ||
*/ | ||
public DoUpdate(@NotNull DoUpdateAction action, @Nullable Expr condition) { | ||
this.action = action; | ||
this.condition = condition; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<AstNode> children() { | ||
List<AstNode> children = new ArrayList<>(); | ||
children.add(action); | ||
if (condition != null) { | ||
children.add(condition); | ||
} | ||
return children; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitConflictActionDoUpdate(this, ctx); | ||
} | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
partiql-ast/src/main/java/org/partiql/ast/dml/ConflictTarget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.partiql.ast.dml; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.partiql.ast.AstNode; | ||
import org.partiql.ast.AstVisitor; | ||
import org.partiql.ast.Identifier; | ||
import org.partiql.ast.IdentifierChain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* This represents the potential targets for the ON CONFLICT clause. | ||
* @see OnConflict | ||
* @see OnConflict#target | ||
*/ | ||
public abstract class ConflictTarget extends AstNode { | ||
|
||
/** | ||
* This is the index variant of the conflict target. | ||
* @see OnConflict | ||
* @see ConflictTarget | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public static final class Index extends ConflictTarget { | ||
/** | ||
* TODO | ||
*/ | ||
// TODO: Should this be a list of identifiers? Or paths? Expressions? | ||
@NotNull | ||
public final List<Identifier> indexes; | ||
|
||
/** | ||
* TODO | ||
* @param indexes TODO | ||
*/ | ||
public Index(@NotNull List<Identifier> indexes) { | ||
this.indexes = indexes; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<AstNode> children() { | ||
return new ArrayList<>(indexes); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitConflictTargetIndex(this, ctx); | ||
} | ||
} | ||
|
||
/** | ||
* This is the ON CONSTRAINT variant of the conflict target. | ||
* @see OnConflict | ||
* @see ConflictTarget | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public static final class Constraint extends ConflictTarget { | ||
/** | ||
* TODO | ||
*/ | ||
@NotNull | ||
public final IdentifierChain name; | ||
|
||
/** | ||
* TODO | ||
* @param name TODO | ||
*/ | ||
public Constraint(@NotNull IdentifierChain name) { | ||
this.name = name; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<AstNode> children() { | ||
List<AstNode> children = new ArrayList<>(); | ||
children.add(name); | ||
return children; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitConflictTargetConstraint(this, ctx); | ||
} | ||
} | ||
} |
Oops, something went wrong.