From 2d3863e4bd1881ecb47703d28c17d3df8bfeca3e Mon Sep 17 00:00:00 2001 From: yliuuuu Date: Tue, 26 Nov 2024 16:51:08 -0800 Subject: [PATCH] address feedback --- partiql-ast/api/partiql-ast.api | 387 +++++++++--------- .../main/java/org/partiql/ast/AstVisitor.java | 15 +- .../main/java/org/partiql/ast/DataType.java | 25 +- .../src/main/java/org/partiql/ast/Ddl.java | 7 - .../main/java/org/partiql/ast/Options.java | 69 ---- .../ast/{ => ddl}/AttributeConstraint.java | 22 +- .../ast/{ => ddl}/ColumnDefinition.java | 27 +- .../partiql/ast/{ => ddl}/CreateTable.java | 22 +- .../main/java/org/partiql/ast/ddl/Ddl.java | 9 + .../java/org/partiql/ast/ddl/KeyValue.java | 40 ++ .../java/org/partiql/ast/ddl/PartitionBy.java | 34 ++ .../ast/{ => ddl}/TableConstraint.java | 15 +- .../src/main/kotlin/org/partiql/ast/Ast.kt | 29 +- .../parser/internal/PartiQLParserDefault.kt | 14 +- .../parser/internal/PartiQLParserDDLTests.kt | 11 +- 15 files changed, 401 insertions(+), 325 deletions(-) delete mode 100644 partiql-ast/src/main/java/org/partiql/ast/Ddl.java delete mode 100644 partiql-ast/src/main/java/org/partiql/ast/Options.java rename partiql-ast/src/main/java/org/partiql/ast/{ => ddl}/AttributeConstraint.java (82%) rename partiql-ast/src/main/java/org/partiql/ast/{ => ddl}/ColumnDefinition.java (58%) rename partiql-ast/src/main/java/org/partiql/ast/{ => ddl}/CreateTable.java (67%) create mode 100644 partiql-ast/src/main/java/org/partiql/ast/ddl/Ddl.java create mode 100644 partiql-ast/src/main/java/org/partiql/ast/ddl/KeyValue.java create mode 100644 partiql-ast/src/main/java/org/partiql/ast/ddl/PartitionBy.java rename partiql-ast/src/main/java/org/partiql/ast/{ => ddl}/TableConstraint.java (90%) diff --git a/partiql-ast/api/partiql-ast.api b/partiql-ast/api/partiql-ast.api index 753001b55..5cb1781c7 100644 --- a/partiql-ast/api/partiql-ast.api +++ b/partiql-ast/api/partiql-ast.api @@ -1,10 +1,10 @@ public final class org/partiql/ast/Ast { public static final field INSTANCE Lorg/partiql/ast/Ast; - public static final fun columnConstraintCheck (Ljava/lang/String;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/AttributeConstraint$Check; - public static final fun columnConstraintNullable (Ljava/lang/String;Z)Lorg/partiql/ast/AttributeConstraint$Nullable; - public static final fun columnConstraintUnique (Ljava/lang/String;Z)Lorg/partiql/ast/AttributeConstraint$Unique; - public static final fun columnDefinition (Lorg/partiql/ast/Identifier;Lorg/partiql/ast/DataType;ZLjava/util/List;Ljava/lang/String;)Lorg/partiql/ast/ColumnDefinition; - public static final fun createTable (Lorg/partiql/ast/IdentifierChain;Ljava/util/List;Ljava/util/List;Lorg/partiql/ast/Options$PartitionBy;Ljava/util/List;)Lorg/partiql/ast/CreateTable; + public static final fun columnConstraintCheck (Ljava/lang/String;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/ddl/AttributeConstraint$Check; + public static final fun columnConstraintNullable (Ljava/lang/String;Z)Lorg/partiql/ast/ddl/AttributeConstraint$Null; + public static final fun columnConstraintUnique (Ljava/lang/String;Z)Lorg/partiql/ast/ddl/AttributeConstraint$Unique; + public static final fun columnDefinition (Lorg/partiql/ast/Identifier;Lorg/partiql/ast/DataType;ZLjava/util/List;Ljava/lang/String;)Lorg/partiql/ast/ddl/ColumnDefinition; + public static final fun createTable (Lorg/partiql/ast/IdentifierChain;Ljava/util/List;Ljava/util/List;Lorg/partiql/ast/ddl/PartitionBy;Ljava/util/List;)Lorg/partiql/ast/ddl/CreateTable; public static final fun exclude (Ljava/util/List;)Lorg/partiql/ast/Exclude; public static final fun excludePath (Lorg/partiql/ast/expr/ExprVarRef;Ljava/util/List;)Lorg/partiql/ast/ExcludePath; public static final fun excludeStepCollIndex (I)Lorg/partiql/ast/ExcludeStep$CollIndex; @@ -75,11 +75,11 @@ public final class org/partiql/ast/Ast { public static final fun groupByKey (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/Identifier;)Lorg/partiql/ast/GroupBy$Key; public static final fun identifier (Ljava/lang/String;Z)Lorg/partiql/ast/Identifier; public static final fun identifierChain (Lorg/partiql/ast/Identifier;Lorg/partiql/ast/IdentifierChain;)Lorg/partiql/ast/IdentifierChain; - public static final fun keyValue (Ljava/lang/String;Lorg/partiql/value/StringValue;)Lorg/partiql/ast/Options$KeyValue; + public static final fun keyValue (Ljava/lang/String;Ljava/lang/String;)Lorg/partiql/ast/ddl/KeyValue; public static final fun let (Ljava/util/List;)Lorg/partiql/ast/Let; public static final fun letBinding (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/Identifier;)Lorg/partiql/ast/Let$Binding; public static final fun orderBy (Ljava/util/List;)Lorg/partiql/ast/OrderBy; - public static final fun partitionBy (Ljava/util/List;)Lorg/partiql/ast/Options$PartitionBy; + public static final fun partitionBy (Ljava/util/List;)Lorg/partiql/ast/ddl/PartitionBy; public static final fun query (Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/Query; public static final fun queryBodySFW (Lorg/partiql/ast/Select;Lorg/partiql/ast/Exclude;Lorg/partiql/ast/From;Lorg/partiql/ast/Let;Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/GroupBy;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/QueryBody$SFW; public static final fun queryBodySetOp (Lorg/partiql/ast/SetOp;ZLorg/partiql/ast/expr/Expr;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/QueryBody$SetOp; @@ -91,9 +91,9 @@ public final class org/partiql/ast/Ast { public static final fun selectValue (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/SetQuantifier;)Lorg/partiql/ast/SelectValue; public static final fun setOp (Lorg/partiql/ast/SetOpType;Lorg/partiql/ast/SetQuantifier;)Lorg/partiql/ast/SetOp; public static final fun sort (Lorg/partiql/ast/expr/Expr;Lorg/partiql/ast/Order;Lorg/partiql/ast/Nulls;)Lorg/partiql/ast/Sort; - public static final fun tableConstraintCheck (Ljava/lang/String;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/TableConstraint$Check; - public static final fun tableConstraintPrimaryKey (Ljava/lang/String;Ljava/util/List;)Lorg/partiql/ast/TableConstraint$PrimaryKey; - public static final fun tableConstraintUnique (Ljava/lang/String;Ljava/util/List;)Lorg/partiql/ast/TableConstraint$Unique; + public static final fun tableConstraintCheck (Ljava/lang/String;Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/ddl/TableConstraint$Check; + public static final fun tableConstraintPrimaryKey (Ljava/lang/String;Ljava/util/List;)Lorg/partiql/ast/ddl/TableConstraint$PrimaryKey; + public static final fun tableConstraintUnique (Ljava/lang/String;Ljava/util/List;)Lorg/partiql/ast/ddl/TableConstraint$Unique; } public abstract class org/partiql/ast/AstEnum : org/partiql/ast/AstNode { @@ -268,12 +268,12 @@ public abstract class org/partiql/ast/AstVisitor { public abstract fun defaultReturn (Lorg/partiql/ast/AstNode;Ljava/lang/Object;)Ljava/lang/Object; public fun defaultVisit (Lorg/partiql/ast/AstNode;Ljava/lang/Object;)Ljava/lang/Object; public fun visit (Lorg/partiql/ast/AstNode;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitCheck (Lorg/partiql/ast/AttributeConstraint$Check;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitCheck (Lorg/partiql/ast/TableConstraint$Check;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitColumnDefinition (Lorg/partiql/ast/ColumnDefinition;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitCreateTable (Lorg/partiql/ast/CreateTable;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCheck (Lorg/partiql/ast/ddl/AttributeConstraint$Check;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCheck (Lorg/partiql/ast/ddl/TableConstraint$Check;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitColumnDefinition (Lorg/partiql/ast/ddl/ColumnDefinition;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCreateTable (Lorg/partiql/ast/ddl/CreateTable;Ljava/lang/Object;)Ljava/lang/Object; public fun visitDataType (Lorg/partiql/ast/DataType;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitDdl (Lorg/partiql/ast/Ddl;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitDdl (Lorg/partiql/ast/ddl/Ddl;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExclude (Lorg/partiql/ast/Exclude;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExcludePath (Lorg/partiql/ast/ExcludePath;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExcludeStep (Lorg/partiql/ast/ExcludeStep;Ljava/lang/Object;)Ljava/lang/Object; @@ -346,18 +346,18 @@ public abstract class org/partiql/ast/AstVisitor { public fun visitGroupByKey (Lorg/partiql/ast/GroupBy$Key;Ljava/lang/Object;)Ljava/lang/Object; public fun visitIdentifier (Lorg/partiql/ast/Identifier;Ljava/lang/Object;)Ljava/lang/Object; public fun visitIdentifierChain (Lorg/partiql/ast/IdentifierChain;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitKeyValue (Lorg/partiql/ast/Options$KeyValue;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitKeyValue (Lorg/partiql/ast/ddl/KeyValue;Ljava/lang/Object;)Ljava/lang/Object; public fun visitLet (Lorg/partiql/ast/Let;Ljava/lang/Object;)Ljava/lang/Object; public fun visitLetBinding (Lorg/partiql/ast/Let$Binding;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitNullable (Lorg/partiql/ast/AttributeConstraint$Nullable;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitNullable (Lorg/partiql/ast/ddl/AttributeConstraint$Null;Ljava/lang/Object;)Ljava/lang/Object; public fun visitOrderBy (Lorg/partiql/ast/OrderBy;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitPartitionBy (Lorg/partiql/ast/Options$PartitionBy;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPartitionBy (Lorg/partiql/ast/ddl/PartitionBy;Ljava/lang/Object;)Ljava/lang/Object; public fun visitPathStep (Lorg/partiql/ast/expr/PathStep;Ljava/lang/Object;)Ljava/lang/Object; public fun visitPathStepAllElements (Lorg/partiql/ast/expr/PathStep$AllElements;Ljava/lang/Object;)Ljava/lang/Object; public fun visitPathStepAllFields (Lorg/partiql/ast/expr/PathStep$AllFields;Ljava/lang/Object;)Ljava/lang/Object; public fun visitPathStepElement (Lorg/partiql/ast/expr/PathStep$Element;Ljava/lang/Object;)Ljava/lang/Object; public fun visitPathStepField (Lorg/partiql/ast/expr/PathStep$Field;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitPrimaryKey (Lorg/partiql/ast/TableConstraint$PrimaryKey;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPrimaryKey (Lorg/partiql/ast/ddl/TableConstraint$PrimaryKey;Ljava/lang/Object;)Ljava/lang/Object; public fun visitQuery (Lorg/partiql/ast/Query;Ljava/lang/Object;)Ljava/lang/Object; public fun visitQueryBody (Lorg/partiql/ast/QueryBody;Ljava/lang/Object;)Ljava/lang/Object; public fun visitQueryBodySFW (Lorg/partiql/ast/QueryBody$SFW;Ljava/lang/Object;)Ljava/lang/Object; @@ -374,114 +374,8 @@ public abstract class org/partiql/ast/AstVisitor { public fun visitSort (Lorg/partiql/ast/Sort;Ljava/lang/Object;)Ljava/lang/Object; public fun visitStatement (Lorg/partiql/ast/Statement;Ljava/lang/Object;)Ljava/lang/Object; public fun visitStructField (Lorg/partiql/ast/DataType$StructField;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitUnique (Lorg/partiql/ast/AttributeConstraint$Unique;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitUnique (Lorg/partiql/ast/TableConstraint$Unique;Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract class org/partiql/ast/AttributeConstraint : org/partiql/ast/AstNode { - public fun ()V -} - -public class org/partiql/ast/AttributeConstraint$Check : org/partiql/ast/AttributeConstraint { - public final field name Ljava/lang/String; - public final field searchCondition Lorg/partiql/ast/expr/Expr; - public fun (Ljava/lang/String;Lorg/partiql/ast/expr/Expr;)V - public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/AttributeConstraint$Check$Builder; - protected fun canEqual (Ljava/lang/Object;)Z - public fun children ()Ljava/util/Collection; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I -} - -public class org/partiql/ast/AttributeConstraint$Check$Builder { - public fun build ()Lorg/partiql/ast/AttributeConstraint$Check; - public fun name (Ljava/lang/String;)Lorg/partiql/ast/AttributeConstraint$Check$Builder; - public fun searchCondition (Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/AttributeConstraint$Check$Builder; - public fun toString ()Ljava/lang/String; -} - -public class org/partiql/ast/AttributeConstraint$Nullable : org/partiql/ast/AttributeConstraint { - public final field isNullable Ljava/lang/Boolean; - public final field name Ljava/lang/String; - public fun (Ljava/lang/String;Ljava/lang/Boolean;)V - public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/AttributeConstraint$Nullable$Builder; - protected fun canEqual (Ljava/lang/Object;)Z - public fun children ()Ljava/util/Collection; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I -} - -public class org/partiql/ast/AttributeConstraint$Nullable$Builder { - public fun build ()Lorg/partiql/ast/AttributeConstraint$Nullable; - public fun isNullable (Ljava/lang/Boolean;)Lorg/partiql/ast/AttributeConstraint$Nullable$Builder; - public fun name (Ljava/lang/String;)Lorg/partiql/ast/AttributeConstraint$Nullable$Builder; - public fun toString ()Ljava/lang/String; -} - -public class org/partiql/ast/AttributeConstraint$Unique : org/partiql/ast/AttributeConstraint { - public final field isPrimary Ljava/lang/Boolean; - public final field name Ljava/lang/String; - public fun (Ljava/lang/String;Ljava/lang/Boolean;)V - public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/AttributeConstraint$Unique$Builder; - protected fun canEqual (Ljava/lang/Object;)Z - public fun children ()Ljava/util/Collection; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I -} - -public class org/partiql/ast/AttributeConstraint$Unique$Builder { - public fun build ()Lorg/partiql/ast/AttributeConstraint$Unique; - public fun isPrimary (Ljava/lang/Boolean;)Lorg/partiql/ast/AttributeConstraint$Unique$Builder; - public fun name (Ljava/lang/String;)Lorg/partiql/ast/AttributeConstraint$Unique$Builder; - public fun toString ()Ljava/lang/String; -} - -public class org/partiql/ast/ColumnDefinition : org/partiql/ast/AstNode { - public fun (Lorg/partiql/ast/Identifier;Lorg/partiql/ast/DataType;Ljava/lang/Boolean;Ljava/util/List;Ljava/lang/String;)V - public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/ColumnDefinition$Builder; - protected fun canEqual (Ljava/lang/Object;)Z - public fun children ()Ljava/util/Collection; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I -} - -public class org/partiql/ast/ColumnDefinition$Builder { - public fun build ()Lorg/partiql/ast/ColumnDefinition; - public fun comment (Ljava/lang/String;)Lorg/partiql/ast/ColumnDefinition$Builder; - public fun constraints (Ljava/util/List;)Lorg/partiql/ast/ColumnDefinition$Builder; - public fun dataType (Lorg/partiql/ast/DataType;)Lorg/partiql/ast/ColumnDefinition$Builder; - public fun isOptional (Ljava/lang/Boolean;)Lorg/partiql/ast/ColumnDefinition$Builder; - public fun name (Lorg/partiql/ast/Identifier;)Lorg/partiql/ast/ColumnDefinition$Builder; - public fun toString ()Ljava/lang/String; -} - -public class org/partiql/ast/CreateTable : org/partiql/ast/Ddl { - public final field columns Ljava/util/List; - public final field constraints Ljava/util/List; - public final field name Lorg/partiql/ast/IdentifierChain; - public final field partitionBy Lorg/partiql/ast/Options$PartitionBy; - public final field tableProperties Ljava/util/List; - public fun (Lorg/partiql/ast/IdentifierChain;Ljava/util/List;Ljava/util/List;Lorg/partiql/ast/Options$PartitionBy;Ljava/util/List;)V - public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/CreateTable$Builder; - protected fun canEqual (Ljava/lang/Object;)Z - public fun children ()Ljava/util/Collection; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I -} - -public class org/partiql/ast/CreateTable$Builder { - public fun build ()Lorg/partiql/ast/CreateTable; - public fun columns (Ljava/util/List;)Lorg/partiql/ast/CreateTable$Builder; - public fun constraints (Ljava/util/List;)Lorg/partiql/ast/CreateTable$Builder; - public fun name (Lorg/partiql/ast/IdentifierChain;)Lorg/partiql/ast/CreateTable$Builder; - public fun partitionBy (Lorg/partiql/ast/Options$PartitionBy;)Lorg/partiql/ast/CreateTable$Builder; - public fun tableProperties (Ljava/util/List;)Lorg/partiql/ast/CreateTable$Builder; - public fun toString ()Ljava/lang/String; + public fun visitUnique (Lorg/partiql/ast/ddl/AttributeConstraint$Unique;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitUnique (Lorg/partiql/ast/ddl/TableConstraint$Unique;Ljava/lang/Object;)Ljava/lang/Object; } public class org/partiql/ast/DataType : org/partiql/ast/AstEnum { @@ -630,10 +524,10 @@ public class org/partiql/ast/DataType : org/partiql/ast/AstEnum { public class org/partiql/ast/DataType$StructField : org/partiql/ast/AstNode { public final field comment Ljava/lang/String; public final field constraints Ljava/util/List; - public final field isOptional Ljava/lang/Boolean; + public final field isOptional Z public final field name Lorg/partiql/ast/Identifier; public final field type Lorg/partiql/ast/DataType; - public fun (Lorg/partiql/ast/Identifier;Lorg/partiql/ast/DataType;Ljava/lang/Boolean;Ljava/util/List;Ljava/lang/String;)V + public fun (Lorg/partiql/ast/Identifier;Lorg/partiql/ast/DataType;ZLjava/util/List;Ljava/lang/String;)V public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; protected fun canEqual (Ljava/lang/Object;)Z public fun children ()Ljava/util/Collection; @@ -671,10 +565,6 @@ public class org/partiql/ast/DatetimeField : org/partiql/ast/AstEnum { public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/DatetimeField; } -public abstract class org/partiql/ast/Ddl : org/partiql/ast/Statement { - public fun ()V -} - public class org/partiql/ast/Exclude : org/partiql/ast/AstNode { public final field excludePaths Ljava/util/List; public fun (Ljava/util/List;)V @@ -1059,46 +949,6 @@ public class org/partiql/ast/Nulls : org/partiql/ast/AstEnum { public static fun parse (Ljava/lang/String;)Lorg/partiql/ast/Nulls; } -public abstract class org/partiql/ast/Options : org/partiql/ast/AstNode { - public fun ()V -} - -public class org/partiql/ast/Options$KeyValue : org/partiql/ast/Options { - public final field key Ljava/lang/String; - public final field value Lorg/partiql/value/StringValue; - public fun (Ljava/lang/String;Lorg/partiql/value/StringValue;)V - public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/Options$KeyValue$Builder; - protected fun canEqual (Ljava/lang/Object;)Z - public fun children ()Ljava/util/Collection; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I -} - -public class org/partiql/ast/Options$KeyValue$Builder { - public fun build ()Lorg/partiql/ast/Options$KeyValue; - public fun key (Ljava/lang/String;)Lorg/partiql/ast/Options$KeyValue$Builder; - public fun toString ()Ljava/lang/String; - public fun value (Lorg/partiql/value/StringValue;)Lorg/partiql/ast/Options$KeyValue$Builder; -} - -public class org/partiql/ast/Options$PartitionBy : org/partiql/ast/Options { - public final field columns Ljava/util/List; - public fun (Ljava/util/List;)V - public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/Options$PartitionBy$Builder; - protected fun canEqual (Ljava/lang/Object;)Z - public fun children ()Ljava/util/Collection; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I -} - -public class org/partiql/ast/Options$PartitionBy$Builder { - public fun build ()Lorg/partiql/ast/Options$PartitionBy; - public fun columns (Ljava/util/List;)Lorg/partiql/ast/Options$PartitionBy$Builder; - public fun toString ()Ljava/lang/String; -} - public class org/partiql/ast/Order : org/partiql/ast/AstEnum { public static final field ASC I public static final field DESC I @@ -1407,64 +1257,215 @@ public abstract class org/partiql/ast/Statement : org/partiql/ast/AstNode { public fun ()V } -public abstract class org/partiql/ast/TableConstraint : org/partiql/ast/AstNode { +public abstract class org/partiql/ast/ddl/AttributeConstraint : org/partiql/ast/AstNode { public fun ()V } -public class org/partiql/ast/TableConstraint$Check : org/partiql/ast/TableConstraint { +public class org/partiql/ast/ddl/AttributeConstraint$Check : org/partiql/ast/ddl/AttributeConstraint { public final field name Ljava/lang/String; public final field searchCondition Lorg/partiql/ast/expr/Expr; public fun (Ljava/lang/String;Lorg/partiql/ast/expr/Expr;)V public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/TableConstraint$Check$Builder; + public static fun builder ()Lorg/partiql/ast/ddl/AttributeConstraint$Check$Builder; protected fun canEqual (Ljava/lang/Object;)Z public fun children ()Ljava/util/Collection; public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I } -public class org/partiql/ast/TableConstraint$Check$Builder { - public fun build ()Lorg/partiql/ast/TableConstraint$Check; - public fun name (Ljava/lang/String;)Lorg/partiql/ast/TableConstraint$Check$Builder; - public fun searchCondition (Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/TableConstraint$Check$Builder; +public class org/partiql/ast/ddl/AttributeConstraint$Check$Builder { + public fun build ()Lorg/partiql/ast/ddl/AttributeConstraint$Check; + public fun name (Ljava/lang/String;)Lorg/partiql/ast/ddl/AttributeConstraint$Check$Builder; + public fun searchCondition (Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/ddl/AttributeConstraint$Check$Builder; public fun toString ()Ljava/lang/String; } -public class org/partiql/ast/TableConstraint$PrimaryKey : org/partiql/ast/TableConstraint { +public class org/partiql/ast/ddl/AttributeConstraint$Null : org/partiql/ast/ddl/AttributeConstraint { + public final field isNullable Ljava/lang/Boolean; + public final field name Ljava/lang/String; + public fun (Ljava/lang/String;Ljava/lang/Boolean;)V + public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun builder ()Lorg/partiql/ast/ddl/AttributeConstraint$Null$Builder; + protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I +} + +public class org/partiql/ast/ddl/AttributeConstraint$Null$Builder { + public fun build ()Lorg/partiql/ast/ddl/AttributeConstraint$Null; + public fun isNullable (Ljava/lang/Boolean;)Lorg/partiql/ast/ddl/AttributeConstraint$Null$Builder; + public fun name (Ljava/lang/String;)Lorg/partiql/ast/ddl/AttributeConstraint$Null$Builder; + public fun toString ()Ljava/lang/String; +} + +public class org/partiql/ast/ddl/AttributeConstraint$Unique : org/partiql/ast/ddl/AttributeConstraint { + public final field isPrimary Ljava/lang/Boolean; + public final field name Ljava/lang/String; + public fun (Ljava/lang/String;Ljava/lang/Boolean;)V + public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun builder ()Lorg/partiql/ast/ddl/AttributeConstraint$Unique$Builder; + protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I +} + +public class org/partiql/ast/ddl/AttributeConstraint$Unique$Builder { + public fun build ()Lorg/partiql/ast/ddl/AttributeConstraint$Unique; + public fun isPrimary (Ljava/lang/Boolean;)Lorg/partiql/ast/ddl/AttributeConstraint$Unique$Builder; + public fun name (Ljava/lang/String;)Lorg/partiql/ast/ddl/AttributeConstraint$Unique$Builder; + public fun toString ()Ljava/lang/String; +} + +public class org/partiql/ast/ddl/ColumnDefinition : org/partiql/ast/AstNode { + public final field comment Ljava/lang/String; + public final field constraints Ljava/util/List; + public final field dataType Lorg/partiql/ast/DataType; + public final field isOptional Z + public final field name Lorg/partiql/ast/Identifier; + public fun (Lorg/partiql/ast/Identifier;Lorg/partiql/ast/DataType;ZLjava/util/List;Ljava/lang/String;)V + public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun builder ()Lorg/partiql/ast/ddl/ColumnDefinition$Builder; + protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I +} + +public class org/partiql/ast/ddl/ColumnDefinition$Builder { + public fun build ()Lorg/partiql/ast/ddl/ColumnDefinition; + public fun comment (Ljava/lang/String;)Lorg/partiql/ast/ddl/ColumnDefinition$Builder; + public fun constraints (Ljava/util/List;)Lorg/partiql/ast/ddl/ColumnDefinition$Builder; + public fun dataType (Lorg/partiql/ast/DataType;)Lorg/partiql/ast/ddl/ColumnDefinition$Builder; + public fun isOptional (Z)Lorg/partiql/ast/ddl/ColumnDefinition$Builder; + public fun name (Lorg/partiql/ast/Identifier;)Lorg/partiql/ast/ddl/ColumnDefinition$Builder; + public fun toString ()Ljava/lang/String; +} + +public class org/partiql/ast/ddl/CreateTable : org/partiql/ast/ddl/Ddl { + public final field columns Ljava/util/List; + public final field constraints Ljava/util/List; + public final field name Lorg/partiql/ast/IdentifierChain; + public final field partitionBy Lorg/partiql/ast/ddl/PartitionBy; + public final field tableProperties Ljava/util/List; + public fun (Lorg/partiql/ast/IdentifierChain;Ljava/util/List;Ljava/util/List;Lorg/partiql/ast/ddl/PartitionBy;Ljava/util/List;)V + public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun builder ()Lorg/partiql/ast/ddl/CreateTable$Builder; + protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I +} + +public class org/partiql/ast/ddl/CreateTable$Builder { + public fun build ()Lorg/partiql/ast/ddl/CreateTable; + public fun columns (Ljava/util/List;)Lorg/partiql/ast/ddl/CreateTable$Builder; + public fun constraints (Ljava/util/List;)Lorg/partiql/ast/ddl/CreateTable$Builder; + public fun name (Lorg/partiql/ast/IdentifierChain;)Lorg/partiql/ast/ddl/CreateTable$Builder; + public fun partitionBy (Lorg/partiql/ast/ddl/PartitionBy;)Lorg/partiql/ast/ddl/CreateTable$Builder; + public fun tableProperties (Ljava/util/List;)Lorg/partiql/ast/ddl/CreateTable$Builder; + public fun toString ()Ljava/lang/String; +} + +public abstract class org/partiql/ast/ddl/Ddl : org/partiql/ast/Statement { + public fun ()V +} + +public class org/partiql/ast/ddl/KeyValue : org/partiql/ast/AstNode { + public final field key Ljava/lang/String; + public final field value Ljava/lang/String; + public fun (Ljava/lang/String;Ljava/lang/String;)V + public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun builder ()Lorg/partiql/ast/ddl/KeyValue$Builder; + protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I +} + +public class org/partiql/ast/ddl/KeyValue$Builder { + public fun build ()Lorg/partiql/ast/ddl/KeyValue; + public fun key (Ljava/lang/String;)Lorg/partiql/ast/ddl/KeyValue$Builder; + public fun toString ()Ljava/lang/String; + public fun value (Ljava/lang/String;)Lorg/partiql/ast/ddl/KeyValue$Builder; +} + +public class org/partiql/ast/ddl/PartitionBy : org/partiql/ast/AstNode { + public final field columns Ljava/util/List; + public fun (Ljava/util/List;)V + public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun builder ()Lorg/partiql/ast/ddl/PartitionBy$Builder; + protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I +} + +public class org/partiql/ast/ddl/PartitionBy$Builder { + public fun build ()Lorg/partiql/ast/ddl/PartitionBy; + public fun columns (Ljava/util/List;)Lorg/partiql/ast/ddl/PartitionBy$Builder; + public fun toString ()Ljava/lang/String; +} + +public abstract class org/partiql/ast/ddl/TableConstraint : org/partiql/ast/AstNode { + public fun ()V +} + +public class org/partiql/ast/ddl/TableConstraint$Check : org/partiql/ast/ddl/TableConstraint { + public final field name Ljava/lang/String; + public final field searchCondition Lorg/partiql/ast/expr/Expr; + public fun (Ljava/lang/String;Lorg/partiql/ast/expr/Expr;)V + public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun builder ()Lorg/partiql/ast/ddl/TableConstraint$Check$Builder; + protected fun canEqual (Ljava/lang/Object;)Z + public fun children ()Ljava/util/Collection; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I +} + +public class org/partiql/ast/ddl/TableConstraint$Check$Builder { + public fun build ()Lorg/partiql/ast/ddl/TableConstraint$Check; + public fun name (Ljava/lang/String;)Lorg/partiql/ast/ddl/TableConstraint$Check$Builder; + public fun searchCondition (Lorg/partiql/ast/expr/Expr;)Lorg/partiql/ast/ddl/TableConstraint$Check$Builder; + public fun toString ()Ljava/lang/String; +} + +public class org/partiql/ast/ddl/TableConstraint$PrimaryKey : org/partiql/ast/ddl/TableConstraint { public final field columns Ljava/util/List; public final field name Ljava/lang/String; public fun (Ljava/lang/String;Ljava/util/List;)V public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/TableConstraint$PrimaryKey$Builder; + public static fun builder ()Lorg/partiql/ast/ddl/TableConstraint$PrimaryKey$Builder; protected fun canEqual (Ljava/lang/Object;)Z public fun children ()Ljava/util/Collection; public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I } -public class org/partiql/ast/TableConstraint$PrimaryKey$Builder { - public fun build ()Lorg/partiql/ast/TableConstraint$PrimaryKey; - public fun columns (Ljava/util/List;)Lorg/partiql/ast/TableConstraint$PrimaryKey$Builder; - public fun name (Ljava/lang/String;)Lorg/partiql/ast/TableConstraint$PrimaryKey$Builder; +public class org/partiql/ast/ddl/TableConstraint$PrimaryKey$Builder { + public fun build ()Lorg/partiql/ast/ddl/TableConstraint$PrimaryKey; + public fun columns (Ljava/util/List;)Lorg/partiql/ast/ddl/TableConstraint$PrimaryKey$Builder; + public fun name (Ljava/lang/String;)Lorg/partiql/ast/ddl/TableConstraint$PrimaryKey$Builder; public fun toString ()Ljava/lang/String; } -public class org/partiql/ast/TableConstraint$Unique : org/partiql/ast/TableConstraint { +public class org/partiql/ast/ddl/TableConstraint$Unique : org/partiql/ast/ddl/TableConstraint { public final field columns Ljava/util/List; - public field name Ljava/lang/String; + public final field name Ljava/lang/String; public fun (Ljava/lang/String;Ljava/util/List;)V public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/TableConstraint$Unique$Builder; + public static fun builder ()Lorg/partiql/ast/ddl/TableConstraint$Unique$Builder; protected fun canEqual (Ljava/lang/Object;)Z public fun children ()Ljava/util/Collection; public fun equals (Ljava/lang/Object;)Z public fun hashCode ()I } -public class org/partiql/ast/TableConstraint$Unique$Builder { - public fun build ()Lorg/partiql/ast/TableConstraint$Unique; - public fun columns (Ljava/util/List;)Lorg/partiql/ast/TableConstraint$Unique$Builder; - public fun name (Ljava/lang/String;)Lorg/partiql/ast/TableConstraint$Unique$Builder; +public class org/partiql/ast/ddl/TableConstraint$Unique$Builder { + public fun build ()Lorg/partiql/ast/ddl/TableConstraint$Unique; + public fun columns (Ljava/util/List;)Lorg/partiql/ast/ddl/TableConstraint$Unique$Builder; + public fun name (Ljava/lang/String;)Lorg/partiql/ast/ddl/TableConstraint$Unique$Builder; public fun toString ()Ljava/lang/String; } diff --git a/partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java b/partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java index a88ac48ce..90c1f3cbf 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java +++ b/partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java @@ -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; @@ -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) { @@ -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); } diff --git a/partiql-ast/src/main/java/org/partiql/ast/DataType.java b/partiql-ast/src/main/java/org/partiql/ast/DataType.java index 1ee77d9ad..4715b6191 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/DataType.java +++ b/partiql-ast/src/main/java/org/partiql/ast/DataType.java @@ -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; @@ -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 constraints; + @Nullable public final String comment; - public StructField(Identifier name, DataType type, Boolean isOptional, List constraints, String comment) { + public StructField( + @NotNull Identifier name, + @NotNull DataType type, + boolean isOptional, + @Nullable List constraints, + @Nullable String comment) { this.name = name; this.type = type; this.isOptional = isOptional; @@ -47,6 +60,7 @@ public Collection children() { ArrayList kids = new ArrayList<>(); kids.add(name); kids.add(type); + kids.addAll(constraints); return kids; } @@ -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"; @@ -712,6 +727,12 @@ public Collection children() { if (name != null) { kids.add(name); } + if (elementType != null) { + kids.add(elementType); + } + if (fields != null) { + kids.addAll(fields); + } return kids; } diff --git a/partiql-ast/src/main/java/org/partiql/ast/Ddl.java b/partiql-ast/src/main/java/org/partiql/ast/Ddl.java deleted file mode 100644 index 319c0ae08..000000000 --- a/partiql-ast/src/main/java/org/partiql/ast/Ddl.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.partiql.ast; - -/** - * TODO docs, equals, hashcode - */ -public abstract class Ddl extends Statement{ -} diff --git a/partiql-ast/src/main/java/org/partiql/ast/Options.java b/partiql-ast/src/main/java/org/partiql/ast/Options.java deleted file mode 100644 index b1c9d9df6..000000000 --- a/partiql-ast/src/main/java/org/partiql/ast/Options.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.partiql.ast; - -import lombok.Builder; -import lombok.EqualsAndHashCode; -import org.jetbrains.annotations.NotNull; -import org.partiql.value.StringValue; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -/** - * TODO docs, equals, hashcode - */ -public abstract class Options extends AstNode { - - /** - * Any option that consists of a key value pair where the key is a string and value is an StringValue. - * - * TODO: equals, hashcode - */ - @Builder(builderClassName = "Builder") - @EqualsAndHashCode(callSuper = false) - public static class KeyValue extends Options{ - @NotNull - public final String key; - @NotNull - public final StringValue value; - - public KeyValue(@NotNull String key, @NotNull StringValue value) { - this.key = key; - this.value = value; - } - - @NotNull - @Override - public Collection children() { - return Collections.emptyList(); - } - - @Override - public R accept(@NotNull AstVisitor visitor, C ctx) { - return visitor.visitKeyValue(this, ctx); - } - } - - @Builder(builderClassName = "Builder") - @EqualsAndHashCode(callSuper = false) - public static class PartitionBy extends Options{ - @NotNull - public final List columns; - - public PartitionBy(@NotNull List columns) { - this.columns = columns; - } - - @NotNull - @Override - public Collection children() { - return new ArrayList<>(columns); - } - - @Override - public R accept(@NotNull AstVisitor visitor, C ctx) { - return visitor.visitPartitionBy(this, ctx); - } - } -} diff --git a/partiql-ast/src/main/java/org/partiql/ast/AttributeConstraint.java b/partiql-ast/src/main/java/org/partiql/ast/ddl/AttributeConstraint.java similarity index 82% rename from partiql-ast/src/main/java/org/partiql/ast/AttributeConstraint.java rename to partiql-ast/src/main/java/org/partiql/ast/ddl/AttributeConstraint.java index 1c416fe9e..2572b56ea 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/AttributeConstraint.java +++ b/partiql-ast/src/main/java/org/partiql/ast/ddl/AttributeConstraint.java @@ -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; @@ -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; } @@ -44,19 +48,20 @@ public R accept(@NotNull AstVisitor 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; } @@ -79,17 +84,17 @@ public R accept(@NotNull AstVisitor 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 children() { @@ -101,5 +106,4 @@ public R accept(@NotNull AstVisitor visitor, C ctx) { return visitor.visitCheck(this, ctx); } } - } diff --git a/partiql-ast/src/main/java/org/partiql/ast/ColumnDefinition.java b/partiql-ast/src/main/java/org/partiql/ast/ddl/ColumnDefinition.java similarity index 58% rename from partiql-ast/src/main/java/org/partiql/ast/ColumnDefinition.java rename to partiql-ast/src/main/java/org/partiql/ast/ddl/ColumnDefinition.java index 5f25f4671..f4135e746 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/ColumnDefinition.java +++ b/partiql-ast/src/main/java/org/partiql/ast/ddl/ColumnDefinition.java @@ -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; @@ -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 constraints; + @Nullable + public final List constraints; - private final String comment; + @Nullable + public final String comment; - public ColumnDefinition(@NotNull Identifier name, @NotNull DataType dataType, @NotNull Boolean isOptional, List constraints, String comment) { + public ColumnDefinition( + @NotNull Identifier name, + @NotNull DataType dataType, + boolean isOptional, + @Nullable List constraints, + @Nullable String comment) { this.name = name; this.dataType = dataType; this.isOptional = isOptional; diff --git a/partiql-ast/src/main/java/org/partiql/ast/CreateTable.java b/partiql-ast/src/main/java/org/partiql/ast/ddl/CreateTable.java similarity index 67% rename from partiql-ast/src/main/java/org/partiql/ast/CreateTable.java rename to partiql-ast/src/main/java/org/partiql/ast/ddl/CreateTable.java index 594b7222f..74b55ab5b 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/CreateTable.java +++ b/partiql-ast/src/main/java/org/partiql/ast/ddl/CreateTable.java @@ -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; @@ -19,15 +22,24 @@ public class CreateTable extends Ddl { @NotNull public final IdentifierChain name; + @Nullable public final List columns; + @Nullable public final List constraints; - public final Options.PartitionBy partitionBy; + @Nullable + public final PartitionBy partitionBy; - public final List tableProperties; + @Nullable + public final List tableProperties; - public CreateTable(@NotNull IdentifierChain name, List columns, List constraints, Options.PartitionBy partitionBy, List tableProperties) { + public CreateTable( + @NotNull IdentifierChain name, + @Nullable List columns, + @Nullable List constraints, + @Nullable PartitionBy partitionBy, + @Nullable List tableProperties) { this.name = name; this.columns = columns; this.constraints = constraints; diff --git a/partiql-ast/src/main/java/org/partiql/ast/ddl/Ddl.java b/partiql-ast/src/main/java/org/partiql/ast/ddl/Ddl.java new file mode 100644 index 000000000..ded6f073d --- /dev/null +++ b/partiql-ast/src/main/java/org/partiql/ast/ddl/Ddl.java @@ -0,0 +1,9 @@ +package org.partiql.ast.ddl; + +import org.partiql.ast.Statement; + +/** + * TODO docs, equals, hashcode + */ +public abstract class Ddl extends Statement { +} diff --git a/partiql-ast/src/main/java/org/partiql/ast/ddl/KeyValue.java b/partiql-ast/src/main/java/org/partiql/ast/ddl/KeyValue.java new file mode 100644 index 000000000..c34b47d6c --- /dev/null +++ b/partiql-ast/src/main/java/org/partiql/ast/ddl/KeyValue.java @@ -0,0 +1,40 @@ +package org.partiql.ast.ddl; + +import lombok.Builder; +import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; +import org.partiql.ast.AstNode; +import org.partiql.ast.AstVisitor; + +import java.util.Collection; +import java.util.Collections; + +/** + * Any option that consists of a key value pair where the key is a string and value is an StringValue. + *

+ * TODO: equals, hashcode + */ +@Builder(builderClassName = "Builder") +@EqualsAndHashCode(callSuper = false) +public class KeyValue extends AstNode { + @NotNull + public final String key; + @NotNull + public final String value; + + public KeyValue(@NotNull String key, @NotNull String value) { + this.key = key; + this.value = value; + } + + @NotNull + @Override + public Collection children() { + return Collections.emptyList(); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return visitor.visitKeyValue(this, ctx); + } +} diff --git a/partiql-ast/src/main/java/org/partiql/ast/ddl/PartitionBy.java b/partiql-ast/src/main/java/org/partiql/ast/ddl/PartitionBy.java new file mode 100644 index 000000000..4531985a5 --- /dev/null +++ b/partiql-ast/src/main/java/org/partiql/ast/ddl/PartitionBy.java @@ -0,0 +1,34 @@ +package org.partiql.ast.ddl; + +import lombok.Builder; +import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; +import org.partiql.ast.AstNode; +import org.partiql.ast.AstVisitor; +import org.partiql.ast.Identifier; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@Builder(builderClassName = "Builder") +@EqualsAndHashCode(callSuper = false) +public class PartitionBy extends AstNode { + @NotNull + public final List columns; + + public PartitionBy(@NotNull List columns) { + this.columns = columns; + } + + @NotNull + @Override + public Collection children() { + return new ArrayList<>(columns); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return visitor.visitPartitionBy(this, ctx); + } +} diff --git a/partiql-ast/src/main/java/org/partiql/ast/TableConstraint.java b/partiql-ast/src/main/java/org/partiql/ast/ddl/TableConstraint.java similarity index 90% rename from partiql-ast/src/main/java/org/partiql/ast/TableConstraint.java rename to partiql-ast/src/main/java/org/partiql/ast/ddl/TableConstraint.java index 7e924e192..b984a4403 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/TableConstraint.java +++ b/partiql-ast/src/main/java/org/partiql/ast/ddl/TableConstraint.java @@ -1,8 +1,12 @@ -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.Identifier; import org.partiql.ast.expr.Expr; import java.util.ArrayList; @@ -14,8 +18,8 @@ public abstract class TableConstraint extends AstNode { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static class Unique extends TableConstraint { - // TODO: Should this be an identifier - public String name; + @Nullable + public final String name; @NotNull public final List columns; @@ -25,7 +29,6 @@ public Unique(String name, @NotNull List column) { this.columns = column; } - @NotNull @Override public Collection children() { @@ -41,6 +44,7 @@ public R accept(@NotNull AstVisitor visitor, C ctx) { @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public static class PrimaryKey extends TableConstraint { + @Nullable public final String name; @NotNull @@ -67,8 +71,8 @@ public R accept(@NotNull AstVisitor visitor, C ctx) { @EqualsAndHashCode(callSuper = false) // TODO: Table Level Check Constraint not yet supported in the grammar public static class Check extends TableConstraint { + @Nullable public final String name; - @NotNull public final Expr searchCondition; @@ -77,7 +81,6 @@ public Check(String name, @NotNull Expr searchCondition) { this.searchCondition = searchCondition; } - @NotNull @Override public Collection children() { diff --git a/partiql-ast/src/main/kotlin/org/partiql/ast/Ast.kt b/partiql-ast/src/main/kotlin/org/partiql/ast/Ast.kt index fb00abfb4..104614401 100644 --- a/partiql-ast/src/main/kotlin/org/partiql/ast/Ast.kt +++ b/partiql-ast/src/main/kotlin/org/partiql/ast/Ast.kt @@ -1,5 +1,11 @@ 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.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 @@ -49,7 +55,6 @@ import org.partiql.ast.graph.GraphRestrictor import org.partiql.ast.graph.GraphSelector import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental -import org.partiql.value.StringValue // TODO docs for all factory methods // Also consider defaults for nullable. Need to look more into backwards compatibility. @@ -512,8 +517,14 @@ public object Ast { // DDL // @JvmStatic - public fun createTable(name: IdentifierChain, columns: List, constraints: List, partitionBy: Options.PartitionBy?, tableProperties: List): CreateTable { - return CreateTable(name, columns, constraints, partitionBy, tableProperties) + public fun createTable(name: IdentifierChain, columns: List, constraints: List, partitionBy: PartitionBy?, tableProperties: List): CreateTable { + return CreateTable( + name, + columns, + constraints, + partitionBy, + tableProperties + ) } @JvmStatic @@ -537,8 +548,8 @@ public object Ast { } @JvmStatic - public fun columnConstraintNullable(name: String?, isNullable: Boolean): AttributeConstraint.Nullable { - return AttributeConstraint.Nullable(name, isNullable) + public fun columnConstraintNullable(name: String?, isNullable: Boolean): AttributeConstraint.Null { + return AttributeConstraint.Null(name, isNullable) } @JvmStatic @@ -553,12 +564,12 @@ public object Ast { @OptIn(PartiQLValueExperimental::class) @JvmStatic - public fun keyValue(key: String, value: StringValue): Options.KeyValue { - return Options.KeyValue(key, value) + public fun keyValue(key: String, value: String): KeyValue { + return KeyValue(key, value) } @JvmStatic - public fun partitionBy(columns: List): Options.PartitionBy { - return Options.PartitionBy(columns) + public fun partitionBy(columns: List): PartitionBy { + return PartitionBy(columns) } } diff --git a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt b/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt index c0d15cb6c..c95e0b460 100644 --- a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt +++ b/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt @@ -123,8 +123,6 @@ import org.partiql.ast.Ast.tableConstraintCheck import org.partiql.ast.Ast.tableConstraintPrimaryKey import org.partiql.ast.Ast.tableConstraintUnique import org.partiql.ast.AstNode -import org.partiql.ast.AttributeConstraint -import org.partiql.ast.ColumnDefinition import org.partiql.ast.DataType import org.partiql.ast.DatetimeField import org.partiql.ast.Exclude @@ -139,7 +137,6 @@ import org.partiql.ast.IdentifierChain import org.partiql.ast.JoinType import org.partiql.ast.Let import org.partiql.ast.Nulls -import org.partiql.ast.Options import org.partiql.ast.Order import org.partiql.ast.Select import org.partiql.ast.SelectItem @@ -147,7 +144,10 @@ import org.partiql.ast.SetOpType import org.partiql.ast.SetQuantifier import org.partiql.ast.Sort import org.partiql.ast.Statement -import org.partiql.ast.TableConstraint +import org.partiql.ast.ddl.AttributeConstraint +import org.partiql.ast.ddl.ColumnDefinition +import org.partiql.ast.ddl.PartitionBy +import org.partiql.ast.ddl.TableConstraint import org.partiql.ast.expr.Expr import org.partiql.ast.expr.ExprArray import org.partiql.ast.expr.ExprBag @@ -580,7 +580,7 @@ internal class PartiQLParserDefault : PartiQLParser { tblPropertiesCtx?.keyValuePair()?.map { val key = it.key.getStringValue() val value = it.value.getStringValue() - keyValue(key, stringValue(value)) + keyValue(key, value) } ?: emptyList() } createTable(qualifiedName, columns, tblConstrs, partitionBy, tblProperties) @@ -637,7 +637,7 @@ internal class PartiQLParserDefault : PartiQLParser { val body = visitAs(ctx.columnConstraint()) when (body) { is AttributeConstraint.Unique -> columnConstraintUnique(constrName, body.isPrimary) - is AttributeConstraint.Nullable -> columnConstraintNullable(constrName, body.isNullable) + is AttributeConstraint.Null -> columnConstraintNullable(constrName, body.isNullable) is AttributeConstraint.Check -> columnConstraintCheck(constrName, body.searchCondition) else -> throw error(ctx, "Unexpected Table Constraint Definition") } @@ -685,7 +685,7 @@ internal class PartiQLParserDefault : PartiQLParser { } override fun visitTblExtensionPartition(ctx: GeneratedParser.TblExtensionPartitionContext) = - ctx.partitionBy().accept(this) as Options.PartitionBy + ctx.partitionBy().accept(this) as PartitionBy override fun visitPartitionColList(ctx: GeneratedParser.PartitionColListContext) = translate(ctx) { partitionBy(ctx.columnName().map { visitSymbolPrimitive(it.symbolPrimitive()) }) diff --git a/partiql-parser/src/test/kotlin/org/partiql/parser/internal/PartiQLParserDDLTests.kt b/partiql-parser/src/test/kotlin/org/partiql/parser/internal/PartiQLParserDDLTests.kt index 06c7e4db1..0f5305223 100644 --- a/partiql-parser/src/test/kotlin/org/partiql/parser/internal/PartiQLParserDDLTests.kt +++ b/partiql-parser/src/test/kotlin/org/partiql/parser/internal/PartiQLParserDDLTests.kt @@ -24,7 +24,6 @@ import org.partiql.ast.DataType import org.partiql.ast.expr.Scope import org.partiql.value.PartiQLValueExperimental import org.partiql.value.int32Value -import org.partiql.value.stringValue import java.util.stream.Stream import kotlin.test.assertEquals @@ -869,7 +868,7 @@ class PartiQLParserDDLTests { listOf(), null, listOf( - keyValue("k1", stringValue("v1")) + keyValue("k1", "v1") ) ) ), @@ -889,7 +888,7 @@ class PartiQLParserDDLTests { listOf(), null, listOf( - keyValue("K1k", stringValue("V1v")) + keyValue("K1k", "V1v") ) ) ), @@ -909,8 +908,8 @@ class PartiQLParserDDLTests { listOf(), null, listOf( - keyValue("k1", stringValue("v1")), - keyValue("k2", stringValue("v2")) + keyValue("k1", "v1"), + keyValue("k2", "v2") ) ) ), @@ -931,7 +930,7 @@ class PartiQLParserDDLTests { listOf(), partitionBy(listOf(identifier("a", false))), listOf( - keyValue("k1", stringValue("v1")), + keyValue("k1", "v1"), ) ) ),