Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
yliuuuu committed Nov 27, 2024
1 parent c9f350a commit 2d3863e
Show file tree
Hide file tree
Showing 15 changed files with 401 additions and 325 deletions.
387 changes: 194 additions & 193 deletions partiql-ast/api/partiql-ast.api

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package org.partiql.ast;

import org.partiql.ast.ddl.AttributeConstraint;
import org.partiql.ast.ddl.ColumnDefinition;
import org.partiql.ast.ddl.CreateTable;
import org.partiql.ast.ddl.Ddl;
import org.partiql.ast.ddl.KeyValue;
import org.partiql.ast.ddl.PartitionBy;
import org.partiql.ast.ddl.TableConstraint;
import org.partiql.ast.expr.Expr;
import org.partiql.ast.expr.ExprAnd;
import org.partiql.ast.expr.ExprArray;
Expand Down Expand Up @@ -65,7 +72,7 @@ public R visitStatement(Statement node, C ctx) {
// DDL
//
public R visitDdl(Ddl node, C ctx) {
return node.accept(this, ctx);
return defaultVisit(node, ctx);
}

public R visitCreateTable(CreateTable node, C ctx) {
Expand All @@ -88,15 +95,15 @@ public R visitCheck(TableConstraint.Check node, C ctx) {
return defaultVisit(node, ctx);
}

public R visitNullable(AttributeConstraint.Nullable node, C ctx) {
public R visitNullable(AttributeConstraint.Null node, C ctx) {
return defaultVisit(node, ctx);
}

public R visitKeyValue(Options.KeyValue node, C ctx) {
public R visitKeyValue(KeyValue node, C ctx) {
return defaultVisit(node, ctx);
}

public R visitPartitionBy(Options.PartitionBy partitionBy, C ctx) {
public R visitPartitionBy(PartitionBy partitionBy, C ctx) {
return defaultVisit(partitionBy, ctx);
}

Expand Down
25 changes: 23 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.partiql.ast.ddl.AttributeConstraint;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -27,13 +29,24 @@ public class DataType extends AstEnum {
// and the fact that parameterized struct type being an extension to SQL-99.
@EqualsAndHashCode(callSuper = false)
public static class StructField extends AstNode {
@NotNull
public final Identifier name;
@NotNull
public final DataType type;
public final Boolean isOptional;

public final boolean isOptional;

@Nullable
public final List<AttributeConstraint> constraints;
@Nullable
public final String comment;

public StructField(Identifier name, DataType type, Boolean isOptional, List<AttributeConstraint> constraints, String comment) {
public StructField(
@NotNull Identifier name,
@NotNull DataType type,
boolean isOptional,
@Nullable List<AttributeConstraint> constraints,
@Nullable String comment) {
this.name = name;
this.type = type;
this.isOptional = isOptional;
Expand All @@ -47,6 +60,7 @@ public Collection<AstNode> children() {
ArrayList<AstNode> kids = new ArrayList<>();
kids.add(name);
kids.add(type);
kids.addAll(constraints);
return kids;
}

Expand Down Expand Up @@ -539,6 +553,7 @@ public String name() {
case STRUCT: return "STRUCT";
case TUPLE: return "TUPLE";
case LIST: return "LIST";
case ARRAY: return "ARRAY";
case BAG: return "BAG";
case SEXP: return "SEXP";
case USER_DEFINED: return "USER_DEFINED";
Expand Down Expand Up @@ -712,6 +727,12 @@ public Collection<AstNode> children() {
if (name != null) {
kids.add(name);
}
if (elementType != null) {
kids.add(elementType);
}
if (fields != null) {
kids.addAll(fields);
}
return kids;
}

Expand Down
7 changes: 0 additions & 7 deletions partiql-ast/src/main/java/org/partiql/ast/Ddl.java

This file was deleted.

69 changes: 0 additions & 69 deletions partiql-ast/src/main/java/org/partiql/ast/Options.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.partiql.ast;
package org.partiql.ast.ddl;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.partiql.ast.AstNode;
import org.partiql.ast.AstVisitor;
import org.partiql.ast.expr.Expr;

import java.util.Collection;
Expand All @@ -14,19 +17,20 @@
public abstract class AttributeConstraint extends AstNode {

// NULL & NOT NULL

/**
* TODO docs, equals, hashcode
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public static class Nullable extends AttributeConstraint {

public static class Null extends AttributeConstraint {
@Nullable
public final String name;

@NotNull
public final Boolean isNullable;

public Nullable(String name, @NotNull Boolean isNullable) {
public Null(@Nullable String name, @NotNull Boolean isNullable) {
this.name = name;
this.isNullable = isNullable;
}
Expand All @@ -44,19 +48,20 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
}

// Unique and primary

/**
* TODO docs, equals, hashcode
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public static class Unique extends AttributeConstraint {

@Nullable
public final String name;

@NotNull
public final Boolean isPrimary;

public Unique(String name, @NotNull Boolean isPrimary) {
public Unique(@Nullable String name, @NotNull Boolean isPrimary) {
this.name = name;
this.isPrimary = isPrimary;
}
Expand All @@ -79,17 +84,17 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public static class Check extends AttributeConstraint {
@Nullable
public final String name;

@NotNull
public final Expr searchCondition;

public Check(String name, @NotNull Expr searchCondition) {
public Check(@Nullable String name, @NotNull Expr searchCondition) {
this.name = name;
this.searchCondition = searchCondition;
}


@NotNull
@Override
public Collection<AstNode> children() {
Expand All @@ -101,5 +106,4 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return visitor.visitCheck(this, ctx);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.partiql.ast;
package org.partiql.ast.ddl;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.partiql.ast.AstNode;
import org.partiql.ast.AstVisitor;
import org.partiql.ast.DataType;
import org.partiql.ast.Identifier;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -16,19 +21,25 @@
public class ColumnDefinition extends AstNode {

@NotNull
private final Identifier name;
public final Identifier name;

@NotNull
private final DataType dataType;
public final DataType dataType;

@NotNull
private final Boolean isOptional;
public final boolean isOptional;

private final List<AttributeConstraint> constraints;
@Nullable
public final List<AttributeConstraint> constraints;

private final String comment;
@Nullable
public final String comment;

public ColumnDefinition(@NotNull Identifier name, @NotNull DataType dataType, @NotNull Boolean isOptional, List<AttributeConstraint> constraints, String comment) {
public ColumnDefinition(
@NotNull Identifier name,
@NotNull DataType dataType,
boolean isOptional,
@Nullable List<AttributeConstraint> constraints,
@Nullable String comment) {
this.name = name;
this.dataType = dataType;
this.isOptional = isOptional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.partiql.ast;
package org.partiql.ast.ddl;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.partiql.ast.expr.Expr;
import org.jetbrains.annotations.Nullable;
import org.partiql.ast.AstNode;
import org.partiql.ast.AstVisitor;
import org.partiql.ast.IdentifierChain;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -19,15 +22,24 @@ public class CreateTable extends Ddl {
@NotNull
public final IdentifierChain name;

@Nullable
public final List<ColumnDefinition> columns;

@Nullable
public final List<TableConstraint> constraints;

public final Options.PartitionBy partitionBy;
@Nullable
public final PartitionBy partitionBy;

public final List<Options.KeyValue> tableProperties;
@Nullable
public final List<KeyValue> tableProperties;

public CreateTable(@NotNull IdentifierChain name, List<ColumnDefinition> columns, List<TableConstraint> constraints, Options.PartitionBy partitionBy, List<Options.KeyValue> tableProperties) {
public CreateTable(
@NotNull IdentifierChain name,
@Nullable List<ColumnDefinition> columns,
@Nullable List<TableConstraint> constraints,
@Nullable PartitionBy partitionBy,
@Nullable List<KeyValue> tableProperties) {
this.name = name;
this.columns = columns;
this.constraints = constraints;
Expand Down
9 changes: 9 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/ddl/Ddl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.partiql.ast.ddl;

import org.partiql.ast.Statement;

/**
* TODO docs, equals, hashcode
*/
public abstract class Ddl extends Statement {
}
Loading

0 comments on commit 2d3863e

Please sign in to comment.