Skip to content

Commit

Permalink
[v1] Add .name method to AstEnum (#1630)
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 authored Oct 28, 2024
1 parent 7f382db commit 246b63c
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 35 deletions.
20 changes: 20 additions & 0 deletions partiql-ast/api/partiql-ast.api
Original file line number Diff line number Diff line change
Expand Up @@ -5634,6 +5634,7 @@ public final class org/partiql/ast/v1/Ast {
public abstract class org/partiql/ast/v1/AstEnum : org/partiql/ast/v1/AstNode {
public fun <init> ()V
public abstract fun code ()I
public abstract fun name ()Ljava/lang/String;
}

public abstract class org/partiql/ast/v1/AstNode {
Expand Down Expand Up @@ -5875,6 +5876,7 @@ public class org/partiql/ast/v1/DataType : org/partiql/ast/v1/AstEnum {
public fun getPrecision ()Ljava/lang/Integer;
public fun getScale ()Ljava/lang/Integer;
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/DataType;
}

Expand Down Expand Up @@ -5904,6 +5906,7 @@ public class org/partiql/ast/v1/DatetimeField : org/partiql/ast/v1/AstEnum {
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/DatetimeField;
}

Expand Down Expand Up @@ -6098,6 +6101,7 @@ public class org/partiql/ast/v1/FromType : org/partiql/ast/v1/AstEnum {
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/FromType;
}

Expand Down Expand Up @@ -6152,6 +6156,7 @@ public class org/partiql/ast/v1/GroupByStrategy : org/partiql/ast/v1/AstEnum {
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/GroupByStrategy;
}

Expand Down Expand Up @@ -6219,6 +6224,7 @@ public class org/partiql/ast/v1/JoinType : org/partiql/ast/v1/AstEnum {
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/JoinType;
}

Expand Down Expand Up @@ -6269,6 +6275,7 @@ public class org/partiql/ast/v1/Nulls : org/partiql/ast/v1/AstEnum {
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/Nulls;
}

Expand All @@ -6286,6 +6293,7 @@ public class org/partiql/ast/v1/Order : org/partiql/ast/v1/AstEnum {
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/Order;
}

Expand Down Expand Up @@ -6519,6 +6527,10 @@ public class org/partiql/ast/v1/SetOp$Builder {
}

public class org/partiql/ast/v1/SetOpType : org/partiql/ast/v1/AstEnum {
public static final field EXCEPT I
public static final field INTERSECT I
public static final field UNION I
public static final field UNKNOWN I
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;
Expand All @@ -6530,6 +6542,7 @@ public class org/partiql/ast/v1/SetOpType : org/partiql/ast/v1/AstEnum {
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/SetOpType;
}

Expand All @@ -6547,6 +6560,7 @@ public class org/partiql/ast/v1/SetQuantifier : org/partiql/ast/v1/AstEnum {
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/SetQuantifier;
}

Expand Down Expand Up @@ -7320,6 +7334,7 @@ public class org/partiql/ast/v1/expr/Scope : org/partiql/ast/v1/AstEnum {
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/Scope;
}

Expand All @@ -7338,6 +7353,7 @@ public class org/partiql/ast/v1/expr/SessionAttribute : org/partiql/ast/v1/AstEn
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/SessionAttribute;
}

Expand All @@ -7357,6 +7373,7 @@ public class org/partiql/ast/v1/expr/TrimSpec : org/partiql/ast/v1/AstEnum {
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/TrimSpec;
}

Expand All @@ -7375,6 +7392,7 @@ public class org/partiql/ast/v1/expr/WindowFunction : org/partiql/ast/v1/AstEnum
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/expr/WindowFunction;
}

Expand Down Expand Up @@ -7402,6 +7420,7 @@ public class org/partiql/ast/v1/graph/GraphDirection : org/partiql/ast/v1/AstEnu
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/graph/GraphDirection;
}

Expand Down Expand Up @@ -7644,6 +7663,7 @@ public class org/partiql/ast/v1/graph/GraphRestrictor : org/partiql/ast/v1/AstEn
public static fun codes ()[I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun name ()Ljava/lang/String;
public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/v1/graph/GraphRestrictor;
}

Expand Down
5 changes: 5 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/v1/AstEnum.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.partiql.ast.v1;

import org.jetbrains.annotations.NotNull;

/**
* TODO docs, equals, hashcode
*/
public abstract class AstEnum extends AstNode {
public abstract int code();

@NotNull
public abstract String name();
}
114 changes: 85 additions & 29 deletions partiql-ast/src/main/java/org/partiql/ast/v1/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,53 +400,109 @@ public int code() {
return code;
}

@NotNull
@Override
public String name() {
switch (code) {
case NULL: return "NULL";
case MISSING: return "MISSING";
case CHARACTER: return "CHARACTER";
case CHAR: return "CHAR";
case CHARACTER_VARYING: return "CHARACTER_VARYING";
case CHAR_VARYING: return "CHAR_VARYING";
case VARCHAR: return "VARCHAR";
case CHARACTER_LARGE_OBJECT: return "CHARACTER_LARGE_OBJECT";
case CHAR_LARGE_OBJECT: return "CHAR_LARGE_OBJECT";
case CLOB: return "CLOB";
case STRING: return "STRING";
case SYMBOL: return "SYMBOL";
case BLOB: return "BLOB";
case BINARY_LARGE_OBJECT: return "BINARY_LARGE_OBJECT";
case BIT: return "BIT";
case BIT_VARYING: return "BIT_VARYING";
case NUMERIC: return "NUMERIC";
case DECIMAL: return "DECIMAL";
case DEC: return "DEC";
case BIGINT: return "BIGINT";
case INT8: return "INT8";
case INTEGER8: return "INTEGER8";
case INT4: return "INT4";
case INTEGER4: return "INTEGER4";
case INTEGER: return "INTEGER";
case INT: return "INT";
case INT2: return "INT2";
case INTEGER2: return "INTEGER2";
case SMALLINT: return "SMALLINT";
case TINYINT: return "TINYINT";
case FLOAT: return "FLOAT";
case REAL: return "REAL";
case DOUBLE_PRECISION: return "DOUBLE_PRECISION";
case BOOLEAN: return "BOOLEAN";
case BOOL: return "BOOL";
case DATE: return "DATE";
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 STRUCT: return "STRUCT";
case TUPLE: return "TUPLE";
case LIST: return "LIST";
case BAG: return "BAG";
case SEXP: return "SEXP";
case USER_DEFINED: return "USER_DEFINED";
default: return "UNKNOWN";
}
}

@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,
CHAR,
CHARACTER_VARYING,
CHAR_VARYING,
VARCHAR,
CHARACTER_LARGE_OBJECT,
CHAR_LARGE_OBJECT,
CHAR_VARYING,
CLOB,
STRING,
SYMBOL,
BLOB,
BINARY_LARGE_OBJECT,
CLOB,
BIT,
BIT_VARYING,
NUMERIC,
DECIMAL,
DEC,
BIGINT,
INT8,
INTEGER8,
INT4,
INTEGER4,
INTEGER,
INT,
INT2,
INTEGER2,
SMALLINT,
TINYINT,
FLOAT,
REAL,
DOUBLE_PRECISION,
BOOLEAN,
BOOL,
DATE,
STRUCT,
TUPLE,
LIST,
SEXP,
BAG,
TIME,
TIME_WITH_TIME_ZONE,
TIMESTAMP,
TIMESTAMP_WITH_TIME_ZONE,
INTERVAL,
STRUCT,
TUPLE,
LIST,
BAG,
SEXP,
USER_DEFINED
};

Expand Down
16 changes: 16 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 @@ -68,6 +68,22 @@ public int code() {
return code;
}

@NotNull
@Override
public String name() {
switch (code) {
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
private static final int[] codes = {
YEAR,
Expand Down
10 changes: 10 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 @@ -38,6 +38,16 @@ public int code() {
return code;
}

@NotNull
@Override
public String name() {
switch (code) {
case SCAN: return "SCAN";
case UNPIVOT: return "UNPIVOT";
default: return "UNKNOWN";
}
}

@NotNull
private static final int[] codes = {
SCAN,
Expand Down
10 changes: 10 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 @@ -44,6 +44,16 @@ public int code() {
return code;
}

@NotNull
@Override
public String name() {
switch (code) {
case FULL: return "FULL";
case PARTIAL: return "PARTIAL";
default: return "UNKNOWN";
}
}

@NotNull
public static GroupByStrategy parse(@NotNull String value) {
switch (value) {
Expand Down
16 changes: 16 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 @@ -68,6 +68,22 @@ public int code() {
return code;
}

@NotNull
@Override
public String name() {
switch (code) {
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
private static final int[] codes = {
INNER,
Expand Down
10 changes: 10 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 @@ -38,6 +38,16 @@ public int code() {
return code;
}

@NotNull
@Override
public String name() {
switch (code) {
case FIRST: return "FIRST";
case LAST: return "LAST";
default: return "UNKNOWN";
}
}

@NotNull
private static final int[] codes = {
FIRST,
Expand Down
Loading

0 comments on commit 246b63c

Please sign in to comment.