From ff87a2aeb0ac655d5e6230037f62425493ae18d4 Mon Sep 17 00:00:00 2001 From: Alan Cai Date: Mon, 4 Nov 2024 15:23:26 -0800 Subject: [PATCH] [v1] Port SqlDialect to v1 AST (#1638) --- partiql-ast/api/partiql-ast.api | 513 +-- .../src/main/java/org/partiql/ast/v1/Ast.kt | 17 +- .../java/org/partiql/ast/v1/AstRewriter.kt | 7 +- .../java/org/partiql/ast/v1/AstVisitor.java | 7 +- .../java/org/partiql/ast/v1/DataType.java | 2 +- .../org/partiql/ast/v1/expr/ExprCast.java | 1 + .../org/partiql/ast/v1/expr/ExprIsType.java | 1 + .../org/partiql/ast/v1/expr/ExprRowValue.java | 36 + .../org/partiql/ast/v1/expr/ExprValues.java | 31 +- .../org/partiql/ast/v1}/sql/Sql.kt | 4 +- .../org/partiql/ast/v1}/sql/SqlBlock.kt | 2 +- .../java/org/partiql/ast/v1/sql/SqlDialect.kt | 824 ++++ .../org/partiql/ast/v1}/sql/SqlLayout.kt | 2 +- .../kotlin/org/partiql/ast/sql/SqlDialect.kt | 824 ---- .../org/partiql/ast/sql/SqlDialectTest.kt | 4078 +++++++++-------- 15 files changed, 3373 insertions(+), 2976 deletions(-) create mode 100644 partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprRowValue.java rename partiql-ast/src/main/{kotlin/org/partiql/ast => java/org/partiql/ast/v1}/sql/Sql.kt (88%) rename partiql-ast/src/main/{kotlin/org/partiql/ast => java/org/partiql/ast/v1}/sql/SqlBlock.kt (98%) create mode 100644 partiql-ast/src/main/java/org/partiql/ast/v1/sql/SqlDialect.kt rename partiql-ast/src/main/{kotlin/org/partiql/ast => java/org/partiql/ast/v1}/sql/SqlLayout.kt (98%) delete mode 100644 partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlDialect.kt diff --git a/partiql-ast/api/partiql-ast.api b/partiql-ast/api/partiql-ast.api index d6f0ac4302..0b96e25de9 100644 --- a/partiql-ast/api/partiql-ast.api +++ b/partiql-ast/api/partiql-ast.api @@ -4983,281 +4983,6 @@ public final class org/partiql/ast/builder/TypeVarcharBuilder { public final fun setLength (Ljava/lang/Integer;)V } -public abstract class org/partiql/ast/sql/SqlBlock { - public static final field Companion Lorg/partiql/ast/sql/SqlBlock$Companion; - public field next Lorg/partiql/ast/sql/SqlBlock; - public static final fun line ()Lorg/partiql/ast/sql/SqlBlock; - public static final fun none ()Lorg/partiql/ast/sql/SqlBlock; -} - -public final class org/partiql/ast/sql/SqlBlock$Companion { - public final fun line ()Lorg/partiql/ast/sql/SqlBlock; - public final fun none ()Lorg/partiql/ast/sql/SqlBlock; -} - -public final class org/partiql/ast/sql/SqlBlock$Line : org/partiql/ast/sql/SqlBlock { - public fun ()V -} - -public final class org/partiql/ast/sql/SqlBlock$Nest : org/partiql/ast/sql/SqlBlock { - public field child Lorg/partiql/ast/sql/SqlBlock; - public field postfix Ljava/lang/String; - public field prefix Ljava/lang/String; - public fun (Ljava/lang/String;Ljava/lang/String;Lorg/partiql/ast/sql/SqlBlock;)V -} - -public final class org/partiql/ast/sql/SqlBlock$None : org/partiql/ast/sql/SqlBlock { - public fun ()V -} - -public final class org/partiql/ast/sql/SqlBlock$Text : org/partiql/ast/sql/SqlBlock { - public field text Ljava/lang/String; - public fun (Ljava/lang/String;)V -} - -public abstract class org/partiql/ast/sql/SqlDialect : org/partiql/ast/visitor/AstBaseVisitor { - public static final field Companion Lorg/partiql/ast/sql/SqlDialect$Companion; - public fun ()V - public synthetic fun defaultReturn (Lorg/partiql/ast/AstNode;Ljava/lang/Object;)Ljava/lang/Object; - public fun defaultReturn (Lorg/partiql/ast/AstNode;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public static final fun getSTANDARD ()Lorg/partiql/ast/sql/SqlDialect; - public final fun transform (Lorg/partiql/ast/AstNode;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExclude (Lorg/partiql/ast/Exclude;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExclude (Lorg/partiql/ast/Exclude;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExcludeItem (Lorg/partiql/ast/Exclude$Item;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExcludeItem (Lorg/partiql/ast/Exclude$Item;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExcludeStepCollIndex (Lorg/partiql/ast/Exclude$Step$CollIndex;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExcludeStepCollIndex (Lorg/partiql/ast/Exclude$Step$CollIndex;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExcludeStepCollWildcard (Lorg/partiql/ast/Exclude$Step$CollWildcard;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExcludeStepCollWildcard (Lorg/partiql/ast/Exclude$Step$CollWildcard;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExcludeStepStructField (Lorg/partiql/ast/Exclude$Step$StructField;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExcludeStepStructField (Lorg/partiql/ast/Exclude$Step$StructField;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExcludeStepStructWildcard (Lorg/partiql/ast/Exclude$Step$StructWildcard;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExcludeStepStructWildcard (Lorg/partiql/ast/Exclude$Step$StructWildcard;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprAnd (Lorg/partiql/ast/Expr$And;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprAnd (Lorg/partiql/ast/Expr$And;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprBetween (Lorg/partiql/ast/Expr$Between;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprBetween (Lorg/partiql/ast/Expr$Between;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprCall (Lorg/partiql/ast/Expr$Call;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprCall (Lorg/partiql/ast/Expr$Call;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprCase (Lorg/partiql/ast/Expr$Case;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprCase (Lorg/partiql/ast/Expr$Case;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprCaseBranch (Lorg/partiql/ast/Expr$Case$Branch;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprCaseBranch (Lorg/partiql/ast/Expr$Case$Branch;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprCast (Lorg/partiql/ast/Expr$Cast;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprCast (Lorg/partiql/ast/Expr$Cast;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprCoalesce (Lorg/partiql/ast/Expr$Coalesce;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprCoalesce (Lorg/partiql/ast/Expr$Coalesce;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprCollection (Lorg/partiql/ast/Expr$Collection;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprCollection (Lorg/partiql/ast/Expr$Collection;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprDateAdd (Lorg/partiql/ast/Expr$DateAdd;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprDateAdd (Lorg/partiql/ast/Expr$DateAdd;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprDateDiff (Lorg/partiql/ast/Expr$DateDiff;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprDateDiff (Lorg/partiql/ast/Expr$DateDiff;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprExtract (Lorg/partiql/ast/Expr$Extract;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprExtract (Lorg/partiql/ast/Expr$Extract;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprInCollection (Lorg/partiql/ast/Expr$InCollection;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprInCollection (Lorg/partiql/ast/Expr$InCollection;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprIsType (Lorg/partiql/ast/Expr$IsType;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprIsType (Lorg/partiql/ast/Expr$IsType;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprLike (Lorg/partiql/ast/Expr$Like;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprLike (Lorg/partiql/ast/Expr$Like;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprLit (Lorg/partiql/ast/Expr$Lit;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprLit (Lorg/partiql/ast/Expr$Lit;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprNot (Lorg/partiql/ast/Expr$Not;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprNot (Lorg/partiql/ast/Expr$Not;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprNullIf (Lorg/partiql/ast/Expr$NullIf;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprNullIf (Lorg/partiql/ast/Expr$NullIf;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprOperator (Lorg/partiql/ast/Expr$Operator;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprOperator (Lorg/partiql/ast/Expr$Operator;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprOr (Lorg/partiql/ast/Expr$Or;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprOr (Lorg/partiql/ast/Expr$Or;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprOverlay (Lorg/partiql/ast/Expr$Overlay;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprOverlay (Lorg/partiql/ast/Expr$Overlay;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprParameter (Lorg/partiql/ast/Expr$Parameter;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprParameter (Lorg/partiql/ast/Expr$Parameter;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprPath (Lorg/partiql/ast/Expr$Path;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprPath (Lorg/partiql/ast/Expr$Path;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprPathStepIndex (Lorg/partiql/ast/Expr$Path$Step$Index;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprPathStepIndex (Lorg/partiql/ast/Expr$Path$Step$Index;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprPathStepSymbol (Lorg/partiql/ast/Expr$Path$Step$Symbol;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprPathStepSymbol (Lorg/partiql/ast/Expr$Path$Step$Symbol;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprPathStepUnpivot (Lorg/partiql/ast/Expr$Path$Step$Unpivot;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprPathStepUnpivot (Lorg/partiql/ast/Expr$Path$Step$Unpivot;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprPathStepWildcard (Lorg/partiql/ast/Expr$Path$Step$Wildcard;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprPathStepWildcard (Lorg/partiql/ast/Expr$Path$Step$Wildcard;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprPosition (Lorg/partiql/ast/Expr$Position;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprPosition (Lorg/partiql/ast/Expr$Position;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprQuerySet (Lorg/partiql/ast/Expr$QuerySet;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprQuerySet (Lorg/partiql/ast/Expr$QuerySet;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprSessionAttribute (Lorg/partiql/ast/Expr$SessionAttribute;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprSessionAttribute (Lorg/partiql/ast/Expr$SessionAttribute;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprStruct (Lorg/partiql/ast/Expr$Struct;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprStruct (Lorg/partiql/ast/Expr$Struct;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprStructField (Lorg/partiql/ast/Expr$Struct$Field;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprStructField (Lorg/partiql/ast/Expr$Struct$Field;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprSubstring (Lorg/partiql/ast/Expr$Substring;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprSubstring (Lorg/partiql/ast/Expr$Substring;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprTrim (Lorg/partiql/ast/Expr$Trim;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprTrim (Lorg/partiql/ast/Expr$Trim;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprValues (Lorg/partiql/ast/Expr$Values;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprValues (Lorg/partiql/ast/Expr$Values;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprValuesRow (Lorg/partiql/ast/Expr$Values$Row;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprValuesRow (Lorg/partiql/ast/Expr$Values$Row;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprVar (Lorg/partiql/ast/Expr$Var;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprVar (Lorg/partiql/ast/Expr$Var;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitExprVariant (Lorg/partiql/ast/Expr$Variant;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprVariant (Lorg/partiql/ast/Expr$Variant;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public fun visitExprWrapped (Lorg/partiql/ast/Expr;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitFromJoin (Lorg/partiql/ast/From$Join;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitFromJoin (Lorg/partiql/ast/From$Join;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitFromValue (Lorg/partiql/ast/From$Value;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitFromValue (Lorg/partiql/ast/From$Value;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitGroupBy (Lorg/partiql/ast/GroupBy;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitGroupBy (Lorg/partiql/ast/GroupBy;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitGroupByKey (Lorg/partiql/ast/GroupBy$Key;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitGroupByKey (Lorg/partiql/ast/GroupBy$Key;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitIdentifierQualified (Lorg/partiql/ast/Identifier$Qualified;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitIdentifierQualified (Lorg/partiql/ast/Identifier$Qualified;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitIdentifierSymbol (Lorg/partiql/ast/Identifier$Symbol;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitIdentifierSymbol (Lorg/partiql/ast/Identifier$Symbol;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitLet (Lorg/partiql/ast/Let;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitLet (Lorg/partiql/ast/Let;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitLetBinding (Lorg/partiql/ast/Let$Binding;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitLetBinding (Lorg/partiql/ast/Let$Binding;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitOrderBy (Lorg/partiql/ast/OrderBy;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitOrderBy (Lorg/partiql/ast/OrderBy;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitPath (Lorg/partiql/ast/Path;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitPath (Lorg/partiql/ast/Path;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitPathStep (Lorg/partiql/ast/Path$Step;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitPathStep (Lorg/partiql/ast/Path$Step;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitPathStepIndex (Lorg/partiql/ast/Path$Step$Index;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitPathStepIndex (Lorg/partiql/ast/Path$Step$Index;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitPathStepSymbol (Lorg/partiql/ast/Path$Step$Symbol;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitPathStepSymbol (Lorg/partiql/ast/Path$Step$Symbol;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitQueryBodySFW (Lorg/partiql/ast/QueryBody$SFW;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitQueryBodySFW (Lorg/partiql/ast/QueryBody$SFW;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitQueryBodySetOp (Lorg/partiql/ast/QueryBody$SetOp;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitQueryBodySetOp (Lorg/partiql/ast/QueryBody$SetOp;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitSelectPivot (Lorg/partiql/ast/Select$Pivot;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitSelectPivot (Lorg/partiql/ast/Select$Pivot;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitSelectProject (Lorg/partiql/ast/Select$Project;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitSelectProject (Lorg/partiql/ast/Select$Project;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitSelectProjectItemAll (Lorg/partiql/ast/Select$Project$Item$All;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitSelectProjectItemAll (Lorg/partiql/ast/Select$Project$Item$All;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitSelectProjectItemExpression (Lorg/partiql/ast/Select$Project$Item$Expression;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitSelectProjectItemExpression (Lorg/partiql/ast/Select$Project$Item$Expression;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitSelectStar (Lorg/partiql/ast/Select$Star;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitSelectStar (Lorg/partiql/ast/Select$Star;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitSelectValue (Lorg/partiql/ast/Select$Value;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitSelectValue (Lorg/partiql/ast/Select$Value;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitSetOp (Lorg/partiql/ast/SetOp;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitSetOp (Lorg/partiql/ast/SetOp;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitSort (Lorg/partiql/ast/Sort;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitSort (Lorg/partiql/ast/Sort;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitStatementQuery (Lorg/partiql/ast/Statement$Query;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitStatementQuery (Lorg/partiql/ast/Statement$Query;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeAny (Lorg/partiql/ast/Type$Any;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeAny (Lorg/partiql/ast/Type$Any;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeBag (Lorg/partiql/ast/Type$Bag;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeBag (Lorg/partiql/ast/Type$Bag;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeBigint (Lorg/partiql/ast/Type$Bigint;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeBigint (Lorg/partiql/ast/Type$Bigint;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeBit (Lorg/partiql/ast/Type$Bit;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeBit (Lorg/partiql/ast/Type$Bit;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeBitVarying (Lorg/partiql/ast/Type$BitVarying;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeBitVarying (Lorg/partiql/ast/Type$BitVarying;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeBlob (Lorg/partiql/ast/Type$Blob;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeBlob (Lorg/partiql/ast/Type$Blob;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeBool (Lorg/partiql/ast/Type$Bool;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeBool (Lorg/partiql/ast/Type$Bool;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeByteString (Lorg/partiql/ast/Type$ByteString;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeByteString (Lorg/partiql/ast/Type$ByteString;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeChar (Lorg/partiql/ast/Type$Char;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeChar (Lorg/partiql/ast/Type$Char;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeClob (Lorg/partiql/ast/Type$Clob;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeClob (Lorg/partiql/ast/Type$Clob;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeCustom (Lorg/partiql/ast/Type$Custom;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeCustom (Lorg/partiql/ast/Type$Custom;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeDate (Lorg/partiql/ast/Type$Date;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeDate (Lorg/partiql/ast/Type$Date;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeDecimal (Lorg/partiql/ast/Type$Decimal;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeDecimal (Lorg/partiql/ast/Type$Decimal;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeFloat32 (Lorg/partiql/ast/Type$Float32;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeFloat32 (Lorg/partiql/ast/Type$Float32;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeFloat64 (Lorg/partiql/ast/Type$Float64;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeFloat64 (Lorg/partiql/ast/Type$Float64;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeInt (Lorg/partiql/ast/Type$Int;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeInt (Lorg/partiql/ast/Type$Int;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeInt2 (Lorg/partiql/ast/Type$Int2;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeInt2 (Lorg/partiql/ast/Type$Int2;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeInt4 (Lorg/partiql/ast/Type$Int4;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeInt4 (Lorg/partiql/ast/Type$Int4;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeInt8 (Lorg/partiql/ast/Type$Int8;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeInt8 (Lorg/partiql/ast/Type$Int8;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeInterval (Lorg/partiql/ast/Type$Interval;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeInterval (Lorg/partiql/ast/Type$Interval;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeList (Lorg/partiql/ast/Type$List;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeList (Lorg/partiql/ast/Type$List;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeMissing (Lorg/partiql/ast/Type$Missing;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeMissing (Lorg/partiql/ast/Type$Missing;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeNullType (Lorg/partiql/ast/Type$NullType;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeNullType (Lorg/partiql/ast/Type$NullType;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeNumeric (Lorg/partiql/ast/Type$Numeric;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeNumeric (Lorg/partiql/ast/Type$Numeric;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeReal (Lorg/partiql/ast/Type$Real;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeReal (Lorg/partiql/ast/Type$Real;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeSexp (Lorg/partiql/ast/Type$Sexp;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeSexp (Lorg/partiql/ast/Type$Sexp;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeSmallint (Lorg/partiql/ast/Type$Smallint;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeSmallint (Lorg/partiql/ast/Type$Smallint;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeString (Lorg/partiql/ast/Type$String;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeString (Lorg/partiql/ast/Type$String;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeStruct (Lorg/partiql/ast/Type$Struct;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeStruct (Lorg/partiql/ast/Type$Struct;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeSymbol (Lorg/partiql/ast/Type$Symbol;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeSymbol (Lorg/partiql/ast/Type$Symbol;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeTime (Lorg/partiql/ast/Type$Time;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeTime (Lorg/partiql/ast/Type$Time;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeTimeWithTz (Lorg/partiql/ast/Type$TimeWithTz;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeTimeWithTz (Lorg/partiql/ast/Type$TimeWithTz;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeTimestamp (Lorg/partiql/ast/Type$Timestamp;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeTimestamp (Lorg/partiql/ast/Type$Timestamp;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeTimestampWithTz (Lorg/partiql/ast/Type$TimestampWithTz;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeTimestampWithTz (Lorg/partiql/ast/Type$TimestampWithTz;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeTinyint (Lorg/partiql/ast/Type$Tinyint;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeTinyint (Lorg/partiql/ast/Type$Tinyint;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeTuple (Lorg/partiql/ast/Type$Tuple;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeTuple (Lorg/partiql/ast/Type$Tuple;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; - public synthetic fun visitTypeVarchar (Lorg/partiql/ast/Type$Varchar;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitTypeVarchar (Lorg/partiql/ast/Type$Varchar;Lorg/partiql/ast/sql/SqlBlock;)Lorg/partiql/ast/sql/SqlBlock; -} - -public final class org/partiql/ast/sql/SqlDialect$Companion { - public final fun getSTANDARD ()Lorg/partiql/ast/sql/SqlDialect; -} - -public final class org/partiql/ast/sql/SqlKt { - public static final fun sql (Lorg/partiql/ast/AstNode;)Ljava/lang/String; - public static final fun sql (Lorg/partiql/ast/AstNode;Lorg/partiql/ast/sql/SqlLayout;)Ljava/lang/String; - public static final fun sql (Lorg/partiql/ast/AstNode;Lorg/partiql/ast/sql/SqlLayout;Lorg/partiql/ast/sql/SqlDialect;)Ljava/lang/String; - public static final fun sql (Lorg/partiql/ast/sql/SqlBlock;Lorg/partiql/ast/sql/SqlLayout;)Ljava/lang/String; - public static synthetic fun sql$default (Lorg/partiql/ast/AstNode;Lorg/partiql/ast/sql/SqlLayout;Lorg/partiql/ast/sql/SqlDialect;ILjava/lang/Object;)Ljava/lang/String; - public static synthetic fun sql$default (Lorg/partiql/ast/sql/SqlBlock;Lorg/partiql/ast/sql/SqlLayout;ILjava/lang/Object;)Ljava/lang/String; -} - -public abstract interface class org/partiql/ast/sql/SqlLayout { - public static final field Companion Lorg/partiql/ast/sql/SqlLayout$Companion; - public static fun getONELINE ()Lorg/partiql/ast/sql/SqlLayout; - public static fun getSTANDARD ()Lorg/partiql/ast/sql/SqlLayout; - public abstract fun print (Lorg/partiql/ast/sql/SqlBlock;)Ljava/lang/String; -} - -public final class org/partiql/ast/sql/SqlLayout$Companion { - public final fun getONELINE ()Lorg/partiql/ast/sql/SqlLayout; - public final fun getSTANDARD ()Lorg/partiql/ast/sql/SqlLayout; -} - public abstract class org/partiql/ast/util/AstRewriter : org/partiql/ast/visitor/AstBaseVisitor { public fun ()V public synthetic fun defaultReturn (Lorg/partiql/ast/AstNode;Ljava/lang/Object;)Ljava/lang/Object; @@ -5571,13 +5296,13 @@ public final class org/partiql/ast/v1/Ast { public static final fun exprPathStepField (Lorg/partiql/ast/v1/Identifier;Lorg/partiql/ast/v1/expr/PathStep;)Lorg/partiql/ast/v1/expr/PathStep$Field; public static final fun exprPosition (Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/expr/Expr;)Lorg/partiql/ast/v1/expr/ExprPosition; public static final fun exprQuerySet (Lorg/partiql/ast/v1/QueryBody;Lorg/partiql/ast/v1/OrderBy;Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/expr/Expr;)Lorg/partiql/ast/v1/expr/ExprQuerySet; + public static final fun exprRowValue (Ljava/util/List;)Lorg/partiql/ast/v1/expr/ExprRowValue; public static final fun exprSessionAttribute (Lorg/partiql/ast/v1/expr/SessionAttribute;)Lorg/partiql/ast/v1/expr/ExprSessionAttribute; public static final fun exprStruct (Ljava/util/List;)Lorg/partiql/ast/v1/expr/ExprStruct; public static final fun exprStructField (Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/expr/Expr;)Lorg/partiql/ast/v1/expr/ExprStruct$Field; public static final fun exprSubstring (Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/expr/Expr;)Lorg/partiql/ast/v1/expr/ExprSubstring; public static final fun exprTrim (Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/expr/TrimSpec;)Lorg/partiql/ast/v1/expr/ExprTrim; public static final fun exprValues (Ljava/util/List;)Lorg/partiql/ast/v1/expr/ExprValues; - public static final fun exprValuesRow (Ljava/util/List;)Lorg/partiql/ast/v1/expr/ExprValues$Row; public static final fun exprVarRef (Lorg/partiql/ast/v1/IdentifierChain;Lorg/partiql/ast/v1/expr/Scope;)Lorg/partiql/ast/v1/expr/ExprVarRef; public static final fun exprVariant (Ljava/lang/String;Ljava/lang/String;)Lorg/partiql/ast/v1/expr/ExprVariant; public static final fun exprWindow (Lorg/partiql/ast/v1/expr/WindowFunction;Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/expr/ExprWindow$Over;)Lorg/partiql/ast/v1/expr/ExprWindow; @@ -5701,6 +5426,8 @@ public abstract class org/partiql/ast/v1/AstRewriter : org/partiql/ast/v1/AstVis public fun visitExprPosition (Lorg/partiql/ast/v1/expr/ExprPosition;Ljava/lang/Object;)Lorg/partiql/ast/v1/AstNode; public synthetic fun visitExprQuerySet (Lorg/partiql/ast/v1/expr/ExprQuerySet;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprQuerySet (Lorg/partiql/ast/v1/expr/ExprQuerySet;Ljava/lang/Object;)Lorg/partiql/ast/v1/AstNode; + public synthetic fun visitExprRowValue (Lorg/partiql/ast/v1/expr/ExprRowValue;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprRowValue (Lorg/partiql/ast/v1/expr/ExprRowValue;Ljava/lang/Object;)Lorg/partiql/ast/v1/AstNode; public synthetic fun visitExprSessionAttribute (Lorg/partiql/ast/v1/expr/ExprSessionAttribute;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprSessionAttribute (Lorg/partiql/ast/v1/expr/ExprSessionAttribute;Ljava/lang/Object;)Lorg/partiql/ast/v1/AstNode; public synthetic fun visitExprStruct (Lorg/partiql/ast/v1/expr/ExprStruct;Ljava/lang/Object;)Ljava/lang/Object; @@ -5713,8 +5440,6 @@ public abstract class org/partiql/ast/v1/AstRewriter : org/partiql/ast/v1/AstVis public fun visitExprTrim (Lorg/partiql/ast/v1/expr/ExprTrim;Ljava/lang/Object;)Lorg/partiql/ast/v1/AstNode; public synthetic fun visitExprValues (Lorg/partiql/ast/v1/expr/ExprValues;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprValues (Lorg/partiql/ast/v1/expr/ExprValues;Ljava/lang/Object;)Lorg/partiql/ast/v1/AstNode; - public synthetic fun visitExprValuesRow (Lorg/partiql/ast/v1/expr/ExprValues$Row;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprValuesRow (Lorg/partiql/ast/v1/expr/ExprValues$Row;Ljava/lang/Object;)Lorg/partiql/ast/v1/AstNode; public synthetic fun visitExprVarRef (Lorg/partiql/ast/v1/expr/ExprVarRef;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprVarRef (Lorg/partiql/ast/v1/expr/ExprVarRef;Ljava/lang/Object;)Lorg/partiql/ast/v1/AstNode; public synthetic fun visitExprVariant (Lorg/partiql/ast/v1/expr/ExprVariant;Ljava/lang/Object;)Ljava/lang/Object; @@ -5794,6 +5519,7 @@ public abstract class org/partiql/ast/v1/AstVisitor { public abstract fun defaultReturn (Lorg/partiql/ast/v1/AstNode;Ljava/lang/Object;)Ljava/lang/Object; public fun defaultVisit (Lorg/partiql/ast/v1/AstNode;Ljava/lang/Object;)Ljava/lang/Object; public fun visit (Lorg/partiql/ast/v1/AstNode;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitDataType (Lorg/partiql/ast/v1/DataType;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExclude (Lorg/partiql/ast/v1/Exclude;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExcludePath (Lorg/partiql/ast/v1/ExcludePath;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExcludeStep (Lorg/partiql/ast/v1/ExcludeStep;Ljava/lang/Object;)Ljava/lang/Object; @@ -5827,13 +5553,13 @@ public abstract class org/partiql/ast/v1/AstVisitor { public fun visitExprPath (Lorg/partiql/ast/v1/expr/ExprPath;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprPosition (Lorg/partiql/ast/v1/expr/ExprPosition;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprQuerySet (Lorg/partiql/ast/v1/expr/ExprQuerySet;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprRowValue (Lorg/partiql/ast/v1/expr/ExprRowValue;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprSessionAttribute (Lorg/partiql/ast/v1/expr/ExprSessionAttribute;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprStruct (Lorg/partiql/ast/v1/expr/ExprStruct;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprStructField (Lorg/partiql/ast/v1/expr/ExprStruct$Field;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprSubstring (Lorg/partiql/ast/v1/expr/ExprSubstring;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprTrim (Lorg/partiql/ast/v1/expr/ExprTrim;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprValues (Lorg/partiql/ast/v1/expr/ExprValues;Ljava/lang/Object;)Ljava/lang/Object; - public fun visitExprValuesRow (Lorg/partiql/ast/v1/expr/ExprValues$Row;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprVarRef (Lorg/partiql/ast/v1/expr/ExprVarRef;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprVariant (Lorg/partiql/ast/v1/expr/ExprVariant;Ljava/lang/Object;)Ljava/lang/Object; public fun visitExprWindow (Lorg/partiql/ast/v1/expr/ExprWindow;Ljava/lang/Object;)Ljava/lang/Object; @@ -7222,6 +6948,23 @@ public class org/partiql/ast/v1/expr/ExprQuerySet$Builder { public fun toString ()Ljava/lang/String; } +public class org/partiql/ast/v1/expr/ExprRowValue : org/partiql/ast/v1/expr/Expr { + public final field values Ljava/util/List; + public fun (Ljava/util/List;)V + public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun builder ()Lorg/partiql/ast/v1/expr/ExprRowValue$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/v1/expr/ExprRowValue$Builder { + public fun build ()Lorg/partiql/ast/v1/expr/ExprRowValue; + public fun toString ()Ljava/lang/String; + public fun values (Ljava/util/List;)Lorg/partiql/ast/v1/expr/ExprRowValue$Builder; +} + public class org/partiql/ast/v1/expr/ExprSessionAttribute : org/partiql/ast/v1/expr/Expr { public final field sessionAttribute Lorg/partiql/ast/v1/expr/SessionAttribute; public fun (Lorg/partiql/ast/v1/expr/SessionAttribute;)V @@ -7334,23 +7077,6 @@ public class org/partiql/ast/v1/expr/ExprValues$Builder { public fun toString ()Ljava/lang/String; } -public class org/partiql/ast/v1/expr/ExprValues$Row : org/partiql/ast/v1/AstNode { - public final field values Ljava/util/List; - public fun (Ljava/util/List;)V - public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun builder ()Lorg/partiql/ast/v1/expr/ExprValues$Row$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/v1/expr/ExprValues$Row$Builder { - public fun build ()Lorg/partiql/ast/v1/expr/ExprValues$Row; - public fun toString ()Ljava/lang/String; - public fun values (Ljava/util/List;)Lorg/partiql/ast/v1/expr/ExprValues$Row$Builder; -} - public class org/partiql/ast/v1/expr/ExprVarRef : org/partiql/ast/v1/expr/Expr { public final field identifierChain Lorg/partiql/ast/v1/IdentifierChain; public final field scope Lorg/partiql/ast/v1/expr/Scope; @@ -7922,6 +7648,201 @@ public class org/partiql/ast/v1/graph/GraphSelector$ShortestKGroup$Builder { public fun toString ()Ljava/lang/String; } +public abstract class org/partiql/ast/v1/sql/SqlBlock { + public static final field Companion Lorg/partiql/ast/v1/sql/SqlBlock$Companion; + public field next Lorg/partiql/ast/v1/sql/SqlBlock; + public static final fun line ()Lorg/partiql/ast/v1/sql/SqlBlock; + public static final fun none ()Lorg/partiql/ast/v1/sql/SqlBlock; +} + +public final class org/partiql/ast/v1/sql/SqlBlock$Companion { + public final fun line ()Lorg/partiql/ast/v1/sql/SqlBlock; + public final fun none ()Lorg/partiql/ast/v1/sql/SqlBlock; +} + +public final class org/partiql/ast/v1/sql/SqlBlock$Line : org/partiql/ast/v1/sql/SqlBlock { + public fun ()V +} + +public final class org/partiql/ast/v1/sql/SqlBlock$Nest : org/partiql/ast/v1/sql/SqlBlock { + public field child Lorg/partiql/ast/v1/sql/SqlBlock; + public field postfix Ljava/lang/String; + public field prefix Ljava/lang/String; + public fun (Ljava/lang/String;Ljava/lang/String;Lorg/partiql/ast/v1/sql/SqlBlock;)V +} + +public final class org/partiql/ast/v1/sql/SqlBlock$None : org/partiql/ast/v1/sql/SqlBlock { + public fun ()V +} + +public final class org/partiql/ast/v1/sql/SqlBlock$Text : org/partiql/ast/v1/sql/SqlBlock { + public field text Ljava/lang/String; + public fun (Ljava/lang/String;)V +} + +public abstract class org/partiql/ast/v1/sql/SqlDialect : org/partiql/ast/v1/AstVisitor { + public static final field Companion Lorg/partiql/ast/v1/sql/SqlDialect$Companion; + public fun ()V + public synthetic fun defaultReturn (Lorg/partiql/ast/v1/AstNode;Ljava/lang/Object;)Ljava/lang/Object; + public fun defaultReturn (Lorg/partiql/ast/v1/AstNode;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public static final fun getSTANDARD ()Lorg/partiql/ast/v1/sql/SqlDialect; + public final fun transform (Lorg/partiql/ast/v1/AstNode;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitDataType (Lorg/partiql/ast/v1/DataType;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitDataType (Lorg/partiql/ast/v1/DataType;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExclude (Lorg/partiql/ast/v1/Exclude;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExclude (Lorg/partiql/ast/v1/Exclude;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExcludePath (Lorg/partiql/ast/v1/ExcludePath;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExcludePath (Lorg/partiql/ast/v1/ExcludePath;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExcludeStepCollIndex (Lorg/partiql/ast/v1/ExcludeStep$CollIndex;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExcludeStepCollIndex (Lorg/partiql/ast/v1/ExcludeStep$CollIndex;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExcludeStepCollWildcard (Lorg/partiql/ast/v1/ExcludeStep$CollWildcard;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExcludeStepCollWildcard (Lorg/partiql/ast/v1/ExcludeStep$CollWildcard;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExcludeStepStructField (Lorg/partiql/ast/v1/ExcludeStep$StructField;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExcludeStepStructField (Lorg/partiql/ast/v1/ExcludeStep$StructField;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExcludeStepStructWildcard (Lorg/partiql/ast/v1/ExcludeStep$StructWildcard;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExcludeStepStructWildcard (Lorg/partiql/ast/v1/ExcludeStep$StructWildcard;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprAnd (Lorg/partiql/ast/v1/expr/ExprAnd;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprAnd (Lorg/partiql/ast/v1/expr/ExprAnd;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprArray (Lorg/partiql/ast/v1/expr/ExprArray;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprArray (Lorg/partiql/ast/v1/expr/ExprArray;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprBag (Lorg/partiql/ast/v1/expr/ExprBag;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprBag (Lorg/partiql/ast/v1/expr/ExprBag;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprBetween (Lorg/partiql/ast/v1/expr/ExprBetween;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprBetween (Lorg/partiql/ast/v1/expr/ExprBetween;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprCall (Lorg/partiql/ast/v1/expr/ExprCall;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprCall (Lorg/partiql/ast/v1/expr/ExprCall;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprCase (Lorg/partiql/ast/v1/expr/ExprCase;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprCase (Lorg/partiql/ast/v1/expr/ExprCase;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprCaseBranch (Lorg/partiql/ast/v1/expr/ExprCase$Branch;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprCaseBranch (Lorg/partiql/ast/v1/expr/ExprCase$Branch;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprCast (Lorg/partiql/ast/v1/expr/ExprCast;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprCast (Lorg/partiql/ast/v1/expr/ExprCast;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprCoalesce (Lorg/partiql/ast/v1/expr/ExprCoalesce;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprCoalesce (Lorg/partiql/ast/v1/expr/ExprCoalesce;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprExtract (Lorg/partiql/ast/v1/expr/ExprExtract;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprExtract (Lorg/partiql/ast/v1/expr/ExprExtract;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprInCollection (Lorg/partiql/ast/v1/expr/ExprInCollection;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprInCollection (Lorg/partiql/ast/v1/expr/ExprInCollection;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprIsType (Lorg/partiql/ast/v1/expr/ExprIsType;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprIsType (Lorg/partiql/ast/v1/expr/ExprIsType;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprLike (Lorg/partiql/ast/v1/expr/ExprLike;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprLike (Lorg/partiql/ast/v1/expr/ExprLike;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprLit (Lorg/partiql/ast/v1/expr/ExprLit;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprLit (Lorg/partiql/ast/v1/expr/ExprLit;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprNot (Lorg/partiql/ast/v1/expr/ExprNot;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprNot (Lorg/partiql/ast/v1/expr/ExprNot;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprNullIf (Lorg/partiql/ast/v1/expr/ExprNullIf;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprNullIf (Lorg/partiql/ast/v1/expr/ExprNullIf;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprOperator (Lorg/partiql/ast/v1/expr/ExprOperator;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprOperator (Lorg/partiql/ast/v1/expr/ExprOperator;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprOr (Lorg/partiql/ast/v1/expr/ExprOr;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprOr (Lorg/partiql/ast/v1/expr/ExprOr;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprOverlay (Lorg/partiql/ast/v1/expr/ExprOverlay;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprOverlay (Lorg/partiql/ast/v1/expr/ExprOverlay;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprParameter (Lorg/partiql/ast/v1/expr/ExprParameter;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprParameter (Lorg/partiql/ast/v1/expr/ExprParameter;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprPath (Lorg/partiql/ast/v1/expr/ExprPath;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprPath (Lorg/partiql/ast/v1/expr/ExprPath;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprPosition (Lorg/partiql/ast/v1/expr/ExprPosition;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprPosition (Lorg/partiql/ast/v1/expr/ExprPosition;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprQuerySet (Lorg/partiql/ast/v1/expr/ExprQuerySet;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprQuerySet (Lorg/partiql/ast/v1/expr/ExprQuerySet;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprRowValue (Lorg/partiql/ast/v1/expr/ExprRowValue;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprRowValue (Lorg/partiql/ast/v1/expr/ExprRowValue;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprSessionAttribute (Lorg/partiql/ast/v1/expr/ExprSessionAttribute;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprSessionAttribute (Lorg/partiql/ast/v1/expr/ExprSessionAttribute;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprStruct (Lorg/partiql/ast/v1/expr/ExprStruct;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprStruct (Lorg/partiql/ast/v1/expr/ExprStruct;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprStructField (Lorg/partiql/ast/v1/expr/ExprStruct$Field;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprStructField (Lorg/partiql/ast/v1/expr/ExprStruct$Field;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprSubstring (Lorg/partiql/ast/v1/expr/ExprSubstring;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprSubstring (Lorg/partiql/ast/v1/expr/ExprSubstring;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprTrim (Lorg/partiql/ast/v1/expr/ExprTrim;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprTrim (Lorg/partiql/ast/v1/expr/ExprTrim;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprValues (Lorg/partiql/ast/v1/expr/ExprValues;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprValues (Lorg/partiql/ast/v1/expr/ExprValues;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprVarRef (Lorg/partiql/ast/v1/expr/ExprVarRef;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprVarRef (Lorg/partiql/ast/v1/expr/ExprVarRef;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitExprVariant (Lorg/partiql/ast/v1/expr/ExprVariant;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExprVariant (Lorg/partiql/ast/v1/expr/ExprVariant;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public fun visitExprWrapped (Lorg/partiql/ast/v1/expr/Expr;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitFrom (Lorg/partiql/ast/v1/From;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitFrom (Lorg/partiql/ast/v1/From;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitFromExpr (Lorg/partiql/ast/v1/FromExpr;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitFromExpr (Lorg/partiql/ast/v1/FromExpr;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitFromJoin (Lorg/partiql/ast/v1/FromJoin;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitFromJoin (Lorg/partiql/ast/v1/FromJoin;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitGroupBy (Lorg/partiql/ast/v1/GroupBy;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitGroupBy (Lorg/partiql/ast/v1/GroupBy;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitGroupByKey (Lorg/partiql/ast/v1/GroupBy$Key;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitGroupByKey (Lorg/partiql/ast/v1/GroupBy$Key;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitIdentifier (Lorg/partiql/ast/v1/Identifier;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitIdentifier (Lorg/partiql/ast/v1/Identifier;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitIdentifierChain (Lorg/partiql/ast/v1/IdentifierChain;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitIdentifierChain (Lorg/partiql/ast/v1/IdentifierChain;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitLet (Lorg/partiql/ast/v1/Let;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitLet (Lorg/partiql/ast/v1/Let;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitLetBinding (Lorg/partiql/ast/v1/Let$Binding;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitLetBinding (Lorg/partiql/ast/v1/Let$Binding;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitOrderBy (Lorg/partiql/ast/v1/OrderBy;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitOrderBy (Lorg/partiql/ast/v1/OrderBy;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitPathStepAllElements (Lorg/partiql/ast/v1/expr/PathStep$AllElements;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPathStepAllElements (Lorg/partiql/ast/v1/expr/PathStep$AllElements;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitPathStepAllFields (Lorg/partiql/ast/v1/expr/PathStep$AllFields;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPathStepAllFields (Lorg/partiql/ast/v1/expr/PathStep$AllFields;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitPathStepElement (Lorg/partiql/ast/v1/expr/PathStep$Element;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPathStepElement (Lorg/partiql/ast/v1/expr/PathStep$Element;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitPathStepField (Lorg/partiql/ast/v1/expr/PathStep$Field;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPathStepField (Lorg/partiql/ast/v1/expr/PathStep$Field;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitQuery (Lorg/partiql/ast/v1/Query;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitQuery (Lorg/partiql/ast/v1/Query;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitQueryBodySFW (Lorg/partiql/ast/v1/QueryBody$SFW;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitQueryBodySFW (Lorg/partiql/ast/v1/QueryBody$SFW;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitQueryBodySetOp (Lorg/partiql/ast/v1/QueryBody$SetOp;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitQueryBodySetOp (Lorg/partiql/ast/v1/QueryBody$SetOp;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitSelectItemExpr (Lorg/partiql/ast/v1/SelectItem$Expr;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSelectItemExpr (Lorg/partiql/ast/v1/SelectItem$Expr;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitSelectItemStar (Lorg/partiql/ast/v1/SelectItem$Star;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSelectItemStar (Lorg/partiql/ast/v1/SelectItem$Star;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitSelectList (Lorg/partiql/ast/v1/SelectList;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSelectList (Lorg/partiql/ast/v1/SelectList;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitSelectPivot (Lorg/partiql/ast/v1/SelectPivot;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSelectPivot (Lorg/partiql/ast/v1/SelectPivot;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitSelectStar (Lorg/partiql/ast/v1/SelectStar;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSelectStar (Lorg/partiql/ast/v1/SelectStar;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitSelectValue (Lorg/partiql/ast/v1/SelectValue;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSelectValue (Lorg/partiql/ast/v1/SelectValue;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitSetOp (Lorg/partiql/ast/v1/SetOp;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSetOp (Lorg/partiql/ast/v1/SetOp;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; + public synthetic fun visitSort (Lorg/partiql/ast/v1/Sort;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSort (Lorg/partiql/ast/v1/Sort;Lorg/partiql/ast/v1/sql/SqlBlock;)Lorg/partiql/ast/v1/sql/SqlBlock; +} + +public final class org/partiql/ast/v1/sql/SqlDialect$Companion { + public final fun getSTANDARD ()Lorg/partiql/ast/v1/sql/SqlDialect; +} + +public final class org/partiql/ast/v1/sql/SqlKt { + public static final fun sql (Lorg/partiql/ast/v1/AstNode;)Ljava/lang/String; + public static final fun sql (Lorg/partiql/ast/v1/AstNode;Lorg/partiql/ast/v1/sql/SqlLayout;)Ljava/lang/String; + public static final fun sql (Lorg/partiql/ast/v1/AstNode;Lorg/partiql/ast/v1/sql/SqlLayout;Lorg/partiql/ast/v1/sql/SqlDialect;)Ljava/lang/String; + public static final fun sql (Lorg/partiql/ast/v1/sql/SqlBlock;Lorg/partiql/ast/v1/sql/SqlLayout;)Ljava/lang/String; + public static synthetic fun sql$default (Lorg/partiql/ast/v1/AstNode;Lorg/partiql/ast/v1/sql/SqlLayout;Lorg/partiql/ast/v1/sql/SqlDialect;ILjava/lang/Object;)Ljava/lang/String; + public static synthetic fun sql$default (Lorg/partiql/ast/v1/sql/SqlBlock;Lorg/partiql/ast/v1/sql/SqlLayout;ILjava/lang/Object;)Ljava/lang/String; +} + +public abstract interface class org/partiql/ast/v1/sql/SqlLayout { + public static final field Companion Lorg/partiql/ast/v1/sql/SqlLayout$Companion; + public static fun getONELINE ()Lorg/partiql/ast/v1/sql/SqlLayout; + public static fun getSTANDARD ()Lorg/partiql/ast/v1/sql/SqlLayout; + public abstract fun print (Lorg/partiql/ast/v1/sql/SqlBlock;)Ljava/lang/String; +} + +public final class org/partiql/ast/v1/sql/SqlLayout$Companion { + public final fun getONELINE ()Lorg/partiql/ast/v1/sql/SqlLayout; + public final fun getSTANDARD ()Lorg/partiql/ast/v1/sql/SqlLayout; +} + public abstract class org/partiql/ast/visitor/AstBaseVisitor : org/partiql/ast/visitor/AstVisitor { public fun ()V public abstract fun defaultReturn (Lorg/partiql/ast/AstNode;Ljava/lang/Object;)Ljava/lang/Object; diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/Ast.kt b/partiql-ast/src/main/java/org/partiql/ast/v1/Ast.kt index a8a543324d..ba99bf03e3 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/Ast.kt +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/Ast.kt @@ -24,6 +24,7 @@ import org.partiql.ast.v1.expr.ExprParameter import org.partiql.ast.v1.expr.ExprPath import org.partiql.ast.v1.expr.ExprPosition import org.partiql.ast.v1.expr.ExprQuerySet +import org.partiql.ast.v1.expr.ExprRowValue import org.partiql.ast.v1.expr.ExprSessionAttribute import org.partiql.ast.v1.expr.ExprStruct import org.partiql.ast.v1.expr.ExprSubstring @@ -50,6 +51,8 @@ import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental // TODO docs for all factory methods and move to Kotlin sources +// Also consider defaults for nullable. Need to look more into backwards compatibility. +// Tracking issue for defaults -- https://github.com/partiql/partiql-lang-kotlin/issues/1640. public object Ast { // Expr @JvmStatic @@ -113,8 +116,8 @@ public object Ast { } @JvmStatic - public fun exprLike(value: Expr, Pattern: Expr, escape: Expr?, not: Boolean): ExprLike { - return ExprLike(value, Pattern, escape, not) + public fun exprLike(value: Expr, pattern: Expr, escape: Expr?, not: Boolean): ExprLike { + return ExprLike(value, pattern, escape, not) } // This representation will be changed in https://github.com/partiql/partiql-lang-kotlin/issues/1589 @@ -195,18 +198,18 @@ public object Ast { } @JvmStatic - public fun exprTrim(Value: Expr, chars: Expr?, trimSpec: TrimSpec?): ExprTrim { - return ExprTrim(Value, chars, trimSpec) + public fun exprTrim(value: Expr, chars: Expr?, trimSpec: TrimSpec?): ExprTrim { + return ExprTrim(value, chars, trimSpec) } @JvmStatic - public fun exprValues(rows: List): ExprValues { + public fun exprValues(rows: List): ExprValues { return ExprValues(rows) } @JvmStatic - public fun exprValuesRow(values: List): ExprValues.Row { - return ExprValues.Row(values) + public fun exprRowValue(values: List): ExprRowValue { + return ExprRowValue(values) } @JvmStatic diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/AstRewriter.kt b/partiql-ast/src/main/java/org/partiql/ast/v1/AstRewriter.kt index e39070a7aa..28dabead83 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/AstRewriter.kt +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/AstRewriter.kt @@ -28,6 +28,7 @@ import org.partiql.ast.v1.expr.ExprParameter import org.partiql.ast.v1.expr.ExprPath import org.partiql.ast.v1.expr.ExprPosition import org.partiql.ast.v1.expr.ExprQuerySet +import org.partiql.ast.v1.expr.ExprRowValue import org.partiql.ast.v1.expr.ExprSessionAttribute import org.partiql.ast.v1.expr.ExprStruct import org.partiql.ast.v1.expr.ExprSubstring @@ -353,7 +354,7 @@ public abstract class AstRewriter : AstVisitor() { } override fun visitExprValues(node: ExprValues, ctx: C): AstNode { - val values = _visitList(node.rows, ctx, ::visitExprValuesRow) + val values = _visitList(node.rows, ctx, ::visitExprRowValue) return if (values !== node.rows) { ExprValues(values) } else { @@ -361,10 +362,10 @@ public abstract class AstRewriter : AstVisitor() { } } - override fun visitExprValuesRow(node: ExprValues.Row, ctx: C): AstNode { + override fun visitExprRowValue(node: ExprRowValue, ctx: C): AstNode { val values = _visitList(node.values, ctx, ::visitExpr) return if (values !== node.values) { - ExprValues.Row(values) + ExprRowValue(values) } else { node } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/AstVisitor.java b/partiql-ast/src/main/java/org/partiql/ast/v1/AstVisitor.java index eb130b00a7..d1ccf6a42c 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/AstVisitor.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/AstVisitor.java @@ -24,6 +24,7 @@ import org.partiql.ast.v1.expr.ExprPath; import org.partiql.ast.v1.expr.ExprPosition; import org.partiql.ast.v1.expr.ExprQuerySet; +import org.partiql.ast.v1.expr.ExprRowValue; import org.partiql.ast.v1.expr.ExprSessionAttribute; import org.partiql.ast.v1.expr.ExprStruct; import org.partiql.ast.v1.expr.ExprSubstring; @@ -148,7 +149,7 @@ public R visitExprValues(ExprValues node, C ctx) { return defaultVisit(node, ctx); } - public R visitExprValuesRow(ExprValues.Row node, C ctx) { + public R visitExprRowValue(ExprRowValue node, C ctx) { return defaultVisit(node, ctx); } @@ -435,4 +436,8 @@ public R visitGraphLabelConj(GraphLabel.Conj node, C ctx) { public R visitGraphLabelDisj(GraphLabel.Disj node, C ctx) { return defaultVisit(node, ctx); } + + public R visitDataType(DataType node, C ctx) { + return defaultVisit(node, ctx); + } } 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 a62790214d..d3111c0dbe 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 @@ -609,6 +609,6 @@ public Collection children() { @Override public R accept(@NotNull AstVisitor visitor, C ctx) { - return null; + return visitor.visitDataType(this, ctx); } } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprCast.java b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprCast.java index 49b00703c4..f22727e543 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprCast.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprCast.java @@ -33,6 +33,7 @@ public ExprCast(@NotNull Expr value, @NotNull DataType asType) { public Collection children() { List kids = new ArrayList<>(); kids.add(value); + kids.add(asType); return kids; } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprIsType.java b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprIsType.java index 55769525bf..19a734c636 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprIsType.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprIsType.java @@ -37,6 +37,7 @@ public ExprIsType(@NotNull Expr value, @NotNull DataType type, boolean not) { public Collection children() { List kids = new ArrayList<>(); kids.add(value); + kids.add(type); return kids; } diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprRowValue.java b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprRowValue.java new file mode 100644 index 0000000000..4220679ac1 --- /dev/null +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprRowValue.java @@ -0,0 +1,36 @@ +package org.partiql.ast.v1.expr; + +import lombok.EqualsAndHashCode; +import org.jetbrains.annotations.NotNull; +import org.partiql.ast.v1.AstNode; +import org.partiql.ast.v1.AstVisitor; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * TODO docs, equals, hashcode + * Also add optional [ROW] keyword property. https://ronsavage.github.io/SQL/sql-99.bnf.html#row%20value%20constructor + */ +@lombok.Builder(builderClassName = "Builder") +@EqualsAndHashCode(callSuper = false) +public class ExprRowValue extends Expr { + @NotNull + public final List values; + + public ExprRowValue(@NotNull List values) { + this.values = values; + } + + @Override + @NotNull + public Collection children() { + return new ArrayList<>(values); + } + + @Override + public R accept(@NotNull AstVisitor visitor, C ctx) { + return visitor.visitExprRowValue(this, ctx); + } +} diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprValues.java b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprValues.java index 2790b4d356..a1a963cbdb 100644 --- a/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprValues.java +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/expr/ExprValues.java @@ -12,14 +12,16 @@ /** * TODO docs, equals, hashcode + * Also may not be an [Expr]? + * Tracking issue for VALUES and subqueries -- https://github.com/partiql/partiql-lang-kotlin/issues/1641. */ @Builder(builderClassName = "Builder") @EqualsAndHashCode(callSuper = false) public class ExprValues extends Expr { @NotNull - public final List rows; + public final List rows; - public ExprValues(@NotNull List rows) { + public ExprValues(@NotNull List rows) { this.rows = rows; } @@ -33,29 +35,4 @@ public Collection children() { public R accept(@NotNull AstVisitor visitor, C ctx) { return visitor.visitExprValues(this, ctx); } - - /** - * TODO docs, equals, hashcode - */ - @lombok.Builder(builderClassName = "Builder") - @EqualsAndHashCode(callSuper = false) - public static class Row extends AstNode { - @NotNull - public final List values; - - public Row(@NotNull List values) { - this.values = values; - } - - @Override - @NotNull - public Collection children() { - return new ArrayList<>(values); - } - - @Override - public R accept(@NotNull AstVisitor visitor, C ctx) { - return visitor.visitExprValuesRow(this, ctx); - } - } } diff --git a/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt b/partiql-ast/src/main/java/org/partiql/ast/v1/sql/Sql.kt similarity index 88% rename from partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt rename to partiql-ast/src/main/java/org/partiql/ast/v1/sql/Sql.kt index f8cc15f4af..85c168d35d 100644 --- a/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/sql/Sql.kt @@ -1,6 +1,6 @@ -package org.partiql.ast.sql +package org.partiql.ast.v1.sql -import org.partiql.ast.AstNode +import org.partiql.ast.v1.AstNode /** * Pretty-print this [AstNode] as SQL text with the given (or standard) [SqlLayout] and [SqlDialect]. diff --git a/partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlBlock.kt b/partiql-ast/src/main/java/org/partiql/ast/v1/sql/SqlBlock.kt similarity index 98% rename from partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlBlock.kt rename to partiql-ast/src/main/java/org/partiql/ast/v1/sql/SqlBlock.kt index c02d1d4a9d..661e8d1110 100644 --- a/partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlBlock.kt +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/sql/SqlBlock.kt @@ -12,7 +12,7 @@ * language governing permissions and limitations under the License. */ -package org.partiql.ast.sql +package org.partiql.ast.v1.sql /** * Representation of some textual elements as a token (singly-linked) list. diff --git a/partiql-ast/src/main/java/org/partiql/ast/v1/sql/SqlDialect.kt b/partiql-ast/src/main/java/org/partiql/ast/v1/sql/SqlDialect.kt new file mode 100644 index 0000000000..d904ad08fc --- /dev/null +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/sql/SqlDialect.kt @@ -0,0 +1,824 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at: + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + */ + +package org.partiql.ast.v1.sql + +import org.partiql.ast.v1.Ast.exprLit +import org.partiql.ast.v1.AstNode +import org.partiql.ast.v1.AstVisitor +import org.partiql.ast.v1.DataType +import org.partiql.ast.v1.Exclude +import org.partiql.ast.v1.ExcludePath +import org.partiql.ast.v1.ExcludeStep +import org.partiql.ast.v1.From +import org.partiql.ast.v1.FromExpr +import org.partiql.ast.v1.FromJoin +import org.partiql.ast.v1.FromType +import org.partiql.ast.v1.GroupBy +import org.partiql.ast.v1.GroupByStrategy +import org.partiql.ast.v1.Identifier +import org.partiql.ast.v1.IdentifierChain +import org.partiql.ast.v1.JoinType +import org.partiql.ast.v1.Let +import org.partiql.ast.v1.Nulls +import org.partiql.ast.v1.Order +import org.partiql.ast.v1.OrderBy +import org.partiql.ast.v1.Query +import org.partiql.ast.v1.QueryBody +import org.partiql.ast.v1.SelectItem +import org.partiql.ast.v1.SelectList +import org.partiql.ast.v1.SelectPivot +import org.partiql.ast.v1.SelectStar +import org.partiql.ast.v1.SelectValue +import org.partiql.ast.v1.SetOp +import org.partiql.ast.v1.SetOpType +import org.partiql.ast.v1.SetQuantifier +import org.partiql.ast.v1.Sort +import org.partiql.ast.v1.expr.Expr +import org.partiql.ast.v1.expr.ExprAnd +import org.partiql.ast.v1.expr.ExprArray +import org.partiql.ast.v1.expr.ExprBag +import org.partiql.ast.v1.expr.ExprBetween +import org.partiql.ast.v1.expr.ExprCall +import org.partiql.ast.v1.expr.ExprCase +import org.partiql.ast.v1.expr.ExprCast +import org.partiql.ast.v1.expr.ExprCoalesce +import org.partiql.ast.v1.expr.ExprExtract +import org.partiql.ast.v1.expr.ExprInCollection +import org.partiql.ast.v1.expr.ExprIsType +import org.partiql.ast.v1.expr.ExprLike +import org.partiql.ast.v1.expr.ExprLit +import org.partiql.ast.v1.expr.ExprNot +import org.partiql.ast.v1.expr.ExprNullIf +import org.partiql.ast.v1.expr.ExprOperator +import org.partiql.ast.v1.expr.ExprOr +import org.partiql.ast.v1.expr.ExprOverlay +import org.partiql.ast.v1.expr.ExprParameter +import org.partiql.ast.v1.expr.ExprPath +import org.partiql.ast.v1.expr.ExprPosition +import org.partiql.ast.v1.expr.ExprQuerySet +import org.partiql.ast.v1.expr.ExprRowValue +import org.partiql.ast.v1.expr.ExprSessionAttribute +import org.partiql.ast.v1.expr.ExprStruct +import org.partiql.ast.v1.expr.ExprSubstring +import org.partiql.ast.v1.expr.ExprTrim +import org.partiql.ast.v1.expr.ExprValues +import org.partiql.ast.v1.expr.ExprVarRef +import org.partiql.ast.v1.expr.ExprVariant +import org.partiql.ast.v1.expr.PathStep +import org.partiql.ast.v1.expr.Scope +import org.partiql.value.MissingValue +import org.partiql.value.NullValue +import org.partiql.value.PartiQLValueExperimental +import org.partiql.value.StringValue +import org.partiql.value.io.PartiQLValueTextWriter +import org.partiql.value.symbolValue +import java.io.ByteArrayOutputStream +import java.io.PrintStream + +/** + * SqlDialect represents the base behavior for transforming an [AstNode] tree into a [SqlBlock] tree. + */ +@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") +public abstract class SqlDialect : AstVisitor() { + + public companion object { + + @JvmStatic + public val STANDARD: SqlDialect = object : SqlDialect() {} + } + + /** + * Default entry-point, can also be us. + */ + public fun transform(node: AstNode): SqlBlock { + val head = SqlBlock.none() + node.accept(this, head) + return head + } + + override fun defaultReturn(node: AstNode, tail: SqlBlock): SqlBlock = + throw UnsupportedOperationException("Cannot print $node") + + // STATEMENTS + + override fun visitQuery(node: Query, tail: SqlBlock): SqlBlock = visitExpr(node.expr, tail) + + // IDENTIFIERS & PATHS + + /** + * Default behavior is to wrap all SFW queries with parentheses. + * + * @param node + * @param tail + */ + public open fun visitExprWrapped(node: Expr, tail: SqlBlock): SqlBlock = when (node) { + is ExprQuerySet -> { + var t = tail + t = t concat "(" + t = visit(node, t) + t = t concat ")" + t + } + else -> visitExpr(node, tail) + } + + override fun visitIdentifier(node: Identifier, tail: SqlBlock): SqlBlock = tail concat node.sql() + + override fun visitIdentifierChain(node: IdentifierChain, tail: SqlBlock): SqlBlock { + var path = node.root.sql() + if (node.next != null) { + path += ".${node.next.sql()}" + } + return tail concat path + } + + override fun visitExclude(node: Exclude, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat " EXCLUDE " + t = t concat list(start = null, end = null) { node.excludePaths } + return t + } + + override fun visitExcludePath(node: ExcludePath, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprVarRef(node.root, t) + t = t concat list(delimiter = null, start = null, end = null) { node.excludeSteps } + return t + } + + override fun visitExcludeStepCollIndex(node: ExcludeStep.CollIndex, tail: SqlBlock): SqlBlock { + return tail concat "[${node.index}]" + } + + override fun visitExcludeStepStructWildcard(node: ExcludeStep.StructWildcard, tail: SqlBlock): SqlBlock { + return tail concat ".*" + } + + override fun visitExcludeStepStructField(node: ExcludeStep.StructField, tail: SqlBlock): SqlBlock { + var t = tail concat "." + t = visitIdentifier(node.symbol, t) + return t + } + + override fun visitExcludeStepCollWildcard(node: ExcludeStep.CollWildcard, tail: SqlBlock): SqlBlock { + return tail concat "[*]" + } + + // TYPES + override fun visitDataType(node: DataType, tail: SqlBlock): SqlBlock { + return when (node.code()) { + // + DataType.NULL, DataType.MISSING -> tail concat node.name() + // + // no params + DataType.STRING, DataType.SYMBOL -> tail concat node.name() + // with params + DataType.CHARACTER, DataType.CHAR, DataType.VARCHAR, DataType.CLOB -> tail concat type(node.name(), node.length) + DataType.CHARACTER_VARYING -> tail concat type("CHARACTER VARYING", node.length) + DataType.CHAR_VARYING -> tail concat type("CHAR VARYING", node.length) + DataType.CHARACTER_LARGE_OBJECT -> tail concat type("CHARACTER LARGE OBJECT", node.length) + DataType.CHAR_LARGE_OBJECT -> tail concat type("CHAR LARGE OBJECT", node.length) + // + DataType.BLOB -> tail concat type(node.name(), node.length) + DataType.BINARY_LARGE_OBJECT -> tail concat type("BINARY LARGE OBJECT", node.length) + // + DataType.BIT -> tail concat type(node.name(), node.length) + DataType.BIT_VARYING -> tail concat type("BIT VARYING", node.length) + // - + // no params + DataType.BIGINT, DataType.INT8, DataType.INTEGER8, DataType.INT4, DataType.INTEGER4, DataType.INTEGER, + DataType.INT, DataType.INT2, DataType.INTEGER2, DataType.SMALLINT, DataType.TINYINT -> tail concat node.name() + // with params + DataType.NUMERIC, DataType.DECIMAL, DataType.DEC -> tail concat type(node.name(), node.precision, node.scale) + // - + DataType.FLOAT, DataType.REAL -> tail concat node.name() + DataType.DOUBLE_PRECISION -> tail concat "DOUBLE PRECISION" + // + DataType.BOOLEAN, DataType.BOOL -> tail concat node.name() + // + // no params + DataType.DATE -> tail concat node.name() + // with params + DataType.TIME, DataType.TIMESTAMP -> tail concat type(node.name(), node.precision) + DataType.TIME_WITH_TIME_ZONE -> tail concat type("TIME WITH TIMEZONE", node.precision, gap = true) + DataType.TIMESTAMP_WITH_TIME_ZONE -> tail concat type("TIMESTAMP WITH TIMEZONE", node.precision, gap = true) + // + DataType.INTERVAL -> tail concat type("INTERVAL", node.precision) + // + DataType.STRUCT, DataType.TUPLE -> tail concat node.name() + // + DataType.LIST, DataType.BAG, DataType.SEXP -> tail concat node.name() + // + DataType.USER_DEFINED -> visitIdentifierChain(node.name, tail) + else -> defaultReturn(node, tail) + } + } + + // Expressions + + @OptIn(PartiQLValueExperimental::class) + override fun visitExprLit(node: ExprLit, tail: SqlBlock): SqlBlock { + // Simplified PartiQL Value writing, as this intentionally omits formatting + val value = when (node.value) { + is MissingValue -> "MISSING" // force uppercase + is NullValue -> "NULL" // force uppercase + else -> { + val buffer = ByteArrayOutputStream() + val valueWriter = PartiQLValueTextWriter(PrintStream(buffer), false) + valueWriter.append(node.value) + buffer.toString() + } + } + return tail concat value + } + + override fun visitExprVariant(node: ExprVariant, tail: SqlBlock): SqlBlock { + if (node.encoding != "ion") { + error("Unsupported encoding ${node.encoding}") + } + val value = node.value + return tail concat "`$value`" + } + + override fun visitExprOperator(node: ExprOperator, tail: SqlBlock): SqlBlock { + val lhs = node.lhs + return if (lhs != null) { + var t = tail + t = visitExprWrapped(node.lhs, t) + t = t concat " ${node.symbol} " + t = visitExprWrapped(node.rhs, t) + t + } else { + var t = tail + t = t concat node.symbol + "(" + t = visitExprWrapped(node.rhs, t) + t = t concat ")" + return t + } + } + + override fun visitExprAnd(node: ExprAnd, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.lhs, t) + t = t concat " AND " + t = visitExprWrapped(node.rhs, t) + return t + } + + override fun visitExprOr(node: ExprOr, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.lhs, t) + t = t concat " OR " + t = visitExprWrapped(node.rhs, t) + return t + } + + override fun visitExprNot(node: ExprNot, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat "NOT (" + t = visitExprWrapped(node.value, t) + t = t concat ")" + return t + } + + override fun visitExprVarRef(node: ExprVarRef, tail: SqlBlock): SqlBlock { + var t = tail + // Prepend @ + if (node.scope.code() == Scope.LOCAL) { + t = t concat "@" + } + t = visitIdentifierChain(node.identifierChain, t) + return t + } + + override fun visitExprSessionAttribute(node: ExprSessionAttribute, tail: SqlBlock): SqlBlock = + tail concat node.sessionAttribute.name() + + override fun visitExprPath(node: ExprPath, tail: SqlBlock): SqlBlock { + var t = visitExprWrapped(node.root, tail) + var cur = node.next + while (cur != null) { + t = visitPathStep(cur, t) + cur = cur.next + } + return t + } + + override fun visitPathStepField(node: PathStep.Field, tail: SqlBlock): SqlBlock = + tail concat ".${node.field.sql()}" + + override fun visitPathStepElement(node: PathStep.Element, tail: SqlBlock): SqlBlock { + var t = tail + val key = node.element + // use [ ] syntax + t = t concat "[" + t = visitExprWrapped(key, t) + t = t concat "]" + return t + } + + override fun visitPathStepAllElements(node: PathStep.AllElements, tail: SqlBlock): SqlBlock = tail concat "[*]" + + override fun visitPathStepAllFields(node: PathStep.AllFields, tail: SqlBlock): SqlBlock = tail concat ".*" + + @OptIn(PartiQLValueExperimental::class) + override fun visitExprCall(node: ExprCall, tail: SqlBlock): SqlBlock { + var t = tail + val f = node.function + // Special case -- COUNT() maps to COUNT(*) + if (f.next == null && f.root.symbol.uppercase() == "COUNT" && node.args.isEmpty()) { + return t concat "COUNT(*)" + } + // Special case -- DATE_ADD('', , ) -> DATE_ADD(, , ) + // Special case -- DATE_DIFF('', , ) -> DATE_DIFF(, , ) + // TODO this will need to be rewritten once PartiQLValue is removed from AST + if (f.next == null && + (f.root.symbol.uppercase() == "DATE_ADD" || f.root.symbol.uppercase() == "DATE_DIFF") && + node.args.size == 3 + ) { + val dtField = ((node.args[0] as ExprLit).value as StringValue).value!! + val newArgs = listOf(exprLit(symbolValue(dtField))) + node.args.drop(1) + t = visitIdentifierChain(f, t) + t = t concat list { newArgs } + return t + } + val start = if (node.setq != null) "(${node.setq.name()} " else "(" + t = visitIdentifierChain(f, t) + t = t concat list(start) { node.args } + return t + } + + override fun visitExprParameter(node: ExprParameter, tail: SqlBlock): SqlBlock = tail concat "?" + + override fun visitExprValues(node: ExprValues, tail: SqlBlock): SqlBlock = + tail concat list(start = "VALUES ", end = "") { node.rows } + + override fun visitExprRowValue(node: ExprRowValue, tail: SqlBlock): SqlBlock = tail concat list { node.values } + + override fun visitExprBag(node: ExprBag, tail: SqlBlock): SqlBlock { + return tail concat list("<<", ">>") { node.values } + } + + override fun visitExprArray(node: ExprArray, tail: SqlBlock): SqlBlock { + return tail concat list("[", "]") { node.values } + } + + override fun visitExprStruct(node: ExprStruct, tail: SqlBlock): SqlBlock = + tail concat list("{", "}") { node.fields } + + override fun visitExprStructField(node: ExprStruct.Field, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.name, t) + t = t concat ": " + t = visitExprWrapped(node.value, t) + return t + } + + override fun visitExprLike(node: ExprLike, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.value, t) + t = t concat if (node.not) " NOT LIKE " else " LIKE " + t = visitExprWrapped(node.pattern, t) + if (node.escape != null) { + t = t concat " ESCAPE " + t = visitExprWrapped(node.escape, t) + } + return t + } + + override fun visitExprBetween(node: ExprBetween, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.value, t) + t = t concat if (node.not) " NOT BETWEEN " else " BETWEEN " + t = visitExprWrapped(node.from, t) + t = t concat " AND " + t = visitExprWrapped(node.to, t) + return t + } + + override fun visitExprInCollection(node: ExprInCollection, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.lhs, t) + t = t concat if (node.not) " NOT IN " else " IN " + t = visitExprWrapped(node.rhs, t) + return t + } + + override fun visitExprIsType(node: ExprIsType, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.value, t) + t = t concat if (node.not) " IS NOT " else " IS " + t = visitDataType(node.type, t) + return t + } + + override fun visitExprCase(node: ExprCase, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat "CASE" + t = when (node.expr) { + null -> t + else -> visitExprWrapped(node.expr, t concat " ") + } + // WHEN(s) + t = node.branches.fold(t) { acc, branch -> visitExprCaseBranch(branch, acc) } + // ELSE + t = when (node.defaultExpr) { + null -> t + else -> { + t = t concat " ELSE " + visitExprWrapped(node.defaultExpr, t) + } + } + t = t concat " END" + return t + } + + override fun visitExprCaseBranch(node: ExprCase.Branch, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat " WHEN " + t = visitExprWrapped(node.condition, t) + t = t concat " THEN " + t = visitExprWrapped(node.expr, t) + return t + } + + override fun visitExprCoalesce(node: ExprCoalesce, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat "COALESCE" + t = t concat list { node.args } + return t + } + + override fun visitExprNullIf(node: ExprNullIf, tail: SqlBlock): SqlBlock { + val args = listOf(node.v1, node.v2) + var t = tail + t = t concat "NULLIF" + t = t concat list { args } + return t + } + + override fun visitExprSubstring(node: ExprSubstring, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat "SUBSTRING(" + t = visitExprWrapped(node.value, t) + if (node.start != null) { + t = t concat " FROM " + t = visitExprWrapped(node.start, t) + } + if (node.length != null) { + t = t concat " FOR " + t = visitExprWrapped(node.length, t) + } + t = t concat ")" + return t + } + + override fun visitExprPosition(node: ExprPosition, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat "POSITION(" + t = visitExprWrapped(node.lhs, t) + t = t concat " IN " + t = visitExprWrapped(node.rhs, t) + t = t concat ")" + return t + } + + override fun visitExprTrim(node: ExprTrim, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat "TRIM(" + // [LEADING|TRAILING|BOTH] + if (node.trimSpec != null) { + t = t concat "${node.trimSpec.name()} " + } + // [ FROM] + if (node.chars != null) { + t = visitExprWrapped(node.chars, t) + t = t concat " FROM " + } + t = visitExprWrapped(node.value, t) + t = t concat ")" + return t + } + + override fun visitExprOverlay(node: ExprOverlay, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat "OVERLAY(" + t = visitExprWrapped(node.value, t) + t = t concat " PLACING " + t = visitExprWrapped(node.placing, t) + t = t concat " FROM " + t = visitExprWrapped(node.from, t) + if (node.forLength != null) { + t = t concat " FOR " + t = visitExprWrapped(node.forLength, t) + } + t = t concat ")" + return t + } + + override fun visitExprExtract(node: ExprExtract, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat "EXTRACT(" + t = t concat node.field.name() + t = t concat " FROM " + t = visitExprWrapped(node.source, t) + t = t concat ")" + return t + } + + override fun visitExprCast(node: ExprCast, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat "CAST(" + t = visitExprWrapped(node.value, t) + t = t concat " AS " + t = visitDataType(node.asType, t) + t = t concat ")" + return t + } + + override fun visitExprQuerySet(node: ExprQuerySet, tail: SqlBlock): SqlBlock { + var t = tail + // visit body (SFW or other SQL set op) + t = visit(node.body, t) + // ORDER BY + t = if (node.orderBy != null) visitOrderBy(node.orderBy, t concat " ") else t + // LIMIT + t = if (node.limit != null) visitExprWrapped(node.limit, t concat " LIMIT ") else t + // OFFSET + t = if (node.offset != null) visitExprWrapped(node.offset, t concat " OFFSET ") else t + return t + } + + // SELECT-FROM-WHERE + + override fun visitQueryBodySFW(node: QueryBody.SFW, tail: SqlBlock): SqlBlock { + var t = tail + // SELECT + t = visit(node.select, t) + // EXCLUDE + t = node.exclude?.let { visit(it, t) } ?: t + // FROM + t = visitFrom(node.from, t concat " FROM ") + // LET + t = if (node.let != null) visitLet(node.let, t concat " ") else t + // WHERE + t = if (node.where != null) visitExprWrapped(node.where, t concat " WHERE ") else t + // GROUP BY + t = if (node.groupBy != null) visitGroupBy(node.groupBy, t concat " ") else t + // HAVING + t = if (node.having != null) visitExprWrapped(node.having, t concat " HAVING ") else t + return t + } + + override fun visitQueryBodySetOp(node: QueryBody.SetOp, tail: SqlBlock): SqlBlock { + val op = mutableListOf() + when (node.isOuter) { + true -> op.add("OUTER") + else -> {} + } + when (node.type.setOpType.code()) { + SetOpType.UNION -> op.add("UNION") + SetOpType.INTERSECT -> op.add("INTERSECT") + SetOpType.EXCEPT -> op.add("EXCEPT") + else -> defaultReturn(node, tail) + } + when (node.type.setq?.code()) { + SetQuantifier.ALL -> op.add("ALL") + SetQuantifier.DISTINCT -> op.add("DISTINCT") + null -> {} + else -> defaultReturn(node, tail) + } + var t = tail + t = visitExprWrapped(node.lhs, t) + t = t concat " ${op.joinToString(" ")} " + t = visitExprWrapped(node.rhs, t) + return t + } + + // SELECT + + override fun visitSelectStar(node: SelectStar, tail: SqlBlock): SqlBlock { + val select = when (node.setq?.code()) { + SetQuantifier.ALL -> "SELECT ALL *" + SetQuantifier.DISTINCT -> "SELECT DISTINCT *" + null -> "SELECT *" + else -> throw UnsupportedOperationException("Cannot print $node") + } + return tail concat select + } + + override fun visitSelectList(node: SelectList, tail: SqlBlock): SqlBlock { + val select = when (node.setq?.code()) { + SetQuantifier.ALL -> "SELECT ALL " + SetQuantifier.DISTINCT -> "SELECT DISTINCT " + null -> "SELECT " + else -> throw UnsupportedOperationException("Cannot print $node") + } + return tail concat list(select, "") { node.items } + } + + override fun visitSelectItemStar(node: SelectItem.Star, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.expr, t) + t = t concat ".*" + return t + } + + override fun visitSelectItemExpr(node: SelectItem.Expr, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.expr, t) + t = if (node.asAlias != null) t concat " AS ${node.asAlias.sql()}" else t + return t + } + + override fun visitSelectPivot(node: SelectPivot, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat "PIVOT " + t = visitExprWrapped(node.key, t) + t = t concat " AT " + t = visitExprWrapped(node.value, t) + return t + } + + override fun visitSelectValue(node: SelectValue, tail: SqlBlock): SqlBlock { + val select = when (node.setq?.code()) { + SetQuantifier.ALL -> "SELECT ALL VALUE " + SetQuantifier.DISTINCT -> "SELECT DISTINCT VALUE " + null -> "SELECT VALUE " + else -> throw UnsupportedOperationException("Cannot print $node") + } + var t = tail + t = t concat select + t = visitExprWrapped(node.constructor, t) + return t + } + + // FROM + override fun visitFrom(node: From, tail: SqlBlock): SqlBlock { + return tail concat list("", "") { node.tableRefs } + } + + override fun visitFromExpr(node: FromExpr, tail: SqlBlock): SqlBlock { + var t = tail + t = when (node.fromType.code()) { + FromType.SCAN -> t + FromType.UNPIVOT -> t concat "UNPIVOT " + else -> defaultReturn(node, tail) + } + t = visitExprWrapped(node.expr, t) + t = if (node.asAlias != null) t concat " AS ${node.asAlias.sql()}" else t + t = if (node.atAlias != null) t concat " AT ${node.atAlias.sql()}" else t + return t + } + + override fun visitFromJoin(node: FromJoin, tail: SqlBlock): SqlBlock { + var t = tail + t = visitFromTableRef(node.lhs, t) + t = t concat when (node.joinType?.code()) { + JoinType.INNER -> " INNER JOIN " + JoinType.LEFT -> " LEFT JOIN " + JoinType.LEFT_OUTER -> " LEFT OUTER JOIN " + JoinType.RIGHT -> " RIGHT JOIN " + JoinType.RIGHT_OUTER -> " RIGHT OUTER JOIN " + JoinType.FULL -> " FULL JOIN " + JoinType.FULL_OUTER -> " FULL OUTER JOIN " + JoinType.CROSS -> " CROSS JOIN " + JoinType.LEFT_CROSS -> " LEFT CROSS JOIN " + null -> " JOIN " + else -> throw UnsupportedOperationException("Cannot print $node") + } + t = visitFromTableRef(node.rhs, t) + t = if (node.condition != null) visit(node.condition, t concat " ON ") else t + return t + } + + // LET + + override fun visitLet(node: Let, tail: SqlBlock): SqlBlock = tail concat list("LET ", "") { node.bindings } + + override fun visitLetBinding(node: Let.Binding, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.expr, t) + t = t concat " AS ${node.asAlias.sql()}" + return t + } + + // GROUP BY + + override fun visitGroupBy(node: GroupBy, tail: SqlBlock): SqlBlock { + var t = tail + t = t concat when (node.strategy.code()) { + GroupByStrategy.FULL -> "GROUP BY " + GroupByStrategy.PARTIAL -> "GROUP PARTIAL BY " + else -> throw UnsupportedOperationException("Cannot print $node") + } + t = t concat list("", "") { node.keys } + t = if (node.asAlias != null) t concat " GROUP AS ${node.asAlias.sql()}" else t + return t + } + + override fun visitGroupByKey(node: GroupBy.Key, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.expr, t) + t = if (node.asAlias != null) t concat " AS ${node.asAlias.sql()}" else t + return t + } + + // SET OPERATORS + + override fun visitSetOp(node: SetOp, tail: SqlBlock): SqlBlock { + val op = when (node.setq) { + null -> node.setOpType.name() + else -> "${node.setOpType.name()} ${node.setq.name()}" + } + return tail concat op + } + + // ORDER BY + + override fun visitOrderBy(node: OrderBy, tail: SqlBlock): SqlBlock = + tail concat list("ORDER BY ", "") { node.sorts } + + override fun visitSort(node: Sort, tail: SqlBlock): SqlBlock { + var t = tail + t = visitExprWrapped(node.expr, t) + t = when (node.order?.code()) { + Order.ASC -> t concat " ASC" + Order.DESC -> t concat " DESC" + null -> t + else -> throw UnsupportedOperationException("Cannot print $node") + } + t = when (node.nulls?.code()) { + Nulls.FIRST -> t concat " NULLS FIRST" + Nulls.LAST -> t concat " NULLS LAST" + null -> t + else -> throw UnsupportedOperationException("Cannot print $node") + } + return t + } + + // --- Block Constructor Helpers + + private infix fun SqlBlock.concat(rhs: String): SqlBlock { + next = SqlBlock.Text(rhs) + return next!! + } + + private infix fun SqlBlock.concat(rhs: SqlBlock): SqlBlock { + next = rhs + return next!! + } + + private fun type(symbol: String, vararg args: Int?, gap: Boolean = false): SqlBlock { + val p = args.filterNotNull() + val t = when { + p.isEmpty() -> symbol + else -> { + val a = p.joinToString(",") + when (gap) { + true -> "$symbol ($a)" + else -> "$symbol($a)" + } + } + } + // types are modeled as text; as we don't way to reflow + return SqlBlock.Text(t) + } + + private fun list( + start: String? = "(", + end: String? = ")", + delimiter: String? = ", ", + children: () -> List, + ): SqlBlock { + val kids = children() + val h = SqlBlock.none() + var t = h + kids.forEachIndexed { i, child -> + t = child.accept(this, t) + t = if (delimiter != null && (i + 1) < kids.size) t concat delimiter else t + } + return SqlBlock.Nest( + prefix = start, + postfix = end, + child = h, + ) + } + + private fun Identifier.sql() = when (isDelimited) { + true -> "\"$symbol\"" + false -> symbol // verbatim .. + } +} diff --git a/partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlLayout.kt b/partiql-ast/src/main/java/org/partiql/ast/v1/sql/SqlLayout.kt similarity index 98% rename from partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlLayout.kt rename to partiql-ast/src/main/java/org/partiql/ast/v1/sql/SqlLayout.kt index f65f79a24e..c1c1fb551a 100644 --- a/partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlLayout.kt +++ b/partiql-ast/src/main/java/org/partiql/ast/v1/sql/SqlLayout.kt @@ -12,7 +12,7 @@ * language governing permissions and limitations under the License. */ -package org.partiql.ast.sql +package org.partiql.ast.v1.sql /** * [SqlLayout] determines how an [SqlBlock] tree is transformed in SQL text. diff --git a/partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlDialect.kt b/partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlDialect.kt deleted file mode 100644 index daac73c3c6..0000000000 --- a/partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlDialect.kt +++ /dev/null @@ -1,824 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at: - * - * http://aws.amazon.com/apache2.0/ - * - * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific - * language governing permissions and limitations under the License. - */ - -package org.partiql.ast.sql - -import org.partiql.ast.AstNode -import org.partiql.ast.Exclude -import org.partiql.ast.Expr -import org.partiql.ast.From -import org.partiql.ast.GroupBy -import org.partiql.ast.Identifier -import org.partiql.ast.Let -import org.partiql.ast.OrderBy -import org.partiql.ast.Path -import org.partiql.ast.QueryBody -import org.partiql.ast.Select -import org.partiql.ast.SetOp -import org.partiql.ast.SetQuantifier -import org.partiql.ast.Sort -import org.partiql.ast.Statement -import org.partiql.ast.Type -import org.partiql.ast.visitor.AstBaseVisitor -import org.partiql.value.MissingValue -import org.partiql.value.NullValue -import org.partiql.value.PartiQLValueExperimental -import org.partiql.value.io.PartiQLValueTextWriter -import java.io.ByteArrayOutputStream -import java.io.PrintStream - -/** - * SqlDialect represents the base behavior for transforming an [AstNode] tree into a [SqlBlock] tree. - */ -@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") -public abstract class SqlDialect : AstBaseVisitor() { - - public companion object { - - @JvmStatic - public val STANDARD: SqlDialect = object : SqlDialect() {} - } - - /** - * Default entry-point, can also be us. - */ - public fun transform(node: AstNode): SqlBlock { - val head = SqlBlock.none() - val tail = head - node.accept(this, tail) - return head - } - - override fun defaultReturn(node: AstNode, tail: SqlBlock): SqlBlock = - throw UnsupportedOperationException("Cannot print $node") - - // STATEMENTS - - override fun visitStatementQuery(node: Statement.Query, tail: SqlBlock): SqlBlock = visitExpr(node.expr, tail) - - // IDENTIFIERS & PATHS - - /** - * Default behavior is to wrap all SFW queries with parentheses. - * - * @param node - * @param tail - */ - public open fun visitExprWrapped(node: Expr, tail: SqlBlock): SqlBlock = when (node) { - is Expr.QuerySet -> { - var t = tail - t = t concat "(" - t = visit(node, t) - t = t concat ")" - t - } - else -> visitExpr(node, tail) - } - - override fun visitIdentifierSymbol(node: Identifier.Symbol, tail: SqlBlock): SqlBlock = tail concat node.sql() - - override fun visitIdentifierQualified(node: Identifier.Qualified, tail: SqlBlock): SqlBlock { - val path = node.steps.fold(node.root.sql()) { p, step -> p + "." + step.sql() } - return tail concat path - } - - override fun visitPath(node: Path, tail: SqlBlock): SqlBlock { - val path = node.steps.fold(node.root.sql()) { p, step -> - when (step) { - is Path.Step.Index -> p + "[${step.index}]" - is Path.Step.Symbol -> p + "." + step.symbol.sql() - } - } - return tail concat path - } - - override fun visitExclude(node: Exclude, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat " EXCLUDE " - t = t concat list(start = null, end = null) { node.items } - return t - } - - override fun visitExcludeItem(node: Exclude.Item, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprVar(node.root, t) - t = t concat list(delimiter = null, start = null, end = null) { node.steps } - return t - } - - override fun visitExcludeStepCollIndex(node: Exclude.Step.CollIndex, tail: SqlBlock): SqlBlock { - return tail concat "[${node.index}]" - } - - override fun visitExcludeStepStructWildcard(node: Exclude.Step.StructWildcard, tail: SqlBlock): SqlBlock { - return tail concat ".*" - } - - override fun visitExcludeStepStructField(node: Exclude.Step.StructField, tail: SqlBlock): SqlBlock { - var t = tail concat "." - t = visitIdentifierSymbol(node.symbol, t) - return t - } - - override fun visitExcludeStepCollWildcard(node: Exclude.Step.CollWildcard, tail: SqlBlock): SqlBlock { - return tail concat "[*]" - } - - // cannot write path step outside the context of a path as we don't want it to reflow - override fun visitPathStep(node: Path.Step, tail: SqlBlock): SqlBlock = - error("path step cannot be written directly") - - override fun visitPathStepSymbol(node: Path.Step.Symbol, tail: SqlBlock): SqlBlock = visitPathStep(node, tail) - - override fun visitPathStepIndex(node: Path.Step.Index, tail: SqlBlock): SqlBlock = visitPathStep(node, tail) - - // TYPES - - override fun visitTypeNullType(node: Type.NullType, tail: SqlBlock): SqlBlock = tail concat "NULL" - - override fun visitTypeMissing(node: Type.Missing, tail: SqlBlock): SqlBlock = tail concat "MISSING" - - override fun visitTypeBool(node: Type.Bool, tail: SqlBlock): SqlBlock = tail concat "BOOL" - - override fun visitTypeTinyint(node: Type.Tinyint, tail: SqlBlock): SqlBlock = tail concat "TINYINT" - - override fun visitTypeSmallint(node: Type.Smallint, tail: SqlBlock): SqlBlock = tail concat "SMALLINT" - - override fun visitTypeInt2(node: Type.Int2, tail: SqlBlock): SqlBlock = tail concat "INT2" - - override fun visitTypeInt4(node: Type.Int4, tail: SqlBlock): SqlBlock = tail concat "INT4" - - override fun visitTypeBigint(node: Type.Bigint, tail: SqlBlock): SqlBlock = tail concat "BIGINT" - - override fun visitTypeInt8(node: Type.Int8, tail: SqlBlock): SqlBlock = tail concat "INT8" - - override fun visitTypeInt(node: Type.Int, tail: SqlBlock): SqlBlock = tail concat "INT" - - override fun visitTypeReal(node: Type.Real, tail: SqlBlock): SqlBlock = tail concat "REAL" - - override fun visitTypeFloat32(node: Type.Float32, tail: SqlBlock): SqlBlock = tail concat "FLOAT32" - - override fun visitTypeFloat64(node: Type.Float64, tail: SqlBlock): SqlBlock = tail concat "DOUBLE PRECISION" - - override fun visitTypeDecimal(node: Type.Decimal, tail: SqlBlock): SqlBlock = - tail concat type("DECIMAL", node.precision, node.scale) - - override fun visitTypeNumeric(node: Type.Numeric, tail: SqlBlock): SqlBlock = - tail concat type("NUMERIC", node.precision, node.scale) - - override fun visitTypeChar(node: Type.Char, tail: SqlBlock): SqlBlock = tail concat type("CHAR", node.length) - - override fun visitTypeVarchar(node: Type.Varchar, tail: SqlBlock): SqlBlock = - tail concat type("VARCHAR", node.length) - - override fun visitTypeString(node: Type.String, tail: SqlBlock): SqlBlock = tail concat "STRING" - - override fun visitTypeSymbol(node: Type.Symbol, tail: SqlBlock): SqlBlock = tail concat "SYMBOL" - - override fun visitTypeBit(node: Type.Bit, tail: SqlBlock): SqlBlock = tail concat type("BIT", node.length) - - override fun visitTypeBitVarying(node: Type.BitVarying, tail: SqlBlock): SqlBlock = - tail concat type("BINARY", node.length) - - override fun visitTypeByteString(node: Type.ByteString, tail: SqlBlock): SqlBlock = - tail concat type("BYTE", node.length) - - override fun visitTypeBlob(node: Type.Blob, tail: SqlBlock): SqlBlock = tail concat type("BLOB", node.length) - - override fun visitTypeClob(node: Type.Clob, tail: SqlBlock): SqlBlock = tail concat type("CLOB", node.length) - - override fun visitTypeBag(node: Type.Bag, tail: SqlBlock): SqlBlock = tail concat "BAG" - - override fun visitTypeList(node: Type.List, tail: SqlBlock): SqlBlock = tail concat "LIST" - - override fun visitTypeSexp(node: Type.Sexp, tail: SqlBlock): SqlBlock = tail concat "SEXP" - - override fun visitTypeTuple(node: Type.Tuple, tail: SqlBlock): SqlBlock = tail concat "TUPLE" - - override fun visitTypeStruct(node: Type.Struct, tail: SqlBlock): SqlBlock = tail concat "STRUCT" - - override fun visitTypeAny(node: Type.Any, tail: SqlBlock): SqlBlock = tail concat "ANY" - - override fun visitTypeDate(node: Type.Date, tail: SqlBlock): SqlBlock = tail concat "DATE" - - override fun visitTypeTime(node: Type.Time, tail: SqlBlock): SqlBlock = tail concat type("TIME", node.precision) - - override fun visitTypeTimeWithTz(node: Type.TimeWithTz, tail: SqlBlock): SqlBlock = - tail concat type("TIME WITH TIMEZONE", node.precision, gap = true) - - override fun visitTypeTimestamp(node: Type.Timestamp, tail: SqlBlock): SqlBlock = - tail concat type("TIMESTAMP", node.precision) - - override fun visitTypeTimestampWithTz(node: Type.TimestampWithTz, tail: SqlBlock): SqlBlock = - tail concat type("TIMESTAMP WITH TIMEZONE", node.precision, gap = true) - - override fun visitTypeInterval(node: Type.Interval, tail: SqlBlock): SqlBlock = - tail concat type("INTERVAL", node.precision) - - // unsupported - override fun visitTypeCustom(node: Type.Custom, tail: SqlBlock): SqlBlock = defaultReturn(node, tail) - - // Expressions - - @OptIn(PartiQLValueExperimental::class) - override fun visitExprLit(node: Expr.Lit, tail: SqlBlock): SqlBlock { - // Simplified PartiQL Value writing, as this intentionally omits formatting - val value = when (node.value) { - is MissingValue -> "MISSING" // force uppercase - is NullValue -> "NULL" // force uppercase - else -> { - val buffer = ByteArrayOutputStream() - val valueWriter = PartiQLValueTextWriter(PrintStream(buffer), false) - valueWriter.append(node.value) - buffer.toString() - } - } - return tail concat value - } - - override fun visitExprVariant(node: Expr.Variant, tail: SqlBlock): SqlBlock { - if (node.encoding != "ion") { - error("Unsupported encoding ${node.encoding}") - } - val value = node.value - return tail concat "`$value`" - } - - override fun visitExprOperator(node: Expr.Operator, tail: SqlBlock): SqlBlock { - val lhs = node.lhs - return if (lhs != null) { - var t = tail - t = visitExprWrapped(node.lhs, t) - t = t concat " ${node.symbol} " - t = visitExprWrapped(node.rhs, t) - t - } else { - var t = tail - t = t concat node.symbol + "(" - t = visitExprWrapped(node.rhs, t) - t = t concat ")" - return t - } - } - - override fun visitExprAnd(node: Expr.And, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.lhs, t) - t = t concat " AND " - t = visitExprWrapped(node.rhs, t) - return t - } - - override fun visitExprOr(node: Expr.Or, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.lhs, t) - t = t concat " OR " - t = visitExprWrapped(node.rhs, t) - return t - } - - override fun visitExprNot(node: Expr.Not, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "NOT (" - t = visitExprWrapped(node.value, t) - t = t concat ")" - return t - } - - override fun visitExprVar(node: Expr.Var, tail: SqlBlock): SqlBlock { - var t = tail - // Prepend @ - if (node.scope == Expr.Var.Scope.LOCAL) { - t = t concat "@" - } - t = visitIdentifier(node.identifier, t) - return t - } - - override fun visitExprSessionAttribute(node: Expr.SessionAttribute, tail: SqlBlock): SqlBlock = - tail concat node.attribute.name - - override fun visitExprPath(node: Expr.Path, tail: SqlBlock): SqlBlock { - var t = visitExprWrapped(node.root, tail) - t = node.steps.fold(t) { b, step -> visitExprPathStep(step, b) } - return t - } - - override fun visitExprPathStepSymbol(node: Expr.Path.Step.Symbol, tail: SqlBlock): SqlBlock = - tail concat ".${node.symbol.sql()}" - - override fun visitExprPathStepIndex(node: Expr.Path.Step.Index, tail: SqlBlock): SqlBlock { - var t = tail - val key = node.key - // use [ ] syntax - t = t concat "[" - t = visitExprWrapped(key, t) - t = t concat "]" - return t - } - - override fun visitExprPathStepWildcard(node: Expr.Path.Step.Wildcard, tail: SqlBlock): SqlBlock = tail concat "[*]" - - override fun visitExprPathStepUnpivot(node: Expr.Path.Step.Unpivot, tail: SqlBlock): SqlBlock = tail concat ".*" - - override fun visitExprCall(node: Expr.Call, tail: SqlBlock): SqlBlock { - var t = tail - val f = node.function - // Special case -- COUNT() maps to COUNT(*) - if (f is Identifier.Symbol && f.symbol == "COUNT" && node.args.isEmpty()) { - return t concat "COUNT(*)" - } - val start = if (node.setq != null) "(${node.setq.name} " else "(" - t = visitIdentifier(f, t) - t = t concat list(start) { node.args } - return t - } - - override fun visitExprParameter(node: Expr.Parameter, tail: SqlBlock): SqlBlock = tail concat "?" - - override fun visitExprValues(node: Expr.Values, tail: SqlBlock): SqlBlock = - tail concat list("VALUES (") { node.rows } - - override fun visitExprValuesRow(node: Expr.Values.Row, tail: SqlBlock): SqlBlock = tail concat list { node.items } - - override fun visitExprCollection(node: Expr.Collection, tail: SqlBlock): SqlBlock { - val (start, end) = when (node.type) { - Expr.Collection.Type.BAG -> "<<" to ">>" - Expr.Collection.Type.ARRAY -> "[" to "]" - Expr.Collection.Type.VALUES -> "VALUES (" to ")" - Expr.Collection.Type.LIST -> "(" to ")" - Expr.Collection.Type.SEXP -> "SEXP (" to ")" - } - return tail concat list(start, end) { node.values } - } - - override fun visitExprStruct(node: Expr.Struct, tail: SqlBlock): SqlBlock = - tail concat list("{", "}") { node.fields } - - override fun visitExprStructField(node: Expr.Struct.Field, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.name, t) - t = t concat ": " - t = visitExprWrapped(node.value, t) - return t - } - - override fun visitExprLike(node: Expr.Like, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.value, t) - t = t concat if (node.not == true) " NOT LIKE " else " LIKE " - t = visitExprWrapped(node.pattern, t) - if (node.escape != null) { - t = t concat " ESCAPE " - t = visitExprWrapped(node.escape!!, t) - } - return t - } - - override fun visitExprBetween(node: Expr.Between, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.value, t) - t = t concat if (node.not == true) " NOT BETWEEN " else " BETWEEN " - t = visitExprWrapped(node.from, t) - t = t concat " AND " - t = visitExprWrapped(node.to, t) - return t - } - - override fun visitExprInCollection(node: Expr.InCollection, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.lhs, t) - t = t concat if (node.not == true) " NOT IN " else " IN " - t = visitExprWrapped(node.rhs, t) - return t - } - - override fun visitExprIsType(node: Expr.IsType, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.value, t) - t = t concat if (node.not == true) " IS NOT " else " IS " - t = visitType(node.type, t) - return t - } - - override fun visitExprCase(node: Expr.Case, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "CASE" - t = when (node.expr) { - null -> t - else -> visitExprWrapped(node.expr!!, t concat " ") - } - // WHEN(s) - t = node.branches.fold(t) { acc, branch -> visitExprCaseBranch(branch, acc) } - // ELSE - t = when (node.default) { - null -> t - else -> { - t = t concat " ELSE " - visitExprWrapped(node.default!!, t) - } - } - t = t concat " END" - return t - } - - override fun visitExprCaseBranch(node: Expr.Case.Branch, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat " WHEN " - t = visitExprWrapped(node.condition, t) - t = t concat " THEN " - t = visitExprWrapped(node.expr, t) - return t - } - - override fun visitExprCoalesce(node: Expr.Coalesce, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "COALESCE" - t = t concat list { node.args } - return t - } - - override fun visitExprNullIf(node: Expr.NullIf, tail: SqlBlock): SqlBlock { - val args = listOf(node.value, node.nullifier) - var t = tail - t = t concat "NULLIF" - t = t concat list { args } - return t - } - - override fun visitExprSubstring(node: Expr.Substring, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "SUBSTRING(" - t = visitExprWrapped(node.value, t) - if (node.start != null) { - t = t concat " FROM " - t = visitExprWrapped(node.start!!, t) - } - if (node.length != null) { - t = t concat " FOR " - t = visitExprWrapped(node.length!!, t) - } - t = t concat ")" - return t - } - - override fun visitExprPosition(node: Expr.Position, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "POSITION(" - t = visitExprWrapped(node.lhs, t) - t = t concat " IN " - t = visitExprWrapped(node.rhs, t) - t = t concat ")" - return t - } - - override fun visitExprTrim(node: Expr.Trim, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "TRIM(" - // [LEADING|TRAILING|BOTH] - if (node.spec != null) { - t = t concat "${node.spec!!.name} " - } - // [ FROM] - if (node.chars != null) { - t = visitExprWrapped(node.chars!!, t) - t = t concat " FROM " - } - t = visitExprWrapped(node.value, t) - t = t concat ")" - return t - } - - override fun visitExprOverlay(node: Expr.Overlay, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "OVERLAY(" - t = visitExprWrapped(node.value, t) - t = t concat " PLACING " - t = visitExprWrapped(node.overlay, t) - t = t concat " FROM " - t = visitExprWrapped(node.start, t) - if (node.length != null) { - t = t concat " FOR " - t = visitExprWrapped(node.length!!, t) - } - t = t concat ")" - return t - } - - override fun visitExprExtract(node: Expr.Extract, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "EXTRACT(" - t = t concat node.field.name - t = t concat " FROM " - t = visitExprWrapped(node.source, t) - t = t concat ")" - return t - } - - override fun visitExprCast(node: Expr.Cast, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "CAST(" - t = visitExprWrapped(node.value, t) - t = t concat " AS " - t = visitType(node.asType, t) - t = t concat ")" - return t - } - - override fun visitExprDateAdd(node: Expr.DateAdd, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "DATE_ADD(" - t = t concat node.field.name - t = t concat ", " - t = visitExprWrapped(node.lhs, t) - t = t concat ", " - t = visitExprWrapped(node.rhs, t) - t = t concat ")" - return t - } - - override fun visitExprDateDiff(node: Expr.DateDiff, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "DATE_DIFF(" - t = t concat node.field.name - t = t concat ", " - t = visitExprWrapped(node.lhs, t) - t = t concat ", " - t = visitExprWrapped(node.rhs, t) - t = t concat ")" - return t - } - - override fun visitExprQuerySet(node: Expr.QuerySet, tail: SqlBlock): SqlBlock { - var t = tail - // visit body (SFW or other SQL set op) - t = visit(node.body, t) - // ORDER BY - t = if (node.orderBy != null) visitOrderBy(node.orderBy, t concat " ") else t - // LIMIT - t = if (node.limit != null) visitExprWrapped(node.limit, t concat " LIMIT ") else t - // OFFSET - t = if (node.offset != null) visitExprWrapped(node.offset, t concat " OFFSET ") else t - return t - } - - // SELECT-FROM-WHERE - - override fun visitQueryBodySFW(node: QueryBody.SFW, tail: SqlBlock): SqlBlock { - var t = tail - // SELECT - t = visit(node.select, t) - // EXCLUDE - t = node.exclude?.let { visit(it, t) } ?: t - // FROM - t = visit(node.from, t concat " FROM ") - // LET - t = if (node.let != null) visitLet(node.let, t concat " ") else t - // WHERE - t = if (node.where != null) visitExprWrapped(node.where, t concat " WHERE ") else t - // GROUP BY - t = if (node.groupBy != null) visitGroupBy(node.groupBy, t concat " ") else t - // HAVING - t = if (node.having != null) visitExprWrapped(node.having, t concat " HAVING ") else t - return t - } - - override fun visitQueryBodySetOp(node: QueryBody.SetOp, tail: SqlBlock): SqlBlock { - val op = mutableListOf() - when (node.isOuter) { - true -> op.add("OUTER") - else -> {} - } - when (node.type.type) { - SetOp.Type.UNION -> op.add("UNION") - SetOp.Type.INTERSECT -> op.add("INTERSECT") - SetOp.Type.EXCEPT -> op.add("EXCEPT") - } - when (node.type.setq) { - SetQuantifier.ALL -> op.add("ALL") - SetQuantifier.DISTINCT -> op.add("DISTINCT") - null -> {} - } - var t = tail - t = visitExprWrapped(node.lhs, t) - t = t concat " ${op.joinToString(" ")} " - t = visitExprWrapped(node.rhs, t) - return t - } - - // SELECT - - override fun visitSelectStar(node: Select.Star, tail: SqlBlock): SqlBlock { - val select = when (node.setq) { - SetQuantifier.ALL -> "SELECT ALL *" - SetQuantifier.DISTINCT -> "SELECT DISTINCT *" - null -> "SELECT *" - } - return tail concat select - } - - override fun visitSelectProject(node: Select.Project, tail: SqlBlock): SqlBlock { - val select = when (node.setq) { - SetQuantifier.ALL -> "SELECT ALL " - SetQuantifier.DISTINCT -> "SELECT DISTINCT " - null -> "SELECT " - } - return tail concat list(select, "") { node.items } - } - - override fun visitSelectProjectItemAll(node: Select.Project.Item.All, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.expr, t) - t = t concat ".*" - return t - } - - override fun visitSelectProjectItemExpression(node: Select.Project.Item.Expression, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.expr, t) - t = if (node.asAlias != null) t concat " AS ${node.asAlias!!.sql()}" else t - return t - } - - override fun visitSelectPivot(node: Select.Pivot, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat "PIVOT " - t = visitExprWrapped(node.key, t) - t = t concat " AT " - t = visitExprWrapped(node.value, t) - return t - } - - override fun visitSelectValue(node: Select.Value, tail: SqlBlock): SqlBlock { - val select = when (node.setq) { - SetQuantifier.ALL -> "SELECT ALL VALUE " - SetQuantifier.DISTINCT -> "SELECT DISTINCT VALUE " - null -> "SELECT VALUE " - } - var t = tail - t = t concat select - t = visitExprWrapped(node.constructor, t) - return t - } - - // FROM - - override fun visitFromValue(node: From.Value, tail: SqlBlock): SqlBlock { - var t = tail - t = when (node.type) { - From.Value.Type.SCAN -> t - From.Value.Type.UNPIVOT -> t concat "UNPIVOT " - } - t = visitExprWrapped(node.expr, t) - t = if (node.asAlias != null) t concat " AS ${node.asAlias!!.sql()}" else t - t = if (node.atAlias != null) t concat " AT ${node.atAlias!!.sql()}" else t - t = if (node.byAlias != null) t concat " BY ${node.byAlias!!.sql()}" else t - return t - } - - override fun visitFromJoin(node: From.Join, tail: SqlBlock): SqlBlock { - var t = tail - t = visitFrom(node.lhs, t) - t = t concat when (node.type) { - From.Join.Type.INNER -> " INNER JOIN " - From.Join.Type.LEFT -> " LEFT JOIN " - From.Join.Type.LEFT_OUTER -> " LEFT OUTER JOIN " - From.Join.Type.RIGHT -> " RIGHT JOIN " - From.Join.Type.RIGHT_OUTER -> " RIGHT OUTER JOIN " - From.Join.Type.FULL -> " FULL JOIN " - From.Join.Type.FULL_OUTER -> " FULL OUTER JOIN " - From.Join.Type.CROSS -> " CROSS JOIN " - From.Join.Type.COMMA -> ", " - null -> " JOIN " - } - t = visitFrom(node.rhs, t) - t = if (node.condition != null) visit(node.condition!!, t concat " ON ") else t - return t - } - - // LET - - override fun visitLet(node: Let, tail: SqlBlock): SqlBlock = tail concat list("LET ", "") { node.bindings } - - override fun visitLetBinding(node: Let.Binding, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.expr, t) - t = t concat " AS ${node.asAlias.sql()}" - return t - } - - // GROUP BY - - override fun visitGroupBy(node: GroupBy, tail: SqlBlock): SqlBlock { - var t = tail - t = t concat when (node.strategy) { - GroupBy.Strategy.FULL -> "GROUP BY " - GroupBy.Strategy.PARTIAL -> "GROUP PARTIAL BY " - } - t = t concat list("", "") { node.keys } - t = if (node.asAlias != null) t concat " GROUP AS ${node.asAlias!!.sql()}" else t - return t - } - - override fun visitGroupByKey(node: GroupBy.Key, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.expr, t) - t = if (node.asAlias != null) t concat " AS ${node.asAlias!!.sql()}" else t - return t - } - - // SET OPERATORS - - override fun visitSetOp(node: SetOp, tail: SqlBlock): SqlBlock { - val op = when (node.setq) { - null -> node.type.name - else -> "${node.type.name} ${node.setq!!.name}" - } - return tail concat op - } - - // ORDER BY - - override fun visitOrderBy(node: OrderBy, tail: SqlBlock): SqlBlock = - tail concat list("ORDER BY ", "") { node.sorts } - - override fun visitSort(node: Sort, tail: SqlBlock): SqlBlock { - var t = tail - t = visitExprWrapped(node.expr, t) - t = when (node.dir) { - Sort.Dir.ASC -> t concat " ASC" - Sort.Dir.DESC -> t concat " DESC" - null -> t - } - t = when (node.nulls) { - Sort.Nulls.FIRST -> t concat " NULLS FIRST" - Sort.Nulls.LAST -> t concat " NULLS LAST" - null -> t - } - return t - } - - // --- Block Constructor Helpers - - private infix fun SqlBlock.concat(rhs: String): SqlBlock { - next = SqlBlock.Text(rhs) - return next!! - } - - private infix fun SqlBlock.concat(rhs: SqlBlock): SqlBlock { - next = rhs - return next!! - } - - private fun type(symbol: String, vararg args: Int?, gap: Boolean = false): SqlBlock { - val p = args.filterNotNull() - val t = when { - p.isEmpty() -> symbol - else -> { - val a = p.joinToString(",") - when (gap) { - true -> "$symbol ($a)" - else -> "$symbol($a)" - } - } - } - // types are modeled as text; as we don't way to reflow - return SqlBlock.Text(t) - } - - private fun list( - start: String? = "(", - end: String? = ")", - delimiter: String? = ", ", - children: () -> List, - ): SqlBlock { - val kids = children() - val h = SqlBlock.none() - var t = h - kids.forEachIndexed { i, child -> - t = child.accept(this, t) - t = if (delimiter != null && (i + 1) < kids.size) t concat delimiter else t - } - return SqlBlock.Nest( - prefix = start, - postfix = end, - child = h, - ) - } - - private fun Identifier.Symbol.sql() = when (caseSensitivity) { - Identifier.CaseSensitivity.SENSITIVE -> "\"$symbol\"" - Identifier.CaseSensitivity.INSENSITIVE -> symbol // verbatim .. - } -} diff --git a/partiql-ast/src/test/kotlin/org/partiql/ast/sql/SqlDialectTest.kt b/partiql-ast/src/test/kotlin/org/partiql/ast/sql/SqlDialectTest.kt index 7c950bf95a..b39237998d 100644 --- a/partiql-ast/src/test/kotlin/org/partiql/ast/sql/SqlDialectTest.kt +++ b/partiql-ast/src/test/kotlin/org/partiql/ast/sql/SqlDialectTest.kt @@ -14,19 +14,88 @@ import org.junit.jupiter.api.parallel.Execution import org.junit.jupiter.api.parallel.ExecutionMode import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource -import org.partiql.ast.AstNode -import org.partiql.ast.DatetimeField -import org.partiql.ast.Expr -import org.partiql.ast.From -import org.partiql.ast.GroupBy -import org.partiql.ast.Identifier -import org.partiql.ast.SetOp -import org.partiql.ast.SetQuantifier -import org.partiql.ast.Sort -import org.partiql.ast.builder.AstBuilder -import org.partiql.ast.builder.ast -import org.partiql.ast.exprLit -import org.partiql.ast.exprVariant +import org.partiql.ast.v1.Ast +import org.partiql.ast.v1.Ast.exclude +import org.partiql.ast.v1.Ast.excludePath +import org.partiql.ast.v1.Ast.excludeStepCollIndex +import org.partiql.ast.v1.Ast.excludeStepCollWildcard +import org.partiql.ast.v1.Ast.excludeStepStructField +import org.partiql.ast.v1.Ast.excludeStepStructWildcard +import org.partiql.ast.v1.Ast.exprArray +import org.partiql.ast.v1.Ast.exprBag +import org.partiql.ast.v1.Ast.exprBetween +import org.partiql.ast.v1.Ast.exprCall +import org.partiql.ast.v1.Ast.exprCase +import org.partiql.ast.v1.Ast.exprCaseBranch +import org.partiql.ast.v1.Ast.exprCast +import org.partiql.ast.v1.Ast.exprCoalesce +import org.partiql.ast.v1.Ast.exprExtract +import org.partiql.ast.v1.Ast.exprInCollection +import org.partiql.ast.v1.Ast.exprIsType +import org.partiql.ast.v1.Ast.exprLike +import org.partiql.ast.v1.Ast.exprLit +import org.partiql.ast.v1.Ast.exprNot +import org.partiql.ast.v1.Ast.exprNullIf +import org.partiql.ast.v1.Ast.exprOperator +import org.partiql.ast.v1.Ast.exprOverlay +import org.partiql.ast.v1.Ast.exprPath +import org.partiql.ast.v1.Ast.exprPathStepAllElements +import org.partiql.ast.v1.Ast.exprPathStepAllFields +import org.partiql.ast.v1.Ast.exprPathStepElement +import org.partiql.ast.v1.Ast.exprPathStepField +import org.partiql.ast.v1.Ast.exprPosition +import org.partiql.ast.v1.Ast.exprQuerySet +import org.partiql.ast.v1.Ast.exprRowValue +import org.partiql.ast.v1.Ast.exprStruct +import org.partiql.ast.v1.Ast.exprStructField +import org.partiql.ast.v1.Ast.exprSubstring +import org.partiql.ast.v1.Ast.exprTrim +import org.partiql.ast.v1.Ast.exprValues +import org.partiql.ast.v1.Ast.exprVarRef +import org.partiql.ast.v1.Ast.exprVariant +import org.partiql.ast.v1.Ast.from +import org.partiql.ast.v1.Ast.fromExpr +import org.partiql.ast.v1.Ast.fromJoin +import org.partiql.ast.v1.Ast.groupBy +import org.partiql.ast.v1.Ast.groupByKey +import org.partiql.ast.v1.Ast.identifier +import org.partiql.ast.v1.Ast.identifierChain +import org.partiql.ast.v1.Ast.letBinding +import org.partiql.ast.v1.Ast.orderBy +import org.partiql.ast.v1.Ast.queryBodySFW +import org.partiql.ast.v1.Ast.queryBodySetOp +import org.partiql.ast.v1.Ast.selectItemExpr +import org.partiql.ast.v1.Ast.selectItemStar +import org.partiql.ast.v1.Ast.selectList +import org.partiql.ast.v1.Ast.selectPivot +import org.partiql.ast.v1.Ast.selectStar +import org.partiql.ast.v1.Ast.selectValue +import org.partiql.ast.v1.Ast.setOp +import org.partiql.ast.v1.Ast.sort +import org.partiql.ast.v1.AstNode +import org.partiql.ast.v1.DataType +import org.partiql.ast.v1.DatetimeField +import org.partiql.ast.v1.Exclude +import org.partiql.ast.v1.From +import org.partiql.ast.v1.FromType +import org.partiql.ast.v1.GroupBy +import org.partiql.ast.v1.GroupByStrategy +import org.partiql.ast.v1.Identifier +import org.partiql.ast.v1.IdentifierChain +import org.partiql.ast.v1.JoinType +import org.partiql.ast.v1.Let +import org.partiql.ast.v1.Nulls +import org.partiql.ast.v1.Order +import org.partiql.ast.v1.OrderBy +import org.partiql.ast.v1.QueryBody +import org.partiql.ast.v1.Select +import org.partiql.ast.v1.SetOpType +import org.partiql.ast.v1.SetQuantifier +import org.partiql.ast.v1.expr.Expr +import org.partiql.ast.v1.expr.Scope +import org.partiql.ast.v1.expr.TrimSpec +import org.partiql.ast.v1.sql.SqlLayout +import org.partiql.ast.v1.sql.sql import org.partiql.value.PartiQLValueExperimental import org.partiql.value.boolValue import org.partiql.value.dateValue @@ -65,11 +134,6 @@ class SqlDialectTest { @Execution(ExecutionMode.CONCURRENT) fun testIdentifiers(case: Case) = case.assert() - @ParameterizedTest(name = "paths #{index}") - @MethodSource("paths") - @Execution(ExecutionMode.CONCURRENT) - fun testPaths(case: Case) = case.assert() - // Types @ParameterizedTest(name = "types #{index}") @@ -188,237 +252,224 @@ class SqlDialectTest { @JvmStatic fun types() = listOf( // SQL - expect("NULL") { typeNullType() }, - expect("BOOL") { typeBool() }, - expect("SMALLINT") { typeSmallint() }, - expect("INT") { typeInt() }, - expect("REAL") { typeReal() }, - expect("FLOAT32") { typeFloat32() }, - expect("DOUBLE PRECISION") { typeFloat64() }, - expect("DECIMAL") { typeDecimal() }, - expect("DECIMAL(2)") { typeDecimal(2) }, - expect("DECIMAL(2,1)") { typeDecimal(2, 1) }, - expect("NUMERIC") { typeNumeric() }, - expect("NUMERIC(2)") { typeNumeric(2) }, - expect("NUMERIC(2,1)") { typeNumeric(2, 1) }, - expect("TIMESTAMP") { typeTimestamp() }, - expect("CHAR") { typeChar() }, - expect("CHAR(1)") { typeChar(1) }, - expect("VARCHAR") { typeVarchar() }, - expect("VARCHAR(1)") { typeVarchar(1) }, - expect("BLOB") { typeBlob() }, - expect("CLOB") { typeClob() }, - expect("DATE") { typeDate() }, - expect("TIME") { typeTime() }, - expect("TIME(1)") { typeTime(1) }, - expect("TIME WITH TIMEZONE") { typeTimeWithTz() }, - expect("TIME WITH TIMEZONE (1)") { typeTimeWithTz(1) }, + expect("NULL", DataType.NULL()), + expect("BOOL", DataType.BOOL()), + expect("SMALLINT", DataType.SMALLINT()), + expect("INT", DataType.INT()), + expect("REAL", DataType.REAL()), + expect("FLOAT", DataType.FLOAT()), + expect("DOUBLE PRECISION", DataType.DOUBLE_PRECISION()), + expect("DECIMAL", DataType.DECIMAL()), + expect("DECIMAL(2)", DataType.DECIMAL(2)), + expect("DECIMAL(2,1)", DataType.DECIMAL(2, 1)), + expect("NUMERIC", DataType.NUMERIC()), + expect("NUMERIC(2)", DataType.NUMERIC(2)), + expect("NUMERIC(2,1)", DataType.NUMERIC(2, 1)), + expect("TIMESTAMP", DataType.TIMESTAMP()), + expect("CHAR", DataType.CHAR()), + expect("CHAR(1)", DataType.CHAR(1)), + expect("VARCHAR", DataType.VARCHAR()), + expect("VARCHAR(1)", DataType.VARCHAR(1)), + expect("BLOB", DataType.BLOB()), + expect("CLOB", DataType.CLOB()), + expect("DATE", DataType.DATE()), + expect("TIME", DataType.TIME()), + expect("TIME(1)", DataType.TIME(1)), + expect("TIME WITH TIMEZONE", DataType.TIME_WITH_TIME_ZONE()), + expect("TIME WITH TIMEZONE (1)", DataType.TIME_WITH_TIME_ZONE(1)), // TODO TIMESTAMP // TODO INTERVAL + // TODO other types in `DataType` // PartiQL - expect("MISSING") { typeMissing() }, - expect("STRING") { typeString() }, - expect("SYMBOL") { typeSymbol() }, - expect("STRUCT") { typeStruct() }, - expect("TUPLE") { typeTuple() }, - expect("LIST") { typeList() }, - expect("SEXP") { typeSexp() }, - expect("BAG") { typeBag() }, - expect("ANY") { typeAny() }, + expect("MISSING", DataType.MISSING()), + expect("STRING", DataType.STRING()), + expect("SYMBOL", DataType.SYMBOL()), + expect("STRUCT", DataType.STRUCT()), + expect("TUPLE", DataType.TUPLE()), + expect("LIST", DataType.LIST()), + expect("SEXP", DataType.SEXP()), + expect("BAG", DataType.BAG()), // Other (??) - expect("INT4") { typeInt4() }, - expect("INT8") { typeInt8() }, + expect("INT4", DataType.INT4()), + expect("INT8", DataType.INT8()), // - fail("PartiQLDialect does not support custom types") { typeCustom("foo") }, + expect( + "FOO.BAR", + DataType.USER_DEFINED( + identifierChain( + root = identifier("FOO", isDelimited = false), + next = identifierChain( + root = identifier(symbol = "BAR", isDelimited = false), + next = null + ) + ) + ) + ), ) @JvmStatic fun exprOperators() = listOf( - expect("NOT (NULL)") { - exprNot { - value = NULL - } - }, - expect("+(NULL)") { - exprOperator { - symbol = "+" - rhs = NULL - } - }, - expect("-(NULL)") { - exprOperator { - symbol = "-" - rhs = NULL - } - }, - expect("NOT (NOT (NULL))") { - exprNot { - value = exprNot { - value = NULL - } - } - }, - expect("+(+(NULL))") { - exprOperator { - symbol = "+" - rhs = exprOperator { - symbol = "+" - rhs = NULL - } - } - }, - expect("-(-(NULL))") { - exprOperator { - symbol = "-" - rhs = exprOperator { - symbol = "-" - rhs = NULL - } - } - }, - expect("+(-(+(NULL)))") { - exprOperator { - symbol = "+" - rhs = exprOperator { - symbol = "-" - rhs = exprOperator { - symbol = "+" + expect( + "NOT (NULL)", + exprNot(value = NULL) + ), + expect( + "+(NULL)", + exprOperator(symbol = "+", lhs = null, rhs = NULL) + ), + expect( + "-(NULL)", + exprOperator(symbol = "-", lhs = null, rhs = NULL) + ), + expect( + "NOT (NOT (NULL))", + exprNot(value = exprNot(value = NULL)) + ), + expect( + "+(+(NULL))", + exprOperator(symbol = "+", lhs = null, rhs = exprOperator(symbol = "+", lhs = null, rhs = NULL)) + ), + expect( + "-(-(NULL))", + exprOperator( + symbol = "-", + lhs = null, + rhs = exprOperator(symbol = "-", lhs = null, rhs = NULL) + ) + ), + expect( + "+(-(+(NULL)))", + exprOperator( + symbol = "+", + lhs = null, + rhs = exprOperator( + symbol = "-", + lhs = null, + rhs = exprOperator( + symbol = "+", + lhs = null, rhs = NULL - } - } - } - }, - expect("NULL + NULL") { - exprOperator { - symbol = "+" - lhs = NULL + ) + ) + ) + ), + expect( + "NULL + NULL", + exprOperator( + symbol = "+", + lhs = NULL, rhs = NULL - } - }, + ) + ), ) @JvmStatic fun identifiers() = listOf( - expect("x") { - id("x") - }, - expect("X") { - id("X") - }, - expect("\"x\"") { - id("x", Identifier.CaseSensitivity.SENSITIVE) - }, - expect("x.y.z") { - identifierQualified { - root = id("x") - steps += id("y") - steps += id("z") - } - }, - expect("x.\"y\".z") { - identifierQualified { - root = id("x") - steps += id("y", Identifier.CaseSensitivity.SENSITIVE) - steps += id("z") - } - }, - expect("\"x\".\"y\".\"z\"") { - identifierQualified { - root = id("x", Identifier.CaseSensitivity.SENSITIVE) - steps += id("y", Identifier.CaseSensitivity.SENSITIVE) - steps += id("z", Identifier.CaseSensitivity.SENSITIVE) - } - }, - ) - - @JvmStatic - fun paths() = listOf( - expect("x.y.z") { - path { - root = id("x") - steps += pathStepSymbol(id("y")) - steps += pathStepSymbol(id("z")) - } - }, - expect("x.y[0]") { - path { - root = id("x") - steps += pathStepSymbol(id("y")) - steps += pathStepIndex(0) - } - }, - expect("x[0].y") { - path { - root = id("x") - steps += pathStepIndex(0) - steps += pathStepSymbol(id("y")) - } - }, - expect("\"x\".\"y\".\"z\"") { - path { - root = id("x", Identifier.CaseSensitivity.SENSITIVE) - steps += pathStepSymbol(id("y", Identifier.CaseSensitivity.SENSITIVE)) - steps += pathStepSymbol(id("z", Identifier.CaseSensitivity.SENSITIVE)) - } - }, + expect( + "x", id("x") + ), + expect( + "X", id("X") + ), + expect( + "\"x\"", id("x", isDelimited = true) + ), + expect( + "x.y.z", + identifierChain( + root = id("x"), + next = identifierChain( + root = id("y"), + next = identifierChain( + root = id("z"), + next = null + ) + ) + ) + ), + expect( + "x.\"y\".z", + identifierChain( + root = id("x"), + next = identifierChain( + root = id("y", isDelimited = true), + next = identifierChain( + root = id("z"), + next = null + ) + ) + ) + ), + expect( + "\"x\".\"y\".\"z\"", + identifierChain( + root = id("x", isDelimited = true), + next = identifierChain( + root = id("y", isDelimited = true), + next = identifierChain( + root = id("z", isDelimited = true), + next = null + ) + ) + ) + ), ) // Expressions + @OptIn(PartiQLValueExperimental::class) @JvmStatic fun exprLitCases() = listOf( - expect("NULL") { - exprLit(nullValue()) - }, - expect("MISSING") { - exprLit(missingValue()) - }, - expect("true") { - exprLit(boolValue(true)) - }, - expect("1") { - exprLit(int8Value(1)) - }, - expect("2") { - exprLit(int16Value(2)) - }, - expect("3") { - exprLit(int32Value(3)) - }, - expect("4") { - exprLit(int64Value(4)) - }, - expect("5") { - exprLit(intValue(BigInteger.valueOf(5))) - }, + expect( + "NULL", exprLit(nullValue()) + ), + expect( + "MISSING", exprLit(missingValue()) + ), + expect( + "true", exprLit(boolValue(true)) + ), + expect( + "1", exprLit(int8Value(1)) + ), + expect( + "2", exprLit(int16Value(2)) + ), + expect( + "3", exprLit(int32Value(3)) + ), + expect( + "4", exprLit(int64Value(4)) + ), + expect( + "5", exprLit(intValue(BigInteger.valueOf(5))) + ), // TODO fix PartiQL Text writer for floats // expect("1.1e0") { - expect("1.1") { - exprLit(float32Value(1.1f)) - }, + expect("1.1", exprLit(float32Value(1.1f))), // TODO fix PartiQL Text writer for floats // expect("1.2e0") { - expect("1.2") { - exprLit(float64Value(1.2)) - }, - expect("1.3") { - exprLit(decimalValue(BigDecimal.valueOf(1.3))) - }, - expect("""'hello'""") { - exprLit(stringValue("hello")) - }, - expect("""hello""") { - exprLit(symbolValue("hello")) - }, - expect("DATE '0001-02-03'") { - exprLit(dateValue(DateTimeValue.date(1, 2, 3))) - }, - expect("TIME '01:02:03.456-00:30'") { - exprLit(timeValue(DateTimeValue.time(1, 2, BigDecimal.valueOf(3.456), TimeZone.UtcOffset.of(-30)))) - }, - expect("TIMESTAMP '0001-02-03 04:05:06.78-00:30'") { - exprLit(timestampValue(DateTimeValue.timestamp(1, 2, 3, 4, 5, BigDecimal.valueOf(6.78), TimeZone.UtcOffset.of(-30)))) - }, + expect( + "1.2", exprLit(float64Value(1.2)) + ), + expect( + "1.3", exprLit(decimalValue(BigDecimal.valueOf(1.3))) + ), + expect( + """'hello'""", exprLit(stringValue("hello")) + ), + expect( + """hello""", exprLit(symbolValue("hello")) + ), + expect( + "DATE '0001-02-03'", exprLit(dateValue(DateTimeValue.date(1, 2, 3))) + ), + expect( + "TIME '01:02:03.456-00:30'", exprLit(timeValue(DateTimeValue.time(1, 2, BigDecimal.valueOf(3.456), TimeZone.UtcOffset.of(-30)))) + ), + expect( + "TIMESTAMP '0001-02-03 04:05:06.78-00:30'", exprLit(timestampValue(DateTimeValue.timestamp(1, 2, 3, 4, 5, BigDecimal.valueOf(6.78), TimeZone.UtcOffset.of(-30)))) + ), // expect("""{{ '''Hello''' '''World''' }}""") { // exprLit(clobValue("HelloWorld".toByteArray())) @@ -430,48 +481,48 @@ class SqlDialectTest { @JvmStatic fun exprIonCases() = listOf( - expect("`null`") { - exprIon(ionNull()) - }, - expect("`true`") { - exprIon(ionBool(true)) - }, - expect("`1`") { - exprIon(ionInt(1)) - }, - expect("`1.2e0`") { - exprIon(ionFloat(1.2)) - }, - expect("`1.3`") { - exprIon(ionDecimal(Decimal.valueOf(1.3))) - }, - expect("""`"hello"`""") { - exprIon(ionString("hello")) - }, - expect("""`hello`""") { - exprIon(ionSymbol("hello")) - }, - expect("`a::b::null`") { - exprIon(ionNull().withAnnotations("a", "b")) - }, - expect("`a::b::true`") { - exprIon(ionBool(true).withAnnotations("a", "b")) - }, - expect("`a::b::1`") { - exprIon(ionInt(1).withAnnotations("a", "b")) - }, - expect("`a::b::1.2e0`") { - exprIon(ionFloat(1.2).withAnnotations("a", "b")) - }, - expect("`a::b::1.3`") { - exprIon(ionDecimal(Decimal.valueOf(1.3)).withAnnotations("a", "b")) - }, - expect("""`a::b::"hello"`""") { - exprIon(ionString("hello").withAnnotations("a", "b")) - }, - expect("""`a::b::hello`""") { - exprIon(ionSymbol("hello").withAnnotations("a", "b")) - }, + expect( + "`null`", exprIon(ionNull()) + ), + expect( + "`true`", exprIon(ionBool(true)) + ), + expect( + "`1`", exprIon(ionInt(1)) + ), + expect( + "`1.2e0`", exprIon(ionFloat(1.2)) + ), + expect( + "`1.3`", exprIon(ionDecimal(Decimal.valueOf(1.3))) + ), + expect( + """`"hello"`""", exprIon(ionString("hello")) + ), + expect( + """`hello`""", exprIon(ionSymbol("hello")) + ), + expect( + "`a::b::null`", exprIon(ionNull().withAnnotations("a", "b")) + ), + expect( + "`a::b::true`", exprIon(ionBool(true).withAnnotations("a", "b")) + ), + expect( + "`a::b::1`", exprIon(ionInt(1).withAnnotations("a", "b")) + ), + expect( + "`a::b::1.2e0`", exprIon(ionFloat(1.2).withAnnotations("a", "b")) + ), + expect( + "`a::b::1.3`", exprIon(ionDecimal(Decimal.valueOf(1.3)).withAnnotations("a", "b")) + ), + expect( + """`a::b::"hello"`""", exprIon(ionString("hello").withAnnotations("a", "b")) + ), + expect( + """`a::b::hello`""", exprIon(ionSymbol("hello").withAnnotations("a", "b")) + ), ) private fun exprIon(value: IonElement): Expr = exprVariant(value.toString(), "ion") @@ -479,1727 +530,2128 @@ class SqlDialectTest { @JvmStatic fun exprVarCases() = listOf( // DEFAULT - expect("x") { - val id = id("x") - exprVar(id, Expr.Var.Scope.DEFAULT) - }, - expect("\"x\"") { - val id = id("x", Identifier.CaseSensitivity.SENSITIVE) - exprVar(id, Expr.Var.Scope.DEFAULT) - }, - expect("x.y.z") { - val id = identifierQualified { - root = id("x") - steps += id("y") - steps += id("z") - } - exprVar(id, Expr.Var.Scope.DEFAULT) - }, - expect("x.\"y\".z") { - val id = identifierQualified { - root = id("x") - steps += id("y", Identifier.CaseSensitivity.SENSITIVE) - steps += id("z") - } - exprVar(id, Expr.Var.Scope.DEFAULT) - }, - expect("\"x\".\"y\".\"z\"") { - val id = identifierQualified { - root = id("x", Identifier.CaseSensitivity.SENSITIVE) - steps += id("y", Identifier.CaseSensitivity.SENSITIVE) - steps += id("z", Identifier.CaseSensitivity.SENSITIVE) - } - exprVar(id, Expr.Var.Scope.DEFAULT) - }, + expect( + "x", + exprVarRef( + identifierChain( + root = id("x"), + next = null + ), + Scope.DEFAULT() + ) + ), + expect( + "\"x\"", + exprVarRef( + identifierChain( + root = id("x", isDelimited = true), + next = null + ), + Scope.DEFAULT() + ) + ), + expect( + "x.y.z", + exprVarRef( + identifierChain( + root = id("x"), + next = identifierChain( + root = id("y"), + next = identifierChain( + root = id("z"), + next = null + ) + ) + ), + Scope.DEFAULT() + ) + ), + expect( + "x.\"y\".z", + exprVarRef( + identifierChain( + root = id("x"), + next = identifierChain( + root = id("y", isDelimited = true), + next = identifierChain( + root = id("z"), + next = null + ) + ) + ), + Scope.DEFAULT() + ) + ), + expect( + "\"x\".\"y\".\"z\"", + exprVarRef( + identifierChain( + root = id("x", isDelimited = true), + next = identifierChain( + root = id("y", isDelimited = true), + next = identifierChain( + root = id("z", isDelimited = true), + next = null + ) + ) + ), + Scope.DEFAULT() + ) + ), // LOCAL - expect("@x") { - val id = id("x") - exprVar(id, Expr.Var.Scope.LOCAL) - }, - expect("@\"x\"") { - val id = id("x", Identifier.CaseSensitivity.SENSITIVE) - exprVar(id, Expr.Var.Scope.LOCAL) - }, - expect("@x.y.z") { - val id = identifierQualified { - root = id("x") - steps += id("y") - steps += id("z") - } - exprVar(id, Expr.Var.Scope.LOCAL) - }, - expect("@x.\"y\".z") { - val id = identifierQualified { - root = id("x") - steps += id("y", Identifier.CaseSensitivity.SENSITIVE) - steps += id("z") - } - exprVar(id, Expr.Var.Scope.LOCAL) - }, - expect("@\"x\".\"y\".\"z\"") { - val id = identifierQualified { - root = id("x", Identifier.CaseSensitivity.SENSITIVE) - steps += id("y", Identifier.CaseSensitivity.SENSITIVE) - steps += id("z", Identifier.CaseSensitivity.SENSITIVE) - } - exprVar(id, Expr.Var.Scope.LOCAL) - }, + expect( + "@x", + exprVarRef( + identifierChain( + root = id("x"), + next = null + ), + Scope.LOCAL() + ) + ), + expect( + "@\"x\"", + exprVarRef( + identifierChain( + root = id("x", isDelimited = true), + next = null + ), + Scope.LOCAL() + ) + ), + expect( + "@x.y.z", + exprVarRef( + identifierChain( + root = id("x"), + next = identifierChain( + root = id("y"), + next = identifierChain( + root = id("z"), + next = null + ) + ) + ), + Scope.LOCAL() + ) + ), + expect( + "@x.\"y\".z", + exprVarRef( + idChain( + root = id("x"), + next = idChain( + root = id("y", isDelimited = true), + next = idChain(root = id("z")) + ) + ), + Scope.LOCAL() + ) + ), + expect( + "@\"x\".\"y\".\"z\"", + exprVarRef( + idChain( + root = id("x", isDelimited = true), + next = idChain( + root = id("y", isDelimited = true), + next = idChain(root = id("z", isDelimited = true)) + ) + ), + Scope.LOCAL() + ) + ), ) @JvmStatic fun exprPathCases() = listOf( - expect("x.y.*") { - exprPath { - root = exprVar { - identifier = id("x") - scope = Expr.Var.Scope.DEFAULT - } - steps += exprPathStepSymbol(id("y")) - steps += exprPathStepUnpivot() - } - }, - expect("x.y[*]") { - exprPath { - root = exprVar { - identifier = id("x") - scope = Expr.Var.Scope.DEFAULT - } - steps += exprPathStepSymbol(id("y")) - steps += exprPathStepWildcard() - } - }, - expect("x[1 + a]") { - exprPath { - root = exprVar { - identifier = id("x") - scope = Expr.Var.Scope.DEFAULT - } - steps += exprPathStepIndex( - exprOperator { - symbol = "+" - lhs = exprLit(int32Value(1)) - rhs = exprVar { - identifier = id("a") - scope = Expr.Var.Scope.DEFAULT - } - } + expect( + "x.y.*", + exprPath( + root = exprVarRef( + identifierChain = idChain(id("x")), + scope = Scope.DEFAULT() + ), + next = exprPathStepField( + value = id("y"), + next = exprPathStepAllFields(next = null) ) - } - }, - expect("x['y']") { - exprPath { - root = exprVar { - identifier = id("x") - scope = Expr.Var.Scope.DEFAULT - } - steps += exprPathStepIndex(exprLit(stringValue("y"))) - } - }, + ) + ), + expect( + "x.y[*]", + exprPath( + root = exprVarRef( + identifierChain = idChain(id("x")), + scope = Scope.DEFAULT() + ), + next = exprPathStepField( + value = id("y"), + next = exprPathStepAllElements(next = null) + ) + ) + ), + expect( + "x[1 + a]", + exprPath( + root = exprVarRef( + identifierChain = idChain(id("x")), + scope = Scope.DEFAULT() + ), + next = exprPathStepElement( + element = exprOperator( + symbol = "+", + lhs = exprLit(int32Value(1)), + rhs = exprVarRef( + identifierChain = idChain(id("a")), + scope = Scope.DEFAULT() + ) + ), + next = null + ) + ) + ), + expect( + "x['y']", + exprPath( + root = exprVarRef( + identifierChain = idChain(id("x")), + scope = Scope.DEFAULT() + ), + next = exprPathStepElement(exprLit(stringValue("y")), next = null) + ) + ), ) @JvmStatic fun exprCallCases() = listOf( - expect("foo(1)") { - exprCall { - function = id("foo") - args += exprLit(int32Value(1)) - } - }, - expect("foo(1, 2)") { - exprCall { - function = id("foo") - args += exprLit(int32Value(1)) - args += exprLit(int32Value(2)) - } - }, - expect("foo.bar(1)") { - exprCall { - function = identifierQualified { - root = id("foo") - steps += id("bar") - } - args += exprLit(int32Value(1)) - } - }, - expect("foo.bar(1, 2)") { - exprCall { - function = identifierQualified { - root = id("foo") - steps += id("bar") - } - args += exprLit(int32Value(1)) - args += exprLit(int32Value(2)) - } - }, + expect( + "foo(1)", + exprCall( + function = idChain(id("foo")), + args = listOf(exprLit(int32Value(1))), + setq = null + ) + ), + expect( + "foo(1, 2)", + exprCall( + function = idChain(id("foo")), + args = listOf( + exprLit(int32Value(1)), + exprLit(int32Value(2)), + ), + setq = null + ) + ), + expect( + "foo.bar(1)", + exprCall( + function = identifierChain( + root = id("foo"), + next = idChain(id("bar")) + ), + args = listOf(exprLit(int32Value(1))), + setq = null + ) + ), + expect( + "foo.bar(1, 2)", + exprCall( + function = identifierChain( + root = id("foo"), + next = idChain(id("bar")) + ), + args = listOf( + exprLit(int32Value(1)), + exprLit(int32Value(2)) + ), + setq = null + ) + ), ) @JvmStatic fun exprAggCases() = listOf( - expect("FOO(x)") { - exprCall { - function = id("FOO") - args += exprVar(id("x"), Expr.Var.Scope.DEFAULT) - } - }, - expect("FOO(ALL x)") { - exprCall { - function = id("FOO") - setq = SetQuantifier.ALL - args += exprVar(id("x"), Expr.Var.Scope.DEFAULT) - } - }, - expect("FOO(DISTINCT x)") { - exprCall { - function = id("FOO") - setq = SetQuantifier.DISTINCT - args += exprVar(id("x"), Expr.Var.Scope.DEFAULT) - } - }, - expect("FOO(x, y)") { - exprCall { - function = id("FOO") - args += exprVar(id("x"), Expr.Var.Scope.DEFAULT) - args += exprVar(id("y"), Expr.Var.Scope.DEFAULT) - } - }, - expect("FOO(ALL x, y)") { - exprCall { - function = id("FOO") - setq = SetQuantifier.ALL - args += exprVar(id("x"), Expr.Var.Scope.DEFAULT) - args += exprVar(id("y"), Expr.Var.Scope.DEFAULT) - } - }, - expect("FOO(DISTINCT x, y)") { - exprCall { - function = id("FOO") - setq = SetQuantifier.DISTINCT - args += exprVar(id("x"), Expr.Var.Scope.DEFAULT) - args += exprVar(id("y"), Expr.Var.Scope.DEFAULT) - } - }, - expect("COUNT(*)") { - exprCall { - function = id("COUNT") // AST representation for COUNT w/ no args maps to COUNT(*) - } - } + expect( + "FOO(x)", + exprCall( + function = idChain(id("FOO")), + args = listOf(exprVarRef(idChain(id("x")), Scope.DEFAULT())), + setq = null + ) + ), + expect( + "FOO(ALL x)", + exprCall( + function = idChain(id("FOO")), + args = listOf(exprVarRef(idChain(id("x")), Scope.DEFAULT())), + setq = SetQuantifier.ALL() + ) + ), + expect( + "FOO(DISTINCT x)", + exprCall( + function = idChain(id("FOO")), + args = listOf(exprVarRef(idChain(id("x")), Scope.DEFAULT())), + setq = SetQuantifier.DISTINCT(), + ) + ), + expect( + "FOO(x, y)", + exprCall( + function = idChain(id("FOO")), + args = listOf( + exprVarRef(idChain(id("x")), Scope.DEFAULT()), + exprVarRef(idChain(id("y")), Scope.DEFAULT()) + ), + setq = null + ) + ), + expect( + "FOO(ALL x, y)", + exprCall( + function = idChain(id("FOO")), + args = listOf( + exprVarRef(idChain(id("x")), Scope.DEFAULT()), + exprVarRef(idChain(id("y")), Scope.DEFAULT()) + ), + setq = SetQuantifier.ALL() + ) + ), + expect( + "FOO(DISTINCT x, y)", + exprCall( + function = idChain(id("FOO")), + args = listOf( + exprVarRef(idChain(id("x")), Scope.DEFAULT()), + exprVarRef(idChain(id("y")), Scope.DEFAULT()) + ), + setq = SetQuantifier.DISTINCT(), + ) + ), + expect( + "COUNT(*)", + exprCall( + function = idChain(id("COUNT")), // AST representation for COUNT w/ no args maps to COUNT(*) + args = emptyList(), + setq = null + ) + ) ) @JvmStatic fun exprCollectionCases() = listOf( - expect("<<>>") { - exprCollection { - type = Expr.Collection.Type.BAG - } - }, - expect("<<1, 2, 3>>") { - exprCollection { - type = Expr.Collection.Type.BAG - values += exprLit(int32Value(1)) - values += exprLit(int32Value(2)) - values += exprLit(int32Value(3)) - } - }, - expect("[]") { - exprCollection { - type = Expr.Collection.Type.ARRAY - } - }, - expect("[1, 2, 3]") { - exprCollection { - type = Expr.Collection.Type.ARRAY - values += exprLit(int32Value(1)) - values += exprLit(int32Value(2)) - values += exprLit(int32Value(3)) - } - }, - expect("VALUES ()") { - exprCollection { - type = Expr.Collection.Type.VALUES - } - }, - expect("VALUES (1, 2, 3)") { - exprCollection { - type = Expr.Collection.Type.VALUES - values += exprLit(int32Value(1)) - values += exprLit(int32Value(2)) - values += exprLit(int32Value(3)) - } - }, - expect("()") { - exprCollection { - type = Expr.Collection.Type.LIST - } - }, - expect("(1, 2, 3)") { - exprCollection { - type = Expr.Collection.Type.LIST - values += exprLit(int32Value(1)) - values += exprLit(int32Value(2)) - values += exprLit(int32Value(3)) - } - }, - expect("SEXP ()") { - exprCollection { - type = Expr.Collection.Type.SEXP - } - }, - expect("SEXP (1, 2, 3)") { - exprCollection { - type = Expr.Collection.Type.SEXP - values += exprLit(int32Value(1)) - values += exprLit(int32Value(2)) - values += exprLit(int32Value(3)) - } - }, + expect( + "<<>>", + exprBag(values = emptyList()) + ), + expect( + "<<1, 2, 3>>", + exprBag( + values = listOf( + exprLit(int32Value(1)), + exprLit(int32Value(2)), + exprLit(int32Value(3)) + ) + ) + ), + expect( + "[]", + exprArray(values = emptyList()) + ), + expect( + "[1, 2, 3]", + exprArray( + values = listOf( + exprLit(int32Value(1)), + exprLit(int32Value(2)), + exprLit(int32Value(3)) + ) + ) + ), + expect( + "VALUES ()", + exprValues( + rows = listOf( + exprRowValue( + values = emptyList() + ) + ) + ) + ), + expect( + "VALUES (1, 2, 3)", + exprValues( + rows = listOf( + exprRowValue( + values = listOf( + exprLit(int32Value(1)), + exprLit(int32Value(2)), + exprLit(int32Value(3)) + ) + ) + ) + ) + ), + expect( + "()", + exprRowValue( + values = emptyList() + ) + ), + expect( + "(1, 2, 3)", + exprRowValue( + values = listOf( + exprLit(int32Value(1)), + exprLit(int32Value(2)), + exprLit(int32Value(3)) + ) + ) + ), + // SEXP not in v1 +// expect( +// "SEXP ()", +// exprCollection { +// type = Expr.Collection.Type.SEXP +// } +// ), +// expect( +// "SEXP (1, 2, 3)", +// exprCollection { +// type = Expr.Collection.Type.SEXP +// values += exprLit(int32Value(1)) +// values += exprLit(int32Value(2)) +// values += exprLit(int32Value(3)) +// } +// ), ) @JvmStatic fun exprStructCases() = listOf( - expect("{}") { - exprStruct() - }, - expect("{a: 1}") { - exprStruct { - fields += exprStructField { - name = exprLit(symbolValue("a")) - value = exprLit(int32Value(1)) - } - } - }, - expect("{a: 1, b: false}") { - exprStruct { - fields += exprStructField { - name = exprLit(symbolValue("a")) - value = exprLit(int32Value(1)) - } - fields += exprStructField { - name = exprLit(symbolValue("b")) - value = exprLit(boolValue(false)) - } - } - }, + expect("{}", exprStruct(listOf())), + expect( + "{a: 1}", + exprStruct( + fields = listOf( + exprStructField( + name = exprLit(symbolValue("a")), + value = exprLit(int32Value(1)) + ) + ) + ) + ), + expect( + "{a: 1, b: false}", + exprStruct( + fields = listOf( + exprStructField( + name = exprLit(symbolValue("a")), + value = exprLit(int32Value(1)) + ), + exprStructField( + name = exprLit(symbolValue("b")), + value = exprLit(boolValue(false)) + ) + ) + ) + ), ) @JvmStatic fun exprSpecialFormCases() = listOf( - expect("x LIKE y") { - exprLike { - value = v("x") - pattern = v("y") - } - }, - expect("x NOT LIKE y") { - exprLike { - value = v("x") - pattern = v("y") + expect( + "x LIKE y", + exprLike( + value = v("x"), + pattern = v("y"), + escape = null, + not = false + ) + ), + expect( + "x NOT LIKE y", + exprLike( + value = v("x"), + pattern = v("y"), + escape = null, not = true - } - }, - expect("x LIKE y ESCAPE z") { - exprLike { - value = v("x") - pattern = v("y") - escape = v("z") - } - }, - expect("x BETWEEN y AND z") { - exprBetween { - value = v("x") - from = v("y") - to = v("z") - } - }, - expect("x NOT BETWEEN y AND z") { - exprBetween { - value = v("x") - from = v("y") - to = v("z") + ) + ), + expect( + "x LIKE y ESCAPE z", + exprLike( + value = v("x"), + pattern = v("y"), + escape = v("z"), + not = false + ) + ), + expect( + "x BETWEEN y AND z", + exprBetween( + value = v("x"), + from = v("y"), + to = v("z"), + not = false + ) + ), + expect( + "x NOT BETWEEN y AND z", + exprBetween( + value = v("x"), + from = v("y"), + to = v("z"), not = true - } - }, - expect("x IN y") { - exprInCollection { - lhs = v("x") - rhs = v("y") - } - }, - expect("x NOT IN y") { - exprInCollection { - lhs = v("x") - rhs = v("y") + ) + ), + expect( + "x IN y", + exprInCollection( + lhs = v("x"), + rhs = v("y"), + not = false + ) + ), + expect( + "x NOT IN y", + exprInCollection( + lhs = v("x"), + rhs = v("y"), not = true - } - }, - expect("x IS BOOL") { - exprIsType { - value = v("x") - type = typeBool() - } - }, - expect("x IS NOT BOOL") { - exprIsType { - value = v("x") - type = typeBool() + ) + ), + expect( + "x IS BOOL", + exprIsType( + value = v("x"), + type = DataType.BOOL(), + not = false + ) + ), + expect( + "x IS NOT BOOL", + exprIsType( + value = v("x"), + type = DataType.BOOL(), not = true - } - }, - expect("NULLIF(x, y)") { - exprNullIf { - value = v("x") - nullifier = v("y") - } - }, - expect("COALESCE(x, y, z)") { - exprCoalesce { - args += v("x") - args += v("y") - args += v("z") - } - }, - expect("SUBSTRING(x)") { - exprSubstring { - value = v("x") - } - }, - expect("SUBSTRING(x FROM i)") { - exprSubstring { - value = v("x") - start = v("i") - } - }, - expect("SUBSTRING(x FROM i FOR n)") { - exprSubstring { - value = v("x") - start = v("i") + ) + ), + expect( + "NULLIF(x, y)", + exprNullIf( + v1 = v("x"), + v2 = v("y") + ) + ), + expect( + "COALESCE(x, y, z)", + exprCoalesce( + args = listOf(v("x"), v("y"), v("z")) + ) + ), + expect( + "SUBSTRING(x)", + exprSubstring( + value = v("x"), + start = null, + length = null + ) + ), + expect( + "SUBSTRING(x FROM i)", + exprSubstring( + value = v("x"), + start = v("i"), + length = null + ) + ), + expect( + "SUBSTRING(x FROM i FOR n)", + exprSubstring( + value = v("x"), + start = v("i"), length = v("n") - } - }, - expect("SUBSTRING(x FOR n)") { - exprSubstring { - value = v("x") + ) + ), + expect( + "SUBSTRING(x FOR n)", + exprSubstring( + value = v("x"), + start = null, length = v("n") - } - }, - expect("POSITION(x IN y)") { - exprPosition { - lhs = v("x") + ) + ), + expect( + "POSITION(x IN y)", + exprPosition( + lhs = v("x"), rhs = v("y") - } - }, - expect("TRIM(x)") { - exprTrim { - value = v("x") - } - }, - expect("TRIM(BOTH x)") { - exprTrim { - value = v("x") - spec = Expr.Trim.Spec.BOTH - } - }, - expect("TRIM(LEADING y FROM x)") { - exprTrim { - value = v("x") - spec = Expr.Trim.Spec.LEADING - chars = v("y") - } - }, - expect("TRIM(y FROM x)") { - exprTrim { - value = v("x") - chars = v("y") - } - }, - expect("OVERLAY(x PLACING y FROM z)") { - exprOverlay { - value = v("x") - overlay = v("y") - start = v("z") - } - }, - expect("OVERLAY(x PLACING y FROM z FOR n)") { - exprOverlay { - value = v("x") - overlay = v("y") - start = v("z") - length = v("n") - } - }, - expect("EXTRACT(MINUTE FROM x)") { - exprExtract { - field = DatetimeField.MINUTE + ) + ), + expect( + "TRIM(x)", + exprTrim( + value = v("x"), + chars = null, + trimSpec = null + ) + ), + expect( + "TRIM(BOTH x)", + exprTrim( + value = v("x"), + chars = null, + trimSpec = TrimSpec.BOTH() + ) + ), + expect( + "TRIM(LEADING y FROM x)", + exprTrim( + value = v("x"), + chars = v("y"), + trimSpec = TrimSpec.LEADING() + ) + ), + expect( + "TRIM(y FROM x)", + exprTrim( + value = v("x"), + chars = v("y"), + trimSpec = null + ) + ), + expect( + "OVERLAY(x PLACING y FROM z)", + exprOverlay( + value = v("x"), + placing = v("y"), + from = v("z"), + forLength = null + ) + ), + expect( + "OVERLAY(x PLACING y FROM z FOR n)", + exprOverlay( + value = v("x"), + placing = v("y"), + from = v("z"), + forLength = v("n") + ) + ), + expect( + "EXTRACT(MINUTE FROM x)", + exprExtract( + field = DatetimeField.MINUTE(), source = v("x") - } - }, - expect("CAST(x AS INT)") { - exprCast { - value = v("x") - asType = typeInt() - } - }, - expect("DATE_ADD(MINUTE, x, y)") { - exprDateAdd { - field = DatetimeField.MINUTE - lhs = v("x") - rhs = v("y") - } - }, - expect("DATE_DIFF(MINUTE, x, y)") { - exprDateDiff { - field = DatetimeField.MINUTE - lhs = v("x") - rhs = v("y") - } - }, - expect("x OUTER UNION y") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.UNION + ) + ), + expect( + "CAST(x AS INT)", + exprCast( + value = v("x"), + asType = DataType.INT() + ) + ), + expect( + "DATE_ADD(MINUTE, x, y)", + exprCall( + function = idChain(id("DATE_ADD")), + args = listOf( + exprLit(stringValue("MINUTE")), + v("x"), + v("y") + ), + setq = null + ) + ), + expect( + "DATE_DIFF(MINUTE, x, y)", + exprCall( + function = idChain(id("DATE_DIFF")), + args = listOf( + exprLit(stringValue("MINUTE")), + v("x"), + v("y") + ), + setq = null + ) + ), + expect( + "x OUTER UNION y", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.UNION(), setq = null - } - isOuter = true - lhs = v("x") + ), + isOuter = true, + lhs = v("x"), rhs = v("y") - } - } - }, - expect("x OUTER UNION ALL y") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.UNION - setq = SetQuantifier.ALL - } - isOuter = true - lhs = v("x") + ), + ) + ), + expect( + "x OUTER UNION ALL y", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.UNION(), + setq = SetQuantifier.ALL() + ), + isOuter = true, + lhs = v("x"), rhs = v("y") - } - } - }, - expect("x OUTER UNION y") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.UNION + ), + ) + ), + expect( + "x OUTER UNION y", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.UNION(), setq = null - } - isOuter = true - lhs = v("x") + ), + isOuter = true, + lhs = v("x"), rhs = v("y") - } - } - }, - expect("x OUTER UNION ALL y") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.UNION - setq = SetQuantifier.ALL - } - isOuter = true - lhs = v("x") + ), + ) + ), + expect( + "x OUTER UNION ALL y", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.UNION(), + setq = SetQuantifier.ALL() + ), + isOuter = true, + lhs = v("x"), rhs = v("y") - } - } - }, - expect("(x UNION y) UNION z") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.UNION + ), + ) + ), + expect( + "(x UNION y) UNION z", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.UNION(), setq = null - } - isOuter = false - lhs = exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.UNION + ), + isOuter = false, + lhs = qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.UNION(), setq = null - } - isOuter = false - lhs = v("x") + ), + isOuter = false, + lhs = v("x"), rhs = v("y") - } - } - rhs = v("z") - } - } - }, - expect("x UNION (y UNION z)") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.UNION + ), + ), + rhs = v("z"), + ), + ) + ), + expect( + "x UNION (y UNION z)", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.UNION(), setq = null - } - isOuter = false - lhs = v("x") - rhs = exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.UNION + ), + isOuter = false, + lhs = v("x"), + rhs = qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.UNION(), setq = null - } - isOuter = false - lhs = v("y") - rhs = v("z") - } - } - } - } - }, - expect("(x EXCEPT y) EXCEPT z") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.EXCEPT + ), + isOuter = false, + lhs = v("y"), + rhs = v("z"), + ), + ) + ), + ) + ), + expect( + "(x EXCEPT y) EXCEPT z", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.EXCEPT(), setq = null - } - isOuter = false - lhs = exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.EXCEPT + ), + isOuter = false, + lhs = qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.EXCEPT(), setq = null - } - isOuter = false - lhs = v("x") + ), + isOuter = false, + lhs = v("x"), rhs = v("y") - } - rhs = v("z") - } - } - } - }, - expect("x EXCEPT (y EXCEPT z)") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.EXCEPT + ), + ), + rhs = v("z") + ), + ) + ), + expect( + "x EXCEPT (y EXCEPT z)", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.EXCEPT(), setq = null - } - isOuter = false - lhs = v("x") - rhs = exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.EXCEPT + ), + isOuter = false, + lhs = v("x"), + rhs = qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.EXCEPT(), setq = null - } - isOuter = false - lhs = v("y") + ), + isOuter = false, + lhs = v("y"), rhs = v("z") - } - } - } - } - }, - expect("(x INTERSECT y) INTERSECT z") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.INTERSECT + ), + ) + ), + ) + ), + expect( + "(x INTERSECT y) INTERSECT z", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.INTERSECT(), setq = null - } - isOuter = false - lhs = exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.INTERSECT + ), + isOuter = false, + lhs = qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.INTERSECT(), setq = null - } - isOuter = false - lhs = v("x") + ), + isOuter = false, + lhs = v("x"), rhs = v("y") - } - } + ), + ), rhs = v("z") - } - } - }, - expect("x INTERSECT (y INTERSECT z)") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.INTERSECT + ), + ) + ), + expect( + "x INTERSECT (y INTERSECT z)", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.INTERSECT(), setq = null - } - isOuter = false - lhs = v("x") - rhs = exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.INTERSECT + ), + isOuter = false, + lhs = v("x"), + rhs = qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.INTERSECT(), setq = null - } - isOuter = false - lhs = v("y") + ), + isOuter = false, + lhs = v("y"), rhs = v("z") - } - } - } - } - }, + ), + ) + ), + ) + ), ) @JvmStatic fun exprCaseCases() = listOf( - expect("CASE WHEN a THEN x WHEN b THEN y END") { - exprCase { - branches += exprCaseBranch(v("a"), v("x")) - branches += exprCaseBranch(v("b"), v("y")) - } - }, - expect("CASE z WHEN a THEN x WHEN b THEN y END") { - exprCase { - expr = v("z") - branches += exprCaseBranch(v("a"), v("x")) - branches += exprCaseBranch(v("b"), v("y")) - } - }, - expect("CASE z WHEN a THEN x ELSE y END") { - exprCase { - expr = v("z") - branches += exprCaseBranch(v("a"), v("x")) - default = v("y") - } - }, + expect( + "CASE WHEN a THEN x WHEN b THEN y END", + exprCase( + expr = null, + branches = listOf( + exprCaseBranch(v("a"), v("x")), + exprCaseBranch(v("b"), v("y")) + ), + defaultExpr = null + ) + ), + expect( + "CASE z WHEN a THEN x WHEN b THEN y END", + exprCase( + expr = v("z"), + branches = listOf( + exprCaseBranch(v("a"), v("x")), + exprCaseBranch(v("b"), v("y")) + ), + defaultExpr = null + ) + ), + expect( + "CASE z WHEN a THEN x ELSE y END", + exprCase( + expr = v("z"), + branches = listOf( + exprCaseBranch(v("a"), v("x")) + ), + defaultExpr = v("y") + ) + ), ) @JvmStatic fun selectClauseCases() = listOf( - expect("SELECT a FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectProject { - items += selectProjectItemExpression(v("a")) - } - from = table("T") - } - } - }, - expect("SELECT a AS x FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectProject { - items += selectProjectItemExpression(v("a"), id("x")) - } - from = table("T") - } - } - }, - expect("SELECT a AS x, b AS y FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectProject { - items += selectProjectItemExpression(v("a"), id("x")) - items += selectProjectItemExpression(v("b"), id("y")) - } + expect( + "SELECT a FROM T", + qSet( + body = sfw( + select = selectList( + items = listOf( + selectItemExpr(v("a"), asAlias = null) + ), + setq = null + ), + from = table("T"), + ), + ) + ), + expect( + "SELECT a AS x FROM T", + qSet( + body = sfw( + select = selectList( + items = listOf(selectItemExpr(v("a"), id("x"))), + setq = null + ), + from = table("T"), + ), + ) + ), + expect( + "SELECT a AS x, b AS y FROM T", + qSet( + body = sfw( + select = selectList( + items = listOf( + selectItemExpr(v("a"), id("x")), + selectItemExpr(v("b"), id("y")) + ), + setq = null + ), from = table("T") - } - } - }, - expect("SELECT ALL a FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectProject { - setq = SetQuantifier.ALL - items += selectProjectItemExpression(v("a")) - } + ), + ) + ), + expect( + "SELECT ALL a FROM T", + qSet( + body = sfw( + select = selectList( + items = listOf(selectItemExpr(v("a"), asAlias = null)), + setq = SetQuantifier.ALL(), + ), from = table("T") - } - } - }, - expect("SELECT DISTINCT a FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectProject { - setq = SetQuantifier.DISTINCT - items += selectProjectItemExpression(v("a")) - } + ) + ) + ), + expect( + "SELECT DISTINCT a FROM T", + qSet( + body = sfw( + select = selectList( + setq = SetQuantifier.DISTINCT(), + items = listOf( + selectItemExpr(v("a"), asAlias = null) + ) + ), from = table("T") - } - } - }, - expect("SELECT a.* FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectProject { - items += selectProjectItemAll(v("a")) - } + ) + ) + ), + expect( + "SELECT a.* FROM T", + qSet( + body = sfw( + select = selectList( + items = listOf(selectItemStar(v("a"))), + setq = null + ), from = table("T") - } - } - }, - expect("SELECT * FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectStar() + ) + ) + ), + expect( + "SELECT * FROM T", + qSet( + body = sfw( + select = selectStar(setq = null), from = table("T") - } - } - }, - expect("SELECT DISTINCT * FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectStar(SetQuantifier.DISTINCT) + ) + ) + ), + expect( + "SELECT DISTINCT * FROM T", + qSet( + body = sfw( + select = selectStar(SetQuantifier.DISTINCT()), from = table("T") - } - } - }, - expect("SELECT ALL * FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectStar(SetQuantifier.ALL) + ) + ) + ), + expect( + "SELECT ALL * FROM T", + qSet( + body = sfw( + select = selectStar(SetQuantifier.ALL()), from = table("T") - } - } - }, - expect("SELECT VALUE a FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectValue { - constructor = v("a") - } + ) + ) + ), + expect( + "SELECT VALUE a FROM T", + qSet( + body = sfw( + select = selectValue( + constructor = v("a"), + setq = null + ), from = table("T") - } - } - }, - expect("SELECT ALL VALUE a FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectValue { - setq = SetQuantifier.ALL + ) + ) + ), + expect( + "SELECT ALL VALUE a FROM T", + qSet( + body = sfw( + select = selectValue( + setq = SetQuantifier.ALL(), constructor = v("a") - } + ), from = table("T") - } - } - }, - expect("SELECT DISTINCT VALUE a FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectValue { - setq = SetQuantifier.DISTINCT + ) + ) + ), + expect( + "SELECT DISTINCT VALUE a FROM T", + qSet( + body = sfw( + select = selectValue( + setq = SetQuantifier.DISTINCT(), constructor = v("a") - } + ), from = table("T") - } - } - }, - expect("PIVOT a AT b FROM T") { - exprQuerySet { - body = queryBodySFW { - select = selectPivot(v("a"), v("b")) + ) + ) + ), + expect( + "PIVOT a AT b FROM T", + qSet( + body = sfw( + select = selectPivot(v("a"), v("b")), from = table("T") - } - } - }, + ) + ) + ), ) @JvmStatic fun excludeClauseCases() = listOf( - expect("SELECT a EXCLUDE t.a FROM T") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.SCAN - } - exclude = exclude { - items += excludeItem { - root = v("t") - steps += insensitiveExcludeStructField("a") - } - } - } - } - }, - expect("SELECT a EXCLUDE a.b, c.d, e.f, g.h FROM T") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.SCAN - } - exclude = exclude { - items += excludeItem { - root = v("a") - steps += insensitiveExcludeStructField("b") - } - items += excludeItem { - root = v("c") - steps += insensitiveExcludeStructField("d") - } - items += excludeItem { - root = v("e") - steps += insensitiveExcludeStructField("f") - } - items += excludeItem { - root = v("g") - steps += insensitiveExcludeStructField("h") - } - } - } - } - }, - expect("SELECT a EXCLUDE t.a.\"b\".*[*].c, \"s\"[0].d.\"e\"[*].f.* FROM T") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.SCAN - } - exclude = exclude { - items += excludeItem { - root = v("t") - steps += mutableListOf( - insensitiveExcludeStructField("a"), - sensitiveExcludeStructField("b"), - excludeStepStructWildcard(), - excludeStepCollWildcard(), - insensitiveExcludeStructField("c"), + expect( + "SELECT a EXCLUDE t.a FROM T", + qSet( + body = sfw( + select = select("a"), + from = from( + listOf( + fromExpr( + expr = v("T"), + fromType = FromType.SCAN(), + asAlias = null, + atAlias = null ) - } - items += excludeItem { - root = exprVar(id("s", Identifier.CaseSensitivity.SENSITIVE), Expr.Var.Scope.DEFAULT) - steps += mutableListOf( - excludeStepCollIndex(0), - insensitiveExcludeStructField("d"), - sensitiveExcludeStructField("e"), - excludeStepCollWildcard(), - insensitiveExcludeStructField("f"), - excludeStepStructWildcard(), + ) + ), + exclude = exclude( + excludePaths = listOf( + excludePath( + varRef = v("t"), + excludeSteps = listOf(insensitiveExcludeStructField("a")) ) - } - } - } - } - }, + ) + ) + ) + ) + ), + expect( + "SELECT a EXCLUDE a.b, c.d, e.f, g.h FROM T", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromExpr( + expr = v("T"), + fromType = FromType.SCAN(), + asAlias = null, + atAlias = null + ) + ) + ), + exclude = exclude( + excludePaths = listOf( + excludePath( + varRef = v("a"), + excludeSteps = listOf(insensitiveExcludeStructField("b")) + ), + excludePath( + varRef = v("c"), + excludeSteps = listOf(insensitiveExcludeStructField("d")) + ), + excludePath( + varRef = v("e"), + excludeSteps = listOf(insensitiveExcludeStructField("f")) + ), + excludePath( + varRef = v("g"), + excludeSteps = listOf(insensitiveExcludeStructField("h")) + ) + ) + ) + ) + ) + ), + expect( + "SELECT a EXCLUDE t.a.\"b\".*[*].c, \"s\"[0].d.\"e\"[*].f.* FROM T", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromExpr( + expr = v("T"), + fromType = FromType.SCAN(), + asAlias = null, + atAlias = null + ) + ) + ), + exclude = exclude( + excludePaths = listOf( + excludePath( + varRef = v("t"), + excludeSteps = listOf( + insensitiveExcludeStructField("a"), + sensitiveExcludeStructField("b"), + excludeStepStructWildcard(), + excludeStepCollWildcard(), + insensitiveExcludeStructField("c"), + ) + ), + excludePath( + varRef = exprVarRef(idChain(id("s", isDelimited = true)), Scope.DEFAULT()), + excludeSteps = listOf( + excludeStepCollIndex(0), + insensitiveExcludeStructField("d"), + sensitiveExcludeStructField("e"), + excludeStepCollWildcard(), + insensitiveExcludeStructField("f"), + excludeStepStructWildcard(), + ) + ) + ) + ) + ) + ) + ), ) - private fun AstBuilder.insensitiveExcludeStructField(str: String) = excludeStepStructField { - symbol = id(str, Identifier.CaseSensitivity.INSENSITIVE) - } + private fun insensitiveExcludeStructField(str: String) = excludeStepStructField( + symbol = id(str, isDelimited = false) + ) - private fun AstBuilder.sensitiveExcludeStructField(str: String) = excludeStepStructField { - symbol = id(str, Identifier.CaseSensitivity.SENSITIVE) - } + private fun sensitiveExcludeStructField(str: String) = excludeStepStructField( + symbol = id(str, isDelimited = true) + ) @JvmStatic fun fromClauseCases() = listOf( - expect("SELECT a FROM T") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.SCAN - } - } - } - }, - expect("SELECT a FROM T AS x") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.SCAN - asAlias = id("x") - } - } - } - }, - expect("SELECT a FROM T AS x AT y") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.SCAN - asAlias = id("x") - atAlias = id("y") - } - } - } - }, - expect("SELECT a FROM T AS x AT y BY z") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.SCAN - asAlias = id("x") - atAlias = id("y") - byAlias = id("z") - } - } - } - }, - expect("SELECT a FROM UNPIVOT T") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.UNPIVOT - } - } - } - }, - expect("SELECT a FROM UNPIVOT T AS x") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.UNPIVOT - asAlias = id("x") - } - } - } - }, - expect("SELECT a FROM UNPIVOT T AS x AT y") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.UNPIVOT - asAlias = id("x") - atAlias = id("y") - } - } - } - }, - expect("SELECT a FROM UNPIVOT T AS x AT y BY z") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromValue { - expr = v("T") - type = From.Value.Type.UNPIVOT - asAlias = id("x") - atAlias = id("y") - byAlias = id("z") - } - } - } - }, + expect( + "SELECT a FROM T", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromExpr( + expr = v("T"), + fromType = FromType.SCAN(), + asAlias = null, + atAlias = null + ) + ) + ) + ) + ) + ), + expect( + "SELECT a FROM T AS x", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromExpr( + expr = v("T"), + fromType = FromType.SCAN(), + asAlias = id("x"), + atAlias = null + ) + ) + ) + ) + ) + ), + expect( + "SELECT a FROM T AS x AT y", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromExpr( + expr = v("T"), + fromType = FromType.SCAN(), + asAlias = id("x"), + atAlias = id("y") + ) + ) + ) + ) + ) + ), + expect( + "SELECT a FROM UNPIVOT T", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromExpr( + expr = v("T"), + fromType = FromType.UNPIVOT(), + asAlias = null, + atAlias = null + ) + ) + ) + ) + ) + ), + expect( + "SELECT a FROM UNPIVOT T AS x", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromExpr( + expr = v("T"), + fromType = FromType.UNPIVOT(), + asAlias = id("x"), + atAlias = null + ) + ) + ) + ) + ) + ), + expect( + "SELECT a FROM UNPIVOT T AS x AT y", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromExpr( + expr = v("T"), + fromType = FromType.UNPIVOT(), + asAlias = id("x"), + atAlias = id("y") + ) + ) + ) + ) + ) + ), ) @JvmStatic fun joinClauseCases() = listOf( - expect("SELECT a FROM T JOIN S") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromJoin { - lhs = table("T") - rhs = table("S") - } - } - } - }, - expect("SELECT a FROM T INNER JOIN S") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromJoin { - type = From.Join.Type.INNER - lhs = table("T") - rhs = table("S") - } - } - } - }, - // expect("SELECT a FROM T, S") { - // exprSFW { - // select = select("a") - // from = fromJoin { - // type = From.Join.Type.FULL - // lhs = table("T") - // rhs = table("S") - // } - // } - // }, - // expect("SELECT a FROM T CROSS JOIN S") { - // exprSFW { - // select = select("a") - // from = fromJoin { - // type = From.Join.Type.FULL - // lhs = table("T") - // rhs = table("S") - // } - // } - // }, - expect("SELECT a FROM T JOIN S ON NULL") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromJoin { - lhs = table("T") - rhs = table("S") - condition = NULL - } - } - } - }, - expect("SELECT a FROM T INNER JOIN S ON NULL") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = fromJoin { - type = From.Join.Type.INNER - lhs = table("T") - rhs = table("S") - condition = NULL - } - } - } - }, + expect( + "SELECT a FROM T JOIN S", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromJoin( + lhs = scan("T"), + rhs = scan("S"), + joinType = null, + condition = null + ) + ) + ) + ) + ) + ), + expect( + "SELECT a FROM T INNER JOIN S", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromJoin( + joinType = JoinType.INNER(), + lhs = scan("T"), + rhs = scan("S"), + condition = null + ) + ) + ) + ) + ) + ), + expect( + "SELECT a FROM T, S", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromExpr( + expr = v("T"), + fromType = FromType.SCAN(), + asAlias = null, + atAlias = null + ), + fromExpr( + expr = v("S"), + fromType = FromType.SCAN(), + asAlias = null, + atAlias = null + ) + ) + ) + ) + ) + ), + expect( + "SELECT a FROM T CROSS JOIN S", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromJoin( + joinType = JoinType.CROSS(), + lhs = scan("T"), + rhs = scan("S"), + condition = null + ) + ) + ) + ) + + ) + ), + expect( + "SELECT a FROM T JOIN S ON NULL", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromJoin( + lhs = scan("T"), + rhs = scan("S"), + joinType = null, + condition = NULL + ) + ) + ) + ) + ) + ), + expect( + "SELECT a FROM T INNER JOIN S ON NULL", + qSet( + body = sfw( + select = select("a"), + from = from( + tableRefs = listOf( + fromJoin( + joinType = JoinType.INNER(), + lhs = scan("T"), + rhs = scan("S"), + condition = NULL + ) + ) + ) + ) + ) + ), ) // These are simple clauses @JvmStatic private fun otherClausesCases() = listOf( - expect("SELECT a FROM T LET x AS i") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - let = let(mutableListOf()) { - bindings += letBinding(v("x"), id("i")) - } - } - } - }, - expect("SELECT a FROM T LET x AS i, y AS j") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - let = let(mutableListOf()) { - bindings += letBinding(v("x"), id("i")) - bindings += letBinding(v("y"), id("j")) - } - } - } - }, - expect("SELECT a FROM T WHERE x") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") + expect( + "SELECT a FROM T LET x AS i", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + let = Ast.let( + bindings = listOf(letBinding(v("x"), id("i"))) + ) + ) + ) + ), + expect( + "SELECT a FROM T LET x AS i, y AS j", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + let = Ast.let( + bindings = listOf( + letBinding(v("x"), id("i")), + letBinding(v("y"), id("j")) + ) + ) + ) + ) + ), + expect( + "SELECT a FROM T WHERE x", + qSet( + body = sfw( + select = select("a"), + from = table("T"), where = v("x") - } - } - }, - expect("SELECT a FROM T LIMIT 1") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ) + ), + expect( + "SELECT a FROM T LIMIT 1", + qSet( + body = sfw( + select = select("a"), from = table("T") - } + ), limit = exprLit(int32Value(1)) - } - }, - expect("SELECT a FROM T OFFSET 2") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ), + expect( + "SELECT a FROM T OFFSET 2", + qSet( + body = sfw( + select = select("a"), from = table("T") - } + ), offset = exprLit(int32Value(2)) - } - }, - expect("SELECT a FROM T LIMIT 1 OFFSET 2") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ), + expect( + "SELECT a FROM T LIMIT 1 OFFSET 2", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - limit = exprLit(int32Value(1)) + ), + limit = exprLit(int32Value(1)), offset = exprLit(int32Value(2)) - } - }, - expect("SELECT a FROM T GROUP BY x HAVING y") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - groupBy = groupBy { - strategy = GroupBy.Strategy.FULL - keys += groupByKey(v("x")) - } + ) + ), + expect( + "SELECT a FROM T GROUP BY x HAVING y", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + groupBy = groupBy( + strategy = GroupByStrategy.FULL(), + keys = listOf(groupByKey(v("x"), asAlias = null)), + asAlias = null + ), having = v("y") - } - } - }, + ) + ) + ), ) @JvmStatic private fun groupByClauseCases() = listOf( - expect("SELECT a FROM T GROUP BY x") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - groupBy = groupBy { - strategy = GroupBy.Strategy.FULL - keys += groupByKey(v("x")) - } - } - } - }, - expect("SELECT a FROM T GROUP BY x AS i") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - groupBy = groupBy { - strategy = GroupBy.Strategy.FULL - keys += groupByKey(v("x"), id("i")) - } - } - } - }, - expect("SELECT a FROM T GROUP BY x, y") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - groupBy = groupBy { - strategy = GroupBy.Strategy.FULL - keys += groupByKey(v("x")) - keys += groupByKey(v("y")) - } - } - } - }, - expect("SELECT a FROM T GROUP BY x AS i, y AS j") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - groupBy = groupBy { - strategy = GroupBy.Strategy.FULL - keys += groupByKey(v("x"), id("i")) - keys += groupByKey(v("y"), id("j")) - } - } - } - }, - expect("SELECT a FROM T GROUP BY x GROUP AS g") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - groupBy = groupBy { - strategy = GroupBy.Strategy.FULL - keys += groupByKey(v("x")) + expect( + "SELECT a FROM T GROUP BY x", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + groupBy = groupBy( + strategy = GroupByStrategy.FULL(), + keys = listOf(groupByKey(v("x"), asAlias = null)), + asAlias = null + ) + ) + ) + ), + expect( + "SELECT a FROM T GROUP BY x AS i", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + groupBy = groupBy( + strategy = GroupByStrategy.FULL(), + keys = listOf(groupByKey(v("x"), id("i"))), + asAlias = null + ) + ) + ) + ), + expect( + "SELECT a FROM T GROUP BY x, y", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + groupBy = groupBy( + strategy = GroupByStrategy.FULL(), + keys = listOf( + groupByKey(v("x"), asAlias = null), + groupByKey(v("y"), asAlias = null) + ), + asAlias = null + ) + ) + ) + ), + expect( + "SELECT a FROM T GROUP BY x AS i, y AS j", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + groupBy = groupBy( + strategy = GroupByStrategy.FULL(), + keys = listOf( + groupByKey(v("x"), id("i")), + groupByKey(v("y"), id("j")) + ), + asAlias = null + ) + ) + ) + ), + expect( + "SELECT a FROM T GROUP BY x GROUP AS g", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + groupBy = groupBy( + strategy = GroupByStrategy.FULL(), + keys = listOf(groupByKey(v("x"), asAlias = null)), asAlias = id("g") - } - } - } - }, - expect("SELECT a FROM T GROUP BY x AS i GROUP AS g") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - groupBy = groupBy { - strategy = GroupBy.Strategy.FULL - keys += groupByKey(v("x"), id("i")) + ) + ) + ) + ), + expect( + "SELECT a FROM T GROUP BY x AS i GROUP AS g", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + groupBy = groupBy( + strategy = GroupByStrategy.FULL(), + keys = listOf(groupByKey(v("x"), id("i"))), asAlias = id("g") - } - } - } - }, - expect("SELECT a FROM T GROUP BY x, y GROUP AS g") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - groupBy = groupBy { - strategy = GroupBy.Strategy.FULL - keys += groupByKey(v("x")) - keys += groupByKey(v("y")) + ) + ) + ) + ), + expect( + "SELECT a FROM T GROUP BY x, y GROUP AS g", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + groupBy = groupBy( + strategy = GroupByStrategy.FULL(), + keys = listOf( + groupByKey(v("x"), asAlias = null), + groupByKey(v("y"), asAlias = null) + ), asAlias = id("g") - } - } - } - }, - expect("SELECT a FROM T GROUP BY x AS i, y AS j GROUP AS g") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - groupBy = groupBy { - strategy = GroupBy.Strategy.FULL - keys += groupByKey(v("x"), id("i")) - keys += groupByKey(v("y"), id("j")) + ) + ) + ) + ), + expect( + "SELECT a FROM T GROUP BY x AS i, y AS j GROUP AS g", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + groupBy = groupBy( + strategy = GroupByStrategy.FULL(), + keys = listOf( + groupByKey(v("x"), id("i")), + groupByKey(v("y"), id("j")) + ), asAlias = id("g") - } - } - } - }, - expect("SELECT a FROM T GROUP PARTIAL BY x") { - exprQuerySet { - body = queryBodySFW { - select = select("a") - from = table("T") - groupBy = groupBy { - strategy = GroupBy.Strategy.PARTIAL - keys += groupByKey(v("x")) - } - } - } - }, + ) + ) + ) + ), + expect( + "SELECT a FROM T GROUP PARTIAL BY x", + qSet( + body = sfw( + select = select("a"), + from = table("T"), + groupBy = groupBy( + strategy = GroupByStrategy.PARTIAL(), + keys = listOf(groupByKey(v("x"), asAlias = null)), + asAlias = null + ) + ) + ) + ), ) @JvmStatic private fun orderByClauseCases() = listOf( - expect("SELECT a FROM T ORDER BY x") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + expect( + "SELECT a FROM T ORDER BY x", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), null, null) - } - } - }, - expect("SELECT a FROM T ORDER BY x ASC") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), order = null, nulls = null)) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x ASC", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), Sort.Dir.ASC, null) - } - } - }, - expect("SELECT a FROM T ORDER BY x DESC") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), Order.ASC(), nulls = null)) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x DESC", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), Sort.Dir.DESC, null) - } - } - }, - expect("SELECT a FROM T ORDER BY x NULLS FIRST") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), Order.DESC(), nulls = null)) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x NULLS FIRST", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), null, Sort.Nulls.FIRST) - } - } - }, - expect("SELECT a FROM T ORDER BY x NULLS LAST") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), order = null, nulls = Nulls.FIRST())) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x NULLS LAST", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), null, Sort.Nulls.LAST) - } - } - }, - expect("SELECT a FROM T ORDER BY x ASC NULLS FIRST") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), order = null, nulls = Nulls.LAST())) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x ASC NULLS FIRST", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), Sort.Dir.ASC, Sort.Nulls.FIRST) - } - } - }, - expect("SELECT a FROM T ORDER BY x ASC NULLS LAST") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), Order.ASC(), Nulls.FIRST())) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x ASC NULLS LAST", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), Sort.Dir.ASC, Sort.Nulls.LAST) - } - } - }, - expect("SELECT a FROM T ORDER BY x DESC NULLS FIRST") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), Order.ASC(), Nulls.LAST())) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x DESC NULLS FIRST", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), Sort.Dir.DESC, Sort.Nulls.FIRST) - } - } - }, - expect("SELECT a FROM T ORDER BY x DESC NULLS LAST") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), Order.DESC(), Nulls.FIRST())) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x DESC NULLS LAST", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), Sort.Dir.DESC, Sort.Nulls.LAST) - } - } - }, - expect("SELECT a FROM T ORDER BY x, y") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), Order.DESC(), Nulls.LAST())) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x, y", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), null, null) - sorts += sort(v("y"), null, null) - } - } - }, - expect("SELECT a FROM T ORDER BY x ASC, y DESC") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf( + sort(v("x"), order = null, nulls = null), + sort(v("y"), order = null, nulls = null) + ) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x ASC, y DESC", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), Sort.Dir.ASC, null) - sorts += sort(v("y"), Sort.Dir.DESC, null) - } - } - }, - expect("SELECT a FROM T ORDER BY x NULLS FIRST, y NULLS LAST") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf( + sort(v("x"), Order.ASC(), nulls = null), + sort(v("y"), Order.DESC(), nulls = null) + ) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x NULLS FIRST, y NULLS LAST", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), null, Sort.Nulls.FIRST) - sorts += sort(v("y"), null, Sort.Nulls.LAST) - } - } - }, - expect("SELECT a FROM T ORDER BY x ASC NULLS FIRST, y DESC NULLS LAST") { - exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + orderBy = orderBy( + sorts = listOf( + sort(v("x"), order = null, Nulls.FIRST()), + sort(v("y"), order = null, Nulls.LAST()) + ) + ) + ) + ), + expect( + "SELECT a FROM T ORDER BY x ASC NULLS FIRST, y DESC NULLS LAST", + qSet( + body = sfw( + select = select("a"), from = table("T") - } - orderBy = orderBy { - sorts += sort(v("x"), Sort.Dir.ASC, Sort.Nulls.FIRST) - sorts += sort(v("y"), Sort.Dir.DESC, Sort.Nulls.LAST) - } - } - }, + ), + orderBy = orderBy( + sorts = listOf( + sort(v("x"), Order.ASC(), Nulls.FIRST()), + sort(v("y"), Order.DESC(), Nulls.LAST()) + ) + ) + ) + ), ) @JvmStatic fun unionClauseCases() = listOf( - expect("(SELECT a FROM T) UNION (SELECT b FROM S)") { - exprQuerySet { - body = queryBodySetOp { - type = setOp { - type = SetOp.Type.UNION + expect( + "(SELECT a FROM T) UNION (SELECT b FROM S)", + qSet( + body = queryBodySetOp( + type = setOp( + setOpType = SetOpType.UNION(), setq = null - } - isOuter = false - lhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + ), + isOuter = false, + lhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("b") + ) + ), + rhs = qSet( + body = sfw( + select = select("b"), from = table("S") - } - } - } - } - }, - expect("(SELECT a FROM T) UNION ALL (SELECT b FROM S)") { - exprQuerySet { - body = queryBodySetOp { - type = setOp(SetOp.Type.UNION, SetQuantifier.ALL) - isOuter = false - lhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ) + ) + ) + ), + expect( + "(SELECT a FROM T) UNION ALL (SELECT b FROM S)", + qSet( + body = queryBodySetOp( + type = setOp(SetOpType.UNION(), SetQuantifier.ALL()), + isOuter = false, + lhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("b") + ) + ), + rhs = qSet( + body = sfw( + select = select("b"), from = table("S") - } - } - } - } - }, - expect("(SELECT a FROM T) UNION DISTINCT (SELECT b FROM S)") { - exprQuerySet { - body = queryBodySetOp { - type = setOp(SetOp.Type.UNION, SetQuantifier.DISTINCT) - isOuter = false - lhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ) + ) + ) + ), + expect( + "(SELECT a FROM T) UNION DISTINCT (SELECT b FROM S)", + qSet( + body = queryBodySetOp( + type = setOp(SetOpType.UNION(), SetQuantifier.DISTINCT()), + isOuter = false, + lhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("b") + ) + ), + rhs = qSet( + body = sfw( + select = select("b"), from = table("S") - } - } - } - } - }, - expect("(SELECT a FROM T) UNION (SELECT b FROM S) LIMIT 1") { - exprQuerySet { - body = queryBodySetOp { - type = setOp(SetOp.Type.UNION, null) - isOuter = false - lhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ) + ) + ) + ), + expect( + "(SELECT a FROM T) UNION (SELECT b FROM S) LIMIT 1", + qSet( + body = queryBodySetOp( + type = setOp(SetOpType.UNION(), setq = null), + isOuter = false, + lhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("b") + ) + ), + rhs = qSet( + body = sfw( + select = select("b"), from = table("S") - } - } - } + ) + ) + ), limit = exprLit(int32Value(1)) // LIMIT associated with SQL set op - } - }, - expect("(SELECT a FROM T) UNION (SELECT b FROM S LIMIT 1)") { - exprQuerySet { - body = queryBodySetOp { - type = setOp(SetOp.Type.UNION, null) - isOuter = false - lhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ), + expect( + "(SELECT a FROM T) UNION (SELECT b FROM S LIMIT 1)", + qSet( + body = queryBodySetOp( + type = setOp(SetOpType.UNION(), null), + isOuter = false, + lhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("b") - from = table("S") - limit = exprLit(int32Value(1)) // LIMIT associated with rhs SFW query - } - } - } - } - }, - expect("(SELECT a FROM T) UNION (SELECT b FROM S) ORDER BY x") { - exprQuerySet { - body = queryBodySetOp { - type = setOp(SetOp.Type.UNION, null) - isOuter = false - lhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ), + rhs = qSet( + body = sfw( + select = select("b"), + from = table("S"), + ), + limit = exprLit(int32Value(1)) // LIMIT associated with rhs SFW query + ) + ) + ) + ), + expect( + "(SELECT a FROM T) UNION (SELECT b FROM S) ORDER BY x", + qSet( + body = queryBodySetOp( + type = setOp(SetOpType.UNION(), null), + isOuter = false, + lhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("b") + ) + ), + rhs = qSet( + body = sfw( + select = select("b"), from = table("S") - } - } - } - orderBy = orderBy { - sorts += sort(v("x"), null, null) // ORDER BY associated with SQL set op - } - } - }, - expect("(SELECT a FROM T) UNION (SELECT b FROM S ORDER BY x)") { - exprQuerySet { - body = queryBodySetOp { - type = setOp(SetOp.Type.UNION, null) - isOuter = false - lhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ) + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), order = null, nulls = null)) // ORDER BY associated with SQL set op + ) + ) + ), + expect( + "(SELECT a FROM T) UNION (SELECT b FROM S ORDER BY x)", + qSet( + body = queryBodySetOp( + type = setOp(SetOpType.UNION(), null), + isOuter = false, + lhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("b") - from = table("S") - orderBy = orderBy { - sorts += sort(v("x"), null, null) // ORDER BY associated with SFW - } - } - } - } - } - }, - expect("(SELECT a FROM T) UNION ((SELECT b FROM S) UNION (SELECT c FROM R))") { - exprQuerySet { - body = queryBodySetOp { - type = setOp(SetOp.Type.UNION, null) - isOuter = false - lhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ), + rhs = qSet( + body = sfw( + select = select("b"), + from = table("S"), + ), + orderBy = orderBy( + sorts = listOf(sort(v("x"), order = null, nulls = null)) // ORDER BY associated with SFW + ) + ), + ) + ) + ), + expect( + "(SELECT a FROM T) UNION ((SELECT b FROM S) UNION (SELECT c FROM R))", + qSet( + body = queryBodySetOp( + type = setOp(SetOpType.UNION(), null), + isOuter = false, + lhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - rhs = exprQuerySet { - body = queryBodySetOp { - type = setOp(SetOp.Type.UNION, null) - isOuter = false - lhs = exprQuerySet { - body = queryBodySFW { - select = select("b") + ) + ), + rhs = qSet( + body = queryBodySetOp( + type = setOp(SetOpType.UNION(), null), + isOuter = false, + lhs = qSet( + body = sfw( + select = select("b"), from = table("S") - } - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("c") + ) + ), + rhs = qSet( + body = sfw( + select = select("c"), from = table("R") - } - } - } - } - } - } - }, - expect("((SELECT a FROM T) UNION (SELECT b FROM S)) UNION (SELECT c FROM R)") { - exprQuerySet { - body = queryBodySetOp { - type = setOp(SetOp.Type.UNION, null) - isOuter = false - lhs = exprQuerySet { - body = queryBodySetOp { - type = setOp(SetOp.Type.UNION, null) - isOuter = false - lhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ) + ) + ) + ) + ) + ), + expect( + "((SELECT a FROM T) UNION (SELECT b FROM S)) UNION (SELECT c FROM R)", + qSet( + body = queryBodySetOp( + type = setOp(SetOpType.UNION(), null), + isOuter = false, + lhs = qSet( + body = queryBodySetOp( + type = setOp(SetOpType.UNION(), null), + isOuter = false, + lhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("b") + ) + ), + rhs = qSet( + body = sfw( + select = select("b"), from = table("S") - } - } - } - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("c") + ) + ) + ) + ), + rhs = qSet( + body = sfw( + select = select("c"), from = table("R") - } - } - } - } - }, + ) + ) + ) + ) + ), ) // These are simple clauses @JvmStatic private fun subqueryCases() = listOf( - expect("1 = (SELECT a FROM T)") { - exprOperator { - symbol = "=" - lhs = exprLit(int32Value(1)) - rhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + expect( + "1 = (SELECT a FROM T)", + exprOperator( + symbol = "=", + lhs = exprLit(int32Value(1)), + rhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - } - }, - expect("(1, 2) = (SELECT a FROM T)") { - exprOperator { - symbol = "=" - lhs = exprCollection { - type = Expr.Collection.Type.LIST - values += exprLit(int32Value(1)) - values += exprLit(int32Value(2)) - } - rhs = exprQuerySet { - body = queryBodySFW { - select = select("a") + ) + ) + ) + ), + expect( + "(1, 2) = (SELECT a FROM T)", + exprOperator( + symbol = "=", + lhs = exprRowValue( + values = listOf( + exprLit(int32Value(1)), + exprLit(int32Value(2)) + ) + ), + rhs = qSet( + body = sfw( + select = select("a"), from = table("T") - } - } - } - }, + ) + ) + ) + ), ) - private fun expect(expected: String, block: AstBuilder.() -> AstNode): Case { - val i = ast(block) - return Case.Success(i, expected) - } - - private fun fail(message: String, block: AstBuilder.() -> AstNode): Case { - val i = ast(block) - return Case.Fail(i, message) + private fun expect( + expected: String, + node: AstNode + ): Case { + return Case.Success(node, expected) } // DSL shorthand - private fun AstBuilder.v(symbol: String) = this.exprVar { - identifier = id(symbol) - scope = Expr.Var.Scope.DEFAULT - } + private fun v(symbol: String) = exprVarRef( + identifierChain = idChain(id(symbol)), + scope = Scope.DEFAULT() + ) - private fun AstBuilder.id( + private fun id( symbol: String, - case: Identifier.CaseSensitivity = Identifier.CaseSensitivity.INSENSITIVE, - ) = this.identifierSymbol(symbol, case) + isDelimited: Boolean = false, + ) = identifier(symbol, isDelimited) - private fun AstBuilder.select(vararg s: String) = selectProject { - s.forEach { - items += selectProjectItemExpression(v(it)) - } - } + private fun idChain( + root: Identifier, + next: IdentifierChain? = null + ) = identifierChain(root, next) - private fun AstBuilder.table(symbol: String) = fromValue { - expr = v(symbol) - type = From.Value.Type.SCAN - } + private fun select(vararg s: String) = selectList( + items = s.map { + selectItemExpr(v(it), asAlias = null) + }, + setq = null + ) + + private fun qSet(body: QueryBody, orderBy: OrderBy? = null, limit: Expr? = null, offset: Expr? = null) = exprQuerySet( + body = body, + orderBy = orderBy, + limit = limit, + offset = offset + ) + + private fun sfw(select: Select, from: From, exclude: Exclude? = null, let: Let? = null, where: Expr? = null, groupBy: GroupBy? = null, having: Expr? = null) = queryBodySFW( + select = select, + exclude = exclude, + from = from, + let = let, + where = where, + groupBy = groupBy, + having = having + ) + + private fun table(symbol: String) = from( + tableRefs = listOf( + fromExpr( + expr = v(symbol), + fromType = FromType.SCAN(), + asAlias = null, + atAlias = null + ) + ) + ) + + private fun scan(symbol: String) = fromExpr( + expr = v(symbol), + fromType = FromType.SCAN(), + asAlias = null, + atAlias = null + ) } sealed class Case {