-
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.
Showing
10 changed files
with
461 additions
and
28 deletions.
There are no files selected for viewing
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
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,57 @@ | ||
package org.partiql.ast; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.partiql.ast.expr.Expr; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* This is the update searched statement. | ||
* @see InsertColumnList | ||
* @see InsertSource | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public final class Delete extends Statement { | ||
// TODO: Equals and hashcode | ||
|
||
/** | ||
* TODO | ||
*/ | ||
@NotNull | ||
public final IdentifierChain tableName; | ||
|
||
/** | ||
* TODO | ||
*/ | ||
@Nullable | ||
public final Expr condition; | ||
|
||
/** | ||
* TODO | ||
* @param tableName TODO | ||
* @param condition TODO | ||
*/ | ||
public Delete(@NotNull IdentifierChain tableName, @Nullable Expr condition) { | ||
this.tableName = tableName; | ||
this.condition = condition; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<AstNode> children() { | ||
List<AstNode> kids = new ArrayList<>(); | ||
kids.add(tableName); | ||
return kids; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitDelete(this, ctx); | ||
} | ||
} |
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,63 @@ | ||
package org.partiql.ast; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* This is the REPLACE INTO statement. | ||
* @see InsertSource | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public final class Replace extends Statement { | ||
// TODO: Equals and hashcode | ||
|
||
/** | ||
* TODO | ||
*/ | ||
@NotNull | ||
public final IdentifierChain tableName; | ||
|
||
/** | ||
* TODO | ||
*/ | ||
@Nullable | ||
public final Identifier asAlias; | ||
|
||
/** | ||
* TODO | ||
*/ | ||
@NotNull | ||
public final InsertSource source; | ||
|
||
/** | ||
* TODO | ||
* @param tableName TODO | ||
* @param asAlias TODO | ||
* @param source TODO | ||
*/ | ||
public Replace(@NotNull IdentifierChain tableName, @Nullable Identifier asAlias, @NotNull InsertSource source) { | ||
this.tableName = tableName; | ||
this.asAlias = asAlias; | ||
this.source = source; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<AstNode> children() { | ||
List<AstNode> kids = new ArrayList<>(); | ||
kids.add(tableName); | ||
return kids; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitReplace(this, ctx); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
partiql-ast/src/main/java/org/partiql/ast/UpdateTarget.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,58 @@ | ||
package org.partiql.ast; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.partiql.ast.expr.Expr; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* This references a column or column's nested properties. In SQL:1999, the EBNF rule is <update target>. | ||
* This implementation differs from SQL by allowing for references to deeply nested data of varying types. | ||
* @see SetClause | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public final class UpdateTarget extends AstNode { | ||
// TODO: Equals and hashcode | ||
|
||
/** | ||
* TODO | ||
*/ | ||
@NotNull | ||
public final Identifier root; | ||
|
||
/** | ||
* TODO | ||
*/ | ||
@NotNull | ||
public final List<UpdateTargetStep> steps; | ||
|
||
/** | ||
* TODO | ||
* @param root TODO | ||
* @param steps TODO | ||
*/ | ||
public UpdateTarget(@NotNull Identifier root, @NotNull List<UpdateTargetStep> steps) { | ||
this.root = root; | ||
this.steps = steps; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<AstNode> children() { | ||
List<AstNode> kids = new ArrayList<>(); | ||
kids.add(root); | ||
kids.addAll(steps); | ||
return kids; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitUpdateTarget(this, ctx); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
partiql-ast/src/main/java/org/partiql/ast/UpdateTargetStep.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,115 @@ | ||
package org.partiql.ast; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.partiql.ast.expr.ExprLit; | ||
import org.partiql.value.PartiQL; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* This references a column or column's nested properties. In SQL:1999, the EBNF rule is <update target>. | ||
* This implementation differs from SQL by allowing for references to deeply nested data of varying types. | ||
* | ||
* @see SetClause | ||
*/ | ||
public abstract class UpdateTargetStep extends AstNode { | ||
|
||
/** | ||
* This is a reference to a field of an array/struct using the bracket notation. | ||
* @see UpdateTarget | ||
* @see UpdateTargetStep | ||
*/ | ||
@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. | ||
|
||
/** | ||
* TODO | ||
*/ | ||
// TODO: Change this to a literal, not an ExprLit | ||
@NotNull | ||
public final ExprLit key; | ||
|
||
/** | ||
* TODO | ||
* @param key TODO | ||
*/ | ||
public Element(@NotNull ExprLit key) { | ||
this.key = key; | ||
} | ||
|
||
/** | ||
* TODO | ||
* @param key TODO | ||
*/ | ||
public Element(int key) { | ||
this.key = new ExprLit(PartiQL.int32Value(key)); | ||
} | ||
|
||
/** | ||
* TODO | ||
* @param key TODO | ||
*/ | ||
public Element(@NotNull String key) { | ||
this.key = new ExprLit(PartiQL.stringValue(key)); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<AstNode> children() { | ||
List<AstNode> kids = new ArrayList<>(); | ||
kids.add(key); | ||
return kids; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitUpdateTargetStepElement(this, ctx); | ||
} | ||
} | ||
|
||
/** | ||
* This is a reference to a field of a struct using the dot notation. | ||
* @see UpdateTarget | ||
* @see UpdateTargetStep | ||
*/ | ||
@Builder(builderClassName = "Builder") | ||
@EqualsAndHashCode(callSuper = false) | ||
public static final class Field extends UpdateTargetStep { | ||
// TODO: Equals and hashcode | ||
|
||
/** | ||
* TODO | ||
*/ | ||
// TODO: Change this to a literal, not an ExprLit | ||
@NotNull | ||
public final Identifier key; | ||
|
||
/** | ||
* TODO | ||
* @param key TODO | ||
*/ | ||
public Field(@NotNull Identifier key) { | ||
this.key = key; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<AstNode> children() { | ||
List<AstNode> kids = new ArrayList<>(); | ||
kids.add(key); | ||
return kids; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) { | ||
return visitor.visitUpdateTargetStepField(this, ctx); | ||
} | ||
} | ||
} |
Oops, something went wrong.