Skip to content

Commit

Permalink
[v1] Add .valueOf and .values methods for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Oct 22, 2024
1 parent 34a0993 commit bb30367
Show file tree
Hide file tree
Showing 16 changed files with 394 additions and 2 deletions.
31 changes: 31 additions & 0 deletions partiql-ast/api/partiql-ast.api
Original file line number Diff line number Diff line change
Expand Up @@ -5855,6 +5855,7 @@ public class org/partiql/ast/v1/DataType : org/partiql/ast/v1/Enum {
public static fun TINYINT ()Lorg/partiql/ast/v1/DataType;
public static fun TUPLE ()Lorg/partiql/ast/v1/DataType;
public static fun UNKNOWN ()Lorg/partiql/ast/v1/DataType;
public static fun USER_DEFINED ()Lorg/partiql/ast/v1/DataType;
public static fun USER_DEFINED (Lorg/partiql/ast/v1/IdentifierChain;)Lorg/partiql/ast/v1/DataType;
public static fun VARCHAR ()Lorg/partiql/ast/v1/DataType;
public static fun VARCHAR (I)Lorg/partiql/ast/v1/DataType;
Expand All @@ -5866,6 +5867,8 @@ public class org/partiql/ast/v1/DataType : org/partiql/ast/v1/Enum {
public fun getPrecision ()Ljava/lang/Integer;
public fun getScale ()Ljava/lang/Integer;
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/DataType;
public static fun values ()[Lorg/partiql/ast/v1/DataType;
}

public class org/partiql/ast/v1/DatetimeField : org/partiql/ast/v1/Enum {
Expand All @@ -5891,6 +5894,8 @@ public class org/partiql/ast/v1/DatetimeField : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/DatetimeField;
public static fun values ()[Lorg/partiql/ast/v1/DatetimeField;
}

public abstract interface class org/partiql/ast/v1/Enum {
Expand Down Expand Up @@ -6085,6 +6090,8 @@ public class org/partiql/ast/v1/FromType : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/FromType;
public static fun values ()[Lorg/partiql/ast/v1/FromType;
}

public class org/partiql/ast/v1/GroupBy : org/partiql/ast/v1/AstNode {
Expand Down Expand Up @@ -6135,6 +6142,8 @@ public class org/partiql/ast/v1/GroupByStrategy : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/GroupByStrategy;
public static fun values ()[Lorg/partiql/ast/v1/GroupByStrategy;
}

public class org/partiql/ast/v1/Identifier : org/partiql/ast/v1/AstNode {
Expand Down Expand Up @@ -6198,6 +6207,8 @@ public class org/partiql/ast/v1/JoinType : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/JoinType;
public static fun values ()[Lorg/partiql/ast/v1/JoinType;
}

public class org/partiql/ast/v1/Let : org/partiql/ast/v1/AstNode {
Expand Down Expand Up @@ -6244,6 +6255,8 @@ public class org/partiql/ast/v1/Nulls : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/Nulls;
public static fun values ()[Lorg/partiql/ast/v1/Nulls;
}

public class org/partiql/ast/v1/Order : org/partiql/ast/v1/Enum {
Expand All @@ -6257,6 +6270,8 @@ public class org/partiql/ast/v1/Order : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/Order;
public static fun values ()[Lorg/partiql/ast/v1/Order;
}

public class org/partiql/ast/v1/OrderBy : org/partiql/ast/v1/AstNode {
Expand Down Expand Up @@ -6497,6 +6512,8 @@ public class org/partiql/ast/v1/SetOpType : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/SetOpType;
public static fun values ()[Lorg/partiql/ast/v1/SetOpType;
}

public class org/partiql/ast/v1/SetQuantifier : org/partiql/ast/v1/Enum {
Expand All @@ -6510,6 +6527,8 @@ public class org/partiql/ast/v1/SetQuantifier : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/SetQuantifier;
public static fun values ()[Lorg/partiql/ast/v1/SetQuantifier;
}

public class org/partiql/ast/v1/Sort : org/partiql/ast/v1/AstNode {
Expand Down Expand Up @@ -7279,6 +7298,8 @@ public class org/partiql/ast/v1/expr/Scope : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/Scope;
public static fun values ()[Lorg/partiql/ast/v1/expr/Scope;
}

public class org/partiql/ast/v1/expr/SessionAttribute : org/partiql/ast/v1/Enum {
Expand All @@ -7293,6 +7314,8 @@ public class org/partiql/ast/v1/expr/SessionAttribute : org/partiql/ast/v1/Enum
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/SessionAttribute;
public static fun values ()[Lorg/partiql/ast/v1/expr/SessionAttribute;
}

public class org/partiql/ast/v1/expr/TrimSpec : org/partiql/ast/v1/Enum {
Expand All @@ -7308,6 +7331,8 @@ public class org/partiql/ast/v1/expr/TrimSpec : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/TrimSpec;
public static fun values ()[Lorg/partiql/ast/v1/expr/TrimSpec;
}

public class org/partiql/ast/v1/expr/WindowFunction : org/partiql/ast/v1/Enum {
Expand All @@ -7322,6 +7347,8 @@ public class org/partiql/ast/v1/expr/WindowFunction : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/WindowFunction;
public static fun values ()[Lorg/partiql/ast/v1/expr/WindowFunction;
}

public class org/partiql/ast/v1/graph/GraphDirection : org/partiql/ast/v1/Enum {
Expand All @@ -7345,6 +7372,8 @@ public class org/partiql/ast/v1/graph/GraphDirection : org/partiql/ast/v1/Enum {
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/graph/GraphDirection;
public static fun values ()[Lorg/partiql/ast/v1/graph/GraphDirection;
}

public abstract class org/partiql/ast/v1/graph/GraphLabel : org/partiql/ast/v1/AstNode {
Expand Down Expand Up @@ -7583,6 +7612,8 @@ public class org/partiql/ast/v1/graph/GraphRestrictor : org/partiql/ast/v1/Enum
public fun code ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun valueOf (Ljava/lang/String;)Lorg/partiql/ast/v1/graph/GraphRestrictor;
public static fun values ()[Lorg/partiql/ast/v1/graph/GraphRestrictor;
}

public abstract class org/partiql/ast/v1/graph/GraphSelector : org/partiql/ast/v1/AstNode {
Expand Down
110 changes: 109 additions & 1 deletion partiql-ast/src/main/java/org/partiql/ast/v1/DataType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.partiql.ast.v1;

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

@EqualsAndHashCode(callSuper = false)
public class DataType implements Enum {
Expand Down Expand Up @@ -349,7 +350,11 @@ public static DataType INTERVAL() {
return new DataType(INTERVAL);
}

public static DataType USER_DEFINED(IdentifierChain name) {
public static DataType USER_DEFINED() {
return new DataType(USER_DEFINED);
}

public static DataType USER_DEFINED(@NotNull IdentifierChain name) {
return new DataType(USER_DEFINED, name);
}

Expand Down Expand Up @@ -391,6 +396,109 @@ public int code() {
return code;
}

public static DataType valueOf(String value) {
switch (value) {
case "NULL": return NULL();
case "MISSING": return MISSING();
case "BOOL": return BOOL();
case "BOOLEAN": return BOOLEAN();
case "TINYINT": return TINYINT();
case "SMALLINT": return SMALLINT();
case "INTEGER2": return INTEGER2();
case "INT2": return INT2();
case "INTEGER": return INTEGER();
case "INT": return INT();
case "INTEGER4": return INTEGER4();
case "INT4": return INT4();
case "INTEGER8": return INTEGER8();
case "INT8": return INT8();
case "BIGINT": return BIGINT();
case "REAL": return REAL();
case "DOUBLE_PRECISION": return DOUBLE_PRECISION();
case "FLOAT": return FLOAT();
case "DECIMAL": return DECIMAL();
case "DEC": return DEC();
case "NUMERIC": return NUMERIC();
case "BIT": return BIT();
case "BIT_VARYING": return BIT_VARYING();
case "CHAR": return CHAR();
case "CHARACTER": return CHARACTER();
case "VARCHAR": return VARCHAR();
case "CHARACTER_LARGE_OBJECT": return CHARACTER_LARGE_OBJECT();
case "CHAR_LARGE_OBJECT": return CHAR_LARGE_OBJECT();
case "CHAR_VARYING": return CHAR_VARYING();
case "STRING": return STRING();
case "SYMBOL": return SYMBOL();
case "BLOB": return BLOB();
case "BINARY_LARGE_OBJECT": return BINARY_LARGE_OBJECT();
case "CLOB": return CLOB();
case "DATE": return DATE();
case "STRUCT": return STRUCT();
case "TUPLE": return TUPLE();
case "LIST": return LIST();
case "SEXP": return SEXP();
case "BAG": return BAG();
case "TIME": return TIME();
case "TIME_WITH_TIME_ZONE": return TIME_WITH_TIME_ZONE();
case "TIMESTAMP": return TIMESTAMP();
case "TIMESTAMP_WITH_TIME_ZONE": return TIMESTAMP_WITH_TIME_ZONE();
case "INTERVAL": return INTERVAL();
case "USER_DEFINED": return USER_DEFINED();
default: return UNKNOWN();
}
}

public static DataType[] values() {
return new DataType[] {
NULL(),
MISSING(),
BOOL(),
BOOLEAN(),
TINYINT(),
SMALLINT(),
INTEGER2(),
INT2(),
INTEGER(),
INT(),
INTEGER4(),
INT4(),
INTEGER8(),
INT8(),
BIGINT(),
REAL(),
DOUBLE_PRECISION(),
FLOAT(),
DECIMAL(),
DEC(),
NUMERIC(),
BIT(),
BIT_VARYING(),
CHAR(),
CHARACTER(),
VARCHAR(),
CHARACTER_LARGE_OBJECT(),
CHAR_LARGE_OBJECT(),
CHAR_VARYING(),
STRING(),
SYMBOL(),
BLOB(),
BINARY_LARGE_OBJECT(),
CLOB(),
DATE(),
STRUCT(),
TUPLE(),
LIST(),
SEXP(),
BAG(),
TIME(),
TIME_WITH_TIME_ZONE(),
TIMESTAMP(),
TIMESTAMP_WITH_TIME_ZONE(),
INTERVAL(),
USER_DEFINED()
};
}

/**
* TODO docs
* @return
Expand Down
27 changes: 27 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/v1/DatetimeField.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,31 @@ private DatetimeField(int code) {
public int code() {
return code;
}

public static DatetimeField valueOf(String value) {
switch (value) {
case "YEAR": return YEAR();
case "MONTH": return MONTH();
case "DAY": return DAY();
case "HOUR": return HOUR();
case "MINUTE": return MINUTE();
case "SECOND": return SECOND();
case "TIMEZONE_HOUR": return TIMEZONE_HOUR();
case "TIMEZONE_MINUTE": return TIMEZONE_MINUTE();
default: return UNKNOWN();
}
}

public static DatetimeField[] values() {
return new DatetimeField[] {
YEAR(),
MONTH(),
DAY(),
HOUR(),
MINUTE(),
SECOND(),
TIMEZONE_HOUR(),
TIMEZONE_MINUTE()
};
}
}
15 changes: 15 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/v1/FromType.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,19 @@ private FromType(int code) {
public int code() {
return code;
}

public static FromType valueOf(String value) {
switch (value) {
case "SCAN": return SCAN();
case "UNPIVOT": return UNPIVOT();
default: return UNKNOWN();
}
}

public static FromType[] values() {
return new FromType[] {
SCAN(),
UNPIVOT()
};
}
}
15 changes: 15 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/v1/GroupByStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,19 @@ private GroupByStrategy(int code) {
public int code() {
return code;
}

public static GroupByStrategy valueOf(String value) {
switch (value) {
case "FULL": return FULL();
case "PARTIAL": return PARTIAL();
default: return UNKNOWN();
}
}

public static GroupByStrategy[] values() {
return new GroupByStrategy[] {
FULL(),
PARTIAL()
};
}
}
27 changes: 27 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/v1/JoinType.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,31 @@ private JoinType(int code) {
public int code() {
return code;
}

public static JoinType valueOf(String value) {
switch (value) {
case "INNER": return INNER();
case "LEFT": return LEFT();
case "LEFT_OUTER": return LEFT_OUTER();
case "RIGHT": return RIGHT();
case "RIGHT_OUTER": return RIGHT_OUTER();
case "FULL": return FULL();
case "FULL_OUTER": return FULL_OUTER();
case "CROSS": return CROSS();
default: return UNKNOWN();
}
}

public static JoinType[] values() {
return new JoinType[] {
INNER(),
LEFT(),
LEFT_OUTER(),
RIGHT(),
RIGHT_OUTER(),
FULL(),
FULL_OUTER(),
CROSS()
};
}
}
16 changes: 16 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/v1/Nulls.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@ private Nulls(int code) {
public int code() {
return code;
}

public static Nulls valueOf(String value) {
switch (value) {
case "UNKNOWN": return UNKNOWN();
case "FIRST": return FIRST();
case "LAST": return LAST();
default: return UNKNOWN();
}
}

public static Nulls[] values() {
return new Nulls[] {
FIRST(),
LAST()
};
}
}
Loading

0 comments on commit bb30367

Please sign in to comment.