Skip to content

Commit

Permalink
[v1] Remove PartiQLValue from AST; refactor AST literals
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Nov 19, 2024
1 parent 10f93bd commit 8579b04
Show file tree
Hide file tree
Showing 31 changed files with 613 additions and 284 deletions.
98 changes: 88 additions & 10 deletions partiql-ast/api/partiql-ast.api
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class org/partiql/ast/Ast {
public static final fun exprInCollection (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/expr/Expr;Z)Lorg/partiql/ast/expr/ExprInCollection;
public static final fun exprIsType (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/DataType;Z)Lorg/partiql/ast/expr/ExprIsType;
public static final fun exprLike (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/expr/Expr;Z)Lorg/partiql/ast/expr/ExprLike;
public static final fun exprLit (Lorg/partiql/value/PartiQLValue;)Lorg/partiql/ast/expr/ExprLit;
public static final fun exprLit (Lorg/partiql/ast/literal/Literal;)Lorg/partiql/ast/expr/ExprLit;
public static final fun exprMatch (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/graph/GraphMatch;)Lorg/partiql/ast/expr/ExprMatch;
public static final fun exprNot (Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/expr/ExprNot;
public static final fun exprNullIf (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/expr/ExprNullIf;
Expand Down Expand Up @@ -72,6 +72,15 @@ 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 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 literalBool (Z)Lorg/partiql/ast/literal/LiteralBool;
public static final fun literalDecimal (Ljava/math/BigDecimal;)Lorg/partiql/ast/literal/LiteralDecimal;
public static final fun literalFloat (Ljava/lang/String;)Lorg/partiql/ast/literal/LiteralDouble;
public static final fun literalInt (I)Lorg/partiql/ast/literal/LiteralInt;
public static final fun literalLong (J)Lorg/partiql/ast/literal/LiteralLong;
public static final fun literalMissing ()Lorg/partiql/ast/literal/LiteralMissing;
public static final fun literalNull ()Lorg/partiql/ast/literal/LiteralNull;
public static final fun literalString (Ljava/lang/String;)Lorg/partiql/ast/literal/LiteralString;
public static final fun literalTypedString (Lorg/partiql/ast/DataType;Ljava/lang/String;)Lorg/partiql/ast/literal/LiteralTypedString;
public static final fun orderBy (Ljava/util/List;)Lorg/partiql/ast/OrderBy;
public static final fun query (Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/Query;
public static final fun queryBodySFW (Lorg/partiql/ast/Select;Lorg/partiql/ast/Exclude;Lorg/partiql/ast/From;Lorg/partiql/ast/Let;Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/GroupBy;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/QueryBody$SFW;
Expand Down Expand Up @@ -1477,22 +1486,15 @@ public class org/partiql/ast/expr/ExprLike$Builder {
}

public class org/partiql/ast/expr/ExprLit : org/partiql/ast/expr/Expr {
public final field value Lorg/partiql/value/PartiQLValue;
public fun <init> (Lorg/partiql/value/PartiQLValue;)V
public field lit Lorg/partiql/ast/literal/Literal;
public fun <init> (Lorg/partiql/ast/literal/Literal;)V
public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object;
public static fun builder ()Lorg/partiql/ast/expr/ExprLit$Builder;
protected fun canEqual (Ljava/lang/Object;)Z
public fun children ()Ljava/util/Collection;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public class org/partiql/ast/expr/ExprLit$Builder {
public fun build ()Lorg/partiql/ast/expr/ExprLit;
public fun toString ()Ljava/lang/String;
public fun value (Lorg/partiql/value/PartiQLValue;)Lorg/partiql/ast/expr/ExprLit$Builder;
}

public class org/partiql/ast/expr/ExprMatch : org/partiql/ast/expr/Expr {
public final field expr Lorg/partiql/ast/expr/Expr;
public final field pattern Lorg/partiql/ast/graph/GraphMatch;
Expand Down Expand Up @@ -2389,6 +2391,82 @@ public class org/partiql/ast/graph/GraphSelector$ShortestKGroup$Builder {
public fun toString ()Ljava/lang/String;
}

public abstract class org/partiql/ast/literal/Literal {
public final field text Ljava/lang/String;
protected fun <init> (Ljava/lang/String;)V
}

public class org/partiql/ast/literal/LiteralBool : org/partiql/ast/literal/Literal {
public field value Z
public fun <init> (Z)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralDecimal : org/partiql/ast/literal/Literal {
public field value Ljava/math/BigDecimal;
public fun <init> (Ljava/math/BigDecimal;)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralDouble : org/partiql/ast/literal/Literal {
public field value D
public fun <init> (Ljava/lang/String;)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralInt : org/partiql/ast/literal/Literal {
public field value I
public fun <init> (I)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralLong : org/partiql/ast/literal/Literal {
public field value J
public fun <init> (J)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralMissing : org/partiql/ast/literal/Literal {
public fun <init> ()V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralNull : org/partiql/ast/literal/Literal {
public fun <init> ()V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralString : org/partiql/ast/literal/Literal {
public field value Ljava/lang/String;
public fun <init> (Ljava/lang/String;)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralTypedString : org/partiql/ast/literal/Literal {
public field type Lorg/partiql/ast/DataType;
public field value Ljava/lang/String;
public fun <init> (Lorg/partiql/ast/DataType;Ljava/lang/String;)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public abstract class org/partiql/ast/sql/SqlBlock {
public static final field Companion Lorg/partiql/ast/sql/SqlBlock$Companion;
public field next Lorg/partiql/ast/sql/SqlBlock;
Expand Down
4 changes: 0 additions & 4 deletions partiql-ast/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ plugins {

dependencies {
api(Deps.ionElement)
api(project(":partiql-types"))
// TODO REMOVE ME ONCE PartiQLValue IS REMOVED
// THE AST NEEDS ITS OWN "VALUE" REPRESENTATION
api(project(":partiql-spi"))
compileOnly(Deps.lombok)
annotationProcessor(Deps.lombok)
}
Expand Down
7 changes: 3 additions & 4 deletions partiql-ast/src/main/java/org/partiql/ast/Explain.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Builder;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.partiql.value.PartiQLValue;
import org.partiql.ast.literal.Literal;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -16,14 +16,13 @@
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class Explain extends Statement {
// TODO get rid of PartiQLValue once https://github.com/partiql/partiql-lang-kotlin/issues/1589 is resolved
@NotNull
public final Map<String, PartiQLValue> options;
public final Map<String, Literal> options;

@NotNull
public final Statement statement;

public Explain(@NotNull Map<String, PartiQLValue> options, @NotNull Statement statement) {
public Explain(@NotNull Map<String, Literal> options, @NotNull Statement statement) {
this.options = options;
this.statement = statement;
}
Expand Down
12 changes: 5 additions & 7 deletions partiql-ast/src/main/java/org/partiql/ast/expr/ExprLit.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
package org.partiql.ast.expr;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.partiql.ast.AstNode;
import org.partiql.ast.AstVisitor;
import org.partiql.value.PartiQLValue;
import org.partiql.ast.literal.Literal;

import java.util.Collection;
import java.util.Collections;

/**
* TODO docs, equals, hashcode
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class ExprLit extends Expr {
@NotNull
public final PartiQLValue value; // This representation be changed in https://github.com/partiql/partiql-lang-kotlin/issues/1589
public Literal lit;

public ExprLit(@NotNull PartiQLValue value) {
this.value = value;
public ExprLit(@NotNull Literal lit) {
this.lit = lit;
}

@Override
@NotNull
@Override
public Collection<AstNode> children() {
return Collections.emptyList();
}
Expand Down
15 changes: 15 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/literal/Literal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.partiql.ast.literal;

import org.jetbrains.annotations.NotNull;

/**
* TODO docs
*/
public abstract class Literal {
@NotNull
public final String text;

protected Literal(@NotNull String _text) {
this.text = _text;
}
}
16 changes: 16 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/literal/LiteralBool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;

/**
* TODO docs
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralBool extends Literal {
public boolean value;

public LiteralBool(boolean value) {
super(String.valueOf(value));
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;

/**
* TODO DOCS
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralDecimal extends Literal {
@NotNull
public BigDecimal value;

public LiteralDecimal(@NotNull BigDecimal value) {
super(value.toString());
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

/**
* TODO docs
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralDouble extends Literal {
public double value;

public LiteralDouble(@NotNull String text) {
super(text);
this.value = Double.parseDouble(text);
}
}
16 changes: 16 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/literal/LiteralInt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;

/**
* TODO docs
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralInt extends Literal {
public int value;

public LiteralInt(int value) {
super(String.format("%d", value));
this.value = value;
}
}
16 changes: 16 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/literal/LiteralLong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;

/**
* TODO docs
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralLong extends Literal {
public long value;

public LiteralLong(long value) {
super(String.format("%d", value));
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;

/**
* TODO docs
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralMissing extends Literal {
public LiteralMissing() {
super("MISSING");
}
}
13 changes: 13 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/literal/LiteralNull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;

/**
* TODO docs
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralNull extends Literal {
public LiteralNull() {
super("NULL");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

/**
* TODO docs
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralString extends Literal {
@NotNull
public String value;

public LiteralString(@NotNull String value) {
super(String.format("'%s'", value));
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.partiql.ast.DataType;

/**
* TODO docs
* Represent type + 'some string value'
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralTypedString extends Literal {
@NotNull
public DataType type;

@NotNull
public String value;

public LiteralTypedString(@NotNull DataType type, @NotNull String value) {
super(String.format("%s '%s'", type.name(), value));
this.type = type;
this.value = value;
}
}
Loading

0 comments on commit 8579b04

Please sign in to comment.