From 7f382dbdb92f38dd44d9dbbc827981449fe9cc03 Mon Sep 17 00:00:00 2001 From: Alan Cai Date: Fri, 25 Oct 2024 09:45:32 -0700 Subject: [PATCH] [v1] Add .valueOf and .values methods for enums (#1628) --- partiql-ast/api/partiql-ast.api | 100 ++++++++++--- .../main/java/org/partiql/ast/v1/AstEnum.java | 8 ++ .../java/org/partiql/ast/v1/DataType.java | 136 +++++++++++++++++- .../org/partiql/ast/v1/DatetimeField.java | 49 ++++++- .../main/java/org/partiql/ast/v1/Enum.java | 8 -- .../java/org/partiql/ast/v1/FromType.java | 37 ++++- .../org/partiql/ast/v1/GroupByStrategy.java | 37 ++++- .../java/org/partiql/ast/v1/JoinType.java | 49 ++++++- .../main/java/org/partiql/ast/v1/Nulls.java | 38 ++++- .../main/java/org/partiql/ast/v1/Order.java | 37 ++++- .../java/org/partiql/ast/v1/SetOpType.java | 39 ++++- .../org/partiql/ast/v1/SetQuantifier.java | 39 ++++- .../java/org/partiql/ast/v1/expr/Scope.java | 42 +++++- .../partiql/ast/v1/expr/SessionAttribute.java | 41 +++++- .../org/partiql/ast/v1/expr/TrimSpec.java | 43 +++++- .../partiql/ast/v1/expr/WindowFunction.java | 41 +++++- .../partiql/ast/v1/graph/GraphDirection.java | 51 ++++++- .../partiql/ast/v1/graph/GraphRestrictor.java | 43 +++++- 18 files changed, 788 insertions(+), 50 deletions(-) create mode 100644 partiql-ast/src/main/java/org/partiql/ast/v1/AstEnum.java delete mode 100644 partiql-ast/src/main/java/org/partiql/ast/v1/Enum.java diff --git a/partiql-ast/api/partiql-ast.api b/partiql-ast/api/partiql-ast.api index b8df7c0cb..c74ffddad 100644 --- a/partiql-ast/api/partiql-ast.api +++ b/partiql-ast/api/partiql-ast.api @@ -5631,6 +5631,11 @@ public final class org/partiql/ast/v1/Ast { public static final fun sort (Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/Order;Lorg/partiql/ast/v1/Nulls;)Lorg/partiql/ast/v1/Sort; } +public abstract class org/partiql/ast/v1/AstEnum : org/partiql/ast/v1/AstNode { + public fun ()V + public abstract fun code ()I +} + public abstract class org/partiql/ast/v1/AstNode { public field tag Ljava/lang/String; public fun ()V @@ -5737,7 +5742,7 @@ public abstract interface class org/partiql/ast/v1/AstVisitor { public abstract fun visitTableRef (Lorg/partiql/ast/v1/FromTableRef;Ljava/lang/Object;)Ljava/lang/Object; } -public class org/partiql/ast/v1/DataType : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/DataType : org/partiql/ast/v1/AstEnum { public static final field BAG I public static final field BIGINT I public static final field BINARY_LARGE_OBJECT I @@ -5855,20 +5860,25 @@ 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; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun getLength ()Ljava/lang/Integer; public fun getName ()Lorg/partiql/ast/v1/IdentifierChain; public fun getPrecision ()Ljava/lang/Integer; public fun getScale ()Ljava/lang/Integer; public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/DataType; } -public class org/partiql/ast/v1/DatetimeField : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/DatetimeField : org/partiql/ast/v1/AstEnum { public static final field DAY I public static final field HOUR I public static final field MINUTE I @@ -5887,14 +5897,14 @@ public class org/partiql/ast/v1/DatetimeField : org/partiql/ast/v1/Enum { public static fun TIMEZONE_MINUTE ()Lorg/partiql/ast/v1/DatetimeField; public static fun UNKNOWN ()Lorg/partiql/ast/v1/DatetimeField; public static fun YEAR ()Lorg/partiql/ast/v1/DatetimeField; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I -} - -public abstract interface class org/partiql/ast/v1/Enum { - public abstract fun code ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/DatetimeField; } public class org/partiql/ast/v1/Exclude : org/partiql/ast/v1/AstNode { @@ -6074,17 +6084,21 @@ public abstract class org/partiql/ast/v1/FromTableRef : org/partiql/ast/v1/AstNo public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; } -public class org/partiql/ast/v1/FromType : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/FromType : org/partiql/ast/v1/AstEnum { public static final field SCAN I public static final field UNKNOWN I public static final field UNPIVOT I public static fun SCAN ()Lorg/partiql/ast/v1/FromType; public static fun UNKNOWN ()Lorg/partiql/ast/v1/FromType; public static fun UNPIVOT ()Lorg/partiql/ast/v1/FromType; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/FromType; } public class org/partiql/ast/v1/GroupBy : org/partiql/ast/v1/AstNode { @@ -6124,17 +6138,21 @@ public class org/partiql/ast/v1/GroupBy$Key$Builder { public fun toString ()Ljava/lang/String; } -public class org/partiql/ast/v1/GroupByStrategy : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/GroupByStrategy : org/partiql/ast/v1/AstEnum { public static final field FULL I public static final field PARTIAL I public static final field UNKNOWN I public static fun FULL ()Lorg/partiql/ast/v1/GroupByStrategy; public static fun PARTIAL ()Lorg/partiql/ast/v1/GroupByStrategy; public static fun UNKNOWN ()Lorg/partiql/ast/v1/GroupByStrategy; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/GroupByStrategy; } public class org/partiql/ast/v1/Identifier : org/partiql/ast/v1/AstNode { @@ -6175,7 +6193,7 @@ public class org/partiql/ast/v1/IdentifierChain$Builder { public fun toString ()Ljava/lang/String; } -public class org/partiql/ast/v1/JoinType : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/JoinType : org/partiql/ast/v1/AstEnum { public static final field CROSS I public static final field FULL I public static final field FULL_OUTER I @@ -6194,10 +6212,14 @@ public class org/partiql/ast/v1/JoinType : org/partiql/ast/v1/Enum { public static fun RIGHT ()Lorg/partiql/ast/v1/JoinType; public static fun RIGHT_OUTER ()Lorg/partiql/ast/v1/JoinType; public static fun UNKNOWN ()Lorg/partiql/ast/v1/JoinType; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/JoinType; } public class org/partiql/ast/v1/Let : org/partiql/ast/v1/AstNode { @@ -6233,30 +6255,38 @@ public class org/partiql/ast/v1/Let$Builder { public fun toString ()Ljava/lang/String; } -public class org/partiql/ast/v1/Nulls : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/Nulls : org/partiql/ast/v1/AstEnum { public static final field FIRST I public static final field LAST I public static final field UNKNOWN I public static fun FIRST ()Lorg/partiql/ast/v1/Nulls; public static fun LAST ()Lorg/partiql/ast/v1/Nulls; public static fun UNKNOWN ()Lorg/partiql/ast/v1/Nulls; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/Nulls; } -public class org/partiql/ast/v1/Order : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/Order : org/partiql/ast/v1/AstEnum { public static final field ASC I public static final field DESC I public static final field UNKNOWN I public static fun ASC ()Lorg/partiql/ast/v1/Order; public static fun DESC ()Lorg/partiql/ast/v1/Order; public static fun UNKNOWN ()Lorg/partiql/ast/v1/Order; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/Order; } public class org/partiql/ast/v1/OrderBy : org/partiql/ast/v1/AstNode { @@ -6488,28 +6518,36 @@ public class org/partiql/ast/v1/SetOp$Builder { public fun toString ()Ljava/lang/String; } -public class org/partiql/ast/v1/SetOpType : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/SetOpType : org/partiql/ast/v1/AstEnum { public static fun EXCEPT ()Lorg/partiql/ast/v1/SetOpType; public static fun INTERSECT ()Lorg/partiql/ast/v1/SetOpType; public static fun UNION ()Lorg/partiql/ast/v1/SetOpType; public static fun UNKNOWN ()Lorg/partiql/ast/v1/SetOpType; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/SetOpType; } -public class org/partiql/ast/v1/SetQuantifier : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/SetQuantifier : org/partiql/ast/v1/AstEnum { public static final field ALL I public static final field DISTINCT I public static final field UNKNOWN I public static fun ALL ()Lorg/partiql/ast/v1/SetQuantifier; public static fun DISTINCT ()Lorg/partiql/ast/v1/SetQuantifier; public static fun UNKNOWN ()Lorg/partiql/ast/v1/SetQuantifier; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/SetQuantifier; } public class org/partiql/ast/v1/Sort : org/partiql/ast/v1/AstNode { @@ -7268,20 +7306,24 @@ public class org/partiql/ast/v1/expr/PathStep$Field : org/partiql/ast/v1/expr/Pa public fun hashCode ()I } -public class org/partiql/ast/v1/expr/Scope : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/expr/Scope : org/partiql/ast/v1/AstEnum { public static final field DEFAULT I public static final field LOCAL I public static final field UNKNOWN I public static fun DEFAULT ()Lorg/partiql/ast/v1/expr/Scope; public static fun LOCAL ()Lorg/partiql/ast/v1/expr/Scope; public static fun UNKNOWN ()Lorg/partiql/ast/v1/expr/Scope; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/Scope; } -public class org/partiql/ast/v1/expr/SessionAttribute : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/expr/SessionAttribute : org/partiql/ast/v1/AstEnum { public static final field CURRENT_DATE I public static final field CURRENT_USER I public static final field UNKNOWN I @@ -7289,13 +7331,17 @@ public class org/partiql/ast/v1/expr/SessionAttribute : org/partiql/ast/v1/Enum public static fun CURRENT_DATE ()Lorg/partiql/ast/v1/expr/SessionAttribute; public static fun CURRENT_USER ()Lorg/partiql/ast/v1/expr/SessionAttribute; public static fun UNKNOWN ()Lorg/partiql/ast/v1/expr/SessionAttribute; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/SessionAttribute; } -public class org/partiql/ast/v1/expr/TrimSpec : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/expr/TrimSpec : org/partiql/ast/v1/AstEnum { public static final field BOTH I public static final field LEADING I public static final field TRAILING I @@ -7304,13 +7350,17 @@ public class org/partiql/ast/v1/expr/TrimSpec : org/partiql/ast/v1/Enum { public static fun LEADING ()Lorg/partiql/ast/v1/expr/TrimSpec; public static fun TRAILING ()Lorg/partiql/ast/v1/expr/TrimSpec; public static fun UNKNOWN ()Lorg/partiql/ast/v1/expr/TrimSpec; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/TrimSpec; } -public class org/partiql/ast/v1/expr/WindowFunction : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/expr/WindowFunction : org/partiql/ast/v1/AstEnum { public static final field LAG I public static final field LEAD I public static final field UNKNOWN I @@ -7318,13 +7368,17 @@ public class org/partiql/ast/v1/expr/WindowFunction : org/partiql/ast/v1/Enum { public static fun LAG ()Lorg/partiql/ast/v1/expr/WindowFunction; public static fun LEAD ()Lorg/partiql/ast/v1/expr/WindowFunction; public static fun UNKNOWN ()Lorg/partiql/ast/v1/expr/WindowFunction; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/WindowFunction; } -public class org/partiql/ast/v1/graph/GraphDirection : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/graph/GraphDirection : org/partiql/ast/v1/AstEnum { public static final field LEFT I public static final field LEFT_OR_RIGHT I public static final field LEFT_OR_UNDIRECTED I @@ -7341,10 +7395,14 @@ public class org/partiql/ast/v1/graph/GraphDirection : org/partiql/ast/v1/Enum { public static fun UNDIRECTED ()Lorg/partiql/ast/v1/graph/GraphDirection; public static fun UNDIRECTED_OR_RIGHT ()Lorg/partiql/ast/v1/graph/GraphDirection; public static fun UNKNOWN ()Lorg/partiql/ast/v1/graph/GraphDirection; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/graph/GraphDirection; } public abstract class org/partiql/ast/v1/graph/GraphLabel : org/partiql/ast/v1/AstNode { @@ -7570,7 +7628,7 @@ public class org/partiql/ast/v1/graph/GraphQuantifier$Builder { public fun upper (Ljava/lang/Long;)Lorg/partiql/ast/v1/graph/GraphQuantifier$Builder; } -public class org/partiql/ast/v1/graph/GraphRestrictor : org/partiql/ast/v1/Enum { +public class org/partiql/ast/v1/graph/GraphRestrictor : org/partiql/ast/v1/AstEnum { public static final field ACYCLIC I public static final field SIMPLE I public static final field TRAIL I @@ -7579,10 +7637,14 @@ public class org/partiql/ast/v1/graph/GraphRestrictor : org/partiql/ast/v1/Enum public static fun SIMPLE ()Lorg/partiql/ast/v1/graph/GraphRestrictor; public static fun TRAIL ()Lorg/partiql/ast/v1/graph/GraphRestrictor; public static fun UNKNOWN ()Lorg/partiql/ast/v1/graph/GraphRestrictor; + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; public fun code ()I + public static fun codes ()[I public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I + public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/graph/GraphRestrictor; } public abstract class org/partiql/ast/v1/graph/GraphSelector : org/partiql/ast/v1/AstNode { diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/AstEnum.java b/partiql-ast/src/main/java/org/partiql/ast/v1/AstEnum.java new file mode 100644 index 000000000..31e644a1f --- /dev/null +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/AstEnum.java @@ -0,0 +1,8 @@ +package org.partiql.ast.v1; + +/** + * TODO docs, equals, hashcode + */ +public abstract class AstEnum extends AstNode { + public abstract int code(); +} diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/DataType.java b/partiql-ast/src/main/java/org/partiql/ast/v1/DataType.java index 2a734b2f9..a23d7531e 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/DataType.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/DataType.java @@ -1,9 +1,14 @@ package org.partiql.ast.v1; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; @EqualsAndHashCode(callSuper = false) -public class DataType implements Enum { +public class DataType extends AstEnum { public static final int UNKNOWN = 0; // public static final int NULL = 1; @@ -349,7 +354,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); } @@ -391,6 +400,114 @@ public int code() { return code; } + @NotNull + private static final int[] codes = { + 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 + }; + + @NotNull + public static DataType parse(@NotNull 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(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + /** * TODO docs * @return @@ -422,4 +539,19 @@ public Integer getLength() { public IdentifierChain getName() { return name; } + + @NotNull + @Override + public Collection children() { + List kids = new ArrayList<>(); + if (name != null) { + kids.add(name); + } + return kids; + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/DatetimeField.java b/partiql-ast/src/main/java/org/partiql/ast/v1/DatetimeField.java index e5a34541c..b97b78355 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/DatetimeField.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/DatetimeField.java @@ -1,12 +1,16 @@ package org.partiql.ast.v1; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class DatetimeField implements Enum { +public class DatetimeField extends AstEnum { public static final int UNKNOWN = 0; public static final int YEAR = 1; public static final int MONTH = 2; @@ -63,4 +67,47 @@ private DatetimeField(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + YEAR, + MONTH, + DAY, + HOUR, + MINUTE, + SECOND, + TIMEZONE_HOUR, + TIMEZONE_MINUTE + }; + + @NotNull + public static DatetimeField parse(@NotNull 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(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/Enum.java b/partiql-ast/src/main/java/org/partiql/ast/v1/Enum.java deleted file mode 100644 index e4551f21f..000000000 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/Enum.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.partiql.ast.v1; - -/** - * TODO docs, equals, hashcode - */ -public interface Enum { - int code(); -} diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/FromType.java b/partiql-ast/src/main/java/org/partiql/ast/v1/FromType.java index b563f70d8..757c8caef 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/FromType.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/FromType.java @@ -1,12 +1,16 @@ package org.partiql.ast.v1; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class FromType implements Enum { +public class FromType extends AstEnum { public static final int UNKNOWN = 0; public static final int SCAN = 1; public static final int UNPIVOT = 2; @@ -33,4 +37,35 @@ private FromType(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + SCAN, + UNPIVOT + }; + + @NotNull + public static FromType parse(@NotNull String value) { + switch (value) { + case "SCAN": return SCAN(); + case "UNPIVOT": return UNPIVOT(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/GroupByStrategy.java b/partiql-ast/src/main/java/org/partiql/ast/v1/GroupByStrategy.java index 3329ea556..c39938404 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/GroupByStrategy.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/GroupByStrategy.java @@ -1,12 +1,16 @@ package org.partiql.ast.v1; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class GroupByStrategy implements Enum { +public class GroupByStrategy extends AstEnum { public static final int UNKNOWN = 0; public static final int FULL = 1; public static final int PARTIAL = 2; @@ -25,6 +29,12 @@ public static GroupByStrategy PARTIAL() { private final int code; + @NotNull + private static final int[] codes = { + FULL, + PARTIAL + }; + private GroupByStrategy(int code) { this.code = code; } @@ -33,4 +43,29 @@ private GroupByStrategy(int code) { public int code() { return code; } + + @NotNull + public static GroupByStrategy parse(@NotNull String value) { + switch (value) { + case "FULL": return FULL(); + case "PARTIAL": return PARTIAL(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/JoinType.java b/partiql-ast/src/main/java/org/partiql/ast/v1/JoinType.java index af4a13ba3..b77ab6aae 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/JoinType.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/JoinType.java @@ -1,12 +1,16 @@ package org.partiql.ast.v1; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class JoinType implements Enum { +public class JoinType extends AstEnum { public static final int UNKNOWN = 0; public static final int INNER = 1; public static final int LEFT = 2; @@ -63,4 +67,47 @@ private JoinType(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + INNER, + LEFT, + LEFT_OUTER, + RIGHT, + RIGHT_OUTER, + FULL, + FULL_OUTER, + CROSS + }; + + @NotNull + public static JoinType parse(@NotNull 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(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/Nulls.java b/partiql-ast/src/main/java/org/partiql/ast/v1/Nulls.java index 4b90b1157..685f8a6b3 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/Nulls.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/Nulls.java @@ -1,12 +1,16 @@ package org.partiql.ast.v1; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class Nulls implements Enum { +public class Nulls extends AstEnum { public static final int UNKNOWN = 0; public static final int FIRST = 1; public static final int LAST = 2; @@ -33,4 +37,36 @@ private Nulls(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + FIRST, + LAST + }; + + @NotNull + public static Nulls parse(@NotNull String value) { + switch (value) { + case "UNKNOWN": return UNKNOWN(); + case "FIRST": return FIRST(); + case "LAST": return LAST(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/Order.java b/partiql-ast/src/main/java/org/partiql/ast/v1/Order.java index eb451ee4a..1b8874d45 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/Order.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/Order.java @@ -1,9 +1,13 @@ package org.partiql.ast.v1; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Collections; @EqualsAndHashCode(callSuper = false) -public class Order implements Enum { +public class Order extends AstEnum { public static final int UNKNOWN = 0; public static final int ASC = 1; public static final int DESC = 2; @@ -30,4 +34,35 @@ private Order(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + ASC, + DESC + }; + + @NotNull + public static Order parse(@NotNull String value) { + switch (value) { + case "ASC": return ASC(); + case "DESC": return DESC(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/SetOpType.java b/partiql-ast/src/main/java/org/partiql/ast/v1/SetOpType.java index 1d5bc233e..8be3789ec 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/SetOpType.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/SetOpType.java @@ -1,12 +1,16 @@ package org.partiql.ast.v1; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class SetOpType implements Enum { +public class SetOpType extends AstEnum { private static final int UNKNOWN = 0; private static final int UNION = 1; private static final int INTERSECT = 2; @@ -38,4 +42,37 @@ private SetOpType(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + UNION, + INTERSECT, + EXCEPT + }; + + @NotNull + public static SetOpType parse(@NotNull String value) { + switch (value) { + case "UNION": return UNION(); + case "INTERSECT": return INTERSECT(); + case "EXCEPT": return EXCEPT(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/SetQuantifier.java b/partiql-ast/src/main/java/org/partiql/ast/v1/SetQuantifier.java index 43f14f2fb..b6a56ee07 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/SetQuantifier.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/SetQuantifier.java @@ -1,12 +1,16 @@ package org.partiql.ast.v1; import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class SetQuantifier implements Enum { +public class SetQuantifier extends AstEnum { public static final int UNKNOWN = 0; public static final int ALL = 1; public static final int DISTINCT = 2; @@ -33,4 +37,35 @@ private SetQuantifier(int code) { public int code() { return code; } -} \ No newline at end of file + + @NotNull + private static final int[] codes = { + ALL, + DISTINCT + }; + + @NotNull + public static SetQuantifier parse(@NotNull String value) { + switch (value) { + case "ALL": return ALL(); + case "DISTINCT": return DISTINCT(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } +} diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/Scope.java b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/Scope.java index 0c65a933c..ce02e250e 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/Scope.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/Scope.java @@ -1,13 +1,19 @@ package org.partiql.ast.v1.expr; import lombok.EqualsAndHashCode; -import org.partiql.ast.v1.Enum; +import org.jetbrains.annotations.NotNull; +import org.partiql.ast.v1.AstEnum; +import org.partiql.ast.v1.AstNode; +import org.partiql.ast.v1.AstVisitor; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class Scope implements Enum { +public class Scope extends AstEnum { public static final int UNKNOWN = 0; public static final int DEFAULT = 1; public static final int LOCAL = 2; @@ -34,4 +40,36 @@ private Scope(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + DEFAULT, + LOCAL + }; + + @NotNull + public static Scope parse(@NotNull String value) { + switch (value) { + case "UNKNOWN": return UNKNOWN(); + case "DEFAULT": return DEFAULT(); + case "LOCAL": return LOCAL(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/SessionAttribute.java b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/SessionAttribute.java index 86c00da63..2ddde378d 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/SessionAttribute.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/SessionAttribute.java @@ -1,13 +1,19 @@ package org.partiql.ast.v1.expr; import lombok.EqualsAndHashCode; -import org.partiql.ast.v1.Enum; +import org.jetbrains.annotations.NotNull; +import org.partiql.ast.v1.AstEnum; +import org.partiql.ast.v1.AstNode; +import org.partiql.ast.v1.AstVisitor; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class SessionAttribute implements Enum { +public class SessionAttribute extends AstEnum { public static final int UNKNOWN = 0; public static final int CURRENT_USER = 1; public static final int CURRENT_DATE = 2; @@ -34,4 +40,35 @@ public SessionAttribute(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + CURRENT_USER, + CURRENT_DATE + }; + + @NotNull + public static SessionAttribute parse(@NotNull String value) { + switch (value) { + case "CURRENT_USER": return CURRENT_USER(); + case "CURRENT_DATE": return CURRENT_DATE(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/TrimSpec.java b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/TrimSpec.java index 3f1295a44..0e63de30a 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/TrimSpec.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/TrimSpec.java @@ -1,10 +1,16 @@ package org.partiql.ast.v1.expr; import lombok.EqualsAndHashCode; -import org.partiql.ast.v1.Enum; +import org.jetbrains.annotations.NotNull; +import org.partiql.ast.v1.AstEnum; +import org.partiql.ast.v1.AstNode; +import org.partiql.ast.v1.AstVisitor; + +import java.util.Collection; +import java.util.Collections; @EqualsAndHashCode(callSuper = false) -public class TrimSpec implements Enum { +public class TrimSpec extends AstEnum { public static final int UNKNOWN = 0; public static final int LEADING = 1; public static final int TRAILING = 2; @@ -36,4 +42,37 @@ private TrimSpec(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + LEADING, + TRAILING, + BOTH + }; + + @NotNull + public static TrimSpec parse(@NotNull String value) { + switch (value) { + case "LEADING": return LEADING(); + case "TRAILING": return TRAILING(); + case "BOTH": return BOTH(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/WindowFunction.java b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/WindowFunction.java index 4085ac92b..edb102f91 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/WindowFunction.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/WindowFunction.java @@ -1,13 +1,19 @@ package org.partiql.ast.v1.expr; import lombok.EqualsAndHashCode; -import org.partiql.ast.v1.Enum; +import org.jetbrains.annotations.NotNull; +import org.partiql.ast.v1.AstEnum; +import org.partiql.ast.v1.AstNode; +import org.partiql.ast.v1.AstVisitor; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class WindowFunction implements Enum { +public class WindowFunction extends AstEnum { public static final int UNKNOWN = 0; public static final int LAG = 0; public static final int LEAD = 0; @@ -34,4 +40,35 @@ public WindowFunction(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + LAG, + LEAD + }; + + @NotNull + public static WindowFunction parse(@NotNull String value) { + switch (value) { + case "LAG": return LAG(); + case "LEAD": return LEAD(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphDirection.java b/partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphDirection.java index c2d8f092c..ddf01bfe5 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphDirection.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphDirection.java @@ -1,13 +1,19 @@ package org.partiql.ast.v1.graph; import lombok.EqualsAndHashCode; -import org.partiql.ast.v1.Enum; +import org.jetbrains.annotations.NotNull; +import org.partiql.ast.v1.AstEnum; +import org.partiql.ast.v1.AstNode; +import org.partiql.ast.v1.AstVisitor; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class GraphDirection implements Enum { +public class GraphDirection extends AstEnum { public static final int UNKNOWN = 0; public static final int LEFT = 1; public static final int UNDIRECTED = 2; @@ -51,6 +57,17 @@ public static GraphDirection LEFT_UNDIRECTED_OR_RIGHT() { private final int code; + @NotNull + private static final int[] codes = { + LEFT, + UNDIRECTED, + RIGHT, + LEFT_OR_UNDIRECTED, + UNDIRECTED_OR_RIGHT, + LEFT_OR_RIGHT, + LEFT_UNDIRECTED_OR_RIGHT + }; + private GraphDirection(int code) { this.code = code; } @@ -59,4 +76,34 @@ private GraphDirection(int code) { public int code() { return code; } + + @NotNull + public static GraphDirection parse(@NotNull String value) { + switch (value) { + case "LEFT": return LEFT(); + case "UNDIRECTED": return UNDIRECTED(); + case "RIGHT": return RIGHT(); + case "LEFT_OR_UNDIRECTED": return LEFT_OR_UNDIRECTED(); + case "UNDIRECTED_OR_RIGHT": return UNDIRECTED_OR_RIGHT(); + case "LEFT_OR_RIGHT": return LEFT_OR_RIGHT(); + case "LEFT_UNDIRECTED_OR_RIGHT": return LEFT_UNDIRECTED_OR_RIGHT(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphRestrictor.java b/partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphRestrictor.java index dcdde8f5c..5b491ef56 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphRestrictor.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphRestrictor.java @@ -1,13 +1,19 @@ package org.partiql.ast.v1.graph; import lombok.EqualsAndHashCode; -import org.partiql.ast.v1.Enum; +import org.jetbrains.annotations.NotNull; +import org.partiql.ast.v1.AstEnum; +import org.partiql.ast.v1.AstNode; +import org.partiql.ast.v1.AstVisitor; + +import java.util.Collection; +import java.util.Collections; /** * TODO docs, equals, hashcode */ @EqualsAndHashCode(callSuper = false) -public class GraphRestrictor implements Enum { +public class GraphRestrictor extends AstEnum { public static final int UNKNOWN = 0; public static final int TRAIL = 1; public static final int ACYCLIC = 2; @@ -39,4 +45,37 @@ private GraphRestrictor(int code) { public int code() { return code; } + + @NotNull + private static final int[] codes = { + TRAIL, + ACYCLIC, + SIMPLE + }; + + @NotNull + public static GraphRestrictor parse(@NotNull String value) { + switch (value) { + case "TRAIL": return TRAIL(); + case "ACYCLIC": return ACYCLIC(); + case "SIMPLE": return SIMPLE(); + default: return UNKNOWN(); + } + } + + @NotNull + public static int[] codes() { + return codes; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return null; + } }