Skip to content

Commit

Permalink
Enum -> AstEnum; values -> codes; other refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Oct 25, 2024
1 parent 5e20948 commit 5db9f62
Show file tree
Hide file tree
Showing 18 changed files with 579 additions and 233 deletions.
129 changes: 80 additions & 49 deletions partiql-ast/api/partiql-ast.api

Large diffs are not rendered by default.

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

/**
* TODO docs, equals, hashcode
*/
public abstract class AstEnum extends AstNode {
public abstract int code();
}
126 changes: 75 additions & 51 deletions partiql-ast/src/main/java/org/partiql/ast/v1/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
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;
// <absent types>
public static final int NULL = 1;
Expand Down Expand Up @@ -396,7 +400,58 @@ public int code() {
return code;
}

public static DataType valueOf(String value) {
@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();
Expand Down Expand Up @@ -448,55 +503,9 @@ public static DataType valueOf(String value) {
}
}

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()
};
@NotNull
public static int[] codes() {
return codes;
}

/**
Expand Down Expand Up @@ -530,4 +539,19 @@ public Integer getLength() {
public IdentifierChain getName() {
return name;
}

@NotNull
@Override
public Collection<AstNode> children() {
List<AstNode> kids = new ArrayList<>();
if (name != null) {
kids.add(name);
}
return kids;
}

@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return null;
}
}
46 changes: 33 additions & 13 deletions partiql-ast/src/main/java/org/partiql/ast/v1/DatetimeField.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -64,7 +68,20 @@ public int code() {
return code;
}

public static DatetimeField valueOf(String value) {
@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();
Expand All @@ -78,16 +95,19 @@ public static DatetimeField valueOf(String value) {
}
}

public static DatetimeField[] values() {
return new DatetimeField[] {
YEAR(),
MONTH(),
DAY(),
HOUR(),
MINUTE(),
SECOND(),
TIMEZONE_HOUR(),
TIMEZONE_MINUTE()
};
@NotNull
public static int[] codes() {
return codes;
}

@NotNull
@Override
public Collection<AstNode> children() {
return Collections.emptyList();
}

@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return null;
}
}
8 changes: 0 additions & 8 deletions partiql-ast/src/main/java/org/partiql/ast/v1/Enum.java

This file was deleted.

34 changes: 27 additions & 7 deletions partiql-ast/src/main/java/org/partiql/ast/v1/FromType.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,18 +38,34 @@ public int code() {
return code;
}

public static FromType valueOf(String value) {
@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();
}
}

public static FromType[] values() {
return new FromType[] {
SCAN(),
UNPIVOT()
};
@NotNull
public static int[] codes() {
return codes;
}

@NotNull
@Override
public Collection<AstNode> children() {
return Collections.emptyList();
}

@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return null;
}
}
34 changes: 27 additions & 7 deletions partiql-ast/src/main/java/org/partiql/ast/v1/GroupByStrategy.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand All @@ -34,18 +44,28 @@ public int code() {
return code;
}

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

public static GroupByStrategy[] values() {
return new GroupByStrategy[] {
FULL(),
PARTIAL()
};
@NotNull
public static int[] codes() {
return codes;
}

@NotNull
@Override
public Collection<AstNode> children() {
return Collections.emptyList();
}

@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return null;
}
}
Loading

0 comments on commit 5db9f62

Please sign in to comment.