diff --git a/lang/src/org/partiql/lang/CompilerPipeline.kt b/lang/src/org/partiql/lang/CompilerPipeline.kt index 2981fc48fe..1bbd7ded32 100644 --- a/lang/src/org/partiql/lang/CompilerPipeline.kt +++ b/lang/src/org/partiql/lang/CompilerPipeline.kt @@ -14,18 +14,27 @@ package org.partiql.lang -import com.amazon.ion.* -import org.partiql.lang.ast.* -import org.partiql.lang.eval.* -import org.partiql.lang.eval.builtins.* +import com.amazon.ion.IonSystem +import org.partiql.lang.ast.ExprNode +import org.partiql.lang.ast.toAstStatement +import org.partiql.lang.ast.toExprNode +import org.partiql.lang.eval.Bindings +import org.partiql.lang.eval.CompileOptions +import org.partiql.lang.eval.EvaluatingCompiler +import org.partiql.lang.eval.ExprFunction +import org.partiql.lang.eval.ExprValueFactory +import org.partiql.lang.eval.Expression +import org.partiql.lang.eval.ThunkReturnTypeAssertions +import org.partiql.lang.eval.builtins.createBuiltinFunctions import org.partiql.lang.eval.builtins.storedprocedure.StoredProcedure import org.partiql.lang.eval.visitors.PipelinedVisitorTransform import org.partiql.lang.eval.visitors.StaticTypeInferenceVisitorTransform import org.partiql.lang.eval.visitors.StaticTypeVisitorTransform -import org.partiql.lang.syntax.* -import org.partiql.lang.util.interruptibleFold -import org.partiql.lang.types.StaticType +import org.partiql.lang.syntax.Parser +import org.partiql.lang.syntax.SqlParser import org.partiql.lang.types.CustomType +import org.partiql.lang.types.StaticType +import org.partiql.lang.util.interruptibleFold /** * Contains all of the information needed for processing steps. @@ -98,7 +107,6 @@ interface CompilerPipeline { fun compile(query: ExprNode): Expression companion object { - /** Kotlin style builder for [CompilerPipeline]. If calling from Java instead use [builder]. */ fun build(ion: IonSystem, block: Builder.() -> Unit) = build(ExprValueFactory.standard(ion), block) @@ -119,8 +127,7 @@ interface CompilerPipeline { /** Returns an implementation of [CompilerPipeline] with all properties set to their defaults. */ @JvmStatic - fun standard(valueFactory: ExprValueFactory): CompilerPipeline = - builder(valueFactory).build() + fun standard(valueFactory: ExprValueFactory): CompilerPipeline = builder(valueFactory).build() } /** @@ -282,10 +289,7 @@ internal class CompilerPipelineImpl( return compiler.compile(queryToCompile.toExprNode(valueFactory.ion)) } - internal fun executePreProcessingSteps( - query: ExprNode, - context: StepContext - ) = preProcessingSteps.interruptibleFold(query) { currentExprNode, step -> - step(currentExprNode, context) + internal fun executePreProcessingSteps(query: ExprNode, context: StepContext) = preProcessingSteps + .interruptibleFold(query) { currentExprNode, step -> step(currentExprNode, context) } } diff --git a/lang/src/org/partiql/lang/Exceptions.kt b/lang/src/org/partiql/lang/Exceptions.kt index 8b2c2f41c8..5ad0a7cf0e 100644 --- a/lang/src/org/partiql/lang/Exceptions.kt +++ b/lang/src/org/partiql/lang/Exceptions.kt @@ -14,9 +14,10 @@ package org.partiql.lang -import org.partiql.lang.errors.* -import org.partiql.lang.errors.Property.* - +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.errors.PropertyValueMap +import org.partiql.lang.errors.UNKNOWN /** * General exception class for the interpreter. @@ -82,8 +83,8 @@ open class SqlException(override var message: String, errorCode?.getErrorMessage(propertyValueMap) ?: UNKNOWN private fun errorLocation(propertyValueMap: PropertyValueMap?): String { - val lineNo = propertyValueMap?.get(LINE_NUMBER)?.longValue() - val columnNo = propertyValueMap?.get(COLUMN_NUMBER)?.longValue() + val lineNo = propertyValueMap?.get(Property.LINE_NUMBER)?.longValue() + val columnNo = propertyValueMap?.get(Property.COLUMN_NUMBER)?.longValue() return "at line ${lineNo ?: UNKNOWN}, column ${columnNo ?: UNKNOWN}" } diff --git a/lang/src/org/partiql/lang/ast/AggregateCallSiteListMeta.kt b/lang/src/org/partiql/lang/ast/AggregateCallSiteListMeta.kt index 5c23c0dff7..35f473f046 100644 --- a/lang/src/org/partiql/lang/ast/AggregateCallSiteListMeta.kt +++ b/lang/src/org/partiql/lang/ast/AggregateCallSiteListMeta.kt @@ -14,7 +14,7 @@ package org.partiql.lang.ast -import com.amazon.ion.* +import com.amazon.ion.IonWriter import org.partiql.lang.domains.PartiqlAst /** diff --git a/lang/src/org/partiql/lang/ast/AstDeserialization.kt b/lang/src/org/partiql/lang/ast/AstDeserialization.kt index 0183bb3c4d..7e519ede91 100644 --- a/lang/src/org/partiql/lang/ast/AstDeserialization.kt +++ b/lang/src/org/partiql/lang/ast/AstDeserialization.kt @@ -14,9 +14,25 @@ package org.partiql.lang.ast -import com.amazon.ion.* +import com.amazon.ion.IonSexp +import com.amazon.ion.IonSymbol +import com.amazon.ion.IonSystem +import com.amazon.ion.IonValue +import com.amazon.ion.IonWriter import org.partiql.lang.types.CustomType -import org.partiql.lang.util.* +import org.partiql.lang.util.args +import org.partiql.lang.util.arity +import org.partiql.lang.util.asIonInt +import org.partiql.lang.util.asIonSexp +import org.partiql.lang.util.asIonStruct +import org.partiql.lang.util.asIonSymbol +import org.partiql.lang.util.checkThreadInterrupted +import org.partiql.lang.util.field +import org.partiql.lang.util.longValue +import org.partiql.lang.util.singleArgWithTag +import org.partiql.lang.util.stringValue +import org.partiql.lang.util.tagText +import org.partiql.lang.util.toListOfIonSexp /** * Deserializes an s-expression based AST. diff --git a/lang/src/org/partiql/lang/ast/AstSerialization.kt b/lang/src/org/partiql/lang/ast/AstSerialization.kt index dee9881085..35d294a887 100644 --- a/lang/src/org/partiql/lang/ast/AstSerialization.kt +++ b/lang/src/org/partiql/lang/ast/AstSerialization.kt @@ -21,7 +21,6 @@ import org.partiql.lang.util.IonWriterContext import org.partiql.lang.util.asIonSexp import org.partiql.lang.util.case import org.partiql.lang.util.checkThreadInterrupted -import kotlin.UnsupportedOperationException /** * Serializes an instance of [ExprNode] to one of the s-expression based ASTs. diff --git a/lang/src/org/partiql/lang/ast/InternalMetas.kt b/lang/src/org/partiql/lang/ast/InternalMetas.kt index 2396fb4527..14e3fc793c 100644 --- a/lang/src/org/partiql/lang/ast/InternalMetas.kt +++ b/lang/src/org/partiql/lang/ast/InternalMetas.kt @@ -14,7 +14,7 @@ package org.partiql.lang.ast -import com.amazon.ion.* +import com.amazon.ion.IonWriter /** * Base class for [Meta] implementations which are used internally by [org.partiql.lang.eval.EvaluatingCompiler] diff --git a/lang/src/org/partiql/lang/ast/IsImplictJoinMeta.kt b/lang/src/org/partiql/lang/ast/IsImplictJoinMeta.kt index 5a0cf6425f..7264433a70 100644 --- a/lang/src/org/partiql/lang/ast/IsImplictJoinMeta.kt +++ b/lang/src/org/partiql/lang/ast/IsImplictJoinMeta.kt @@ -11,15 +11,8 @@ * 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.lang.ast -import com.amazon.ion.* -import org.partiql.lang.ast.* - /** * Meta node intended to be attached to an instance of [FromSourcedJoin] to indicate that no * join condition was specified in the original query and therefore this is an implicit join. diff --git a/lang/src/org/partiql/lang/ast/IsIonLiteralMeta.kt b/lang/src/org/partiql/lang/ast/IsIonLiteralMeta.kt index 97e81efa8a..5b91be7f31 100644 --- a/lang/src/org/partiql/lang/ast/IsIonLiteralMeta.kt +++ b/lang/src/org/partiql/lang/ast/IsIonLiteralMeta.kt @@ -17,9 +17,6 @@ */ package org.partiql.lang.ast -import com.amazon.ion.* -import org.partiql.lang.ast.* - /** * Meta node intended to be attached to an instance of [Literal] to indicate that it was * designated as an `ionLiteral` in the parsed statement. diff --git a/lang/src/org/partiql/lang/ast/MemoizedMetaDeserializer.kt b/lang/src/org/partiql/lang/ast/MemoizedMetaDeserializer.kt index 498974c265..41e0927d69 100644 --- a/lang/src/org/partiql/lang/ast/MemoizedMetaDeserializer.kt +++ b/lang/src/org/partiql/lang/ast/MemoizedMetaDeserializer.kt @@ -14,7 +14,7 @@ package org.partiql.lang.ast -import com.amazon.ion.* +import com.amazon.ion.IonValue /** * Provides a common way to "deserialize" a memoized meta instance. diff --git a/lang/src/org/partiql/lang/ast/SourceLocationMeta.kt b/lang/src/org/partiql/lang/ast/SourceLocationMeta.kt index 06f6324e4c..32f1d84bf4 100644 --- a/lang/src/org/partiql/lang/ast/SourceLocationMeta.kt +++ b/lang/src/org/partiql/lang/ast/SourceLocationMeta.kt @@ -14,9 +14,13 @@ package org.partiql.lang.ast -import com.amazon.ion.* +import com.amazon.ion.IonValue +import com.amazon.ion.IonWriter import com.amazon.ionelement.api.metaOrNull -import org.partiql.lang.util.* +import org.partiql.lang.util.IonWriterContext +import org.partiql.lang.util.asIonStruct +import org.partiql.lang.util.field +import org.partiql.lang.util.longValue /** * Represents a specific location within a source file. diff --git a/lang/src/org/partiql/lang/ast/StatementToExprNode.kt b/lang/src/org/partiql/lang/ast/StatementToExprNode.kt index e8a3eda893..cb3f29ce9c 100644 --- a/lang/src/org/partiql/lang/ast/StatementToExprNode.kt +++ b/lang/src/org/partiql/lang/ast/StatementToExprNode.kt @@ -5,38 +5,26 @@ package org.partiql.lang.ast import com.amazon.ion.IonSystem import com.amazon.ionelement.api.toIonValue import org.partiql.lang.domains.PartiqlAst -import org.partiql.lang.domains.PartiqlAst.* import org.partiql.lang.types.StaticType import org.partiql.lang.util.checkThreadInterrupted import org.partiql.lang.util.toIntExact - import org.partiql.pig.runtime.SymbolPrimitive -import org.partiql.lang.ast.SetQuantifier as ExprNodeSetQuantifier // Conflicts with PartiqlAst.SetQuantifier -import org.partiql.lang.ast.ReturningMapping as ExprNodeReturningMapping // Conflicts with PartiqlAst.ReturningMapping - -// Note that IntelliJ believes the next 3 aliases are unused without the @file:Suppress("UnusedImport") above, -// however they are actually preventing naming collisions between their ExprNode and PartiqlAst counterparts so don't -// remove them! -import org.partiql.lang.ast.CaseSensitivity as ExprNodeCaseSensitivity // Conflicts with PartiqlAst.CaseSensitivity -import org.partiql.lang.ast.ScopeQualifier as ExprNodeScopeQualifier // Conflicts with PartiqlAst.ScopeQualifier -import org.partiql.lang.ast.GroupingStrategy as ExprNodeGroupingStrategy // Conflicts with PartiqlAst.GroupingStrategy - internal typealias PartiQlMetaContainer = org.partiql.lang.ast.MetaContainer internal typealias IonElementMetaContainer = com.amazon.ionelement.api.MetaContainer /** Converts a [partiql_ast.statement] to an [ExprNode], preserving all metas where possible. */ -fun Statement.toExprNode(ion: IonSystem): ExprNode = +fun PartiqlAst.Statement.toExprNode(ion: IonSystem): ExprNode = StatementTransformer(ion).transform(this) -internal fun Expr.toExprNode(ion: IonSystem): ExprNode { +internal fun PartiqlAst.Expr.toExprNode(ion: IonSystem): ExprNode { return StatementTransformer(ion).transform(this) } -internal fun SetQuantifier.toExprNodeSetQuantifier(): ExprNodeSetQuantifier = +internal fun PartiqlAst.SetQuantifier.toExprNodeSetQuantifier(): SetQuantifier = when (this) { - is SetQuantifier.All -> ExprNodeSetQuantifier.ALL - is SetQuantifier.Distinct -> ExprNodeSetQuantifier.DISTINCT + is PartiqlAst.SetQuantifier.All -> SetQuantifier.ALL + is PartiqlAst.SetQuantifier.Distinct -> SetQuantifier.DISTINCT } internal fun com.amazon.ionelement.api.MetaContainer.toPartiQlMetaContainer(): PartiQlMetaContainer { @@ -48,145 +36,143 @@ internal fun com.amazon.ionelement.api.MetaContainer.toPartiQlMetaContainer(): P partiQlMeta } - return org.partiql.lang.ast.metaContainerOf(nonLocationMetas) + return metaContainerOf(nonLocationMetas) } private class StatementTransformer(val ion: IonSystem) { - fun transform(stmt: Statement): ExprNode = + fun transform(stmt: PartiqlAst.Statement): ExprNode = when (stmt) { - is Statement.Query -> stmt.toExprNode() - is Statement.Dml -> stmt.toExprNode() - is Statement.Ddl -> stmt.toExprNode() - is Statement.Exec -> stmt.toExprNode() + is PartiqlAst.Statement.Query -> stmt.toExprNode() + is PartiqlAst.Statement.Dml -> stmt.toExprNode() + is PartiqlAst.Statement.Ddl -> stmt.toExprNode() + is PartiqlAst.Statement.Exec -> stmt.toExprNode() } - fun transform(stmt: Expr): ExprNode = + fun transform(stmt: PartiqlAst.Expr): ExprNode = stmt.toExprNode() - private fun Statement.Query.toExprNode(): ExprNode { + private fun PartiqlAst.Statement.Query.toExprNode(): ExprNode { return this.expr.toExprNode() } - private fun List.toExprNodeList(): List = + private fun List.toExprNodeList(): List = this.map { it.toExprNode() } - private fun Expr.toExprNode(): ExprNode { + private fun PartiqlAst.Expr.toExprNode(): ExprNode { checkThreadInterrupted() val metas = this.metas.toPartiQlMetaContainer() return when (this) { - is Expr.Missing -> LiteralMissing(metas) + is PartiqlAst.Expr.Missing -> LiteralMissing(metas) // https://github.com/amzn/ion-element-kotlin/issues/35, .asAnyElement() is unfortunately needed for now - is Expr.Lit -> Literal(value.asAnyElement().toIonValue(ion), metas) - is Expr.Id -> VariableReference(name.text, case.toCaseSensitivity(), qualifier.toScopeQualifier(), metas) - is Expr.Parameter -> Parameter(index.value.toInt(), metas) - is Expr.Not -> NAry(NAryOp.NOT, listOf(expr.toExprNode()), metas) - is Expr.Pos -> expr.toExprNode() - is Expr.Neg -> NAry(NAryOp.SUB, listOf(expr.toExprNode()), metas) - is Expr.Plus -> NAry(NAryOp.ADD, operands.toExprNodeList(), metas) - is Expr.Minus -> NAry(NAryOp.SUB, operands.toExprNodeList(), metas) - is Expr.Times -> NAry(NAryOp.MUL, operands.toExprNodeList(), metas) - is Expr.Divide -> NAry(NAryOp.DIV, operands.toExprNodeList(), metas) - is Expr.Modulo -> NAry(NAryOp.MOD, operands.toExprNodeList(), metas) - is Expr.Concat -> NAry(NAryOp.STRING_CONCAT, operands.toExprNodeList(), metas) - is Expr.And -> NAry(NAryOp.AND, operands.toExprNodeList(), metas) - is Expr.Or -> NAry(NAryOp.OR, operands.toExprNodeList(), metas) - is Expr.Eq -> NAry(NAryOp.EQ, operands.toExprNodeList(), metas) - is Expr.Ne -> NAry(NAryOp.NE, operands.toExprNodeList(), metas) - is Expr.Gt -> NAry(NAryOp.GT, operands.toExprNodeList(), metas) - is Expr.Gte -> NAry(NAryOp.GTE, operands.toExprNodeList(), metas) - is Expr.Lt -> NAry(NAryOp.LT, operands.toExprNodeList(), metas) - is Expr.Lte -> NAry(NAryOp.LTE, operands.toExprNodeList(), metas) - - is Expr.Union -> + is PartiqlAst.Expr.Lit -> Literal(value.asAnyElement().toIonValue(ion), metas) + is PartiqlAst.Expr.Id -> VariableReference(name.text, case.toCaseSensitivity(), qualifier.toScopeQualifier(), metas) + is PartiqlAst.Expr.Parameter -> Parameter(index.value.toInt(), metas) + is PartiqlAst.Expr.Not -> NAry(NAryOp.NOT, listOf(expr.toExprNode()), metas) + is PartiqlAst.Expr.Pos -> expr.toExprNode() + is PartiqlAst.Expr.Neg -> NAry(NAryOp.SUB, listOf(expr.toExprNode()), metas) + is PartiqlAst.Expr.Plus -> NAry(NAryOp.ADD, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Minus -> NAry(NAryOp.SUB, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Times -> NAry(NAryOp.MUL, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Divide -> NAry(NAryOp.DIV, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Modulo -> NAry(NAryOp.MOD, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Concat -> NAry(NAryOp.STRING_CONCAT, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.And -> NAry(NAryOp.AND, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Or -> NAry(NAryOp.OR, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Eq -> NAry(NAryOp.EQ, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Ne -> NAry(NAryOp.NE, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Gt -> NAry(NAryOp.GT, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Gte -> NAry(NAryOp.GTE, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Lt -> NAry(NAryOp.LT, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.Lte -> NAry(NAryOp.LTE, operands.toExprNodeList(), metas) + + is PartiqlAst.Expr.Union -> NAry( - when(setq) { - is SetQuantifier.Distinct -> NAryOp.UNION - is SetQuantifier.All -> NAryOp.UNION_ALL + when (setq) { + is PartiqlAst.SetQuantifier.Distinct -> NAryOp.UNION + is PartiqlAst.SetQuantifier.All -> NAryOp.UNION_ALL }, operands.toExprNodeList(), metas) - is Expr.Intersect -> + is PartiqlAst.Expr.Intersect -> NAry( - when(setq) { - is SetQuantifier.Distinct -> NAryOp.INTERSECT - is SetQuantifier.All -> NAryOp.INTERSECT_ALL + when (setq) { + is PartiqlAst.SetQuantifier.Distinct -> NAryOp.INTERSECT + is PartiqlAst.SetQuantifier.All -> NAryOp.INTERSECT_ALL }, operands.toExprNodeList(), metas) - is Expr.Except -> + is PartiqlAst.Expr.Except -> NAry( - when(setq) { - is SetQuantifier.Distinct -> NAryOp.EXCEPT - is SetQuantifier.All -> NAryOp.EXCEPT_ALL + when (setq) { + is PartiqlAst.SetQuantifier.Distinct -> NAryOp.EXCEPT + is PartiqlAst.SetQuantifier.All -> NAryOp.EXCEPT_ALL }, operands.toExprNodeList(), metas) - - - is Expr.Like -> NAry(NAryOp.LIKE, listOfNotNull(value.toExprNode(), pattern.toExprNode(), escape?.toExprNode()), metas) - is Expr.Between -> NAry(NAryOp.BETWEEN, listOf(value.toExprNode(), from.toExprNode(), to.toExprNode()), metas) - is Expr.InCollection -> NAry(NAryOp.IN, operands.toExprNodeList(), metas) - is Expr.IsType -> Typed(TypedOp.IS, value.toExprNode(), type.toExprNodeType(), metas) - is Expr.Cast -> Typed(TypedOp.CAST, value.toExprNode(), asType.toExprNodeType(), metas) - is Expr.CanCast -> Typed(TypedOp.CAN_CAST, value.toExprNode(), asType.toExprNodeType(), metas) - is Expr.CanLosslessCast -> Typed(TypedOp.CAN_LOSSLESS_CAST, value.toExprNode(), asType.toExprNodeType(), metas) - - is Expr.SimpleCase -> + is PartiqlAst.Expr.Like -> NAry(NAryOp.LIKE, listOfNotNull(value.toExprNode(), pattern.toExprNode(), escape?.toExprNode()), metas) + is PartiqlAst.Expr.Between -> NAry(NAryOp.BETWEEN, listOf(value.toExprNode(), from.toExprNode(), to.toExprNode()), metas) + is PartiqlAst.Expr.InCollection -> NAry(NAryOp.IN, operands.toExprNodeList(), metas) + is PartiqlAst.Expr.IsType -> Typed(TypedOp.IS, value.toExprNode(), type.toExprNodeType(), metas) + is PartiqlAst.Expr.Cast -> Typed(TypedOp.CAST, value.toExprNode(), asType.toExprNodeType(), metas) + is PartiqlAst.Expr.CanCast -> Typed(TypedOp.CAN_CAST, value.toExprNode(), asType.toExprNodeType(), metas) + is PartiqlAst.Expr.CanLosslessCast -> Typed(TypedOp.CAN_LOSSLESS_CAST, value.toExprNode(), asType.toExprNodeType(), metas) + + is PartiqlAst.Expr.SimpleCase -> SimpleCase( expr.toExprNode(), cases.pairs.map { SimpleCaseWhen(it.first.toExprNode(), it.second.toExprNode()) }, default?.toExprNode(), metas) - is Expr.SearchedCase -> + is PartiqlAst.Expr.SearchedCase -> SearchedCase( cases.pairs.map { SearchedCaseWhen(it.first.toExprNode(), it.second.toExprNode()) }, this.default?.toExprNode(), metas) - is Expr.Struct -> Struct(this.fields.map { StructField(it.first.toExprNode(), it.second.toExprNode()) }, metas) - is Expr.Bag -> Seq(SeqType.BAG, values.toExprNodeList(), metas) - is Expr.List -> Seq(SeqType.LIST, values.toExprNodeList(), metas) - is Expr.Sexp -> Seq(SeqType.SEXP, values.toExprNodeList(), metas) - is Expr.Path -> + is PartiqlAst.Expr.Struct -> Struct(this.fields.map { StructField(it.first.toExprNode(), it.second.toExprNode()) }, metas) + is PartiqlAst.Expr.Bag -> Seq(SeqType.BAG, values.toExprNodeList(), metas) + is PartiqlAst.Expr.List -> Seq(SeqType.LIST, values.toExprNodeList(), metas) + is PartiqlAst.Expr.Sexp -> Seq(SeqType.SEXP, values.toExprNodeList(), metas) + is PartiqlAst.Expr.Path -> Path( root.toExprNode(), steps.map { val componentMetas = it.metas.toPartiQlMetaContainer() when (it) { - is PathStep.PathExpr -> + is PartiqlAst.PathStep.PathExpr -> PathComponentExpr( it.index.toExprNode(), it.case.toCaseSensitivity(), componentMetas) - is PathStep.PathUnpivot -> PathComponentUnpivot(componentMetas) - is PathStep.PathWildcard -> PathComponentWildcard(componentMetas) + is PartiqlAst.PathStep.PathUnpivot -> PathComponentUnpivot(componentMetas) + is PartiqlAst.PathStep.PathWildcard -> PathComponentWildcard(componentMetas) } }, metas) - is Expr.Call -> + is PartiqlAst.Expr.Call -> NAry( NAryOp.CALL, listOf( VariableReference( funcName.text, - org.partiql.lang.ast.CaseSensitivity.INSENSITIVE, - org.partiql.lang.ast.ScopeQualifier.UNQUALIFIED, + CaseSensitivity.INSENSITIVE, + ScopeQualifier.UNQUALIFIED, emptyMetaContainer) ) + args.map { it.toExprNode() }, metas) - is Expr.CallAgg -> + is PartiqlAst.Expr.CallAgg -> CallAgg( VariableReference( funcName.text, - org.partiql.lang.ast.CaseSensitivity.INSENSITIVE, - org.partiql.lang.ast.ScopeQualifier.UNQUALIFIED, + CaseSensitivity.INSENSITIVE, + ScopeQualifier.UNQUALIFIED, funcName.metas.toPartiQlMetaContainer()), setq.toSetQuantifier(), arg.toExprNode(), metas) - is Expr.Select -> + is PartiqlAst.Expr.Select -> Select( - setQuantifier = setq?.toSetQuantifier() ?: ExprNodeSetQuantifier.ALL, + setQuantifier = setq?.toSetQuantifier() ?: SetQuantifier.ALL, projection = project.toSelectProjection(), from = from.toFromSource(), fromLet = fromLet?.toLetSource(), @@ -198,8 +184,8 @@ private class StatementTransformer(val ion: IonSystem) { offset = offset?.toExprNode(), metas = metas ) - is Expr.Date -> DateLiteral(year.value.toInt(), month.value.toInt(), day.value.toInt(), metas) - is Expr.LitTime -> + is PartiqlAst.Expr.Date -> DateLiteral(year.value.toInt(), month.value.toInt(), day.value.toInt(), metas) + is PartiqlAst.Expr.LitTime -> TimeLiteral( value.hour.value.toInt(), value.minute.value.toInt(), @@ -210,23 +196,23 @@ private class StatementTransformer(val ion: IonSystem) { value.tzMinutes?.value?.toInt(), metas ) - is Expr.NullIf -> NullIf(expr1.toExprNode(), expr2.toExprNode(), metas) - is Expr.Coalesce -> Coalesce(args.map { it.toExprNode() }, metas) + is PartiqlAst.Expr.NullIf -> NullIf(expr1.toExprNode(), expr2.toExprNode(), metas) + is PartiqlAst.Expr.Coalesce -> Coalesce(args.map { it.toExprNode() }, metas) } } - private fun Projection.toSelectProjection(): SelectProjection { + private fun PartiqlAst.Projection.toSelectProjection(): SelectProjection { val metas = this.metas.toPartiQlMetaContainer() return when (this) { - is Projection.ProjectStar -> SelectProjectionList(listOf(SelectListItemStar(metas)), metas) - is Projection.ProjectValue -> SelectProjectionValue(this.value.toExprNode(), metas) - is Projection.ProjectPivot -> SelectProjectionPivot(this.value.toExprNode(), this.key.toExprNode(), metas) - is Projection.ProjectList -> + is PartiqlAst.Projection.ProjectStar -> SelectProjectionList(listOf(SelectListItemStar(metas)), metas) + is PartiqlAst.Projection.ProjectValue -> SelectProjectionValue(this.value.toExprNode(), metas) + is PartiqlAst.Projection.ProjectPivot -> SelectProjectionPivot(this.value.toExprNode(), this.key.toExprNode(), metas) + is PartiqlAst.Projection.ProjectList -> SelectProjectionList( this.projectItems.map { when (it) { - is ProjectItem.ProjectAll -> SelectListItemProjectAll(it.expr.toExprNode()) - is ProjectItem.ProjectExpr -> + is PartiqlAst.ProjectItem.ProjectAll -> SelectListItemProjectAll(it.expr.toExprNode()) + is PartiqlAst.ProjectItem.ProjectExpr -> SelectListItemExpr( it.expr.toExprNode(), it.asAlias?.toSymbolicName()) @@ -265,15 +251,15 @@ private class StatementTransformer(val ion: IonSystem) { } } - private fun JoinType.toJoinOp(): JoinOp = + private fun PartiqlAst.JoinType.toJoinOp(): JoinOp = when (this) { - is JoinType.Inner -> JoinOp.INNER - is JoinType.Left -> JoinOp.LEFT - is JoinType.Right -> JoinOp.RIGHT - is JoinType.Full -> JoinOp.OUTER + is PartiqlAst.JoinType.Inner -> JoinOp.INNER + is PartiqlAst.JoinType.Left -> JoinOp.LEFT + is PartiqlAst.JoinType.Right -> JoinOp.RIGHT + is PartiqlAst.JoinType.Full -> JoinOp.OUTER } - private fun Let.toLetSource(): LetSource { + private fun PartiqlAst.Let.toLetSource(): LetSource { return LetSource( this.letBindings.map { LetBinding( @@ -299,7 +285,7 @@ private class StatementTransformer(val ion: IonSystem) { else -> OrderingSpec.ASC } - private fun PartiqlAst.GroupBy.toGroupBy(): org.partiql.lang.ast.GroupBy = + private fun PartiqlAst.GroupBy.toGroupBy(): GroupBy = GroupBy( grouping = strategy.toGroupingStrategy(), groupByItems = keyList.keys.map { @@ -309,82 +295,82 @@ private class StatementTransformer(val ion: IonSystem) { }, groupName = groupAsAlias?.toSymbolicName()) - private fun GroupingStrategy.toGroupingStrategy(): org.partiql.lang.ast.GroupingStrategy = + private fun PartiqlAst.GroupingStrategy.toGroupingStrategy(): GroupingStrategy = when(this) { - is GroupingStrategy.GroupFull-> org.partiql.lang.ast.GroupingStrategy.FULL - is GroupingStrategy.GroupPartial -> org.partiql.lang.ast.GroupingStrategy.PARTIAL + is PartiqlAst.GroupingStrategy.GroupFull-> GroupingStrategy.FULL + is PartiqlAst.GroupingStrategy.GroupPartial -> GroupingStrategy.PARTIAL } - private fun Type.toExprNodeType(): DataType { + private fun PartiqlAst.Type.toExprNodeType(): DataType { val metas = this.metas.toPartiQlMetaContainer() return when (this) { - is Type.NullType -> DataType(SqlDataType.NULL, listOf(), metas) - is Type.MissingType -> DataType(SqlDataType.MISSING, listOf(), metas) - is Type.BooleanType -> DataType(SqlDataType.BOOLEAN, listOf(), metas) - is Type.IntegerType -> DataType(SqlDataType.INTEGER, listOf(), metas) - is Type.SmallintType -> DataType(SqlDataType.SMALLINT, listOf(), metas) - is Type.Integer4Type -> DataType(SqlDataType.INTEGER4, listOf(), metas) - is Type.Integer8Type -> DataType(SqlDataType.INTEGER8, listOf(), metas) - is Type.FloatType -> DataType(SqlDataType.FLOAT, listOfNotNull(precision?.value?.toIntExact()), metas) - is Type.RealType -> DataType(SqlDataType.REAL, listOf(), metas) - is Type.DoublePrecisionType -> DataType(SqlDataType.DOUBLE_PRECISION, listOf(), metas) - is Type.DecimalType -> DataType(SqlDataType.DECIMAL, listOfNotNull(precision?.value?.toIntExact(), scale?.value?.toIntExact()), metas) - is Type.NumericType -> DataType(SqlDataType.NUMERIC, listOfNotNull(precision?.value?.toIntExact(), scale?.value?.toIntExact()), metas) - is Type.TimestampType -> DataType(SqlDataType.TIMESTAMP, listOf(), metas) - is Type.CharacterType -> DataType(SqlDataType.CHARACTER, listOfNotNull(length?.value?.toIntExact()), metas) - is Type.CharacterVaryingType -> DataType(SqlDataType.CHARACTER_VARYING, listOfNotNull(length?.value?.toIntExact()), metas) - is Type.StringType -> DataType(SqlDataType.STRING, listOf(), metas) - is Type.SymbolType -> DataType(SqlDataType.SYMBOL, listOf(), metas) - is Type.BlobType -> DataType(SqlDataType.BLOB, listOf(), metas) - is Type.ClobType -> DataType(SqlDataType.CLOB, listOf(), metas) - is Type.StructType -> DataType(SqlDataType.STRUCT, listOf(), metas) - is Type.TupleType -> DataType(SqlDataType.TUPLE, listOf(), metas) - is Type.ListType -> DataType(SqlDataType.LIST, listOf(), metas) - is Type.SexpType -> DataType(SqlDataType.SEXP, listOf(), metas) - is Type.BagType -> DataType(SqlDataType.BAG, listOf(), metas) - is Type.AnyType -> DataType(SqlDataType.ANY, listOf(), metas) - is Type.CustomType -> DataType(SqlDataType.CustomDataType(this.name.text), listOf(), metas) - is Type.DateType -> DataType(SqlDataType.DATE, listOf(), metas) - is Type.TimeType -> DataType(SqlDataType.TIME, listOfNotNull(precision?.value?.toIntExact()), metas) - is Type.TimeWithTimeZoneType -> DataType(SqlDataType.TIME_WITH_TIME_ZONE, listOfNotNull(precision?.value?.toIntExact()), metas) + is PartiqlAst.Type.NullType -> DataType(SqlDataType.NULL, listOf(), metas) + is PartiqlAst.Type.MissingType -> DataType(SqlDataType.MISSING, listOf(), metas) + is PartiqlAst.Type.BooleanType -> DataType(SqlDataType.BOOLEAN, listOf(), metas) + is PartiqlAst.Type.IntegerType -> DataType(SqlDataType.INTEGER, listOf(), metas) + is PartiqlAst.Type.SmallintType -> DataType(SqlDataType.SMALLINT, listOf(), metas) + is PartiqlAst.Type.Integer4Type -> DataType(SqlDataType.INTEGER4, listOf(), metas) + is PartiqlAst.Type.Integer8Type -> DataType(SqlDataType.INTEGER8, listOf(), metas) + is PartiqlAst.Type.FloatType -> DataType(SqlDataType.FLOAT, listOfNotNull(precision?.value?.toIntExact()), metas) + is PartiqlAst.Type.RealType -> DataType(SqlDataType.REAL, listOf(), metas) + is PartiqlAst.Type.DoublePrecisionType -> DataType(SqlDataType.DOUBLE_PRECISION, listOf(), metas) + is PartiqlAst.Type.DecimalType -> DataType(SqlDataType.DECIMAL, listOfNotNull(precision?.value?.toIntExact(), scale?.value?.toIntExact()), metas) + is PartiqlAst.Type.NumericType -> DataType(SqlDataType.NUMERIC, listOfNotNull(precision?.value?.toIntExact(), scale?.value?.toIntExact()), metas) + is PartiqlAst.Type.TimestampType -> DataType(SqlDataType.TIMESTAMP, listOf(), metas) + is PartiqlAst.Type.CharacterType -> DataType(SqlDataType.CHARACTER, listOfNotNull(length?.value?.toIntExact()), metas) + is PartiqlAst.Type.CharacterVaryingType -> DataType(SqlDataType.CHARACTER_VARYING, listOfNotNull(length?.value?.toIntExact()), metas) + is PartiqlAst.Type.StringType -> DataType(SqlDataType.STRING, listOf(), metas) + is PartiqlAst.Type.SymbolType -> DataType(SqlDataType.SYMBOL, listOf(), metas) + is PartiqlAst.Type.BlobType -> DataType(SqlDataType.BLOB, listOf(), metas) + is PartiqlAst.Type.ClobType -> DataType(SqlDataType.CLOB, listOf(), metas) + is PartiqlAst.Type.StructType -> DataType(SqlDataType.STRUCT, listOf(), metas) + is PartiqlAst.Type.TupleType -> DataType(SqlDataType.TUPLE, listOf(), metas) + is PartiqlAst.Type.ListType -> DataType(SqlDataType.LIST, listOf(), metas) + is PartiqlAst.Type.SexpType -> DataType(SqlDataType.SEXP, listOf(), metas) + is PartiqlAst.Type.BagType -> DataType(SqlDataType.BAG, listOf(), metas) + is PartiqlAst.Type.AnyType -> DataType(SqlDataType.ANY, listOf(), metas) + is PartiqlAst.Type.CustomType -> DataType(SqlDataType.CustomDataType(this.name.text), listOf(), metas) + is PartiqlAst.Type.DateType -> DataType(SqlDataType.DATE, listOf(), metas) + is PartiqlAst.Type.TimeType -> DataType(SqlDataType.TIME, listOfNotNull(precision?.value?.toIntExact()), metas) + is PartiqlAst.Type.TimeWithTimeZoneType -> DataType(SqlDataType.TIME_WITH_TIME_ZONE, listOfNotNull(precision?.value?.toIntExact()), metas) // TODO: Remove these hardcoded nodes from the PIG domain once [https://github.com/partiql/partiql-lang-kotlin/issues/510] is resolved. - is Type.EsBoolean, - is Type.EsInteger, - is Type.EsText, - is Type.EsAny, - is Type.EsFloat, - is Type.RsBigint, - is Type.RsBoolean, - is Type.RsDoublePrecision, - is Type.RsInteger, - is Type.RsReal, - is Type.RsVarcharMax, - is Type.SparkBoolean, - is Type.SparkDouble, - is Type.SparkFloat, - is Type.SparkInteger, - is Type.SparkLong, - is Type.SparkShort -> error("$this node should not be present in PartiQLAST. Consider transforming the AST using CustomTypeVisitorTransform.") + is PartiqlAst.Type.EsBoolean, + is PartiqlAst.Type.EsInteger, + is PartiqlAst.Type.EsText, + is PartiqlAst.Type.EsAny, + is PartiqlAst.Type.EsFloat, + is PartiqlAst.Type.RsBigint, + is PartiqlAst.Type.RsBoolean, + is PartiqlAst.Type.RsDoublePrecision, + is PartiqlAst.Type.RsInteger, + is PartiqlAst.Type.RsReal, + is PartiqlAst.Type.RsVarcharMax, + is PartiqlAst.Type.SparkBoolean, + is PartiqlAst.Type.SparkDouble, + is PartiqlAst.Type.SparkFloat, + is PartiqlAst.Type.SparkInteger, + is PartiqlAst.Type.SparkLong, + is PartiqlAst.Type.SparkShort -> error("$this node should not be present in PartiQLAST. Consider transforming the AST using CustomTypeVisitorTransform.") } } - private fun PartiqlAst.SetQuantifier.toSetQuantifier(): ExprNodeSetQuantifier = + private fun PartiqlAst.SetQuantifier.toSetQuantifier(): SetQuantifier = when (this) { - is PartiqlAst.SetQuantifier.All -> ExprNodeSetQuantifier.ALL - is PartiqlAst.SetQuantifier.Distinct -> ExprNodeSetQuantifier.DISTINCT + is PartiqlAst.SetQuantifier.All -> SetQuantifier.ALL + is PartiqlAst.SetQuantifier.Distinct -> SetQuantifier.DISTINCT } - private fun ScopeQualifier.toScopeQualifier(): org.partiql.lang.ast.ScopeQualifier = + private fun PartiqlAst.ScopeQualifier.toScopeQualifier(): ScopeQualifier = when (this) { - is ScopeQualifier.Unqualified -> org.partiql.lang.ast.ScopeQualifier.UNQUALIFIED - is ScopeQualifier.LocalsFirst -> org.partiql.lang.ast.ScopeQualifier.LEXICAL + is PartiqlAst.ScopeQualifier.Unqualified -> ScopeQualifier.UNQUALIFIED + is PartiqlAst.ScopeQualifier.LocalsFirst -> ScopeQualifier.LEXICAL } - private fun CaseSensitivity.toCaseSensitivity(): org.partiql.lang.ast.CaseSensitivity = + private fun PartiqlAst.CaseSensitivity.toCaseSensitivity(): CaseSensitivity = when (this) { - is CaseSensitivity.CaseSensitive -> org.partiql.lang.ast.CaseSensitivity.SENSITIVE - is CaseSensitivity.CaseInsensitive -> org.partiql.lang.ast.CaseSensitivity.INSENSITIVE + is PartiqlAst.CaseSensitivity.CaseSensitive -> CaseSensitivity.SENSITIVE + is PartiqlAst.CaseSensitivity.CaseInsensitive -> CaseSensitivity.INSENSITIVE } private fun PartiqlAst.OnConflict.toOnConflictNode(): OnConflict { @@ -446,20 +432,20 @@ private class StatementTransformer(val ion: IonSystem) { } } - private fun ReturningMapping.toExprNodeReturningMapping(): ExprNodeReturningMapping = + private fun PartiqlAst.ReturningMapping.toExprNodeReturningMapping(): ReturningMapping = when(this) { - is ReturningMapping.ModifiedOld -> ExprNodeReturningMapping.MODIFIED_OLD - is ReturningMapping.ModifiedNew -> ExprNodeReturningMapping.MODIFIED_NEW - is ReturningMapping.AllOld -> ExprNodeReturningMapping.ALL_OLD - is ReturningMapping.AllNew -> ExprNodeReturningMapping.ALL_NEW + is PartiqlAst.ReturningMapping.ModifiedOld -> ReturningMapping.MODIFIED_OLD + is PartiqlAst.ReturningMapping.ModifiedNew -> ReturningMapping.MODIFIED_NEW + is PartiqlAst.ReturningMapping.AllOld -> ReturningMapping.ALL_OLD + is PartiqlAst.ReturningMapping.AllNew -> ReturningMapping.ALL_NEW } - private fun Statement.Ddl.toExprNode(): ExprNode { + private fun PartiqlAst.Statement.Ddl.toExprNode(): ExprNode { val op = this.op val metas = this.metas.toPartiQlMetaContainer() return when(op) { - is DdlOp.CreateTable -> CreateTable(op.tableName.text, metas) - is DdlOp.DropTable -> + is PartiqlAst.DdlOp.CreateTable -> CreateTable(op.tableName.text, metas) + is PartiqlAst.DdlOp.DropTable -> DropTable( tableId = Identifier( id = op.tableName.name.text, @@ -467,7 +453,7 @@ private class StatementTransformer(val ion: IonSystem) { metas = emptyMetaContainer ), metas = metas) - is DdlOp.CreateIndex -> + is PartiqlAst.DdlOp.CreateIndex -> CreateIndex( tableId = Identifier( id = op.indexName.name.text, @@ -476,7 +462,7 @@ private class StatementTransformer(val ion: IonSystem) { ), keys = op.fields.map { it.toExprNode() }, metas = metas) - is DdlOp.DropIndex -> + is PartiqlAst.DdlOp.DropIndex -> DropIndex( tableId = Identifier( id = op.table.name.text, @@ -492,7 +478,7 @@ private class StatementTransformer(val ion: IonSystem) { } } - private fun Statement.Exec.toExprNode(): ExprNode { + private fun PartiqlAst.Statement.Exec.toExprNode(): ExprNode { return Exec(procedureName.toSymbolicName(), this.args.toExprNodeList(), metas.toPartiQlMetaContainer()) } } diff --git a/lang/src/org/partiql/lang/ast/Util.kt b/lang/src/org/partiql/lang/ast/Util.kt index 8fdcf0806b..aec028b67d 100644 --- a/lang/src/org/partiql/lang/ast/Util.kt +++ b/lang/src/org/partiql/lang/ast/Util.kt @@ -15,9 +15,9 @@ package org.partiql.lang.ast -import com.amazon.ion.* -import org.partiql.lang.ast.SetQuantifier.* -import org.partiql.lang.errors.* +import com.amazon.ion.IonSystem +import org.partiql.lang.errors.Property +import org.partiql.lang.errors.PropertyValueMap fun PropertyValueMap.addSourceLocation(metas: MetaContainer): PropertyValueMap { (metas.find(SourceLocationMeta.TAG) as? SourceLocationMeta)?.let { @@ -44,7 +44,7 @@ fun createCountStar(ion: IonSystem, metas: MetaContainer): CallAgg { case = CaseSensitivity.INSENSITIVE, scopeQualifier = ScopeQualifier.UNQUALIFIED, metas = srcLocationMetaOnly), - setQuantifier = ALL, + setQuantifier = SetQuantifier.ALL, arg = Literal(ion.newInt(1), srcLocationMetaOnly), metas = metas.add(IsCountStarMeta.instance) ) diff --git a/lang/src/org/partiql/lang/ast/ast.kt b/lang/src/org/partiql/lang/ast/ast.kt index 1d90333ff9..950e717611 100644 --- a/lang/src/org/partiql/lang/ast/ast.kt +++ b/lang/src/org/partiql/lang/ast/ast.kt @@ -14,9 +14,11 @@ package org.partiql.lang.ast -import com.amazon.ion.* -import org.partiql.lang.util.* -import java.util.* +import com.amazon.ion.IonType +import com.amazon.ion.IonValue +import org.partiql.lang.util.interruptibleMap +import org.partiql.lang.util.stringValue +import java.util.Arrays /** * Base type for all AST nodes. @@ -155,7 +157,6 @@ data class Literal( override val children: List = listOf() } - /** Represents the literal value `MISSING`. */ data class LiteralMissing( override val metas: MetaContainer diff --git a/lang/src/org/partiql/lang/ast/meta.kt b/lang/src/org/partiql/lang/ast/meta.kt index bb950436c2..56d6497b63 100644 --- a/lang/src/org/partiql/lang/ast/meta.kt +++ b/lang/src/org/partiql/lang/ast/meta.kt @@ -14,9 +14,10 @@ package org.partiql.lang.ast -import com.amazon.ion.* -import org.partiql.lang.util.* -import java.util.* +import com.amazon.ion.IonWriter +import org.partiql.lang.util.IonWriterContext +import java.util.Arrays +import java.util.TreeMap /** * The [Meta] interface is implemented by classes that provide an object mapping view to AST meta nodes. diff --git a/lang/src/org/partiql/lang/ast/passes/AstRewriterBase.kt b/lang/src/org/partiql/lang/ast/passes/AstRewriterBase.kt index ba7b20ce0e..02f51c084d 100644 --- a/lang/src/org/partiql/lang/ast/passes/AstRewriterBase.kt +++ b/lang/src/org/partiql/lang/ast/passes/AstRewriterBase.kt @@ -14,7 +14,74 @@ package org.partiql.lang.ast.passes -import org.partiql.lang.ast.* +import org.partiql.lang.ast.Assignment +import org.partiql.lang.ast.AssignmentOp +import org.partiql.lang.ast.CallAgg +import org.partiql.lang.ast.Coalesce +import org.partiql.lang.ast.CreateIndex +import org.partiql.lang.ast.CreateTable +import org.partiql.lang.ast.DataManipulation +import org.partiql.lang.ast.DataManipulationOperation +import org.partiql.lang.ast.DataType +import org.partiql.lang.ast.DateLiteral +import org.partiql.lang.ast.DeleteOp +import org.partiql.lang.ast.DmlOpList +import org.partiql.lang.ast.DropIndex +import org.partiql.lang.ast.DropTable +import org.partiql.lang.ast.Exec +import org.partiql.lang.ast.ExprNode +import org.partiql.lang.ast.FromSource +import org.partiql.lang.ast.FromSourceExpr +import org.partiql.lang.ast.FromSourceJoin +import org.partiql.lang.ast.FromSourceLet +import org.partiql.lang.ast.FromSourceUnpivot +import org.partiql.lang.ast.GroupBy +import org.partiql.lang.ast.GroupByItem +import org.partiql.lang.ast.HasMetas +import org.partiql.lang.ast.Identifier +import org.partiql.lang.ast.InsertOp +import org.partiql.lang.ast.InsertValueOp +import org.partiql.lang.ast.LetBinding +import org.partiql.lang.ast.LetSource +import org.partiql.lang.ast.LetVariables +import org.partiql.lang.ast.Literal +import org.partiql.lang.ast.LiteralMissing +import org.partiql.lang.ast.MetaContainer +import org.partiql.lang.ast.NAry +import org.partiql.lang.ast.NullIf +import org.partiql.lang.ast.OnConflict +import org.partiql.lang.ast.OrderBy +import org.partiql.lang.ast.Parameter +import org.partiql.lang.ast.Path +import org.partiql.lang.ast.PathComponent +import org.partiql.lang.ast.PathComponentExpr +import org.partiql.lang.ast.PathComponentUnpivot +import org.partiql.lang.ast.PathComponentWildcard +import org.partiql.lang.ast.RemoveOp +import org.partiql.lang.ast.ReturningElem +import org.partiql.lang.ast.ReturningExpr +import org.partiql.lang.ast.SearchedCase +import org.partiql.lang.ast.SearchedCaseWhen +import org.partiql.lang.ast.Select +import org.partiql.lang.ast.SelectListItem +import org.partiql.lang.ast.SelectListItemExpr +import org.partiql.lang.ast.SelectListItemProjectAll +import org.partiql.lang.ast.SelectListItemStar +import org.partiql.lang.ast.SelectProjection +import org.partiql.lang.ast.SelectProjectionList +import org.partiql.lang.ast.SelectProjectionPivot +import org.partiql.lang.ast.SelectProjectionValue +import org.partiql.lang.ast.Seq +import org.partiql.lang.ast.SeqType +import org.partiql.lang.ast.SimpleCase +import org.partiql.lang.ast.SimpleCaseWhen +import org.partiql.lang.ast.SortSpec +import org.partiql.lang.ast.Struct +import org.partiql.lang.ast.StructField +import org.partiql.lang.ast.SymbolicName +import org.partiql.lang.ast.TimeLiteral +import org.partiql.lang.ast.Typed +import org.partiql.lang.ast.VariableReference import org.partiql.lang.util.checkThreadInterrupted /** @@ -35,8 +102,8 @@ open class AstRewriterBase : AstRewriter { override fun rewriteExprNode(node: ExprNode): ExprNode { checkThreadInterrupted() return when (node) { - is Literal -> rewriteLiteral(node) - is LiteralMissing -> rewriteLiteralMissing(node) + is Literal -> rewriteLiteral(node) + is LiteralMissing -> rewriteLiteralMissing(node) is VariableReference -> rewriteVariableReference(node) is NAry -> rewriteNAry(node) is CallAgg -> rewriteCallAgg(node) @@ -53,8 +120,8 @@ open class AstRewriterBase : AstRewriter { is CreateIndex -> rewriteCreateIndex(node) is DropTable -> rewriteDropTable(node) is DropIndex -> rewriteDropIndex(node) - is NullIf -> rewriteNullIf(node) - is Coalesce -> rewriteCoalesce(node) + is NullIf -> rewriteNullIf(node) + is Coalesce -> rewriteCoalesce(node) is Exec -> rewriteExec(node) is DateLiteral -> rewriteDate(node) is TimeLiteral -> rewriteTime(node) @@ -210,7 +277,7 @@ open class AstRewriterBase : AstRewriter { open fun rewriteSelectProjection(projection: SelectProjection): SelectProjection = when (projection) { - is SelectProjectionList -> rewriteSelectProjectionList(projection) + is SelectProjectionList -> rewriteSelectProjectionList(projection) is SelectProjectionValue -> rewriteSelectProjectionValue(projection) is SelectProjectionPivot -> rewriteSelectProjectionPivot(projection) } @@ -231,8 +298,8 @@ open class AstRewriterBase : AstRewriter { open fun rewriteSelectListItem(item: SelectListItem): SelectListItem = when(item) { - is SelectListItemStar -> rewriteSelectListItemStar(item) - is SelectListItemExpr -> rewriteSelectListItemExpr(item) + is SelectListItemStar -> rewriteSelectListItemStar(item) + is SelectListItemExpr -> rewriteSelectListItemExpr(item) is SelectListItemProjectAll -> rewriteSelectListItemProjectAll(item) } @@ -252,7 +319,7 @@ open class AstRewriterBase : AstRewriter { when(pathComponent) { is PathComponentUnpivot -> rewritePathComponentUnpivot(pathComponent) is PathComponentWildcard -> rewritePathComponentWildcard(pathComponent) - is PathComponentExpr -> rewritePathComponentExpr(pathComponent) + is PathComponentExpr -> rewritePathComponentExpr(pathComponent) } open fun rewritePathComponentUnpivot(pathComponent: PathComponentUnpivot): PathComponent = @@ -270,12 +337,12 @@ open class AstRewriterBase : AstRewriter { open fun rewriteFromSource(fromSource: FromSource): FromSource = when(fromSource) { is FromSourceJoin -> rewriteFromSourceJoin(fromSource) - is FromSourceLet -> rewriteFromSourceLet(fromSource) + is FromSourceLet -> rewriteFromSourceLet(fromSource) } open fun rewriteFromSourceLet(fromSourceLet: FromSourceLet): FromSourceLet = when(fromSourceLet) { - is FromSourceExpr -> rewriteFromSourceExpr(fromSourceLet) + is FromSourceExpr -> rewriteFromSourceExpr(fromSourceLet) is FromSourceUnpivot -> rewriteFromSourceUnpivot(fromSourceLet) } @@ -406,11 +473,11 @@ open class AstRewriterBase : AstRewriter { open fun rewriteDataManipulationOperation(node: DataManipulationOperation): DataManipulationOperation = when(node) { - is InsertOp -> rewriteDataManipulationOperationInsertOp(node) + is InsertOp -> rewriteDataManipulationOperationInsertOp(node) is InsertValueOp -> rewriteDataManipulationOperationInsertValueOp(node) - is AssignmentOp -> rewriteDataManipulationOperationAssignmentOp(node) - is RemoveOp -> rewriteDataManipulationOperationRemoveOp(node) - is DeleteOp -> rewriteDataManipulationOperationDeleteOp() + is AssignmentOp -> rewriteDataManipulationOperationAssignmentOp(node) + is RemoveOp -> rewriteDataManipulationOperationRemoveOp(node) + is DeleteOp -> rewriteDataManipulationOperationDeleteOp() } open fun rewriteDataManipulationOperationInsertOp(node: InsertOp): DataManipulationOperation = diff --git a/lang/src/org/partiql/lang/ast/passes/AstVisitor.kt b/lang/src/org/partiql/lang/ast/passes/AstVisitor.kt index d4556656d3..e5d2f19645 100644 --- a/lang/src/org/partiql/lang/ast/passes/AstVisitor.kt +++ b/lang/src/org/partiql/lang/ast/passes/AstVisitor.kt @@ -14,7 +14,14 @@ package org.partiql.lang.ast.passes -import org.partiql.lang.ast.* +import org.partiql.lang.ast.DataManipulationOperation +import org.partiql.lang.ast.DataType +import org.partiql.lang.ast.ExprNode +import org.partiql.lang.ast.FromSource +import org.partiql.lang.ast.OnConflict +import org.partiql.lang.ast.PathComponent +import org.partiql.lang.ast.SelectListItem +import org.partiql.lang.ast.SelectProjection /** * Used in conjunction with [AstWalker], implementors of this interface can easily inspect an AST. diff --git a/lang/src/org/partiql/lang/ast/passes/AstWalker.kt b/lang/src/org/partiql/lang/ast/passes/AstWalker.kt index 24989265a0..45f8ae345a 100644 --- a/lang/src/org/partiql/lang/ast/passes/AstWalker.kt +++ b/lang/src/org/partiql/lang/ast/passes/AstWalker.kt @@ -14,8 +14,58 @@ package org.partiql.lang.ast.passes -import org.partiql.lang.ast.* -import org.partiql.lang.util.* +import org.partiql.lang.ast.AssignmentOp +import org.partiql.lang.ast.CallAgg +import org.partiql.lang.ast.Coalesce +import org.partiql.lang.ast.ConflictAction +import org.partiql.lang.ast.CreateIndex +import org.partiql.lang.ast.CreateTable +import org.partiql.lang.ast.DataManipulation +import org.partiql.lang.ast.DataManipulationOperation +import org.partiql.lang.ast.DateLiteral +import org.partiql.lang.ast.DeleteOp +import org.partiql.lang.ast.DmlOpList +import org.partiql.lang.ast.DropIndex +import org.partiql.lang.ast.DropTable +import org.partiql.lang.ast.Exec +import org.partiql.lang.ast.ExprNode +import org.partiql.lang.ast.FromSource +import org.partiql.lang.ast.FromSourceExpr +import org.partiql.lang.ast.FromSourceJoin +import org.partiql.lang.ast.FromSourceUnpivot +import org.partiql.lang.ast.InsertOp +import org.partiql.lang.ast.InsertValueOp +import org.partiql.lang.ast.Literal +import org.partiql.lang.ast.LiteralMissing +import org.partiql.lang.ast.MetaContainer +import org.partiql.lang.ast.NAry +import org.partiql.lang.ast.NullIf +import org.partiql.lang.ast.OnConflict +import org.partiql.lang.ast.Parameter +import org.partiql.lang.ast.Path +import org.partiql.lang.ast.PathComponentExpr +import org.partiql.lang.ast.PathComponentUnpivot +import org.partiql.lang.ast.PathComponentWildcard +import org.partiql.lang.ast.RemoveOp +import org.partiql.lang.ast.ReturningColumn +import org.partiql.lang.ast.ReturningWildcard +import org.partiql.lang.ast.SearchedCase +import org.partiql.lang.ast.Select +import org.partiql.lang.ast.SelectListItemExpr +import org.partiql.lang.ast.SelectListItemProjectAll +import org.partiql.lang.ast.SelectListItemStar +import org.partiql.lang.ast.SelectProjection +import org.partiql.lang.ast.SelectProjectionList +import org.partiql.lang.ast.SelectProjectionPivot +import org.partiql.lang.ast.SelectProjectionValue +import org.partiql.lang.ast.Seq +import org.partiql.lang.ast.SimpleCase +import org.partiql.lang.ast.Struct +import org.partiql.lang.ast.TimeLiteral +import org.partiql.lang.ast.Typed +import org.partiql.lang.ast.VariableReference +import org.partiql.lang.util.case +import org.partiql.lang.util.checkThreadInterrupted /** * Contains the logic necessary to walk every node in the AST and invokes methods of [AstVisitor] along the way. @@ -35,29 +85,29 @@ open class AstWalker(private val visitor: AstVisitor) { is Literal, is LiteralMissing, is VariableReference, - is Parameter -> case { + is Parameter -> case { // Leaf nodes have no children to walk. } - is NAry -> case { + is NAry -> case { val (_, args, _: MetaContainer) = expr args.forEach { it -> walkExprNode(it) } } - is CallAgg -> case { + is CallAgg -> case { val (funcExpr, _, arg, _: MetaContainer) = expr walkExprNode(funcExpr) walkExprNode(arg) } - is Typed -> case { + is Typed -> case { val (_, exp, sqlDataType, _: MetaContainer) = expr walkExprNode(exp) visitor.visitDataType(sqlDataType) } - is Path -> case { + is Path -> case { walkPath(expr) } - is SimpleCase -> case { + is SimpleCase -> case { val (valueExpr, branches, elseExpr, _: MetaContainer) = expr walkExprNode(valueExpr) branches.forEach { @@ -74,20 +124,20 @@ open class AstWalker(private val visitor: AstVisitor) { } walkExprNode(elseExpr) } - is Struct -> case { + is Struct -> case { val (fields, _: MetaContainer) = expr fields.forEach { val (nameExpr, valueExpr) = it walkExprNode(nameExpr, valueExpr) } } - is Seq -> case { + is Seq -> case { val (_, items, _: MetaContainer) = expr items.forEach { walkExprNode(it) } } - is Select -> case { + is Select -> case { val (_, projection, from, fromLet, where, groupBy, having, orderBy, limit, offset, _: MetaContainer) = expr walkSelectProjection(projection) walkFromSource(from) @@ -109,12 +159,12 @@ open class AstWalker(private val visitor: AstVisitor) { walkExprNode(limit) walkExprNode(offset) } - is NullIf -> case { + is NullIf -> case { val (expr1, expr2, _) = expr walkExprNode(expr1) walkExprNode(expr2) } - is Coalesce -> case { + is Coalesce -> case { val (args, _) = expr args.map { walkExprNode(it) @@ -130,7 +180,7 @@ open class AstWalker(private val visitor: AstVisitor) { returning?.let { it.returningElems.forEach { re -> when (re.columnComponent) { - is ReturningColumn -> case { + is ReturningColumn -> case { walkExprNode(re.columnComponent.column) } is ReturningWildcard -> case { @@ -162,7 +212,7 @@ open class AstWalker(private val visitor: AstVisitor) { is PathComponentWildcard -> case { //Leaf nodes have no children to walk. } - is PathComponentExpr -> case { + is PathComponentExpr -> case { val (exp) = it walkExprNode(exp) } @@ -173,7 +223,7 @@ open class AstWalker(private val visitor: AstVisitor) { private fun walkFromSource(fromSource: FromSource) { visitor.visitFromSource(fromSource) when (fromSource) { - is FromSourceExpr -> case { + is FromSourceExpr -> case { val (exp, _) = fromSource walkExprNode(exp) } @@ -181,7 +231,7 @@ open class AstWalker(private val visitor: AstVisitor) { val (exp, _, _) = fromSource walkExprNode(exp) } - is FromSourceJoin -> case { + is FromSourceJoin -> case { val (_, leftRef, rightRef, condition, _: MetaContainer) = fromSource walkFromSource(leftRef) walkFromSource(rightRef) @@ -201,15 +251,15 @@ open class AstWalker(private val visitor: AstVisitor) { val (asExpr, atExpr) = projection walkExprNode(asExpr, atExpr) } - is SelectProjectionList -> case { + is SelectProjectionList -> case { val (items) = projection items.forEach { visitor.visitSelectListItem(it) when (it) { - is SelectListItemStar -> case { + is SelectListItemStar -> case { //Leaf nodes have no children to walk. } - is SelectListItemExpr -> case { + is SelectListItemExpr -> case { walkExprNode(it.expr) } is SelectListItemProjectAll -> case { diff --git a/lang/src/org/partiql/lang/ast/passes/SemanticException.kt b/lang/src/org/partiql/lang/ast/passes/SemanticException.kt index 4abeb31dfe..e5fc58fe95 100644 --- a/lang/src/org/partiql/lang/ast/passes/SemanticException.kt +++ b/lang/src/org/partiql/lang/ast/passes/SemanticException.kt @@ -14,8 +14,11 @@ package org.partiql.lang.ast.passes -import org.partiql.lang.* -import org.partiql.lang.errors.* +import org.partiql.lang.SqlException +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Problem +import org.partiql.lang.errors.Property +import org.partiql.lang.errors.PropertyValueMap import org.partiql.lang.util.propertyValueMapOf /** diff --git a/lang/src/org/partiql/lang/domains/partiql-domains.kt b/lang/src/org/partiql/lang/domains/partiql-domains.kt deleted file mode 100644 index 186ba2cf61..0000000000 --- a/lang/src/org/partiql/lang/domains/partiql-domains.kt +++ /dev/null @@ -1,18599 +0,0 @@ -/** - * This code was generated by the PartiQL I.R. Generator. - * Do not modify this file. - */ -@file:Suppress("unused", "MemberVisibilityCanBePrivate", "FunctionName", - "CanBePrimaryConstructorProperty", "UNNECESSARY_SAFE_CALL", - "USELESS_ELVIS", "RemoveRedundantQualifierName", "LocalVariableName") - -package org.partiql.lang.domains - -import com.amazon.ionelement.api.* -import org.partiql.pig.runtime.* - -class PartiqlAst private constructor() { - ///////////////////////////////////////////////////////////////////////////// - // Builder - ///////////////////////////////////////////////////////////////////////////// - companion object { - @JvmStatic - fun BUILDER() : Builder = PartiqlAstBuilder - - fun build(block: Builder.() -> T) = - PartiqlAstBuilder.block() - - fun transform(element: AnyElement): PartiqlAstNode = - transform(element.asSexp()) - - fun transform(element: SexpElement): PartiqlAstNode = - IonElementTransformer().transform(element) - } - - interface Builder { - fun newMetaContainer() = emptyMetaContainer() - - // Tuples - /** - * Creates an instance of [PartiqlAst.TimeValue]. - */ - fun timeValue( - hour: Long, - minute: Long, - second: Long, - nano: Long, - precision: Long, - tzMinutes: Long? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.TimeValue = - PartiqlAst.TimeValue( - hour = hour.asPrimitive(), - minute = minute.asPrimitive(), - second = second.asPrimitive(), - nano = nano.asPrimitive(), - precision = precision.asPrimitive(), - tzMinutes = tzMinutes?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.TimeValue]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun timeValue_( - hour: org.partiql.pig.runtime.LongPrimitive, - minute: org.partiql.pig.runtime.LongPrimitive, - second: org.partiql.pig.runtime.LongPrimitive, - nano: org.partiql.pig.runtime.LongPrimitive, - precision: org.partiql.pig.runtime.LongPrimitive, - tzMinutes: org.partiql.pig.runtime.LongPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.TimeValue = - PartiqlAst.TimeValue( - hour = hour, - minute = minute, - second = second, - nano = nano, - precision = precision, - tzMinutes = tzMinutes, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Let]. - */ - fun let( - letBindings: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Let = - PartiqlAst.Let( - letBindings = letBindings, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Let]. - */ - fun let( - letBindings0: LetBinding, - vararg letBindings: LetBinding, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Let = - PartiqlAst.Let( - letBindings = listOf(letBindings0) + letBindings.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.LetBinding]. - */ - fun letBinding( - expr: Expr, - name: String, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.LetBinding = - PartiqlAst.LetBinding( - expr = expr, - name = name.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.LetBinding]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun letBinding_( - expr: Expr, - name: org.partiql.pig.runtime.SymbolPrimitive, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.LetBinding = - PartiqlAst.LetBinding( - expr = expr, - name = name, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.ExprPair]. - */ - fun exprPair( - first: Expr, - second: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ExprPair = - PartiqlAst.ExprPair( - first = first, - second = second, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.ExprPairList]. - */ - fun exprPairList( - pairs: kotlin.collections.List = emptyList(), - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ExprPairList = - PartiqlAst.ExprPairList( - pairs = pairs, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.ExprPairList]. - */ - fun exprPairList( - vararg pairs: ExprPair, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ExprPairList = - PartiqlAst.ExprPairList( - pairs = pairs.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.GroupBy]. - */ - fun groupBy( - strategy: GroupingStrategy, - keyList: GroupKeyList, - groupAsAlias: String? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.GroupBy = - PartiqlAst.GroupBy( - strategy = strategy, - keyList = keyList, - groupAsAlias = groupAsAlias?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.GroupBy]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun groupBy_( - strategy: GroupingStrategy, - keyList: GroupKeyList, - groupAsAlias: org.partiql.pig.runtime.SymbolPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.GroupBy = - PartiqlAst.GroupBy( - strategy = strategy, - keyList = keyList, - groupAsAlias = groupAsAlias, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.GroupKeyList]. - */ - fun groupKeyList( - keys: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.GroupKeyList = - PartiqlAst.GroupKeyList( - keys = keys, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.GroupKeyList]. - */ - fun groupKeyList( - keys0: GroupKey, - vararg keys: GroupKey, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.GroupKeyList = - PartiqlAst.GroupKeyList( - keys = listOf(keys0) + keys.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.GroupKey]. - */ - fun groupKey( - expr: Expr, - asAlias: String? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.GroupKey = - PartiqlAst.GroupKey( - expr = expr, - asAlias = asAlias?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.GroupKey]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun groupKey_( - expr: Expr, - asAlias: org.partiql.pig.runtime.SymbolPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.GroupKey = - PartiqlAst.GroupKey( - expr = expr, - asAlias = asAlias, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.OrderBy]. - */ - fun orderBy( - sortSpecs: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.OrderBy = - PartiqlAst.OrderBy( - sortSpecs = sortSpecs, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.OrderBy]. - */ - fun orderBy( - sortSpecs0: SortSpec, - vararg sortSpecs: SortSpec, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.OrderBy = - PartiqlAst.OrderBy( - sortSpecs = listOf(sortSpecs0) + sortSpecs.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.SortSpec]. - */ - fun sortSpec( - expr: Expr, - orderingSpec: OrderingSpec? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.SortSpec = - PartiqlAst.SortSpec( - expr = expr, - orderingSpec = orderingSpec, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.DmlOpList]. - */ - fun dmlOpList( - ops: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DmlOpList = - PartiqlAst.DmlOpList( - ops = ops, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.DmlOpList]. - */ - fun dmlOpList( - ops0: DmlOp, - vararg ops: DmlOp, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DmlOpList = - PartiqlAst.DmlOpList( - ops = listOf(ops0) + ops.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.OnConflict]. - */ - fun onConflict( - expr: Expr, - conflictAction: ConflictAction, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.OnConflict = - PartiqlAst.OnConflict( - expr = expr, - conflictAction = conflictAction, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.ReturningExpr]. - */ - fun returningExpr( - elems: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ReturningExpr = - PartiqlAst.ReturningExpr( - elems = elems, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.ReturningExpr]. - */ - fun returningExpr( - elems0: ReturningElem, - vararg elems: ReturningElem, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ReturningExpr = - PartiqlAst.ReturningExpr( - elems = listOf(elems0) + elems.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.ReturningElem]. - */ - fun returningElem( - mapping: ReturningMapping, - column: ColumnComponent, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ReturningElem = - PartiqlAst.ReturningElem( - mapping = mapping, - column = column, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Identifier]. - */ - fun identifier( - name: String, - case: CaseSensitivity, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Identifier = - PartiqlAst.Identifier( - name = name.asPrimitive(), - case = case, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Identifier]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun identifier_( - name: org.partiql.pig.runtime.SymbolPrimitive, - case: CaseSensitivity, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Identifier = - PartiqlAst.Identifier( - name = name, - case = case, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Assignment]. - */ - fun assignment( - target: Expr, - value: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Assignment = - PartiqlAst.Assignment( - target = target, - value = value, - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: Statement - /** - * Creates an instance of [PartiqlAst.Statement.Query]. - */ - fun query( - expr: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Statement.Query = - PartiqlAst.Statement.Query( - expr = expr, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Statement.Dml]. - */ - fun dml( - operations: DmlOpList, - from: FromSource? = null, - where: Expr? = null, - returning: ReturningExpr? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Statement.Dml = - PartiqlAst.Statement.Dml( - operations = operations, - from = from, - where = where, - returning = returning, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Statement.Ddl]. - */ - fun ddl( - op: DdlOp, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Statement.Ddl = - PartiqlAst.Statement.Ddl( - op = op, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Statement.Exec]. - */ - fun exec( - procedureName: String, - args: kotlin.collections.List = emptyList(), - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Statement.Exec = - PartiqlAst.Statement.Exec( - procedureName = procedureName.asPrimitive(), - args = args, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Statement.Exec]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun exec_( - procedureName: org.partiql.pig.runtime.SymbolPrimitive, - args: kotlin.collections.List = emptyList(), - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Statement.Exec = - PartiqlAst.Statement.Exec( - procedureName = procedureName, - args = args, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Statement.Exec]. - */ - fun exec( - procedureName: String, - vararg args: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Statement.Exec = - PartiqlAst.Statement.Exec( - procedureName = procedureName?.asPrimitive(), - args = args.toList(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Statement.Exec]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun exec_( - procedureName: org.partiql.pig.runtime.SymbolPrimitive, - vararg args: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Statement.Exec = - PartiqlAst.Statement.Exec( - procedureName = procedureName, - args = args.toList(), - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: Expr - /** - * Creates an instance of [PartiqlAst.Expr.Missing]. - */ - fun missing( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Missing = - PartiqlAst.Expr.Missing( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Lit]. - */ - fun lit( - value: com.amazon.ionelement.api.IonElement, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Lit = - PartiqlAst.Expr.Lit( - value = value.asAnyElement(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Id]. - */ - fun id( - name: String, - case: CaseSensitivity, - qualifier: ScopeQualifier, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Id = - PartiqlAst.Expr.Id( - name = name.asPrimitive(), - case = case, - qualifier = qualifier, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Id]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun id_( - name: org.partiql.pig.runtime.SymbolPrimitive, - case: CaseSensitivity, - qualifier: ScopeQualifier, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Id = - PartiqlAst.Expr.Id( - name = name, - case = case, - qualifier = qualifier, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Parameter]. - */ - fun parameter( - index: Long, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Parameter = - PartiqlAst.Expr.Parameter( - index = index.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Parameter]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun parameter_( - index: org.partiql.pig.runtime.LongPrimitive, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Parameter = - PartiqlAst.Expr.Parameter( - index = index, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Not]. - */ - fun not( - expr: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Not = - PartiqlAst.Expr.Not( - expr = expr, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Pos]. - */ - fun pos( - expr: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Pos = - PartiqlAst.Expr.Pos( - expr = expr, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Neg]. - */ - fun neg( - expr: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Neg = - PartiqlAst.Expr.Neg( - expr = expr, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Plus]. - */ - fun plus( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Plus = - PartiqlAst.Expr.Plus( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Plus]. - */ - fun plus( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Plus = - PartiqlAst.Expr.Plus( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Minus]. - */ - fun minus( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Minus = - PartiqlAst.Expr.Minus( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Minus]. - */ - fun minus( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Minus = - PartiqlAst.Expr.Minus( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Times]. - */ - fun times( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Times = - PartiqlAst.Expr.Times( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Times]. - */ - fun times( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Times = - PartiqlAst.Expr.Times( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Divide]. - */ - fun divide( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Divide = - PartiqlAst.Expr.Divide( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Divide]. - */ - fun divide( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Divide = - PartiqlAst.Expr.Divide( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Modulo]. - */ - fun modulo( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Modulo = - PartiqlAst.Expr.Modulo( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Modulo]. - */ - fun modulo( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Modulo = - PartiqlAst.Expr.Modulo( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Concat]. - */ - fun concat( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Concat = - PartiqlAst.Expr.Concat( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Concat]. - */ - fun concat( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Concat = - PartiqlAst.Expr.Concat( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.And]. - */ - fun and( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.And = - PartiqlAst.Expr.And( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.And]. - */ - fun and( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.And = - PartiqlAst.Expr.And( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Or]. - */ - fun or( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Or = - PartiqlAst.Expr.Or( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Or]. - */ - fun or( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Or = - PartiqlAst.Expr.Or( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Eq]. - */ - fun eq( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Eq = - PartiqlAst.Expr.Eq( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Eq]. - */ - fun eq( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Eq = - PartiqlAst.Expr.Eq( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Ne]. - */ - fun ne( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Ne = - PartiqlAst.Expr.Ne( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Ne]. - */ - fun ne( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Ne = - PartiqlAst.Expr.Ne( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Gt]. - */ - fun gt( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Gt = - PartiqlAst.Expr.Gt( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Gt]. - */ - fun gt( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Gt = - PartiqlAst.Expr.Gt( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Gte]. - */ - fun gte( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Gte = - PartiqlAst.Expr.Gte( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Gte]. - */ - fun gte( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Gte = - PartiqlAst.Expr.Gte( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Lt]. - */ - fun lt( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Lt = - PartiqlAst.Expr.Lt( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Lt]. - */ - fun lt( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Lt = - PartiqlAst.Expr.Lt( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Lte]. - */ - fun lte( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Lte = - PartiqlAst.Expr.Lte( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Lte]. - */ - fun lte( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Lte = - PartiqlAst.Expr.Lte( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Like]. - */ - fun like( - value: Expr, - pattern: Expr, - escape: Expr? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Like = - PartiqlAst.Expr.Like( - value = value, - pattern = pattern, - escape = escape, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Between]. - */ - fun between( - value: Expr, - from: Expr, - to: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Between = - PartiqlAst.Expr.Between( - value = value, - from = from, - to = to, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.InCollection]. - */ - fun inCollection( - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.InCollection = - PartiqlAst.Expr.InCollection( - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.InCollection]. - */ - fun inCollection( - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.InCollection = - PartiqlAst.Expr.InCollection( - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.IsType]. - */ - fun isType( - value: Expr, - type: Type, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.IsType = - PartiqlAst.Expr.IsType( - value = value, - type = type, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.SimpleCase]. - */ - fun simpleCase( - expr: Expr, - cases: ExprPairList, - default: Expr? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.SimpleCase = - PartiqlAst.Expr.SimpleCase( - expr = expr, - cases = cases, - default = default, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.SearchedCase]. - */ - fun searchedCase( - cases: ExprPairList, - default: Expr? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.SearchedCase = - PartiqlAst.Expr.SearchedCase( - cases = cases, - default = default, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Struct]. - */ - fun struct( - fields: kotlin.collections.List = emptyList(), - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Struct = - PartiqlAst.Expr.Struct( - fields = fields, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Struct]. - */ - fun struct( - vararg fields: ExprPair, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Struct = - PartiqlAst.Expr.Struct( - fields = fields.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Bag]. - */ - fun bag( - values: kotlin.collections.List = emptyList(), - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Bag = - PartiqlAst.Expr.Bag( - values = values, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Bag]. - */ - fun bag( - vararg values: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Bag = - PartiqlAst.Expr.Bag( - values = values.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.List]. - */ - fun list( - values: kotlin.collections.List = emptyList(), - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.List = - PartiqlAst.Expr.List( - values = values, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.List]. - */ - fun list( - vararg values: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.List = - PartiqlAst.Expr.List( - values = values.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Sexp]. - */ - fun sexp( - values: kotlin.collections.List = emptyList(), - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Sexp = - PartiqlAst.Expr.Sexp( - values = values, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Sexp]. - */ - fun sexp( - vararg values: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Sexp = - PartiqlAst.Expr.Sexp( - values = values.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Date]. - */ - fun date( - year: Long, - month: Long, - day: Long, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Date = - PartiqlAst.Expr.Date( - year = year.asPrimitive(), - month = month.asPrimitive(), - day = day.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Date]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun date_( - year: org.partiql.pig.runtime.LongPrimitive, - month: org.partiql.pig.runtime.LongPrimitive, - day: org.partiql.pig.runtime.LongPrimitive, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Date = - PartiqlAst.Expr.Date( - year = year, - month = month, - day = day, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.LitTime]. - */ - fun litTime( - value: TimeValue, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.LitTime = - PartiqlAst.Expr.LitTime( - value = value, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Union]. - */ - fun union( - setq: SetQuantifier, - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Union = - PartiqlAst.Expr.Union( - setq = setq, - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Union]. - */ - fun union( - setq: SetQuantifier, - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Union = - PartiqlAst.Expr.Union( - setq = setq, - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Except]. - */ - fun except( - setq: SetQuantifier, - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Except = - PartiqlAst.Expr.Except( - setq = setq, - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Except]. - */ - fun except( - setq: SetQuantifier, - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Except = - PartiqlAst.Expr.Except( - setq = setq, - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Intersect]. - */ - fun intersect( - setq: SetQuantifier, - operands: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Intersect = - PartiqlAst.Expr.Intersect( - setq = setq, - operands = operands, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Intersect]. - */ - fun intersect( - setq: SetQuantifier, - operands0: Expr, - operands1: Expr, - vararg operands: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Intersect = - PartiqlAst.Expr.Intersect( - setq = setq, - operands = listOf(operands0, operands1) + operands.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Path]. - */ - fun path( - root: Expr, - steps: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Path = - PartiqlAst.Expr.Path( - root = root, - steps = steps, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Path]. - */ - fun path( - root: Expr, - steps0: PathStep, - vararg steps: PathStep, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Path = - PartiqlAst.Expr.Path( - root = root, - steps = listOf(steps0) + steps.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Call]. - */ - fun call( - funcName: String, - args: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Call = - PartiqlAst.Expr.Call( - funcName = funcName.asPrimitive(), - args = args, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Call]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun call_( - funcName: org.partiql.pig.runtime.SymbolPrimitive, - args: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Call = - PartiqlAst.Expr.Call( - funcName = funcName, - args = args, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Call]. - */ - fun call( - funcName: String, - args0: Expr, - vararg args: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Call = - PartiqlAst.Expr.Call( - funcName = funcName?.asPrimitive(), - args = listOf(args0) + args.toList(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Call]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun call_( - funcName: org.partiql.pig.runtime.SymbolPrimitive, - args0: Expr, - vararg args: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Call = - PartiqlAst.Expr.Call( - funcName = funcName, - args = listOf(args0) + args.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.CallAgg]. - */ - fun callAgg( - setq: SetQuantifier, - funcName: String, - arg: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.CallAgg = - PartiqlAst.Expr.CallAgg( - setq = setq, - funcName = funcName.asPrimitive(), - arg = arg, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.CallAgg]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun callAgg_( - setq: SetQuantifier, - funcName: org.partiql.pig.runtime.SymbolPrimitive, - arg: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.CallAgg = - PartiqlAst.Expr.CallAgg( - setq = setq, - funcName = funcName, - arg = arg, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Cast]. - */ - fun cast( - value: Expr, - asType: Type, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Cast = - PartiqlAst.Expr.Cast( - value = value, - asType = asType, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.CanCast]. - */ - fun canCast( - value: Expr, - asType: Type, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.CanCast = - PartiqlAst.Expr.CanCast( - value = value, - asType = asType, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.CanLosslessCast]. - */ - fun canLosslessCast( - value: Expr, - asType: Type, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.CanLosslessCast = - PartiqlAst.Expr.CanLosslessCast( - value = value, - asType = asType, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.NullIf]. - */ - fun nullIf( - expr1: Expr, - expr2: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.NullIf = - PartiqlAst.Expr.NullIf( - expr1 = expr1, - expr2 = expr2, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Coalesce]. - */ - fun coalesce( - args: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Coalesce = - PartiqlAst.Expr.Coalesce( - args = args, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Expr.Coalesce]. - */ - fun coalesce( - args0: Expr, - vararg args: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Coalesce = - PartiqlAst.Expr.Coalesce( - args = listOf(args0) + args.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Expr.Select]. - */ - fun select( - setq: SetQuantifier? = null, - project: Projection, - from: FromSource, - fromLet: Let? = null, - where: Expr? = null, - group: GroupBy? = null, - having: Expr? = null, - order: OrderBy? = null, - limit: Expr? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Expr.Select = - PartiqlAst.Expr.Select( - setq = setq, - project = project, - from = from, - fromLet = fromLet, - where = where, - group = group, - having = having, - order = order, - limit = limit, - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: PathStep - /** - * Creates an instance of [PartiqlAst.PathStep.PathExpr]. - */ - fun pathExpr( - index: Expr, - case: CaseSensitivity, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.PathStep.PathExpr = - PartiqlAst.PathStep.PathExpr( - index = index, - case = case, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.PathStep.PathWildcard]. - */ - fun pathWildcard( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.PathStep.PathWildcard = - PartiqlAst.PathStep.PathWildcard( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.PathStep.PathUnpivot]. - */ - fun pathUnpivot( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.PathStep.PathUnpivot = - PartiqlAst.PathStep.PathUnpivot( - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: Projection - /** - * Creates an instance of [PartiqlAst.Projection.ProjectStar]. - */ - fun projectStar( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Projection.ProjectStar = - PartiqlAst.Projection.ProjectStar( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Projection.ProjectList]. - */ - fun projectList( - projectItems: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Projection.ProjectList = - PartiqlAst.Projection.ProjectList( - projectItems = projectItems, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Projection.ProjectList]. - */ - fun projectList( - projectItems0: ProjectItem, - vararg projectItems: ProjectItem, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Projection.ProjectList = - PartiqlAst.Projection.ProjectList( - projectItems = listOf(projectItems0) + projectItems.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Projection.ProjectPivot]. - */ - fun projectPivot( - value: Expr, - key: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Projection.ProjectPivot = - PartiqlAst.Projection.ProjectPivot( - value = value, - key = key, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Projection.ProjectValue]. - */ - fun projectValue( - value: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Projection.ProjectValue = - PartiqlAst.Projection.ProjectValue( - value = value, - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: ProjectItem - /** - * Creates an instance of [PartiqlAst.ProjectItem.ProjectAll]. - */ - fun projectAll( - expr: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ProjectItem.ProjectAll = - PartiqlAst.ProjectItem.ProjectAll( - expr = expr, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.ProjectItem.ProjectExpr]. - */ - fun projectExpr( - expr: Expr, - asAlias: String? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ProjectItem.ProjectExpr = - PartiqlAst.ProjectItem.ProjectExpr( - expr = expr, - asAlias = asAlias?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.ProjectItem.ProjectExpr]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun projectExpr_( - expr: Expr, - asAlias: org.partiql.pig.runtime.SymbolPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ProjectItem.ProjectExpr = - PartiqlAst.ProjectItem.ProjectExpr( - expr = expr, - asAlias = asAlias, - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: FromSource - /** - * Creates an instance of [PartiqlAst.FromSource.Scan]. - */ - fun scan( - expr: Expr, - asAlias: String? = null, - atAlias: String? = null, - byAlias: String? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.FromSource.Scan = - PartiqlAst.FromSource.Scan( - expr = expr, - asAlias = asAlias?.asPrimitive(), - atAlias = atAlias?.asPrimitive(), - byAlias = byAlias?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.FromSource.Scan]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun scan_( - expr: Expr, - asAlias: org.partiql.pig.runtime.SymbolPrimitive? = null, - atAlias: org.partiql.pig.runtime.SymbolPrimitive? = null, - byAlias: org.partiql.pig.runtime.SymbolPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.FromSource.Scan = - PartiqlAst.FromSource.Scan( - expr = expr, - asAlias = asAlias, - atAlias = atAlias, - byAlias = byAlias, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.FromSource.Unpivot]. - */ - fun unpivot( - expr: Expr, - asAlias: String? = null, - atAlias: String? = null, - byAlias: String? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.FromSource.Unpivot = - PartiqlAst.FromSource.Unpivot( - expr = expr, - asAlias = asAlias?.asPrimitive(), - atAlias = atAlias?.asPrimitive(), - byAlias = byAlias?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.FromSource.Unpivot]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun unpivot_( - expr: Expr, - asAlias: org.partiql.pig.runtime.SymbolPrimitive? = null, - atAlias: org.partiql.pig.runtime.SymbolPrimitive? = null, - byAlias: org.partiql.pig.runtime.SymbolPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.FromSource.Unpivot = - PartiqlAst.FromSource.Unpivot( - expr = expr, - asAlias = asAlias, - atAlias = atAlias, - byAlias = byAlias, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.FromSource.Join]. - */ - fun join( - type: JoinType, - left: FromSource, - right: FromSource, - predicate: Expr? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.FromSource.Join = - PartiqlAst.FromSource.Join( - type = type, - left = left, - right = right, - predicate = predicate, - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: JoinType - /** - * Creates an instance of [PartiqlAst.JoinType.Inner]. - */ - fun inner( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.JoinType.Inner = - PartiqlAst.JoinType.Inner( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.JoinType.Left]. - */ - fun left( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.JoinType.Left = - PartiqlAst.JoinType.Left( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.JoinType.Right]. - */ - fun right( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.JoinType.Right = - PartiqlAst.JoinType.Right( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.JoinType.Full]. - */ - fun full( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.JoinType.Full = - PartiqlAst.JoinType.Full( - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: GroupingStrategy - /** - * Creates an instance of [PartiqlAst.GroupingStrategy.GroupFull]. - */ - fun groupFull( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.GroupingStrategy.GroupFull = - PartiqlAst.GroupingStrategy.GroupFull( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.GroupingStrategy.GroupPartial]. - */ - fun groupPartial( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.GroupingStrategy.GroupPartial = - PartiqlAst.GroupingStrategy.GroupPartial( - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: OrderingSpec - /** - * Creates an instance of [PartiqlAst.OrderingSpec.Asc]. - */ - fun asc( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.OrderingSpec.Asc = - PartiqlAst.OrderingSpec.Asc( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.OrderingSpec.Desc]. - */ - fun desc( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.OrderingSpec.Desc = - PartiqlAst.OrderingSpec.Desc( - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: CaseSensitivity - /** - * Creates an instance of [PartiqlAst.CaseSensitivity.CaseSensitive]. - */ - fun caseSensitive( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.CaseSensitivity.CaseSensitive = - PartiqlAst.CaseSensitivity.CaseSensitive( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.CaseSensitivity.CaseInsensitive]. - */ - fun caseInsensitive( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.CaseSensitivity.CaseInsensitive = - PartiqlAst.CaseSensitivity.CaseInsensitive( - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: ScopeQualifier - /** - * Creates an instance of [PartiqlAst.ScopeQualifier.Unqualified]. - */ - fun unqualified( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ScopeQualifier.Unqualified = - PartiqlAst.ScopeQualifier.Unqualified( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.ScopeQualifier.LocalsFirst]. - */ - fun localsFirst( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ScopeQualifier.LocalsFirst = - PartiqlAst.ScopeQualifier.LocalsFirst( - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: SetQuantifier - /** - * Creates an instance of [PartiqlAst.SetQuantifier.All]. - */ - fun all( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.SetQuantifier.All = - PartiqlAst.SetQuantifier.All( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.SetQuantifier.Distinct]. - */ - fun distinct( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.SetQuantifier.Distinct = - PartiqlAst.SetQuantifier.Distinct( - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: DmlOp - /** - * Creates an instance of [PartiqlAst.DmlOp.Insert]. - */ - fun insert( - target: Expr, - values: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DmlOp.Insert = - PartiqlAst.DmlOp.Insert( - target = target, - values = values, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.DmlOp.InsertValue]. - */ - fun insertValue( - target: Expr, - value: Expr, - index: Expr? = null, - onConflict: OnConflict? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DmlOp.InsertValue = - PartiqlAst.DmlOp.InsertValue( - target = target, - value = value, - index = index, - onConflict = onConflict, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.DmlOp.Set]. - */ - fun set( - assignment: Assignment, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DmlOp.Set = - PartiqlAst.DmlOp.Set( - assignment = assignment, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.DmlOp.Remove]. - */ - fun remove( - target: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DmlOp.Remove = - PartiqlAst.DmlOp.Remove( - target = target, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.DmlOp.Delete]. - */ - fun delete( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DmlOp.Delete = - PartiqlAst.DmlOp.Delete( - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: ConflictAction - /** - * Creates an instance of [PartiqlAst.ConflictAction.DoNothing]. - */ - fun doNothing( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ConflictAction.DoNothing = - PartiqlAst.ConflictAction.DoNothing( - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: DdlOp - /** - * Creates an instance of [PartiqlAst.DdlOp.CreateTable]. - */ - fun createTable( - tableName: String, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DdlOp.CreateTable = - PartiqlAst.DdlOp.CreateTable( - tableName = tableName.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.DdlOp.CreateTable]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun createTable_( - tableName: org.partiql.pig.runtime.SymbolPrimitive, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DdlOp.CreateTable = - PartiqlAst.DdlOp.CreateTable( - tableName = tableName, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.DdlOp.DropTable]. - */ - fun dropTable( - tableName: Identifier, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DdlOp.DropTable = - PartiqlAst.DdlOp.DropTable( - tableName = tableName, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.DdlOp.UndropTable]. - */ - fun undropTable( - tableName: String, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DdlOp.UndropTable = - PartiqlAst.DdlOp.UndropTable( - tableName = tableName.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.DdlOp.UndropTable]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun undropTable_( - tableName: org.partiql.pig.runtime.SymbolPrimitive, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DdlOp.UndropTable = - PartiqlAst.DdlOp.UndropTable( - tableName = tableName, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.DdlOp.CreateIndex]. - */ - fun createIndex( - indexName: Identifier, - fields: kotlin.collections.List, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DdlOp.CreateIndex = - PartiqlAst.DdlOp.CreateIndex( - indexName = indexName, - fields = fields, - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.DdlOp.CreateIndex]. - */ - fun createIndex( - indexName: Identifier, - fields0: Expr, - vararg fields: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DdlOp.CreateIndex = - PartiqlAst.DdlOp.CreateIndex( - indexName = indexName, - fields = listOf(fields0) + fields.toList(), - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.DdlOp.DropIndex]. - */ - fun dropIndex( - table: Identifier, - keys: Identifier, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.DdlOp.DropIndex = - PartiqlAst.DdlOp.DropIndex( - table = table, - keys = keys, - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: ColumnComponent - /** - * Creates an instance of [PartiqlAst.ColumnComponent.ReturningWildcard]. - */ - fun returningWildcard( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ColumnComponent.ReturningWildcard = - PartiqlAst.ColumnComponent.ReturningWildcard( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.ColumnComponent.ReturningColumn]. - */ - fun returningColumn( - expr: Expr, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ColumnComponent.ReturningColumn = - PartiqlAst.ColumnComponent.ReturningColumn( - expr = expr, - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: ReturningMapping - /** - * Creates an instance of [PartiqlAst.ReturningMapping.ModifiedNew]. - */ - fun modifiedNew( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ReturningMapping.ModifiedNew = - PartiqlAst.ReturningMapping.ModifiedNew( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.ReturningMapping.ModifiedOld]. - */ - fun modifiedOld( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ReturningMapping.ModifiedOld = - PartiqlAst.ReturningMapping.ModifiedOld( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.ReturningMapping.AllNew]. - */ - fun allNew( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ReturningMapping.AllNew = - PartiqlAst.ReturningMapping.AllNew( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.ReturningMapping.AllOld]. - */ - fun allOld( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.ReturningMapping.AllOld = - PartiqlAst.ReturningMapping.AllOld( - metas = newMetaContainer() + metas - ) - - - // Variants for Sum: Type - /** - * Creates an instance of [PartiqlAst.Type.NullType]. - */ - fun nullType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.NullType = - PartiqlAst.Type.NullType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.BooleanType]. - */ - fun booleanType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.BooleanType = - PartiqlAst.Type.BooleanType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.SmallintType]. - */ - fun smallintType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.SmallintType = - PartiqlAst.Type.SmallintType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.Integer4Type]. - */ - fun integer4Type( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.Integer4Type = - PartiqlAst.Type.Integer4Type( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.Integer8Type]. - */ - fun integer8Type( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.Integer8Type = - PartiqlAst.Type.Integer8Type( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.IntegerType]. - */ - fun integerType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.IntegerType = - PartiqlAst.Type.IntegerType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.FloatType]. - */ - fun floatType( - precision: Long? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.FloatType = - PartiqlAst.Type.FloatType( - precision = precision?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Type.FloatType]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun floatType_( - precision: org.partiql.pig.runtime.LongPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.FloatType = - PartiqlAst.Type.FloatType( - precision = precision, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.RealType]. - */ - fun realType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.RealType = - PartiqlAst.Type.RealType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.DoublePrecisionType]. - */ - fun doublePrecisionType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.DoublePrecisionType = - PartiqlAst.Type.DoublePrecisionType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.DecimalType]. - */ - fun decimalType( - precision: Long? = null, - scale: Long? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.DecimalType = - PartiqlAst.Type.DecimalType( - precision = precision?.asPrimitive(), - scale = scale?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Type.DecimalType]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun decimalType_( - precision: org.partiql.pig.runtime.LongPrimitive? = null, - scale: org.partiql.pig.runtime.LongPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.DecimalType = - PartiqlAst.Type.DecimalType( - precision = precision, - scale = scale, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.NumericType]. - */ - fun numericType( - precision: Long? = null, - scale: Long? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.NumericType = - PartiqlAst.Type.NumericType( - precision = precision?.asPrimitive(), - scale = scale?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Type.NumericType]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun numericType_( - precision: org.partiql.pig.runtime.LongPrimitive? = null, - scale: org.partiql.pig.runtime.LongPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.NumericType = - PartiqlAst.Type.NumericType( - precision = precision, - scale = scale, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.TimestampType]. - */ - fun timestampType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.TimestampType = - PartiqlAst.Type.TimestampType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.CharacterType]. - */ - fun characterType( - length: Long? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.CharacterType = - PartiqlAst.Type.CharacterType( - length = length?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Type.CharacterType]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun characterType_( - length: org.partiql.pig.runtime.LongPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.CharacterType = - PartiqlAst.Type.CharacterType( - length = length, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.CharacterVaryingType]. - */ - fun characterVaryingType( - length: Long? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.CharacterVaryingType = - PartiqlAst.Type.CharacterVaryingType( - length = length?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Type.CharacterVaryingType]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun characterVaryingType_( - length: org.partiql.pig.runtime.LongPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.CharacterVaryingType = - PartiqlAst.Type.CharacterVaryingType( - length = length, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.MissingType]. - */ - fun missingType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.MissingType = - PartiqlAst.Type.MissingType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.StringType]. - */ - fun stringType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.StringType = - PartiqlAst.Type.StringType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.SymbolType]. - */ - fun symbolType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.SymbolType = - PartiqlAst.Type.SymbolType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.BlobType]. - */ - fun blobType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.BlobType = - PartiqlAst.Type.BlobType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.ClobType]. - */ - fun clobType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.ClobType = - PartiqlAst.Type.ClobType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.DateType]. - */ - fun dateType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.DateType = - PartiqlAst.Type.DateType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.TimeType]. - */ - fun timeType( - precision: Long? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.TimeType = - PartiqlAst.Type.TimeType( - precision = precision?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Type.TimeType]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun timeType_( - precision: org.partiql.pig.runtime.LongPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.TimeType = - PartiqlAst.Type.TimeType( - precision = precision, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.TimeWithTimeZoneType]. - */ - fun timeWithTimeZoneType( - precision: Long? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.TimeWithTimeZoneType = - PartiqlAst.Type.TimeWithTimeZoneType( - precision = precision?.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Type.TimeWithTimeZoneType]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun timeWithTimeZoneType_( - precision: org.partiql.pig.runtime.LongPrimitive? = null, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.TimeWithTimeZoneType = - PartiqlAst.Type.TimeWithTimeZoneType( - precision = precision, - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.StructType]. - */ - fun structType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.StructType = - PartiqlAst.Type.StructType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.TupleType]. - */ - fun tupleType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.TupleType = - PartiqlAst.Type.TupleType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.ListType]. - */ - fun listType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.ListType = - PartiqlAst.Type.ListType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.SexpType]. - */ - fun sexpType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.SexpType = - PartiqlAst.Type.SexpType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.BagType]. - */ - fun bagType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.BagType = - PartiqlAst.Type.BagType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.AnyType]. - */ - fun anyType( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.AnyType = - PartiqlAst.Type.AnyType( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.EsBoolean]. - */ - fun esBoolean( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.EsBoolean = - PartiqlAst.Type.EsBoolean( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.EsInteger]. - */ - fun esInteger( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.EsInteger = - PartiqlAst.Type.EsInteger( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.EsFloat]. - */ - fun esFloat( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.EsFloat = - PartiqlAst.Type.EsFloat( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.EsText]. - */ - fun esText( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.EsText = - PartiqlAst.Type.EsText( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.EsAny]. - */ - fun esAny( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.EsAny = - PartiqlAst.Type.EsAny( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.SparkShort]. - */ - fun sparkShort( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.SparkShort = - PartiqlAst.Type.SparkShort( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.SparkInteger]. - */ - fun sparkInteger( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.SparkInteger = - PartiqlAst.Type.SparkInteger( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.SparkLong]. - */ - fun sparkLong( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.SparkLong = - PartiqlAst.Type.SparkLong( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.SparkDouble]. - */ - fun sparkDouble( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.SparkDouble = - PartiqlAst.Type.SparkDouble( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.SparkBoolean]. - */ - fun sparkBoolean( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.SparkBoolean = - PartiqlAst.Type.SparkBoolean( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.SparkFloat]. - */ - fun sparkFloat( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.SparkFloat = - PartiqlAst.Type.SparkFloat( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.RsVarcharMax]. - */ - fun rsVarcharMax( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.RsVarcharMax = - PartiqlAst.Type.RsVarcharMax( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.RsInteger]. - */ - fun rsInteger( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.RsInteger = - PartiqlAst.Type.RsInteger( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.RsBigint]. - */ - fun rsBigint( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.RsBigint = - PartiqlAst.Type.RsBigint( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.RsBoolean]. - */ - fun rsBoolean( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.RsBoolean = - PartiqlAst.Type.RsBoolean( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.RsReal]. - */ - fun rsReal( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.RsReal = - PartiqlAst.Type.RsReal( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.RsDoublePrecision]. - */ - fun rsDoublePrecision( - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.RsDoublePrecision = - PartiqlAst.Type.RsDoublePrecision( - metas = newMetaContainer() + metas - ) - - - /** - * Creates an instance of [PartiqlAst.Type.CustomType]. - */ - fun customType( - name: String, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.CustomType = - PartiqlAst.Type.CustomType( - name = name.asPrimitive(), - metas = newMetaContainer() + metas - ) - - /** - * Creates an instance of [PartiqlAst.Type.CustomType]. - * - * Use this variant when metas must be passed to primitive child elements. - * - * (The "_" suffix is needed to work-around conflicts due to type erasure and ambiguities with null arguments.) - */ - fun customType_( - name: org.partiql.pig.runtime.SymbolPrimitive, - metas: MetaContainer = emptyMetaContainer() - ): PartiqlAst.Type.CustomType = - PartiqlAst.Type.CustomType( - name = name, - metas = newMetaContainer() + metas - ) - } - - /** Default implementation of [Builder] that uses all default method implementations. */ - private object PartiqlAstBuilder : Builder - - /** Base class for all PartiqlAst types. */ - abstract class PartiqlAstNode : DomainNode { - abstract override fun copy(metas: MetaContainer): PartiqlAstNode - override fun toString() = toIonElement().toString() - abstract override fun withMeta(metaKey: String, metaValue: Any): PartiqlAstNode - abstract override fun toIonElement(): SexpElement - } - - - ///////////////////////////////////////////////////////////////////////////// - // Tuple Types - ///////////////////////////////////////////////////////////////////////////// - class TimeValue( - val hour: org.partiql.pig.runtime.LongPrimitive, - val minute: org.partiql.pig.runtime.LongPrimitive, - val second: org.partiql.pig.runtime.LongPrimitive, - val nano: org.partiql.pig.runtime.LongPrimitive, - val precision: org.partiql.pig.runtime.LongPrimitive, - val tzMinutes: org.partiql.pig.runtime.LongPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): TimeValue = - TimeValue( - hour = hour, - minute = minute, - second = second, - nano = nano, - precision = precision, - tzMinutes = tzMinutes, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): TimeValue = - TimeValue( - hour = hour, - minute = minute, - second = second, - nano = nano, - precision = precision, - tzMinutes = tzMinutes, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("time_value"), - hour.toIonElement(), - minute.toIonElement(), - second.toIonElement(), - nano.toIonElement(), - precision.toIonElement(), - tzMinutes?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - hour: org.partiql.pig.runtime.LongPrimitive = this.hour, - minute: org.partiql.pig.runtime.LongPrimitive = this.minute, - second: org.partiql.pig.runtime.LongPrimitive = this.second, - nano: org.partiql.pig.runtime.LongPrimitive = this.nano, - precision: org.partiql.pig.runtime.LongPrimitive = this.precision, - tzMinutes: org.partiql.pig.runtime.LongPrimitive? = this.tzMinutes, - metas: MetaContainer = this.metas - ) = - TimeValue( - hour, - minute, - second, - nano, - precision, - tzMinutes, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != TimeValue::class.java) return false - - other as TimeValue - if (hour != other.hour) return false - if (minute != other.minute) return false - if (second != other.second) return false - if (nano != other.nano) return false - if (precision != other.precision) return false - if (tzMinutes != other.tzMinutes) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = hour.hashCode() - hc = 31 * hc + minute.hashCode() - hc = 31 * hc + second.hashCode() - hc = 31 * hc + nano.hashCode() - hc = 31 * hc + precision.hashCode() - hc = 31 * hc + tzMinutes.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Let( - val letBindings: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): Let = - Let( - letBindings = letBindings, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Let = - Let( - letBindings = letBindings, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("let"), - *letBindings.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - letBindings: kotlin.collections.List = this.letBindings, - metas: MetaContainer = this.metas - ) = - Let( - letBindings, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Let::class.java) return false - - other as Let - if (letBindings != other.letBindings) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = letBindings.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class LetBinding( - val expr: Expr, - val name: org.partiql.pig.runtime.SymbolPrimitive, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): LetBinding = - LetBinding( - expr = expr, - name = name, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): LetBinding = - LetBinding( - expr = expr, - name = name, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("let_binding"), - expr.toIonElement(), - name.toIonElement(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - name: org.partiql.pig.runtime.SymbolPrimitive = this.name, - metas: MetaContainer = this.metas - ) = - LetBinding( - expr, - name, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != LetBinding::class.java) return false - - other as LetBinding - if (expr != other.expr) return false - if (name != other.name) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc = 31 * hc + name.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class ExprPair( - val first: Expr, - val second: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): ExprPair = - ExprPair( - first = first, - second = second, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ExprPair = - ExprPair( - first = first, - second = second, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("expr_pair"), - first.toIonElement(), - second.toIonElement(), - metas = metas) - return elements - } - - fun copy( - first: Expr = this.first, - second: Expr = this.second, - metas: MetaContainer = this.metas - ) = - ExprPair( - first, - second, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ExprPair::class.java) return false - - other as ExprPair - if (first != other.first) return false - if (second != other.second) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = first.hashCode() - hc = 31 * hc + second.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class ExprPairList( - val pairs: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): ExprPairList = - ExprPairList( - pairs = pairs, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ExprPairList = - ExprPairList( - pairs = pairs, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("expr_pair_list"), - *pairs.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - pairs: kotlin.collections.List = this.pairs, - metas: MetaContainer = this.metas - ) = - ExprPairList( - pairs, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ExprPairList::class.java) return false - - other as ExprPairList - if (pairs != other.pairs) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = pairs.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class GroupBy( - val strategy: GroupingStrategy, - val keyList: GroupKeyList, - val groupAsAlias: org.partiql.pig.runtime.SymbolPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): GroupBy = - GroupBy( - strategy = strategy, - keyList = keyList, - groupAsAlias = groupAsAlias, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): GroupBy = - GroupBy( - strategy = strategy, - keyList = keyList, - groupAsAlias = groupAsAlias, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("group_by"), - strategy.toIonElement(), - keyList.toIonElement(), - groupAsAlias?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - strategy: GroupingStrategy = this.strategy, - keyList: GroupKeyList = this.keyList, - groupAsAlias: org.partiql.pig.runtime.SymbolPrimitive? = this.groupAsAlias, - metas: MetaContainer = this.metas - ) = - GroupBy( - strategy, - keyList, - groupAsAlias, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != GroupBy::class.java) return false - - other as GroupBy - if (strategy != other.strategy) return false - if (keyList != other.keyList) return false - if (groupAsAlias != other.groupAsAlias) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = strategy.hashCode() - hc = 31 * hc + keyList.hashCode() - hc = 31 * hc + groupAsAlias.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class GroupKeyList( - val keys: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): GroupKeyList = - GroupKeyList( - keys = keys, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): GroupKeyList = - GroupKeyList( - keys = keys, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("group_key_list"), - *keys.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - keys: kotlin.collections.List = this.keys, - metas: MetaContainer = this.metas - ) = - GroupKeyList( - keys, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != GroupKeyList::class.java) return false - - other as GroupKeyList - if (keys != other.keys) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = keys.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class GroupKey( - val expr: Expr, - val asAlias: org.partiql.pig.runtime.SymbolPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): GroupKey = - GroupKey( - expr = expr, - asAlias = asAlias, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): GroupKey = - GroupKey( - expr = expr, - asAlias = asAlias, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("group_key"), - expr.toIonElement(), - asAlias?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - asAlias: org.partiql.pig.runtime.SymbolPrimitive? = this.asAlias, - metas: MetaContainer = this.metas - ) = - GroupKey( - expr, - asAlias, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != GroupKey::class.java) return false - - other as GroupKey - if (expr != other.expr) return false - if (asAlias != other.asAlias) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc = 31 * hc + asAlias.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class OrderBy( - val sortSpecs: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): OrderBy = - OrderBy( - sortSpecs = sortSpecs, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): OrderBy = - OrderBy( - sortSpecs = sortSpecs, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("order_by"), - *sortSpecs.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - sortSpecs: kotlin.collections.List = this.sortSpecs, - metas: MetaContainer = this.metas - ) = - OrderBy( - sortSpecs, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != OrderBy::class.java) return false - - other as OrderBy - if (sortSpecs != other.sortSpecs) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = sortSpecs.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class SortSpec( - val expr: Expr, - val orderingSpec: OrderingSpec?, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): SortSpec = - SortSpec( - expr = expr, - orderingSpec = orderingSpec, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SortSpec = - SortSpec( - expr = expr, - orderingSpec = orderingSpec, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("sort_spec"), - expr.toIonElement(), - orderingSpec?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - orderingSpec: OrderingSpec? = this.orderingSpec, - metas: MetaContainer = this.metas - ) = - SortSpec( - expr, - orderingSpec, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SortSpec::class.java) return false - - other as SortSpec - if (expr != other.expr) return false - if (orderingSpec != other.orderingSpec) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc = 31 * hc + orderingSpec.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class DmlOpList( - val ops: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): DmlOpList = - DmlOpList( - ops = ops, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): DmlOpList = - DmlOpList( - ops = ops, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("dml_op_list"), - *ops.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - ops: kotlin.collections.List = this.ops, - metas: MetaContainer = this.metas - ) = - DmlOpList( - ops, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != DmlOpList::class.java) return false - - other as DmlOpList - if (ops != other.ops) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = ops.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class OnConflict( - val expr: Expr, - val conflictAction: ConflictAction, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): OnConflict = - OnConflict( - expr = expr, - conflictAction = conflictAction, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): OnConflict = - OnConflict( - expr = expr, - conflictAction = conflictAction, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("on_conflict"), - expr.toIonElement(), - conflictAction.toIonElement(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - conflictAction: ConflictAction = this.conflictAction, - metas: MetaContainer = this.metas - ) = - OnConflict( - expr, - conflictAction, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != OnConflict::class.java) return false - - other as OnConflict - if (expr != other.expr) return false - if (conflictAction != other.conflictAction) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc = 31 * hc + conflictAction.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class ReturningExpr( - val elems: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): ReturningExpr = - ReturningExpr( - elems = elems, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ReturningExpr = - ReturningExpr( - elems = elems, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("returning_expr"), - *elems.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - elems: kotlin.collections.List = this.elems, - metas: MetaContainer = this.metas - ) = - ReturningExpr( - elems, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ReturningExpr::class.java) return false - - other as ReturningExpr - if (elems != other.elems) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = elems.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class ReturningElem( - val mapping: ReturningMapping, - val column: ColumnComponent, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): ReturningElem = - ReturningElem( - mapping = mapping, - column = column, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ReturningElem = - ReturningElem( - mapping = mapping, - column = column, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("returning_elem"), - mapping.toIonElement(), - column.toIonElement(), - metas = metas) - return elements - } - - fun copy( - mapping: ReturningMapping = this.mapping, - column: ColumnComponent = this.column, - metas: MetaContainer = this.metas - ) = - ReturningElem( - mapping, - column, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ReturningElem::class.java) return false - - other as ReturningElem - if (mapping != other.mapping) return false - if (column != other.column) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = mapping.hashCode() - hc = 31 * hc + column.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Identifier( - val name: org.partiql.pig.runtime.SymbolPrimitive, - val case: CaseSensitivity, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): Identifier = - Identifier( - name = name, - case = case, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Identifier = - Identifier( - name = name, - case = case, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("identifier"), - name.toIonElement(), - case.toIonElement(), - metas = metas) - return elements - } - - fun copy( - name: org.partiql.pig.runtime.SymbolPrimitive = this.name, - case: CaseSensitivity = this.case, - metas: MetaContainer = this.metas - ) = - Identifier( - name, - case, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Identifier::class.java) return false - - other as Identifier - if (name != other.name) return false - if (case != other.case) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = name.hashCode() - hc = 31 * hc + case.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Assignment( - val target: Expr, - val value: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): PartiqlAstNode() { - - override fun copy(metas: MetaContainer): Assignment = - Assignment( - target = target, - value = value, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Assignment = - Assignment( - target = target, - value = value, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("assignment"), - target.toIonElement(), - value.toIonElement(), - metas = metas) - return elements - } - - fun copy( - target: Expr = this.target, - value: Expr = this.value, - metas: MetaContainer = this.metas - ) = - Assignment( - target, - value, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Assignment::class.java) return false - - other as Assignment - if (target != other.target) return false - if (value != other.value) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = target.hashCode() - hc = 31 * hc + value.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - - ///////////////////////////////////////////////////////////////////////////// - // Sum Types - ///////////////////////////////////////////////////////////////////////////// - - sealed class Statement(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): Statement = - when (this) { - is Query -> copy(metas = metas) - is Dml -> copy(metas = metas) - is Ddl -> copy(metas = metas) - is Exec -> copy(metas = metas) - } - - class Query( - val expr: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): Statement() { - - override fun copy(metas: MetaContainer): Query = - Query( - expr = expr, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Query = - Query( - expr = expr, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("query"), - expr.toIonElement(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - metas: MetaContainer = this.metas - ) = - Query( - expr, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Query::class.java) return false - - other as Query - if (expr != other.expr) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Dml( - val operations: DmlOpList, - val from: FromSource?, - val where: Expr?, - val returning: ReturningExpr?, - override val metas: MetaContainer = emptyMetaContainer() - ): Statement() { - - override fun copy(metas: MetaContainer): Dml = - Dml( - operations = operations, - from = from, - where = where, - returning = returning, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Dml = - Dml( - operations = operations, - from = from, - where = where, - returning = returning, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = listOfNotNull( - ionSymbol("dml"), - operations?.let { ionSexpOf(ionSymbol("operations"), it.toIonElement()) }, - from?.let { ionSexpOf(ionSymbol("from"), it.toIonElement()) }, - where?.let { ionSexpOf(ionSymbol("where"), it.toIonElement()) }, - returning?.let { ionSexpOf(ionSymbol("returning"), it.toIonElement()) } - ) - - return ionSexpOf(elements, metas = metas) - } - - fun copy( - operations: DmlOpList = this.operations, - from: FromSource? = this.from, - where: Expr? = this.where, - returning: ReturningExpr? = this.returning, - metas: MetaContainer = this.metas - ) = - Dml( - operations, - from, - where, - returning, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Dml::class.java) return false - - other as Dml - if (operations != other.operations) return false - if (from != other.from) return false - if (where != other.where) return false - if (returning != other.returning) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operations.hashCode() - hc = 31 * hc + from.hashCode() - hc = 31 * hc + where.hashCode() - hc = 31 * hc + returning.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Ddl( - val op: DdlOp, - override val metas: MetaContainer = emptyMetaContainer() - ): Statement() { - - override fun copy(metas: MetaContainer): Ddl = - Ddl( - op = op, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Ddl = - Ddl( - op = op, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("ddl"), - op.toIonElement(), - metas = metas) - return elements - } - - fun copy( - op: DdlOp = this.op, - metas: MetaContainer = this.metas - ) = - Ddl( - op, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Ddl::class.java) return false - - other as Ddl - if (op != other.op) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = op.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Exec( - val procedureName: org.partiql.pig.runtime.SymbolPrimitive, - val args: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Statement() { - - override fun copy(metas: MetaContainer): Exec = - Exec( - procedureName = procedureName, - args = args, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Exec = - Exec( - procedureName = procedureName, - args = args, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("exec"), - procedureName.toIonElement(), - *args.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - procedureName: org.partiql.pig.runtime.SymbolPrimitive = this.procedureName, - args: kotlin.collections.List = this.args, - metas: MetaContainer = this.metas - ) = - Exec( - procedureName, - args, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Exec::class.java) return false - - other as Exec - if (procedureName != other.procedureName) return false - if (args != other.args) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = procedureName.hashCode() - hc = 31 * hc + args.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - /** Converts instances of [PartiqlAst.Statement] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.Statement): T = when(node) { - is PartiqlAst.Statement.Query -> convertQuery(node) - is PartiqlAst.Statement.Dml -> convertDml(node) - is PartiqlAst.Statement.Ddl -> convertDdl(node) - is PartiqlAst.Statement.Exec -> convertExec(node) - } - - fun convertQuery(node: PartiqlAst.Statement.Query): T - fun convertDml(node: PartiqlAst.Statement.Dml): T - fun convertDdl(node: PartiqlAst.Statement.Ddl): T - fun convertExec(node: PartiqlAst.Statement.Exec): T - } - } - - sealed class Expr(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): Expr = - when (this) { - is Missing -> copy(metas = metas) - is Lit -> copy(metas = metas) - is Id -> copy(metas = metas) - is Parameter -> copy(metas = metas) - is Not -> copy(metas = metas) - is Pos -> copy(metas = metas) - is Neg -> copy(metas = metas) - is Plus -> copy(metas = metas) - is Minus -> copy(metas = metas) - is Times -> copy(metas = metas) - is Divide -> copy(metas = metas) - is Modulo -> copy(metas = metas) - is Concat -> copy(metas = metas) - is And -> copy(metas = metas) - is Or -> copy(metas = metas) - is Eq -> copy(metas = metas) - is Ne -> copy(metas = metas) - is Gt -> copy(metas = metas) - is Gte -> copy(metas = metas) - is Lt -> copy(metas = metas) - is Lte -> copy(metas = metas) - is Like -> copy(metas = metas) - is Between -> copy(metas = metas) - is InCollection -> copy(metas = metas) - is IsType -> copy(metas = metas) - is SimpleCase -> copy(metas = metas) - is SearchedCase -> copy(metas = metas) - is Struct -> copy(metas = metas) - is Bag -> copy(metas = metas) - is List -> copy(metas = metas) - is Sexp -> copy(metas = metas) - is Date -> copy(metas = metas) - is LitTime -> copy(metas = metas) - is Union -> copy(metas = metas) - is Except -> copy(metas = metas) - is Intersect -> copy(metas = metas) - is Path -> copy(metas = metas) - is Call -> copy(metas = metas) - is CallAgg -> copy(metas = metas) - is Cast -> copy(metas = metas) - is CanCast -> copy(metas = metas) - is CanLosslessCast -> copy(metas = metas) - is NullIf -> copy(metas = metas) - is Coalesce -> copy(metas = metas) - is Select -> copy(metas = metas) - } - - class Missing( - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Missing = - Missing( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Missing = - Missing( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("missing"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Missing::class.java) return false - - return true - } - - override fun hashCode(): Int = 2000 - } - - class Lit( - val value: com.amazon.ionelement.api.AnyElement, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Lit = - Lit( - value = value, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Lit = - Lit( - value = value, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("lit"), - value.toIonElement(), - metas = metas) - return elements - } - - fun copy( - value: com.amazon.ionelement.api.AnyElement = this.value, - metas: MetaContainer = this.metas - ) = - Lit( - value, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Lit::class.java) return false - - other as Lit - if (value != other.value) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = value.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Id( - val name: org.partiql.pig.runtime.SymbolPrimitive, - val case: CaseSensitivity, - val qualifier: ScopeQualifier, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Id = - Id( - name = name, - case = case, - qualifier = qualifier, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Id = - Id( - name = name, - case = case, - qualifier = qualifier, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("id"), - name.toIonElement(), - case.toIonElement(), - qualifier.toIonElement(), - metas = metas) - return elements - } - - fun copy( - name: org.partiql.pig.runtime.SymbolPrimitive = this.name, - case: CaseSensitivity = this.case, - qualifier: ScopeQualifier = this.qualifier, - metas: MetaContainer = this.metas - ) = - Id( - name, - case, - qualifier, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Id::class.java) return false - - other as Id - if (name != other.name) return false - if (case != other.case) return false - if (qualifier != other.qualifier) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = name.hashCode() - hc = 31 * hc + case.hashCode() - hc = 31 * hc + qualifier.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Parameter( - val index: org.partiql.pig.runtime.LongPrimitive, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Parameter = - Parameter( - index = index, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Parameter = - Parameter( - index = index, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("parameter"), - index.toIonElement(), - metas = metas) - return elements - } - - fun copy( - index: org.partiql.pig.runtime.LongPrimitive = this.index, - metas: MetaContainer = this.metas - ) = - Parameter( - index, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Parameter::class.java) return false - - other as Parameter - if (index != other.index) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = index.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Not( - val expr: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Not = - Not( - expr = expr, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Not = - Not( - expr = expr, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("not"), - expr.toIonElement(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - metas: MetaContainer = this.metas - ) = - Not( - expr, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Not::class.java) return false - - other as Not - if (expr != other.expr) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Pos( - val expr: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Pos = - Pos( - expr = expr, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Pos = - Pos( - expr = expr, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("pos"), - expr.toIonElement(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - metas: MetaContainer = this.metas - ) = - Pos( - expr, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Pos::class.java) return false - - other as Pos - if (expr != other.expr) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Neg( - val expr: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Neg = - Neg( - expr = expr, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Neg = - Neg( - expr = expr, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("neg"), - expr.toIonElement(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - metas: MetaContainer = this.metas - ) = - Neg( - expr, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Neg::class.java) return false - - other as Neg - if (expr != other.expr) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Plus( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Plus = - Plus( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Plus = - Plus( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("plus"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Plus( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Plus::class.java) return false - - other as Plus - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Minus( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Minus = - Minus( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Minus = - Minus( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("minus"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Minus( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Minus::class.java) return false - - other as Minus - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Times( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Times = - Times( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Times = - Times( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("times"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Times( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Times::class.java) return false - - other as Times - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Divide( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Divide = - Divide( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Divide = - Divide( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("divide"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Divide( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Divide::class.java) return false - - other as Divide - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Modulo( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Modulo = - Modulo( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Modulo = - Modulo( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("modulo"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Modulo( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Modulo::class.java) return false - - other as Modulo - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Concat( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Concat = - Concat( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Concat = - Concat( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("concat"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Concat( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Concat::class.java) return false - - other as Concat - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class And( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): And = - And( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): And = - And( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("and"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - And( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != And::class.java) return false - - other as And - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Or( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Or = - Or( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Or = - Or( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("or"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Or( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Or::class.java) return false - - other as Or - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Eq( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Eq = - Eq( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Eq = - Eq( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("eq"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Eq( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Eq::class.java) return false - - other as Eq - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Ne( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Ne = - Ne( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Ne = - Ne( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("ne"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Ne( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Ne::class.java) return false - - other as Ne - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Gt( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Gt = - Gt( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Gt = - Gt( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("gt"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Gt( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Gt::class.java) return false - - other as Gt - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Gte( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Gte = - Gte( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Gte = - Gte( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("gte"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Gte( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Gte::class.java) return false - - other as Gte - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Lt( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Lt = - Lt( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Lt = - Lt( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("lt"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Lt( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Lt::class.java) return false - - other as Lt - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Lte( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Lte = - Lte( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Lte = - Lte( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("lte"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Lte( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Lte::class.java) return false - - other as Lte - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Like( - val value: Expr, - val pattern: Expr, - val escape: Expr?, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Like = - Like( - value = value, - pattern = pattern, - escape = escape, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Like = - Like( - value = value, - pattern = pattern, - escape = escape, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("like"), - value.toIonElement(), - pattern.toIonElement(), - escape?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - value: Expr = this.value, - pattern: Expr = this.pattern, - escape: Expr? = this.escape, - metas: MetaContainer = this.metas - ) = - Like( - value, - pattern, - escape, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Like::class.java) return false - - other as Like - if (value != other.value) return false - if (pattern != other.pattern) return false - if (escape != other.escape) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = value.hashCode() - hc = 31 * hc + pattern.hashCode() - hc = 31 * hc + escape.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Between( - val value: Expr, - val from: Expr, - val to: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Between = - Between( - value = value, - from = from, - to = to, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Between = - Between( - value = value, - from = from, - to = to, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("between"), - value.toIonElement(), - from.toIonElement(), - to.toIonElement(), - metas = metas) - return elements - } - - fun copy( - value: Expr = this.value, - from: Expr = this.from, - to: Expr = this.to, - metas: MetaContainer = this.metas - ) = - Between( - value, - from, - to, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Between::class.java) return false - - other as Between - if (value != other.value) return false - if (from != other.from) return false - if (to != other.to) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = value.hashCode() - hc = 31 * hc + from.hashCode() - hc = 31 * hc + to.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class InCollection( - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): InCollection = - InCollection( - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): InCollection = - InCollection( - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("in_collection"), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - InCollection( - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != InCollection::class.java) return false - - other as InCollection - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class IsType( - val value: Expr, - val type: Type, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): IsType = - IsType( - value = value, - type = type, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): IsType = - IsType( - value = value, - type = type, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("is_type"), - value.toIonElement(), - type.toIonElement(), - metas = metas) - return elements - } - - fun copy( - value: Expr = this.value, - type: Type = this.type, - metas: MetaContainer = this.metas - ) = - IsType( - value, - type, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != IsType::class.java) return false - - other as IsType - if (value != other.value) return false - if (type != other.type) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = value.hashCode() - hc = 31 * hc + type.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class SimpleCase( - val expr: Expr, - val cases: ExprPairList, - val default: Expr?, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): SimpleCase = - SimpleCase( - expr = expr, - cases = cases, - default = default, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SimpleCase = - SimpleCase( - expr = expr, - cases = cases, - default = default, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("simple_case"), - expr.toIonElement(), - cases.toIonElement(), - default?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - cases: ExprPairList = this.cases, - default: Expr? = this.default, - metas: MetaContainer = this.metas - ) = - SimpleCase( - expr, - cases, - default, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SimpleCase::class.java) return false - - other as SimpleCase - if (expr != other.expr) return false - if (cases != other.cases) return false - if (default != other.default) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc = 31 * hc + cases.hashCode() - hc = 31 * hc + default.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class SearchedCase( - val cases: ExprPairList, - val default: Expr?, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): SearchedCase = - SearchedCase( - cases = cases, - default = default, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SearchedCase = - SearchedCase( - cases = cases, - default = default, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("searched_case"), - cases.toIonElement(), - default?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - cases: ExprPairList = this.cases, - default: Expr? = this.default, - metas: MetaContainer = this.metas - ) = - SearchedCase( - cases, - default, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SearchedCase::class.java) return false - - other as SearchedCase - if (cases != other.cases) return false - if (default != other.default) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = cases.hashCode() - hc = 31 * hc + default.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Struct( - val fields: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Struct = - Struct( - fields = fields, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Struct = - Struct( - fields = fields, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("struct"), - *fields.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - fields: kotlin.collections.List = this.fields, - metas: MetaContainer = this.metas - ) = - Struct( - fields, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Struct::class.java) return false - - other as Struct - if (fields != other.fields) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = fields.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Bag( - val values: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Bag = - Bag( - values = values, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Bag = - Bag( - values = values, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("bag"), - *values.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - values: kotlin.collections.List = this.values, - metas: MetaContainer = this.metas - ) = - Bag( - values, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Bag::class.java) return false - - other as Bag - if (values != other.values) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = values.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class List( - val values: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): List = - List( - values = values, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): List = - List( - values = values, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("list"), - *values.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - values: kotlin.collections.List = this.values, - metas: MetaContainer = this.metas - ) = - List( - values, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != List::class.java) return false - - other as List - if (values != other.values) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = values.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Sexp( - val values: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Sexp = - Sexp( - values = values, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Sexp = - Sexp( - values = values, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("sexp"), - *values.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - values: kotlin.collections.List = this.values, - metas: MetaContainer = this.metas - ) = - Sexp( - values, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Sexp::class.java) return false - - other as Sexp - if (values != other.values) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = values.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Date( - val year: org.partiql.pig.runtime.LongPrimitive, - val month: org.partiql.pig.runtime.LongPrimitive, - val day: org.partiql.pig.runtime.LongPrimitive, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Date = - Date( - year = year, - month = month, - day = day, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Date = - Date( - year = year, - month = month, - day = day, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("date"), - year.toIonElement(), - month.toIonElement(), - day.toIonElement(), - metas = metas) - return elements - } - - fun copy( - year: org.partiql.pig.runtime.LongPrimitive = this.year, - month: org.partiql.pig.runtime.LongPrimitive = this.month, - day: org.partiql.pig.runtime.LongPrimitive = this.day, - metas: MetaContainer = this.metas - ) = - Date( - year, - month, - day, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Date::class.java) return false - - other as Date - if (year != other.year) return false - if (month != other.month) return false - if (day != other.day) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = year.hashCode() - hc = 31 * hc + month.hashCode() - hc = 31 * hc + day.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class LitTime( - val value: TimeValue, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): LitTime = - LitTime( - value = value, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): LitTime = - LitTime( - value = value, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("lit_time"), - value.toIonElement(), - metas = metas) - return elements - } - - fun copy( - value: TimeValue = this.value, - metas: MetaContainer = this.metas - ) = - LitTime( - value, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != LitTime::class.java) return false - - other as LitTime - if (value != other.value) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = value.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Union( - val setq: SetQuantifier, - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Union = - Union( - setq = setq, - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Union = - Union( - setq = setq, - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("union"), - setq.toIonElement(), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - setq: SetQuantifier = this.setq, - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Union( - setq, - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Union::class.java) return false - - other as Union - if (setq != other.setq) return false - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = setq.hashCode() - hc = 31 * hc + operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Except( - val setq: SetQuantifier, - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Except = - Except( - setq = setq, - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Except = - Except( - setq = setq, - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("except"), - setq.toIonElement(), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - setq: SetQuantifier = this.setq, - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Except( - setq, - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Except::class.java) return false - - other as Except - if (setq != other.setq) return false - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = setq.hashCode() - hc = 31 * hc + operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Intersect( - val setq: SetQuantifier, - val operands: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Intersect = - Intersect( - setq = setq, - operands = operands, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Intersect = - Intersect( - setq = setq, - operands = operands, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("intersect"), - setq.toIonElement(), - *operands.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - setq: SetQuantifier = this.setq, - operands: kotlin.collections.List = this.operands, - metas: MetaContainer = this.metas - ) = - Intersect( - setq, - operands, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Intersect::class.java) return false - - other as Intersect - if (setq != other.setq) return false - if (operands != other.operands) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = setq.hashCode() - hc = 31 * hc + operands.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Path( - val root: Expr, - val steps: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Path = - Path( - root = root, - steps = steps, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Path = - Path( - root = root, - steps = steps, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("path"), - root.toIonElement(), - *steps.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - root: Expr = this.root, - steps: kotlin.collections.List = this.steps, - metas: MetaContainer = this.metas - ) = - Path( - root, - steps, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Path::class.java) return false - - other as Path - if (root != other.root) return false - if (steps != other.steps) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = root.hashCode() - hc = 31 * hc + steps.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Call( - val funcName: org.partiql.pig.runtime.SymbolPrimitive, - val args: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Call = - Call( - funcName = funcName, - args = args, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Call = - Call( - funcName = funcName, - args = args, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("call"), - funcName.toIonElement(), - *args.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - funcName: org.partiql.pig.runtime.SymbolPrimitive = this.funcName, - args: kotlin.collections.List = this.args, - metas: MetaContainer = this.metas - ) = - Call( - funcName, - args, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Call::class.java) return false - - other as Call - if (funcName != other.funcName) return false - if (args != other.args) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = funcName.hashCode() - hc = 31 * hc + args.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class CallAgg( - val setq: SetQuantifier, - val funcName: org.partiql.pig.runtime.SymbolPrimitive, - val arg: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): CallAgg = - CallAgg( - setq = setq, - funcName = funcName, - arg = arg, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): CallAgg = - CallAgg( - setq = setq, - funcName = funcName, - arg = arg, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("call_agg"), - setq.toIonElement(), - funcName.toIonElement(), - arg.toIonElement(), - metas = metas) - return elements - } - - fun copy( - setq: SetQuantifier = this.setq, - funcName: org.partiql.pig.runtime.SymbolPrimitive = this.funcName, - arg: Expr = this.arg, - metas: MetaContainer = this.metas - ) = - CallAgg( - setq, - funcName, - arg, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != CallAgg::class.java) return false - - other as CallAgg - if (setq != other.setq) return false - if (funcName != other.funcName) return false - if (arg != other.arg) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = setq.hashCode() - hc = 31 * hc + funcName.hashCode() - hc = 31 * hc + arg.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Cast( - val value: Expr, - val asType: Type, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Cast = - Cast( - value = value, - asType = asType, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Cast = - Cast( - value = value, - asType = asType, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("cast"), - value.toIonElement(), - asType.toIonElement(), - metas = metas) - return elements - } - - fun copy( - value: Expr = this.value, - asType: Type = this.asType, - metas: MetaContainer = this.metas - ) = - Cast( - value, - asType, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Cast::class.java) return false - - other as Cast - if (value != other.value) return false - if (asType != other.asType) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = value.hashCode() - hc = 31 * hc + asType.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class CanCast( - val value: Expr, - val asType: Type, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): CanCast = - CanCast( - value = value, - asType = asType, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): CanCast = - CanCast( - value = value, - asType = asType, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("can_cast"), - value.toIonElement(), - asType.toIonElement(), - metas = metas) - return elements - } - - fun copy( - value: Expr = this.value, - asType: Type = this.asType, - metas: MetaContainer = this.metas - ) = - CanCast( - value, - asType, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != CanCast::class.java) return false - - other as CanCast - if (value != other.value) return false - if (asType != other.asType) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = value.hashCode() - hc = 31 * hc + asType.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class CanLosslessCast( - val value: Expr, - val asType: Type, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): CanLosslessCast = - CanLosslessCast( - value = value, - asType = asType, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): CanLosslessCast = - CanLosslessCast( - value = value, - asType = asType, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("can_lossless_cast"), - value.toIonElement(), - asType.toIonElement(), - metas = metas) - return elements - } - - fun copy( - value: Expr = this.value, - asType: Type = this.asType, - metas: MetaContainer = this.metas - ) = - CanLosslessCast( - value, - asType, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != CanLosslessCast::class.java) return false - - other as CanLosslessCast - if (value != other.value) return false - if (asType != other.asType) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = value.hashCode() - hc = 31 * hc + asType.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class NullIf( - val expr1: Expr, - val expr2: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): NullIf = - NullIf( - expr1 = expr1, - expr2 = expr2, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): NullIf = - NullIf( - expr1 = expr1, - expr2 = expr2, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("null_if"), - expr1.toIonElement(), - expr2.toIonElement(), - metas = metas) - return elements - } - - fun copy( - expr1: Expr = this.expr1, - expr2: Expr = this.expr2, - metas: MetaContainer = this.metas - ) = - NullIf( - expr1, - expr2, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != NullIf::class.java) return false - - other as NullIf - if (expr1 != other.expr1) return false - if (expr2 != other.expr2) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr1.hashCode() - hc = 31 * hc + expr2.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Coalesce( - val args: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Coalesce = - Coalesce( - args = args, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Coalesce = - Coalesce( - args = args, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("coalesce"), - *args.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - args: kotlin.collections.List = this.args, - metas: MetaContainer = this.metas - ) = - Coalesce( - args, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Coalesce::class.java) return false - - other as Coalesce - if (args != other.args) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = args.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Select( - val setq: SetQuantifier?, - val project: Projection, - val from: FromSource, - val fromLet: Let?, - val where: Expr?, - val group: GroupBy?, - val having: Expr?, - val order: OrderBy?, - val limit: Expr?, - override val metas: MetaContainer = emptyMetaContainer() - ): Expr() { - - override fun copy(metas: MetaContainer): Select = - Select( - setq = setq, - project = project, - from = from, - fromLet = fromLet, - where = where, - group = group, - having = having, - order = order, - limit = limit, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Select = - Select( - setq = setq, - project = project, - from = from, - fromLet = fromLet, - where = where, - group = group, - having = having, - order = order, - limit = limit, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = listOfNotNull( - ionSymbol("select"), - setq?.let { ionSexpOf(ionSymbol("setq"), it.toIonElement()) }, - project?.let { ionSexpOf(ionSymbol("project"), it.toIonElement()) }, - from?.let { ionSexpOf(ionSymbol("from"), it.toIonElement()) }, - fromLet?.let { ionSexpOf(ionSymbol("from_let"), it.toIonElement()) }, - where?.let { ionSexpOf(ionSymbol("where"), it.toIonElement()) }, - group?.let { ionSexpOf(ionSymbol("group"), it.toIonElement()) }, - having?.let { ionSexpOf(ionSymbol("having"), it.toIonElement()) }, - order?.let { ionSexpOf(ionSymbol("order"), it.toIonElement()) }, - limit?.let { ionSexpOf(ionSymbol("limit"), it.toIonElement()) } - ) - - return ionSexpOf(elements, metas = metas) - } - - fun copy( - setq: SetQuantifier? = this.setq, - project: Projection = this.project, - from: FromSource = this.from, - fromLet: Let? = this.fromLet, - where: Expr? = this.where, - group: GroupBy? = this.group, - having: Expr? = this.having, - order: OrderBy? = this.order, - limit: Expr? = this.limit, - metas: MetaContainer = this.metas - ) = - Select( - setq, - project, - from, - fromLet, - where, - group, - having, - order, - limit, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Select::class.java) return false - - other as Select - if (setq != other.setq) return false - if (project != other.project) return false - if (from != other.from) return false - if (fromLet != other.fromLet) return false - if (where != other.where) return false - if (group != other.group) return false - if (having != other.having) return false - if (order != other.order) return false - if (limit != other.limit) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = setq.hashCode() - hc = 31 * hc + project.hashCode() - hc = 31 * hc + from.hashCode() - hc = 31 * hc + fromLet.hashCode() - hc = 31 * hc + where.hashCode() - hc = 31 * hc + group.hashCode() - hc = 31 * hc + having.hashCode() - hc = 31 * hc + order.hashCode() - hc = 31 * hc + limit.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - /** Converts instances of [PartiqlAst.Expr] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.Expr): T = when(node) { - is PartiqlAst.Expr.Missing -> convertMissing(node) - is PartiqlAst.Expr.Lit -> convertLit(node) - is PartiqlAst.Expr.Id -> convertId(node) - is PartiqlAst.Expr.Parameter -> convertParameter(node) - is PartiqlAst.Expr.Not -> convertNot(node) - is PartiqlAst.Expr.Pos -> convertPos(node) - is PartiqlAst.Expr.Neg -> convertNeg(node) - is PartiqlAst.Expr.Plus -> convertPlus(node) - is PartiqlAst.Expr.Minus -> convertMinus(node) - is PartiqlAst.Expr.Times -> convertTimes(node) - is PartiqlAst.Expr.Divide -> convertDivide(node) - is PartiqlAst.Expr.Modulo -> convertModulo(node) - is PartiqlAst.Expr.Concat -> convertConcat(node) - is PartiqlAst.Expr.And -> convertAnd(node) - is PartiqlAst.Expr.Or -> convertOr(node) - is PartiqlAst.Expr.Eq -> convertEq(node) - is PartiqlAst.Expr.Ne -> convertNe(node) - is PartiqlAst.Expr.Gt -> convertGt(node) - is PartiqlAst.Expr.Gte -> convertGte(node) - is PartiqlAst.Expr.Lt -> convertLt(node) - is PartiqlAst.Expr.Lte -> convertLte(node) - is PartiqlAst.Expr.Like -> convertLike(node) - is PartiqlAst.Expr.Between -> convertBetween(node) - is PartiqlAst.Expr.InCollection -> convertInCollection(node) - is PartiqlAst.Expr.IsType -> convertIsType(node) - is PartiqlAst.Expr.SimpleCase -> convertSimpleCase(node) - is PartiqlAst.Expr.SearchedCase -> convertSearchedCase(node) - is PartiqlAst.Expr.Struct -> convertStruct(node) - is PartiqlAst.Expr.Bag -> convertBag(node) - is PartiqlAst.Expr.List -> convertList(node) - is PartiqlAst.Expr.Sexp -> convertSexp(node) - is PartiqlAst.Expr.Date -> convertDate(node) - is PartiqlAst.Expr.LitTime -> convertLitTime(node) - is PartiqlAst.Expr.Union -> convertUnion(node) - is PartiqlAst.Expr.Except -> convertExcept(node) - is PartiqlAst.Expr.Intersect -> convertIntersect(node) - is PartiqlAst.Expr.Path -> convertPath(node) - is PartiqlAst.Expr.Call -> convertCall(node) - is PartiqlAst.Expr.CallAgg -> convertCallAgg(node) - is PartiqlAst.Expr.Cast -> convertCast(node) - is PartiqlAst.Expr.CanCast -> convertCanCast(node) - is PartiqlAst.Expr.CanLosslessCast -> convertCanLosslessCast(node) - is PartiqlAst.Expr.NullIf -> convertNullIf(node) - is PartiqlAst.Expr.Coalesce -> convertCoalesce(node) - is PartiqlAst.Expr.Select -> convertSelect(node) - } - - fun convertMissing(node: PartiqlAst.Expr.Missing): T - fun convertLit(node: PartiqlAst.Expr.Lit): T - fun convertId(node: PartiqlAst.Expr.Id): T - fun convertParameter(node: PartiqlAst.Expr.Parameter): T - fun convertNot(node: PartiqlAst.Expr.Not): T - fun convertPos(node: PartiqlAst.Expr.Pos): T - fun convertNeg(node: PartiqlAst.Expr.Neg): T - fun convertPlus(node: PartiqlAst.Expr.Plus): T - fun convertMinus(node: PartiqlAst.Expr.Minus): T - fun convertTimes(node: PartiqlAst.Expr.Times): T - fun convertDivide(node: PartiqlAst.Expr.Divide): T - fun convertModulo(node: PartiqlAst.Expr.Modulo): T - fun convertConcat(node: PartiqlAst.Expr.Concat): T - fun convertAnd(node: PartiqlAst.Expr.And): T - fun convertOr(node: PartiqlAst.Expr.Or): T - fun convertEq(node: PartiqlAst.Expr.Eq): T - fun convertNe(node: PartiqlAst.Expr.Ne): T - fun convertGt(node: PartiqlAst.Expr.Gt): T - fun convertGte(node: PartiqlAst.Expr.Gte): T - fun convertLt(node: PartiqlAst.Expr.Lt): T - fun convertLte(node: PartiqlAst.Expr.Lte): T - fun convertLike(node: PartiqlAst.Expr.Like): T - fun convertBetween(node: PartiqlAst.Expr.Between): T - fun convertInCollection(node: PartiqlAst.Expr.InCollection): T - fun convertIsType(node: PartiqlAst.Expr.IsType): T - fun convertSimpleCase(node: PartiqlAst.Expr.SimpleCase): T - fun convertSearchedCase(node: PartiqlAst.Expr.SearchedCase): T - fun convertStruct(node: PartiqlAst.Expr.Struct): T - fun convertBag(node: PartiqlAst.Expr.Bag): T - fun convertList(node: PartiqlAst.Expr.List): T - fun convertSexp(node: PartiqlAst.Expr.Sexp): T - fun convertDate(node: PartiqlAst.Expr.Date): T - fun convertLitTime(node: PartiqlAst.Expr.LitTime): T - fun convertUnion(node: PartiqlAst.Expr.Union): T - fun convertExcept(node: PartiqlAst.Expr.Except): T - fun convertIntersect(node: PartiqlAst.Expr.Intersect): T - fun convertPath(node: PartiqlAst.Expr.Path): T - fun convertCall(node: PartiqlAst.Expr.Call): T - fun convertCallAgg(node: PartiqlAst.Expr.CallAgg): T - fun convertCast(node: PartiqlAst.Expr.Cast): T - fun convertCanCast(node: PartiqlAst.Expr.CanCast): T - fun convertCanLosslessCast(node: PartiqlAst.Expr.CanLosslessCast): T - fun convertNullIf(node: PartiqlAst.Expr.NullIf): T - fun convertCoalesce(node: PartiqlAst.Expr.Coalesce): T - fun convertSelect(node: PartiqlAst.Expr.Select): T - } - } - - sealed class PathStep(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): PathStep = - when (this) { - is PathExpr -> copy(metas = metas) - is PathWildcard -> copy(metas = metas) - is PathUnpivot -> copy(metas = metas) - } - - class PathExpr( - val index: Expr, - val case: CaseSensitivity, - override val metas: MetaContainer = emptyMetaContainer() - ): PathStep() { - - override fun copy(metas: MetaContainer): PathExpr = - PathExpr( - index = index, - case = case, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): PathExpr = - PathExpr( - index = index, - case = case, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("path_expr"), - index.toIonElement(), - case.toIonElement(), - metas = metas) - return elements - } - - fun copy( - index: Expr = this.index, - case: CaseSensitivity = this.case, - metas: MetaContainer = this.metas - ) = - PathExpr( - index, - case, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != PathExpr::class.java) return false - - other as PathExpr - if (index != other.index) return false - if (case != other.case) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = index.hashCode() - hc = 31 * hc + case.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class PathWildcard( - override val metas: MetaContainer = emptyMetaContainer() - ): PathStep() { - - override fun copy(metas: MetaContainer): PathWildcard = - PathWildcard( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): PathWildcard = - PathWildcard( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("path_wildcard"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != PathWildcard::class.java) return false - - return true - } - - override fun hashCode(): Int = 3001 - } - - class PathUnpivot( - override val metas: MetaContainer = emptyMetaContainer() - ): PathStep() { - - override fun copy(metas: MetaContainer): PathUnpivot = - PathUnpivot( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): PathUnpivot = - PathUnpivot( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("path_unpivot"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != PathUnpivot::class.java) return false - - return true - } - - override fun hashCode(): Int = 3002 - } - - /** Converts instances of [PartiqlAst.PathStep] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.PathStep): T = when(node) { - is PartiqlAst.PathStep.PathExpr -> convertPathExpr(node) - is PartiqlAst.PathStep.PathWildcard -> convertPathWildcard(node) - is PartiqlAst.PathStep.PathUnpivot -> convertPathUnpivot(node) - } - - fun convertPathExpr(node: PartiqlAst.PathStep.PathExpr): T - fun convertPathWildcard(node: PartiqlAst.PathStep.PathWildcard): T - fun convertPathUnpivot(node: PartiqlAst.PathStep.PathUnpivot): T - } - } - - sealed class Projection(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): Projection = - when (this) { - is ProjectStar -> copy(metas = metas) - is ProjectList -> copy(metas = metas) - is ProjectPivot -> copy(metas = metas) - is ProjectValue -> copy(metas = metas) - } - - class ProjectStar( - override val metas: MetaContainer = emptyMetaContainer() - ): Projection() { - - override fun copy(metas: MetaContainer): ProjectStar = - ProjectStar( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ProjectStar = - ProjectStar( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("project_star"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ProjectStar::class.java) return false - - return true - } - - override fun hashCode(): Int = 4000 - } - - class ProjectList( - val projectItems: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): Projection() { - - override fun copy(metas: MetaContainer): ProjectList = - ProjectList( - projectItems = projectItems, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ProjectList = - ProjectList( - projectItems = projectItems, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("project_list"), - *projectItems.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - projectItems: kotlin.collections.List = this.projectItems, - metas: MetaContainer = this.metas - ) = - ProjectList( - projectItems, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ProjectList::class.java) return false - - other as ProjectList - if (projectItems != other.projectItems) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = projectItems.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class ProjectPivot( - val value: Expr, - val key: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): Projection() { - - override fun copy(metas: MetaContainer): ProjectPivot = - ProjectPivot( - value = value, - key = key, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ProjectPivot = - ProjectPivot( - value = value, - key = key, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("project_pivot"), - value.toIonElement(), - key.toIonElement(), - metas = metas) - return elements - } - - fun copy( - value: Expr = this.value, - key: Expr = this.key, - metas: MetaContainer = this.metas - ) = - ProjectPivot( - value, - key, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ProjectPivot::class.java) return false - - other as ProjectPivot - if (value != other.value) return false - if (key != other.key) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = value.hashCode() - hc = 31 * hc + key.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class ProjectValue( - val value: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): Projection() { - - override fun copy(metas: MetaContainer): ProjectValue = - ProjectValue( - value = value, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ProjectValue = - ProjectValue( - value = value, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("project_value"), - value.toIonElement(), - metas = metas) - return elements - } - - fun copy( - value: Expr = this.value, - metas: MetaContainer = this.metas - ) = - ProjectValue( - value, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ProjectValue::class.java) return false - - other as ProjectValue - if (value != other.value) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = value.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - /** Converts instances of [PartiqlAst.Projection] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.Projection): T = when(node) { - is PartiqlAst.Projection.ProjectStar -> convertProjectStar(node) - is PartiqlAst.Projection.ProjectList -> convertProjectList(node) - is PartiqlAst.Projection.ProjectPivot -> convertProjectPivot(node) - is PartiqlAst.Projection.ProjectValue -> convertProjectValue(node) - } - - fun convertProjectStar(node: PartiqlAst.Projection.ProjectStar): T - fun convertProjectList(node: PartiqlAst.Projection.ProjectList): T - fun convertProjectPivot(node: PartiqlAst.Projection.ProjectPivot): T - fun convertProjectValue(node: PartiqlAst.Projection.ProjectValue): T - } - } - - sealed class ProjectItem(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): ProjectItem = - when (this) { - is ProjectAll -> copy(metas = metas) - is ProjectExpr -> copy(metas = metas) - } - - class ProjectAll( - val expr: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): ProjectItem() { - - override fun copy(metas: MetaContainer): ProjectAll = - ProjectAll( - expr = expr, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ProjectAll = - ProjectAll( - expr = expr, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("project_all"), - expr.toIonElement(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - metas: MetaContainer = this.metas - ) = - ProjectAll( - expr, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ProjectAll::class.java) return false - - other as ProjectAll - if (expr != other.expr) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class ProjectExpr( - val expr: Expr, - val asAlias: org.partiql.pig.runtime.SymbolPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): ProjectItem() { - - override fun copy(metas: MetaContainer): ProjectExpr = - ProjectExpr( - expr = expr, - asAlias = asAlias, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ProjectExpr = - ProjectExpr( - expr = expr, - asAlias = asAlias, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("project_expr"), - expr.toIonElement(), - asAlias?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - asAlias: org.partiql.pig.runtime.SymbolPrimitive? = this.asAlias, - metas: MetaContainer = this.metas - ) = - ProjectExpr( - expr, - asAlias, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ProjectExpr::class.java) return false - - other as ProjectExpr - if (expr != other.expr) return false - if (asAlias != other.asAlias) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc = 31 * hc + asAlias.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - /** Converts instances of [PartiqlAst.ProjectItem] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.ProjectItem): T = when(node) { - is PartiqlAst.ProjectItem.ProjectAll -> convertProjectAll(node) - is PartiqlAst.ProjectItem.ProjectExpr -> convertProjectExpr(node) - } - - fun convertProjectAll(node: PartiqlAst.ProjectItem.ProjectAll): T - fun convertProjectExpr(node: PartiqlAst.ProjectItem.ProjectExpr): T - } - } - - sealed class FromSource(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): FromSource = - when (this) { - is Scan -> copy(metas = metas) - is Unpivot -> copy(metas = metas) - is Join -> copy(metas = metas) - } - - class Scan( - val expr: Expr, - val asAlias: org.partiql.pig.runtime.SymbolPrimitive?, - val atAlias: org.partiql.pig.runtime.SymbolPrimitive?, - val byAlias: org.partiql.pig.runtime.SymbolPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): FromSource() { - - override fun copy(metas: MetaContainer): Scan = - Scan( - expr = expr, - asAlias = asAlias, - atAlias = atAlias, - byAlias = byAlias, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Scan = - Scan( - expr = expr, - asAlias = asAlias, - atAlias = atAlias, - byAlias = byAlias, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("scan"), - expr.toIonElement(), - asAlias?.toIonElement() ?: ionNull(), - atAlias?.toIonElement() ?: ionNull(), - byAlias?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - asAlias: org.partiql.pig.runtime.SymbolPrimitive? = this.asAlias, - atAlias: org.partiql.pig.runtime.SymbolPrimitive? = this.atAlias, - byAlias: org.partiql.pig.runtime.SymbolPrimitive? = this.byAlias, - metas: MetaContainer = this.metas - ) = - Scan( - expr, - asAlias, - atAlias, - byAlias, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Scan::class.java) return false - - other as Scan - if (expr != other.expr) return false - if (asAlias != other.asAlias) return false - if (atAlias != other.atAlias) return false - if (byAlias != other.byAlias) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc = 31 * hc + asAlias.hashCode() - hc = 31 * hc + atAlias.hashCode() - hc = 31 * hc + byAlias.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Unpivot( - val expr: Expr, - val asAlias: org.partiql.pig.runtime.SymbolPrimitive?, - val atAlias: org.partiql.pig.runtime.SymbolPrimitive?, - val byAlias: org.partiql.pig.runtime.SymbolPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): FromSource() { - - override fun copy(metas: MetaContainer): Unpivot = - Unpivot( - expr = expr, - asAlias = asAlias, - atAlias = atAlias, - byAlias = byAlias, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Unpivot = - Unpivot( - expr = expr, - asAlias = asAlias, - atAlias = atAlias, - byAlias = byAlias, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("unpivot"), - expr.toIonElement(), - asAlias?.toIonElement() ?: ionNull(), - atAlias?.toIonElement() ?: ionNull(), - byAlias?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - asAlias: org.partiql.pig.runtime.SymbolPrimitive? = this.asAlias, - atAlias: org.partiql.pig.runtime.SymbolPrimitive? = this.atAlias, - byAlias: org.partiql.pig.runtime.SymbolPrimitive? = this.byAlias, - metas: MetaContainer = this.metas - ) = - Unpivot( - expr, - asAlias, - atAlias, - byAlias, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Unpivot::class.java) return false - - other as Unpivot - if (expr != other.expr) return false - if (asAlias != other.asAlias) return false - if (atAlias != other.atAlias) return false - if (byAlias != other.byAlias) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc = 31 * hc + asAlias.hashCode() - hc = 31 * hc + atAlias.hashCode() - hc = 31 * hc + byAlias.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Join( - val type: JoinType, - val left: FromSource, - val right: FromSource, - val predicate: Expr?, - override val metas: MetaContainer = emptyMetaContainer() - ): FromSource() { - - override fun copy(metas: MetaContainer): Join = - Join( - type = type, - left = left, - right = right, - predicate = predicate, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Join = - Join( - type = type, - left = left, - right = right, - predicate = predicate, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("join"), - type.toIonElement(), - left.toIonElement(), - right.toIonElement(), - predicate?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - type: JoinType = this.type, - left: FromSource = this.left, - right: FromSource = this.right, - predicate: Expr? = this.predicate, - metas: MetaContainer = this.metas - ) = - Join( - type, - left, - right, - predicate, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Join::class.java) return false - - other as Join - if (type != other.type) return false - if (left != other.left) return false - if (right != other.right) return false - if (predicate != other.predicate) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = type.hashCode() - hc = 31 * hc + left.hashCode() - hc = 31 * hc + right.hashCode() - hc = 31 * hc + predicate.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - /** Converts instances of [PartiqlAst.FromSource] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.FromSource): T = when(node) { - is PartiqlAst.FromSource.Scan -> convertScan(node) - is PartiqlAst.FromSource.Unpivot -> convertUnpivot(node) - is PartiqlAst.FromSource.Join -> convertJoin(node) - } - - fun convertScan(node: PartiqlAst.FromSource.Scan): T - fun convertUnpivot(node: PartiqlAst.FromSource.Unpivot): T - fun convertJoin(node: PartiqlAst.FromSource.Join): T - } - } - - sealed class JoinType(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): JoinType = - when (this) { - is Inner -> copy(metas = metas) - is Left -> copy(metas = metas) - is Right -> copy(metas = metas) - is Full -> copy(metas = metas) - } - - class Inner( - override val metas: MetaContainer = emptyMetaContainer() - ): JoinType() { - - override fun copy(metas: MetaContainer): Inner = - Inner( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Inner = - Inner( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("inner"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Inner::class.java) return false - - return true - } - - override fun hashCode(): Int = 7000 - } - - class Left( - override val metas: MetaContainer = emptyMetaContainer() - ): JoinType() { - - override fun copy(metas: MetaContainer): Left = - Left( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Left = - Left( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("left"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Left::class.java) return false - - return true - } - - override fun hashCode(): Int = 7001 - } - - class Right( - override val metas: MetaContainer = emptyMetaContainer() - ): JoinType() { - - override fun copy(metas: MetaContainer): Right = - Right( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Right = - Right( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("right"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Right::class.java) return false - - return true - } - - override fun hashCode(): Int = 7002 - } - - class Full( - override val metas: MetaContainer = emptyMetaContainer() - ): JoinType() { - - override fun copy(metas: MetaContainer): Full = - Full( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Full = - Full( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("full"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Full::class.java) return false - - return true - } - - override fun hashCode(): Int = 7003 - } - - /** Converts instances of [PartiqlAst.JoinType] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.JoinType): T = when(node) { - is PartiqlAst.JoinType.Inner -> convertInner(node) - is PartiqlAst.JoinType.Left -> convertLeft(node) - is PartiqlAst.JoinType.Right -> convertRight(node) - is PartiqlAst.JoinType.Full -> convertFull(node) - } - - fun convertInner(node: PartiqlAst.JoinType.Inner): T - fun convertLeft(node: PartiqlAst.JoinType.Left): T - fun convertRight(node: PartiqlAst.JoinType.Right): T - fun convertFull(node: PartiqlAst.JoinType.Full): T - } - } - - sealed class GroupingStrategy(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): GroupingStrategy = - when (this) { - is GroupFull -> copy(metas = metas) - is GroupPartial -> copy(metas = metas) - } - - class GroupFull( - override val metas: MetaContainer = emptyMetaContainer() - ): GroupingStrategy() { - - override fun copy(metas: MetaContainer): GroupFull = - GroupFull( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): GroupFull = - GroupFull( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("group_full"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != GroupFull::class.java) return false - - return true - } - - override fun hashCode(): Int = 8000 - } - - class GroupPartial( - override val metas: MetaContainer = emptyMetaContainer() - ): GroupingStrategy() { - - override fun copy(metas: MetaContainer): GroupPartial = - GroupPartial( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): GroupPartial = - GroupPartial( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("group_partial"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != GroupPartial::class.java) return false - - return true - } - - override fun hashCode(): Int = 8001 - } - - /** Converts instances of [PartiqlAst.GroupingStrategy] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.GroupingStrategy): T = when(node) { - is PartiqlAst.GroupingStrategy.GroupFull -> convertGroupFull(node) - is PartiqlAst.GroupingStrategy.GroupPartial -> convertGroupPartial(node) - } - - fun convertGroupFull(node: PartiqlAst.GroupingStrategy.GroupFull): T - fun convertGroupPartial(node: PartiqlAst.GroupingStrategy.GroupPartial): T - } - } - - sealed class OrderingSpec(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): OrderingSpec = - when (this) { - is Asc -> copy(metas = metas) - is Desc -> copy(metas = metas) - } - - class Asc( - override val metas: MetaContainer = emptyMetaContainer() - ): OrderingSpec() { - - override fun copy(metas: MetaContainer): Asc = - Asc( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Asc = - Asc( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("asc"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Asc::class.java) return false - - return true - } - - override fun hashCode(): Int = 9000 - } - - class Desc( - override val metas: MetaContainer = emptyMetaContainer() - ): OrderingSpec() { - - override fun copy(metas: MetaContainer): Desc = - Desc( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Desc = - Desc( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("desc"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Desc::class.java) return false - - return true - } - - override fun hashCode(): Int = 9001 - } - - /** Converts instances of [PartiqlAst.OrderingSpec] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.OrderingSpec): T = when(node) { - is PartiqlAst.OrderingSpec.Asc -> convertAsc(node) - is PartiqlAst.OrderingSpec.Desc -> convertDesc(node) - } - - fun convertAsc(node: PartiqlAst.OrderingSpec.Asc): T - fun convertDesc(node: PartiqlAst.OrderingSpec.Desc): T - } - } - - sealed class CaseSensitivity(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): CaseSensitivity = - when (this) { - is CaseSensitive -> copy(metas = metas) - is CaseInsensitive -> copy(metas = metas) - } - - class CaseSensitive( - override val metas: MetaContainer = emptyMetaContainer() - ): CaseSensitivity() { - - override fun copy(metas: MetaContainer): CaseSensitive = - CaseSensitive( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): CaseSensitive = - CaseSensitive( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("case_sensitive"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != CaseSensitive::class.java) return false - - return true - } - - override fun hashCode(): Int = 10000 - } - - class CaseInsensitive( - override val metas: MetaContainer = emptyMetaContainer() - ): CaseSensitivity() { - - override fun copy(metas: MetaContainer): CaseInsensitive = - CaseInsensitive( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): CaseInsensitive = - CaseInsensitive( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("case_insensitive"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != CaseInsensitive::class.java) return false - - return true - } - - override fun hashCode(): Int = 10001 - } - - /** Converts instances of [PartiqlAst.CaseSensitivity] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.CaseSensitivity): T = when(node) { - is PartiqlAst.CaseSensitivity.CaseSensitive -> convertCaseSensitive(node) - is PartiqlAst.CaseSensitivity.CaseInsensitive -> convertCaseInsensitive(node) - } - - fun convertCaseSensitive(node: PartiqlAst.CaseSensitivity.CaseSensitive): T - fun convertCaseInsensitive(node: PartiqlAst.CaseSensitivity.CaseInsensitive): T - } - } - - sealed class ScopeQualifier(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): ScopeQualifier = - when (this) { - is Unqualified -> copy(metas = metas) - is LocalsFirst -> copy(metas = metas) - } - - class Unqualified( - override val metas: MetaContainer = emptyMetaContainer() - ): ScopeQualifier() { - - override fun copy(metas: MetaContainer): Unqualified = - Unqualified( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Unqualified = - Unqualified( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("unqualified"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Unqualified::class.java) return false - - return true - } - - override fun hashCode(): Int = 11000 - } - - class LocalsFirst( - override val metas: MetaContainer = emptyMetaContainer() - ): ScopeQualifier() { - - override fun copy(metas: MetaContainer): LocalsFirst = - LocalsFirst( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): LocalsFirst = - LocalsFirst( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("locals_first"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != LocalsFirst::class.java) return false - - return true - } - - override fun hashCode(): Int = 11001 - } - - /** Converts instances of [PartiqlAst.ScopeQualifier] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.ScopeQualifier): T = when(node) { - is PartiqlAst.ScopeQualifier.Unqualified -> convertUnqualified(node) - is PartiqlAst.ScopeQualifier.LocalsFirst -> convertLocalsFirst(node) - } - - fun convertUnqualified(node: PartiqlAst.ScopeQualifier.Unqualified): T - fun convertLocalsFirst(node: PartiqlAst.ScopeQualifier.LocalsFirst): T - } - } - - sealed class SetQuantifier(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): SetQuantifier = - when (this) { - is All -> copy(metas = metas) - is Distinct -> copy(metas = metas) - } - - class All( - override val metas: MetaContainer = emptyMetaContainer() - ): SetQuantifier() { - - override fun copy(metas: MetaContainer): All = - All( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): All = - All( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("all"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != All::class.java) return false - - return true - } - - override fun hashCode(): Int = 12000 - } - - class Distinct( - override val metas: MetaContainer = emptyMetaContainer() - ): SetQuantifier() { - - override fun copy(metas: MetaContainer): Distinct = - Distinct( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Distinct = - Distinct( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("distinct"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Distinct::class.java) return false - - return true - } - - override fun hashCode(): Int = 12001 - } - - /** Converts instances of [PartiqlAst.SetQuantifier] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.SetQuantifier): T = when(node) { - is PartiqlAst.SetQuantifier.All -> convertAll(node) - is PartiqlAst.SetQuantifier.Distinct -> convertDistinct(node) - } - - fun convertAll(node: PartiqlAst.SetQuantifier.All): T - fun convertDistinct(node: PartiqlAst.SetQuantifier.Distinct): T - } - } - - sealed class DmlOp(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): DmlOp = - when (this) { - is Insert -> copy(metas = metas) - is InsertValue -> copy(metas = metas) - is Set -> copy(metas = metas) - is Remove -> copy(metas = metas) - is Delete -> copy(metas = metas) - } - - class Insert( - val target: Expr, - val values: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): DmlOp() { - - override fun copy(metas: MetaContainer): Insert = - Insert( - target = target, - values = values, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Insert = - Insert( - target = target, - values = values, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("insert"), - target.toIonElement(), - values.toIonElement(), - metas = metas) - return elements - } - - fun copy( - target: Expr = this.target, - values: Expr = this.values, - metas: MetaContainer = this.metas - ) = - Insert( - target, - values, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Insert::class.java) return false - - other as Insert - if (target != other.target) return false - if (values != other.values) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = target.hashCode() - hc = 31 * hc + values.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class InsertValue( - val target: Expr, - val value: Expr, - val index: Expr?, - val onConflict: OnConflict?, - override val metas: MetaContainer = emptyMetaContainer() - ): DmlOp() { - - override fun copy(metas: MetaContainer): InsertValue = - InsertValue( - target = target, - value = value, - index = index, - onConflict = onConflict, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): InsertValue = - InsertValue( - target = target, - value = value, - index = index, - onConflict = onConflict, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("insert_value"), - target.toIonElement(), - value.toIonElement(), - index?.toIonElement() ?: ionNull(), - onConflict?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - target: Expr = this.target, - value: Expr = this.value, - index: Expr? = this.index, - onConflict: OnConflict? = this.onConflict, - metas: MetaContainer = this.metas - ) = - InsertValue( - target, - value, - index, - onConflict, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != InsertValue::class.java) return false - - other as InsertValue - if (target != other.target) return false - if (value != other.value) return false - if (index != other.index) return false - if (onConflict != other.onConflict) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = target.hashCode() - hc = 31 * hc + value.hashCode() - hc = 31 * hc + index.hashCode() - hc = 31 * hc + onConflict.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Set( - val assignment: Assignment, - override val metas: MetaContainer = emptyMetaContainer() - ): DmlOp() { - - override fun copy(metas: MetaContainer): Set = - Set( - assignment = assignment, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Set = - Set( - assignment = assignment, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("set"), - assignment.toIonElement(), - metas = metas) - return elements - } - - fun copy( - assignment: Assignment = this.assignment, - metas: MetaContainer = this.metas - ) = - Set( - assignment, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Set::class.java) return false - - other as Set - if (assignment != other.assignment) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = assignment.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Remove( - val target: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): DmlOp() { - - override fun copy(metas: MetaContainer): Remove = - Remove( - target = target, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Remove = - Remove( - target = target, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("remove"), - target.toIonElement(), - metas = metas) - return elements - } - - fun copy( - target: Expr = this.target, - metas: MetaContainer = this.metas - ) = - Remove( - target, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Remove::class.java) return false - - other as Remove - if (target != other.target) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = target.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class Delete( - override val metas: MetaContainer = emptyMetaContainer() - ): DmlOp() { - - override fun copy(metas: MetaContainer): Delete = - Delete( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Delete = - Delete( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("delete"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Delete::class.java) return false - - return true - } - - override fun hashCode(): Int = 13004 - } - - /** Converts instances of [PartiqlAst.DmlOp] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.DmlOp): T = when(node) { - is PartiqlAst.DmlOp.Insert -> convertInsert(node) - is PartiqlAst.DmlOp.InsertValue -> convertInsertValue(node) - is PartiqlAst.DmlOp.Set -> convertSet(node) - is PartiqlAst.DmlOp.Remove -> convertRemove(node) - is PartiqlAst.DmlOp.Delete -> convertDelete(node) - } - - fun convertInsert(node: PartiqlAst.DmlOp.Insert): T - fun convertInsertValue(node: PartiqlAst.DmlOp.InsertValue): T - fun convertSet(node: PartiqlAst.DmlOp.Set): T - fun convertRemove(node: PartiqlAst.DmlOp.Remove): T - fun convertDelete(node: PartiqlAst.DmlOp.Delete): T - } - } - - sealed class ConflictAction(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): ConflictAction = - when (this) { - is DoNothing -> copy(metas = metas) - } - - class DoNothing( - override val metas: MetaContainer = emptyMetaContainer() - ): ConflictAction() { - - override fun copy(metas: MetaContainer): DoNothing = - DoNothing( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): DoNothing = - DoNothing( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("do_nothing"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != DoNothing::class.java) return false - - return true - } - - override fun hashCode(): Int = 14000 - } - - /** Converts instances of [PartiqlAst.ConflictAction] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.ConflictAction): T = when(node) { - is PartiqlAst.ConflictAction.DoNothing -> convertDoNothing(node) - } - - fun convertDoNothing(node: PartiqlAst.ConflictAction.DoNothing): T - } - } - - sealed class DdlOp(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): DdlOp = - when (this) { - is CreateTable -> copy(metas = metas) - is DropTable -> copy(metas = metas) - is UndropTable -> copy(metas = metas) - is CreateIndex -> copy(metas = metas) - is DropIndex -> copy(metas = metas) - } - - class CreateTable( - val tableName: org.partiql.pig.runtime.SymbolPrimitive, - override val metas: MetaContainer = emptyMetaContainer() - ): DdlOp() { - - override fun copy(metas: MetaContainer): CreateTable = - CreateTable( - tableName = tableName, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): CreateTable = - CreateTable( - tableName = tableName, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("create_table"), - tableName.toIonElement(), - metas = metas) - return elements - } - - fun copy( - tableName: org.partiql.pig.runtime.SymbolPrimitive = this.tableName, - metas: MetaContainer = this.metas - ) = - CreateTable( - tableName, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != CreateTable::class.java) return false - - other as CreateTable - if (tableName != other.tableName) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = tableName.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class DropTable( - val tableName: Identifier, - override val metas: MetaContainer = emptyMetaContainer() - ): DdlOp() { - - override fun copy(metas: MetaContainer): DropTable = - DropTable( - tableName = tableName, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): DropTable = - DropTable( - tableName = tableName, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("drop_table"), - tableName.toIonElement(), - metas = metas) - return elements - } - - fun copy( - tableName: Identifier = this.tableName, - metas: MetaContainer = this.metas - ) = - DropTable( - tableName, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != DropTable::class.java) return false - - other as DropTable - if (tableName != other.tableName) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = tableName.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class UndropTable( - val tableName: org.partiql.pig.runtime.SymbolPrimitive, - override val metas: MetaContainer = emptyMetaContainer() - ): DdlOp() { - - override fun copy(metas: MetaContainer): UndropTable = - UndropTable( - tableName = tableName, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): UndropTable = - UndropTable( - tableName = tableName, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("undrop_table"), - tableName.toIonElement(), - metas = metas) - return elements - } - - fun copy( - tableName: org.partiql.pig.runtime.SymbolPrimitive = this.tableName, - metas: MetaContainer = this.metas - ) = - UndropTable( - tableName, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != UndropTable::class.java) return false - - other as UndropTable - if (tableName != other.tableName) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = tableName.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class CreateIndex( - val indexName: Identifier, - val fields: kotlin.collections.List, - override val metas: MetaContainer = emptyMetaContainer() - ): DdlOp() { - - override fun copy(metas: MetaContainer): CreateIndex = - CreateIndex( - indexName = indexName, - fields = fields, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): CreateIndex = - CreateIndex( - indexName = indexName, - fields = fields, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("create_index"), - indexName.toIonElement(), - *fields.map { it.toIonElement() }.toTypedArray(), - metas = metas) - return elements - } - - fun copy( - indexName: Identifier = this.indexName, - fields: kotlin.collections.List = this.fields, - metas: MetaContainer = this.metas - ) = - CreateIndex( - indexName, - fields, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != CreateIndex::class.java) return false - - other as CreateIndex - if (indexName != other.indexName) return false - if (fields != other.fields) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = indexName.hashCode() - hc = 31 * hc + fields.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class DropIndex( - val table: Identifier, - val keys: Identifier, - override val metas: MetaContainer = emptyMetaContainer() - ): DdlOp() { - - override fun copy(metas: MetaContainer): DropIndex = - DropIndex( - table = table, - keys = keys, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): DropIndex = - DropIndex( - table = table, - keys = keys, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = listOfNotNull( - ionSymbol("drop_index"), - table?.let { ionSexpOf(ionSymbol("table"), it.toIonElement()) }, - keys?.let { ionSexpOf(ionSymbol("keys"), it.toIonElement()) } - ) - - return ionSexpOf(elements, metas = metas) - } - - fun copy( - table: Identifier = this.table, - keys: Identifier = this.keys, - metas: MetaContainer = this.metas - ) = - DropIndex( - table, - keys, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != DropIndex::class.java) return false - - other as DropIndex - if (table != other.table) return false - if (keys != other.keys) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = table.hashCode() - hc = 31 * hc + keys.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - /** Converts instances of [PartiqlAst.DdlOp] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.DdlOp): T = when(node) { - is PartiqlAst.DdlOp.CreateTable -> convertCreateTable(node) - is PartiqlAst.DdlOp.DropTable -> convertDropTable(node) - is PartiqlAst.DdlOp.UndropTable -> convertUndropTable(node) - is PartiqlAst.DdlOp.CreateIndex -> convertCreateIndex(node) - is PartiqlAst.DdlOp.DropIndex -> convertDropIndex(node) - } - - fun convertCreateTable(node: PartiqlAst.DdlOp.CreateTable): T - fun convertDropTable(node: PartiqlAst.DdlOp.DropTable): T - fun convertUndropTable(node: PartiqlAst.DdlOp.UndropTable): T - fun convertCreateIndex(node: PartiqlAst.DdlOp.CreateIndex): T - fun convertDropIndex(node: PartiqlAst.DdlOp.DropIndex): T - } - } - - sealed class ColumnComponent(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): ColumnComponent = - when (this) { - is ReturningWildcard -> copy(metas = metas) - is ReturningColumn -> copy(metas = metas) - } - - class ReturningWildcard( - override val metas: MetaContainer = emptyMetaContainer() - ): ColumnComponent() { - - override fun copy(metas: MetaContainer): ReturningWildcard = - ReturningWildcard( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ReturningWildcard = - ReturningWildcard( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("returning_wildcard"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ReturningWildcard::class.java) return false - - return true - } - - override fun hashCode(): Int = 16000 - } - - class ReturningColumn( - val expr: Expr, - override val metas: MetaContainer = emptyMetaContainer() - ): ColumnComponent() { - - override fun copy(metas: MetaContainer): ReturningColumn = - ReturningColumn( - expr = expr, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ReturningColumn = - ReturningColumn( - expr = expr, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("returning_column"), - expr.toIonElement(), - metas = metas) - return elements - } - - fun copy( - expr: Expr = this.expr, - metas: MetaContainer = this.metas - ) = - ReturningColumn( - expr, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ReturningColumn::class.java) return false - - other as ReturningColumn - if (expr != other.expr) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = expr.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - /** Converts instances of [PartiqlAst.ColumnComponent] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.ColumnComponent): T = when(node) { - is PartiqlAst.ColumnComponent.ReturningWildcard -> convertReturningWildcard(node) - is PartiqlAst.ColumnComponent.ReturningColumn -> convertReturningColumn(node) - } - - fun convertReturningWildcard(node: PartiqlAst.ColumnComponent.ReturningWildcard): T - fun convertReturningColumn(node: PartiqlAst.ColumnComponent.ReturningColumn): T - } - } - - sealed class ReturningMapping(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): ReturningMapping = - when (this) { - is ModifiedNew -> copy(metas = metas) - is ModifiedOld -> copy(metas = metas) - is AllNew -> copy(metas = metas) - is AllOld -> copy(metas = metas) - } - - class ModifiedNew( - override val metas: MetaContainer = emptyMetaContainer() - ): ReturningMapping() { - - override fun copy(metas: MetaContainer): ModifiedNew = - ModifiedNew( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ModifiedNew = - ModifiedNew( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("modified_new"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ModifiedNew::class.java) return false - - return true - } - - override fun hashCode(): Int = 17000 - } - - class ModifiedOld( - override val metas: MetaContainer = emptyMetaContainer() - ): ReturningMapping() { - - override fun copy(metas: MetaContainer): ModifiedOld = - ModifiedOld( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ModifiedOld = - ModifiedOld( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("modified_old"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ModifiedOld::class.java) return false - - return true - } - - override fun hashCode(): Int = 17001 - } - - class AllNew( - override val metas: MetaContainer = emptyMetaContainer() - ): ReturningMapping() { - - override fun copy(metas: MetaContainer): AllNew = - AllNew( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): AllNew = - AllNew( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("all_new"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != AllNew::class.java) return false - - return true - } - - override fun hashCode(): Int = 17002 - } - - class AllOld( - override val metas: MetaContainer = emptyMetaContainer() - ): ReturningMapping() { - - override fun copy(metas: MetaContainer): AllOld = - AllOld( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): AllOld = - AllOld( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("all_old"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != AllOld::class.java) return false - - return true - } - - override fun hashCode(): Int = 17003 - } - - /** Converts instances of [PartiqlAst.ReturningMapping] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.ReturningMapping): T = when(node) { - is PartiqlAst.ReturningMapping.ModifiedNew -> convertModifiedNew(node) - is PartiqlAst.ReturningMapping.ModifiedOld -> convertModifiedOld(node) - is PartiqlAst.ReturningMapping.AllNew -> convertAllNew(node) - is PartiqlAst.ReturningMapping.AllOld -> convertAllOld(node) - } - - fun convertModifiedNew(node: PartiqlAst.ReturningMapping.ModifiedNew): T - fun convertModifiedOld(node: PartiqlAst.ReturningMapping.ModifiedOld): T - fun convertAllNew(node: PartiqlAst.ReturningMapping.AllNew): T - fun convertAllOld(node: PartiqlAst.ReturningMapping.AllOld): T - } - } - - sealed class Type(override val metas: MetaContainer = emptyMetaContainer()) : PartiqlAstNode() { - override fun copy(metas: MetaContainer): Type = - when (this) { - is NullType -> copy(metas = metas) - is BooleanType -> copy(metas = metas) - is SmallintType -> copy(metas = metas) - is Integer4Type -> copy(metas = metas) - is Integer8Type -> copy(metas = metas) - is IntegerType -> copy(metas = metas) - is FloatType -> copy(metas = metas) - is RealType -> copy(metas = metas) - is DoublePrecisionType -> copy(metas = metas) - is DecimalType -> copy(metas = metas) - is NumericType -> copy(metas = metas) - is TimestampType -> copy(metas = metas) - is CharacterType -> copy(metas = metas) - is CharacterVaryingType -> copy(metas = metas) - is MissingType -> copy(metas = metas) - is StringType -> copy(metas = metas) - is SymbolType -> copy(metas = metas) - is BlobType -> copy(metas = metas) - is ClobType -> copy(metas = metas) - is DateType -> copy(metas = metas) - is TimeType -> copy(metas = metas) - is TimeWithTimeZoneType -> copy(metas = metas) - is StructType -> copy(metas = metas) - is TupleType -> copy(metas = metas) - is ListType -> copy(metas = metas) - is SexpType -> copy(metas = metas) - is BagType -> copy(metas = metas) - is AnyType -> copy(metas = metas) - is EsBoolean -> copy(metas = metas) - is EsInteger -> copy(metas = metas) - is EsFloat -> copy(metas = metas) - is EsText -> copy(metas = metas) - is EsAny -> copy(metas = metas) - is SparkShort -> copy(metas = metas) - is SparkInteger -> copy(metas = metas) - is SparkLong -> copy(metas = metas) - is SparkDouble -> copy(metas = metas) - is SparkBoolean -> copy(metas = metas) - is SparkFloat -> copy(metas = metas) - is RsVarcharMax -> copy(metas = metas) - is RsInteger -> copy(metas = metas) - is RsBigint -> copy(metas = metas) - is RsBoolean -> copy(metas = metas) - is RsReal -> copy(metas = metas) - is RsDoublePrecision -> copy(metas = metas) - is CustomType -> copy(metas = metas) - } - - class NullType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): NullType = - NullType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): NullType = - NullType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("null_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != NullType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18000 - } - - class BooleanType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): BooleanType = - BooleanType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): BooleanType = - BooleanType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("boolean_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != BooleanType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18001 - } - - class SmallintType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): SmallintType = - SmallintType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SmallintType = - SmallintType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("smallint_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SmallintType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18002 - } - - class Integer4Type( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): Integer4Type = - Integer4Type( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Integer4Type = - Integer4Type( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("integer4_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Integer4Type::class.java) return false - - return true - } - - override fun hashCode(): Int = 18003 - } - - class Integer8Type( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): Integer8Type = - Integer8Type( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): Integer8Type = - Integer8Type( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("integer8_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != Integer8Type::class.java) return false - - return true - } - - override fun hashCode(): Int = 18004 - } - - class IntegerType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): IntegerType = - IntegerType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): IntegerType = - IntegerType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("integer_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != IntegerType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18005 - } - - class FloatType( - val precision: org.partiql.pig.runtime.LongPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): FloatType = - FloatType( - precision = precision, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): FloatType = - FloatType( - precision = precision, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("float_type"), - precision?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - precision: org.partiql.pig.runtime.LongPrimitive? = this.precision, - metas: MetaContainer = this.metas - ) = - FloatType( - precision, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != FloatType::class.java) return false - - other as FloatType - if (precision != other.precision) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = precision.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class RealType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): RealType = - RealType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): RealType = - RealType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("real_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != RealType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18007 - } - - class DoublePrecisionType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): DoublePrecisionType = - DoublePrecisionType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): DoublePrecisionType = - DoublePrecisionType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("double_precision_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != DoublePrecisionType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18008 - } - - class DecimalType( - val precision: org.partiql.pig.runtime.LongPrimitive?, - val scale: org.partiql.pig.runtime.LongPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): DecimalType = - DecimalType( - precision = precision, - scale = scale, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): DecimalType = - DecimalType( - precision = precision, - scale = scale, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("decimal_type"), - precision?.toIonElement() ?: ionNull(), - scale?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - precision: org.partiql.pig.runtime.LongPrimitive? = this.precision, - scale: org.partiql.pig.runtime.LongPrimitive? = this.scale, - metas: MetaContainer = this.metas - ) = - DecimalType( - precision, - scale, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != DecimalType::class.java) return false - - other as DecimalType - if (precision != other.precision) return false - if (scale != other.scale) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = precision.hashCode() - hc = 31 * hc + scale.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class NumericType( - val precision: org.partiql.pig.runtime.LongPrimitive?, - val scale: org.partiql.pig.runtime.LongPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): NumericType = - NumericType( - precision = precision, - scale = scale, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): NumericType = - NumericType( - precision = precision, - scale = scale, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("numeric_type"), - precision?.toIonElement() ?: ionNull(), - scale?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - precision: org.partiql.pig.runtime.LongPrimitive? = this.precision, - scale: org.partiql.pig.runtime.LongPrimitive? = this.scale, - metas: MetaContainer = this.metas - ) = - NumericType( - precision, - scale, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != NumericType::class.java) return false - - other as NumericType - if (precision != other.precision) return false - if (scale != other.scale) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = precision.hashCode() - hc = 31 * hc + scale.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class TimestampType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): TimestampType = - TimestampType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): TimestampType = - TimestampType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("timestamp_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != TimestampType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18011 - } - - class CharacterType( - val length: org.partiql.pig.runtime.LongPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): CharacterType = - CharacterType( - length = length, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): CharacterType = - CharacterType( - length = length, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("character_type"), - length?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - length: org.partiql.pig.runtime.LongPrimitive? = this.length, - metas: MetaContainer = this.metas - ) = - CharacterType( - length, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != CharacterType::class.java) return false - - other as CharacterType - if (length != other.length) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = length.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class CharacterVaryingType( - val length: org.partiql.pig.runtime.LongPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): CharacterVaryingType = - CharacterVaryingType( - length = length, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): CharacterVaryingType = - CharacterVaryingType( - length = length, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("character_varying_type"), - length?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - length: org.partiql.pig.runtime.LongPrimitive? = this.length, - metas: MetaContainer = this.metas - ) = - CharacterVaryingType( - length, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != CharacterVaryingType::class.java) return false - - other as CharacterVaryingType - if (length != other.length) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = length.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class MissingType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): MissingType = - MissingType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): MissingType = - MissingType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("missing_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != MissingType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18014 - } - - class StringType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): StringType = - StringType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): StringType = - StringType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("string_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != StringType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18015 - } - - class SymbolType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): SymbolType = - SymbolType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SymbolType = - SymbolType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("symbol_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SymbolType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18016 - } - - class BlobType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): BlobType = - BlobType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): BlobType = - BlobType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("blob_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != BlobType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18017 - } - - class ClobType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): ClobType = - ClobType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ClobType = - ClobType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("clob_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ClobType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18018 - } - - class DateType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): DateType = - DateType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): DateType = - DateType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("date_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != DateType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18019 - } - - class TimeType( - val precision: org.partiql.pig.runtime.LongPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): TimeType = - TimeType( - precision = precision, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): TimeType = - TimeType( - precision = precision, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("time_type"), - precision?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - precision: org.partiql.pig.runtime.LongPrimitive? = this.precision, - metas: MetaContainer = this.metas - ) = - TimeType( - precision, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != TimeType::class.java) return false - - other as TimeType - if (precision != other.precision) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = precision.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class TimeWithTimeZoneType( - val precision: org.partiql.pig.runtime.LongPrimitive?, - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): TimeWithTimeZoneType = - TimeWithTimeZoneType( - precision = precision, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): TimeWithTimeZoneType = - TimeWithTimeZoneType( - precision = precision, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("time_with_time_zone_type"), - precision?.toIonElement() ?: ionNull(), - metas = metas) - return elements - } - - fun copy( - precision: org.partiql.pig.runtime.LongPrimitive? = this.precision, - metas: MetaContainer = this.metas - ) = - TimeWithTimeZoneType( - precision, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != TimeWithTimeZoneType::class.java) return false - - other as TimeWithTimeZoneType - if (precision != other.precision) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = precision.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - class StructType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): StructType = - StructType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): StructType = - StructType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("struct_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != StructType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18022 - } - - class TupleType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): TupleType = - TupleType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): TupleType = - TupleType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("tuple_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != TupleType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18023 - } - - class ListType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): ListType = - ListType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): ListType = - ListType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("list_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != ListType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18024 - } - - class SexpType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): SexpType = - SexpType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SexpType = - SexpType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("sexp_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SexpType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18025 - } - - class BagType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): BagType = - BagType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): BagType = - BagType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("bag_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != BagType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18026 - } - - class AnyType( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): AnyType = - AnyType( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): AnyType = - AnyType( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("any_type"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != AnyType::class.java) return false - - return true - } - - override fun hashCode(): Int = 18027 - } - - class EsBoolean( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): EsBoolean = - EsBoolean( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): EsBoolean = - EsBoolean( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("es_boolean"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != EsBoolean::class.java) return false - - return true - } - - override fun hashCode(): Int = 18028 - } - - class EsInteger( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): EsInteger = - EsInteger( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): EsInteger = - EsInteger( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("es_integer"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != EsInteger::class.java) return false - - return true - } - - override fun hashCode(): Int = 18029 - } - - class EsFloat( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): EsFloat = - EsFloat( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): EsFloat = - EsFloat( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("es_float"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != EsFloat::class.java) return false - - return true - } - - override fun hashCode(): Int = 18030 - } - - class EsText( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): EsText = - EsText( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): EsText = - EsText( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("es_text"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != EsText::class.java) return false - - return true - } - - override fun hashCode(): Int = 18031 - } - - class EsAny( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): EsAny = - EsAny( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): EsAny = - EsAny( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("es_any"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != EsAny::class.java) return false - - return true - } - - override fun hashCode(): Int = 18032 - } - - class SparkShort( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): SparkShort = - SparkShort( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SparkShort = - SparkShort( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("spark_short"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SparkShort::class.java) return false - - return true - } - - override fun hashCode(): Int = 18033 - } - - class SparkInteger( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): SparkInteger = - SparkInteger( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SparkInteger = - SparkInteger( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("spark_integer"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SparkInteger::class.java) return false - - return true - } - - override fun hashCode(): Int = 18034 - } - - class SparkLong( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): SparkLong = - SparkLong( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SparkLong = - SparkLong( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("spark_long"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SparkLong::class.java) return false - - return true - } - - override fun hashCode(): Int = 18035 - } - - class SparkDouble( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): SparkDouble = - SparkDouble( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SparkDouble = - SparkDouble( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("spark_double"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SparkDouble::class.java) return false - - return true - } - - override fun hashCode(): Int = 18036 - } - - class SparkBoolean( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): SparkBoolean = - SparkBoolean( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SparkBoolean = - SparkBoolean( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("spark_boolean"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SparkBoolean::class.java) return false - - return true - } - - override fun hashCode(): Int = 18037 - } - - class SparkFloat( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): SparkFloat = - SparkFloat( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): SparkFloat = - SparkFloat( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("spark_float"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != SparkFloat::class.java) return false - - return true - } - - override fun hashCode(): Int = 18038 - } - - class RsVarcharMax( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): RsVarcharMax = - RsVarcharMax( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): RsVarcharMax = - RsVarcharMax( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("rs_varchar_max"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != RsVarcharMax::class.java) return false - - return true - } - - override fun hashCode(): Int = 18039 - } - - class RsInteger( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): RsInteger = - RsInteger( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): RsInteger = - RsInteger( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("rs_integer"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != RsInteger::class.java) return false - - return true - } - - override fun hashCode(): Int = 18040 - } - - class RsBigint( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): RsBigint = - RsBigint( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): RsBigint = - RsBigint( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("rs_bigint"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != RsBigint::class.java) return false - - return true - } - - override fun hashCode(): Int = 18041 - } - - class RsBoolean( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): RsBoolean = - RsBoolean( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): RsBoolean = - RsBoolean( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("rs_boolean"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != RsBoolean::class.java) return false - - return true - } - - override fun hashCode(): Int = 18042 - } - - class RsReal( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): RsReal = - RsReal( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): RsReal = - RsReal( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("rs_real"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != RsReal::class.java) return false - - return true - } - - override fun hashCode(): Int = 18043 - } - - class RsDoublePrecision( - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): RsDoublePrecision = - RsDoublePrecision( - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): RsDoublePrecision = - RsDoublePrecision( - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("rs_double_precision"), - metas = metas) - return elements - } - - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != RsDoublePrecision::class.java) return false - - return true - } - - override fun hashCode(): Int = 18044 - } - - class CustomType( - val name: org.partiql.pig.runtime.SymbolPrimitive, - override val metas: MetaContainer = emptyMetaContainer() - ): Type() { - - override fun copy(metas: MetaContainer): CustomType = - CustomType( - name = name, - metas = metas) - - override fun withMeta(metaKey: String, metaValue: Any): CustomType = - CustomType( - name = name, - metas = metas + metaContainerOf(metaKey to metaValue)) - - override fun toIonElement(): SexpElement { - val elements = ionSexpOf( - ionSymbol("custom_type"), - name.toIonElement(), - metas = metas) - return elements - } - - fun copy( - name: org.partiql.pig.runtime.SymbolPrimitive = this.name, - metas: MetaContainer = this.metas - ) = - CustomType( - name, - metas) - - override fun equals(other: Any?): Boolean { - if (other == null) return false - if (this === other) return true - if (other.javaClass != CustomType::class.java) return false - - other as CustomType - if (name != other.name) return false - return true - } - - private val myHashCode by lazy(LazyThreadSafetyMode.PUBLICATION) { - var hc = name.hashCode() - hc - } - - override fun hashCode(): Int = myHashCode - } - - /** Converts instances of [PartiqlAst.Type] to any [T]. */ - interface Converter { - fun convert(node: PartiqlAst.Type): T = when(node) { - is PartiqlAst.Type.NullType -> convertNullType(node) - is PartiqlAst.Type.BooleanType -> convertBooleanType(node) - is PartiqlAst.Type.SmallintType -> convertSmallintType(node) - is PartiqlAst.Type.Integer4Type -> convertInteger4Type(node) - is PartiqlAst.Type.Integer8Type -> convertInteger8Type(node) - is PartiqlAst.Type.IntegerType -> convertIntegerType(node) - is PartiqlAst.Type.FloatType -> convertFloatType(node) - is PartiqlAst.Type.RealType -> convertRealType(node) - is PartiqlAst.Type.DoublePrecisionType -> convertDoublePrecisionType(node) - is PartiqlAst.Type.DecimalType -> convertDecimalType(node) - is PartiqlAst.Type.NumericType -> convertNumericType(node) - is PartiqlAst.Type.TimestampType -> convertTimestampType(node) - is PartiqlAst.Type.CharacterType -> convertCharacterType(node) - is PartiqlAst.Type.CharacterVaryingType -> convertCharacterVaryingType(node) - is PartiqlAst.Type.MissingType -> convertMissingType(node) - is PartiqlAst.Type.StringType -> convertStringType(node) - is PartiqlAst.Type.SymbolType -> convertSymbolType(node) - is PartiqlAst.Type.BlobType -> convertBlobType(node) - is PartiqlAst.Type.ClobType -> convertClobType(node) - is PartiqlAst.Type.DateType -> convertDateType(node) - is PartiqlAst.Type.TimeType -> convertTimeType(node) - is PartiqlAst.Type.TimeWithTimeZoneType -> convertTimeWithTimeZoneType(node) - is PartiqlAst.Type.StructType -> convertStructType(node) - is PartiqlAst.Type.TupleType -> convertTupleType(node) - is PartiqlAst.Type.ListType -> convertListType(node) - is PartiqlAst.Type.SexpType -> convertSexpType(node) - is PartiqlAst.Type.BagType -> convertBagType(node) - is PartiqlAst.Type.AnyType -> convertAnyType(node) - is PartiqlAst.Type.EsBoolean -> convertEsBoolean(node) - is PartiqlAst.Type.EsInteger -> convertEsInteger(node) - is PartiqlAst.Type.EsFloat -> convertEsFloat(node) - is PartiqlAst.Type.EsText -> convertEsText(node) - is PartiqlAst.Type.EsAny -> convertEsAny(node) - is PartiqlAst.Type.SparkShort -> convertSparkShort(node) - is PartiqlAst.Type.SparkInteger -> convertSparkInteger(node) - is PartiqlAst.Type.SparkLong -> convertSparkLong(node) - is PartiqlAst.Type.SparkDouble -> convertSparkDouble(node) - is PartiqlAst.Type.SparkBoolean -> convertSparkBoolean(node) - is PartiqlAst.Type.SparkFloat -> convertSparkFloat(node) - is PartiqlAst.Type.RsVarcharMax -> convertRsVarcharMax(node) - is PartiqlAst.Type.RsInteger -> convertRsInteger(node) - is PartiqlAst.Type.RsBigint -> convertRsBigint(node) - is PartiqlAst.Type.RsBoolean -> convertRsBoolean(node) - is PartiqlAst.Type.RsReal -> convertRsReal(node) - is PartiqlAst.Type.RsDoublePrecision -> convertRsDoublePrecision(node) - is PartiqlAst.Type.CustomType -> convertCustomType(node) - } - - fun convertNullType(node: PartiqlAst.Type.NullType): T - fun convertBooleanType(node: PartiqlAst.Type.BooleanType): T - fun convertSmallintType(node: PartiqlAst.Type.SmallintType): T - fun convertInteger4Type(node: PartiqlAst.Type.Integer4Type): T - fun convertInteger8Type(node: PartiqlAst.Type.Integer8Type): T - fun convertIntegerType(node: PartiqlAst.Type.IntegerType): T - fun convertFloatType(node: PartiqlAst.Type.FloatType): T - fun convertRealType(node: PartiqlAst.Type.RealType): T - fun convertDoublePrecisionType(node: PartiqlAst.Type.DoublePrecisionType): T - fun convertDecimalType(node: PartiqlAst.Type.DecimalType): T - fun convertNumericType(node: PartiqlAst.Type.NumericType): T - fun convertTimestampType(node: PartiqlAst.Type.TimestampType): T - fun convertCharacterType(node: PartiqlAst.Type.CharacterType): T - fun convertCharacterVaryingType(node: PartiqlAst.Type.CharacterVaryingType): T - fun convertMissingType(node: PartiqlAst.Type.MissingType): T - fun convertStringType(node: PartiqlAst.Type.StringType): T - fun convertSymbolType(node: PartiqlAst.Type.SymbolType): T - fun convertBlobType(node: PartiqlAst.Type.BlobType): T - fun convertClobType(node: PartiqlAst.Type.ClobType): T - fun convertDateType(node: PartiqlAst.Type.DateType): T - fun convertTimeType(node: PartiqlAst.Type.TimeType): T - fun convertTimeWithTimeZoneType(node: PartiqlAst.Type.TimeWithTimeZoneType): T - fun convertStructType(node: PartiqlAst.Type.StructType): T - fun convertTupleType(node: PartiqlAst.Type.TupleType): T - fun convertListType(node: PartiqlAst.Type.ListType): T - fun convertSexpType(node: PartiqlAst.Type.SexpType): T - fun convertBagType(node: PartiqlAst.Type.BagType): T - fun convertAnyType(node: PartiqlAst.Type.AnyType): T - fun convertEsBoolean(node: PartiqlAst.Type.EsBoolean): T - fun convertEsInteger(node: PartiqlAst.Type.EsInteger): T - fun convertEsFloat(node: PartiqlAst.Type.EsFloat): T - fun convertEsText(node: PartiqlAst.Type.EsText): T - fun convertEsAny(node: PartiqlAst.Type.EsAny): T - fun convertSparkShort(node: PartiqlAst.Type.SparkShort): T - fun convertSparkInteger(node: PartiqlAst.Type.SparkInteger): T - fun convertSparkLong(node: PartiqlAst.Type.SparkLong): T - fun convertSparkDouble(node: PartiqlAst.Type.SparkDouble): T - fun convertSparkBoolean(node: PartiqlAst.Type.SparkBoolean): T - fun convertSparkFloat(node: PartiqlAst.Type.SparkFloat): T - fun convertRsVarcharMax(node: PartiqlAst.Type.RsVarcharMax): T - fun convertRsInteger(node: PartiqlAst.Type.RsInteger): T - fun convertRsBigint(node: PartiqlAst.Type.RsBigint): T - fun convertRsBoolean(node: PartiqlAst.Type.RsBoolean): T - fun convertRsReal(node: PartiqlAst.Type.RsReal): T - fun convertRsDoublePrecision(node: PartiqlAst.Type.RsDoublePrecision): T - fun convertCustomType(node: PartiqlAst.Type.CustomType): T - } - } - - ///////////////////////////////////////////////////////////////////////////// - // IonElementTransformer - ///////////////////////////////////////////////////////////////////////////// - - - private class IonElementTransformer : IonElementTransformerBase() { - - override fun innerTransform(sexp: SexpElement): PartiqlAstNode { - return when(sexp.tag) { - ////////////////////////////////////// - // Tuple Types - ////////////////////////////////////// - "time_value" -> { - sexp.requireArityOrMalformed(IntRange(5, 6)) - val hour = sexp.getRequired(0).toLongPrimitive() - val minute = sexp.getRequired(1).toLongPrimitive() - val second = sexp.getRequired(2).toLongPrimitive() - val nano = sexp.getRequired(3).toLongPrimitive() - val precision = sexp.getRequired(4).toLongPrimitive() - val tzMinutes = sexp.getOptional(5)?.toLongPrimitive() - PartiqlAst.TimeValue( - hour, - minute, - second, - nano, - precision, - tzMinutes, - metas = sexp.metas) - } - "let" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val letBindings = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Let( - letBindings, - metas = sexp.metas) - } - "let_binding" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val expr = sexp.getRequired(0).transformExpect() - val name = sexp.getRequired(1).toSymbolPrimitive() - PartiqlAst.LetBinding( - expr, - name, - metas = sexp.metas) - } - "expr_pair" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val first = sexp.getRequired(0).transformExpect() - val second = sexp.getRequired(1).transformExpect() - PartiqlAst.ExprPair( - first, - second, - metas = sexp.metas) - } - "expr_pair_list" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val pairs = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.ExprPairList( - pairs, - metas = sexp.metas) - } - "group_by" -> { - sexp.requireArityOrMalformed(IntRange(2, 3)) - val strategy = sexp.getRequired(0).transformExpect() - val keyList = sexp.getRequired(1).transformExpect() - val groupAsAlias = sexp.getOptional(2)?.toSymbolPrimitive() - PartiqlAst.GroupBy( - strategy, - keyList, - groupAsAlias, - metas = sexp.metas) - } - "group_key_list" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val keys = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.GroupKeyList( - keys, - metas = sexp.metas) - } - "group_key" -> { - sexp.requireArityOrMalformed(IntRange(1, 2)) - val expr = sexp.getRequired(0).transformExpect() - val asAlias = sexp.getOptional(1)?.toSymbolPrimitive() - PartiqlAst.GroupKey( - expr, - asAlias, - metas = sexp.metas) - } - "order_by" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val sortSpecs = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.OrderBy( - sortSpecs, - metas = sexp.metas) - } - "sort_spec" -> { - sexp.requireArityOrMalformed(IntRange(1, 2)) - val expr = sexp.getRequired(0).transformExpect() - val orderingSpec = sexp.getOptional(1)?.transformExpect() - PartiqlAst.SortSpec( - expr, - orderingSpec, - metas = sexp.metas) - } - "dml_op_list" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val ops = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.DmlOpList( - ops, - metas = sexp.metas) - } - "on_conflict" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val expr = sexp.getRequired(0).transformExpect() - val conflictAction = sexp.getRequired(1).transformExpect() - PartiqlAst.OnConflict( - expr, - conflictAction, - metas = sexp.metas) - } - "returning_expr" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val elems = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.ReturningExpr( - elems, - metas = sexp.metas) - } - "returning_elem" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val mapping = sexp.getRequired(0).transformExpect() - val column = sexp.getRequired(1).transformExpect() - PartiqlAst.ReturningElem( - mapping, - column, - metas = sexp.metas) - } - "identifier" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val name = sexp.getRequired(0).toSymbolPrimitive() - val case = sexp.getRequired(1).transformExpect() - PartiqlAst.Identifier( - name, - case, - metas = sexp.metas) - } - "assignment" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val target = sexp.getRequired(0).transformExpect() - val value = sexp.getRequired(1).transformExpect() - PartiqlAst.Assignment( - target, - value, - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'Statement' - ////////////////////////////////////// - "query" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val expr = sexp.getRequired(0).transformExpect() - PartiqlAst.Statement.Query( - expr, - metas = sexp.metas) - } - "dml" -> { - val ir = sexp.transformToIntermediateRecord() - - val operations = ir.processRequiredField("operations") { it.transformExpect() } - val from = ir.processOptionalField("from") { it.transformExpect() } - val where = ir.processOptionalField("where") { it.transformExpect() } - val returning = ir.processOptionalField("returning") { it.transformExpect() } - - ir.malformedIfAnyUnprocessedFieldsRemain() - - Statement.Dml(operations, from, where, returning, metas = sexp.metas) - } - "ddl" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val op = sexp.getRequired(0).transformExpect() - PartiqlAst.Statement.Ddl( - op, - metas = sexp.metas) - } - "exec" -> { - sexp.requireArityOrMalformed(IntRange(1, 2147483647)) - val procedureName = sexp.getRequired(0).toSymbolPrimitive() - val args = sexp.values.drop(2).map { it.transformExpect() } - PartiqlAst.Statement.Exec( - procedureName, - args, - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'Expr' - ////////////////////////////////////// - "missing" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Expr.Missing( - metas = sexp.metas) - } - "lit" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val value = sexp.getRequiredIon(0) - PartiqlAst.Expr.Lit( - value, - metas = sexp.metas) - } - "id" -> { - sexp.requireArityOrMalformed(IntRange(3, 3)) - val name = sexp.getRequired(0).toSymbolPrimitive() - val case = sexp.getRequired(1).transformExpect() - val qualifier = sexp.getRequired(2).transformExpect() - PartiqlAst.Expr.Id( - name, - case, - qualifier, - metas = sexp.metas) - } - "parameter" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val index = sexp.getRequired(0).toLongPrimitive() - PartiqlAst.Expr.Parameter( - index, - metas = sexp.metas) - } - "not" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val expr = sexp.getRequired(0).transformExpect() - PartiqlAst.Expr.Not( - expr, - metas = sexp.metas) - } - "pos" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val expr = sexp.getRequired(0).transformExpect() - PartiqlAst.Expr.Pos( - expr, - metas = sexp.metas) - } - "neg" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val expr = sexp.getRequired(0).transformExpect() - PartiqlAst.Expr.Neg( - expr, - metas = sexp.metas) - } - "plus" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Plus( - operands, - metas = sexp.metas) - } - "minus" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Minus( - operands, - metas = sexp.metas) - } - "times" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Times( - operands, - metas = sexp.metas) - } - "divide" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Divide( - operands, - metas = sexp.metas) - } - "modulo" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Modulo( - operands, - metas = sexp.metas) - } - "concat" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Concat( - operands, - metas = sexp.metas) - } - "and" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.And( - operands, - metas = sexp.metas) - } - "or" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Or( - operands, - metas = sexp.metas) - } - "eq" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Eq( - operands, - metas = sexp.metas) - } - "ne" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Ne( - operands, - metas = sexp.metas) - } - "gt" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Gt( - operands, - metas = sexp.metas) - } - "gte" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Gte( - operands, - metas = sexp.metas) - } - "lt" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Lt( - operands, - metas = sexp.metas) - } - "lte" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Lte( - operands, - metas = sexp.metas) - } - "like" -> { - sexp.requireArityOrMalformed(IntRange(2, 3)) - val value = sexp.getRequired(0).transformExpect() - val pattern = sexp.getRequired(1).transformExpect() - val escape = sexp.getOptional(2)?.transformExpect() - PartiqlAst.Expr.Like( - value, - pattern, - escape, - metas = sexp.metas) - } - "between" -> { - sexp.requireArityOrMalformed(IntRange(3, 3)) - val value = sexp.getRequired(0).transformExpect() - val from = sexp.getRequired(1).transformExpect() - val to = sexp.getRequired(2).transformExpect() - PartiqlAst.Expr.Between( - value, - from, - to, - metas = sexp.metas) - } - "in_collection" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val operands = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.InCollection( - operands, - metas = sexp.metas) - } - "is_type" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val value = sexp.getRequired(0).transformExpect() - val type = sexp.getRequired(1).transformExpect() - PartiqlAst.Expr.IsType( - value, - type, - metas = sexp.metas) - } - "simple_case" -> { - sexp.requireArityOrMalformed(IntRange(2, 3)) - val expr = sexp.getRequired(0).transformExpect() - val cases = sexp.getRequired(1).transformExpect() - val default = sexp.getOptional(2)?.transformExpect() - PartiqlAst.Expr.SimpleCase( - expr, - cases, - default, - metas = sexp.metas) - } - "searched_case" -> { - sexp.requireArityOrMalformed(IntRange(1, 2)) - val cases = sexp.getRequired(0).transformExpect() - val default = sexp.getOptional(1)?.transformExpect() - PartiqlAst.Expr.SearchedCase( - cases, - default, - metas = sexp.metas) - } - "struct" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val fields = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Struct( - fields, - metas = sexp.metas) - } - "bag" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val values = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Bag( - values, - metas = sexp.metas) - } - "list" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val values = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.List( - values, - metas = sexp.metas) - } - "sexp" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val values = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Sexp( - values, - metas = sexp.metas) - } - "date" -> { - sexp.requireArityOrMalformed(IntRange(3, 3)) - val year = sexp.getRequired(0).toLongPrimitive() - val month = sexp.getRequired(1).toLongPrimitive() - val day = sexp.getRequired(2).toLongPrimitive() - PartiqlAst.Expr.Date( - year, - month, - day, - metas = sexp.metas) - } - "lit_time" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val value = sexp.getRequired(0).transformExpect() - PartiqlAst.Expr.LitTime( - value, - metas = sexp.metas) - } - "union" -> { - sexp.requireArityOrMalformed(IntRange(1, 2147483647)) - val setq = sexp.getRequired(0).transformExpect() - val operands = sexp.values.drop(2).map { it.transformExpect() } - PartiqlAst.Expr.Union( - setq, - operands, - metas = sexp.metas) - } - "except" -> { - sexp.requireArityOrMalformed(IntRange(1, 2147483647)) - val setq = sexp.getRequired(0).transformExpect() - val operands = sexp.values.drop(2).map { it.transformExpect() } - PartiqlAst.Expr.Except( - setq, - operands, - metas = sexp.metas) - } - "intersect" -> { - sexp.requireArityOrMalformed(IntRange(1, 2147483647)) - val setq = sexp.getRequired(0).transformExpect() - val operands = sexp.values.drop(2).map { it.transformExpect() } - PartiqlAst.Expr.Intersect( - setq, - operands, - metas = sexp.metas) - } - "path" -> { - sexp.requireArityOrMalformed(IntRange(1, 2147483647)) - val root = sexp.getRequired(0).transformExpect() - val steps = sexp.values.drop(2).map { it.transformExpect() } - PartiqlAst.Expr.Path( - root, - steps, - metas = sexp.metas) - } - "call" -> { - sexp.requireArityOrMalformed(IntRange(1, 2147483647)) - val funcName = sexp.getRequired(0).toSymbolPrimitive() - val args = sexp.values.drop(2).map { it.transformExpect() } - PartiqlAst.Expr.Call( - funcName, - args, - metas = sexp.metas) - } - "call_agg" -> { - sexp.requireArityOrMalformed(IntRange(3, 3)) - val setq = sexp.getRequired(0).transformExpect() - val funcName = sexp.getRequired(1).toSymbolPrimitive() - val arg = sexp.getRequired(2).transformExpect() - PartiqlAst.Expr.CallAgg( - setq, - funcName, - arg, - metas = sexp.metas) - } - "cast" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val value = sexp.getRequired(0).transformExpect() - val asType = sexp.getRequired(1).transformExpect() - PartiqlAst.Expr.Cast( - value, - asType, - metas = sexp.metas) - } - "can_cast" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val value = sexp.getRequired(0).transformExpect() - val asType = sexp.getRequired(1).transformExpect() - PartiqlAst.Expr.CanCast( - value, - asType, - metas = sexp.metas) - } - "can_lossless_cast" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val value = sexp.getRequired(0).transformExpect() - val asType = sexp.getRequired(1).transformExpect() - PartiqlAst.Expr.CanLosslessCast( - value, - asType, - metas = sexp.metas) - } - "null_if" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val expr1 = sexp.getRequired(0).transformExpect() - val expr2 = sexp.getRequired(1).transformExpect() - PartiqlAst.Expr.NullIf( - expr1, - expr2, - metas = sexp.metas) - } - "coalesce" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val args = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Expr.Coalesce( - args, - metas = sexp.metas) - } - "select" -> { - val ir = sexp.transformToIntermediateRecord() - - val setq = ir.processOptionalField("setq") { it.transformExpect() } - val project = ir.processRequiredField("project") { it.transformExpect() } - val from = ir.processRequiredField("from") { it.transformExpect() } - val fromLet = ir.processOptionalField("from_let") { it.transformExpect() } - val where = ir.processOptionalField("where") { it.transformExpect() } - val group = ir.processOptionalField("group") { it.transformExpect() } - val having = ir.processOptionalField("having") { it.transformExpect() } - val order = ir.processOptionalField("order") { it.transformExpect() } - val limit = ir.processOptionalField("limit") { it.transformExpect() } - - ir.malformedIfAnyUnprocessedFieldsRemain() - - Expr.Select(setq, project, from, fromLet, where, group, having, order, limit, metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'PathStep' - ////////////////////////////////////// - "path_expr" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val index = sexp.getRequired(0).transformExpect() - val case = sexp.getRequired(1).transformExpect() - PartiqlAst.PathStep.PathExpr( - index, - case, - metas = sexp.metas) - } - "path_wildcard" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.PathStep.PathWildcard( - metas = sexp.metas) - } - "path_unpivot" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.PathStep.PathUnpivot( - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'Projection' - ////////////////////////////////////// - "project_star" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Projection.ProjectStar( - metas = sexp.metas) - } - "project_list" -> { - sexp.requireArityOrMalformed(IntRange(0, 2147483647)) - val projectItems = sexp.values.drop(1).map { it.transformExpect() } - PartiqlAst.Projection.ProjectList( - projectItems, - metas = sexp.metas) - } - "project_pivot" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val value = sexp.getRequired(0).transformExpect() - val key = sexp.getRequired(1).transformExpect() - PartiqlAst.Projection.ProjectPivot( - value, - key, - metas = sexp.metas) - } - "project_value" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val value = sexp.getRequired(0).transformExpect() - PartiqlAst.Projection.ProjectValue( - value, - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'ProjectItem' - ////////////////////////////////////// - "project_all" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val expr = sexp.getRequired(0).transformExpect() - PartiqlAst.ProjectItem.ProjectAll( - expr, - metas = sexp.metas) - } - "project_expr" -> { - sexp.requireArityOrMalformed(IntRange(1, 2)) - val expr = sexp.getRequired(0).transformExpect() - val asAlias = sexp.getOptional(1)?.toSymbolPrimitive() - PartiqlAst.ProjectItem.ProjectExpr( - expr, - asAlias, - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'FromSource' - ////////////////////////////////////// - "scan" -> { - sexp.requireArityOrMalformed(IntRange(1, 4)) - val expr = sexp.getRequired(0).transformExpect() - val asAlias = sexp.getOptional(1)?.toSymbolPrimitive() - val atAlias = sexp.getOptional(2)?.toSymbolPrimitive() - val byAlias = sexp.getOptional(3)?.toSymbolPrimitive() - PartiqlAst.FromSource.Scan( - expr, - asAlias, - atAlias, - byAlias, - metas = sexp.metas) - } - "unpivot" -> { - sexp.requireArityOrMalformed(IntRange(1, 4)) - val expr = sexp.getRequired(0).transformExpect() - val asAlias = sexp.getOptional(1)?.toSymbolPrimitive() - val atAlias = sexp.getOptional(2)?.toSymbolPrimitive() - val byAlias = sexp.getOptional(3)?.toSymbolPrimitive() - PartiqlAst.FromSource.Unpivot( - expr, - asAlias, - atAlias, - byAlias, - metas = sexp.metas) - } - "join" -> { - sexp.requireArityOrMalformed(IntRange(3, 4)) - val type = sexp.getRequired(0).transformExpect() - val left = sexp.getRequired(1).transformExpect() - val right = sexp.getRequired(2).transformExpect() - val predicate = sexp.getOptional(3)?.transformExpect() - PartiqlAst.FromSource.Join( - type, - left, - right, - predicate, - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'JoinType' - ////////////////////////////////////// - "inner" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.JoinType.Inner( - metas = sexp.metas) - } - "left" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.JoinType.Left( - metas = sexp.metas) - } - "right" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.JoinType.Right( - metas = sexp.metas) - } - "full" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.JoinType.Full( - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'GroupingStrategy' - ////////////////////////////////////// - "group_full" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.GroupingStrategy.GroupFull( - metas = sexp.metas) - } - "group_partial" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.GroupingStrategy.GroupPartial( - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'OrderingSpec' - ////////////////////////////////////// - "asc" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.OrderingSpec.Asc( - metas = sexp.metas) - } - "desc" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.OrderingSpec.Desc( - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'CaseSensitivity' - ////////////////////////////////////// - "case_sensitive" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.CaseSensitivity.CaseSensitive( - metas = sexp.metas) - } - "case_insensitive" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.CaseSensitivity.CaseInsensitive( - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'ScopeQualifier' - ////////////////////////////////////// - "unqualified" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.ScopeQualifier.Unqualified( - metas = sexp.metas) - } - "locals_first" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.ScopeQualifier.LocalsFirst( - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'SetQuantifier' - ////////////////////////////////////// - "all" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.SetQuantifier.All( - metas = sexp.metas) - } - "distinct" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.SetQuantifier.Distinct( - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'DmlOp' - ////////////////////////////////////// - "insert" -> { - sexp.requireArityOrMalformed(IntRange(2, 2)) - val target = sexp.getRequired(0).transformExpect() - val values = sexp.getRequired(1).transformExpect() - PartiqlAst.DmlOp.Insert( - target, - values, - metas = sexp.metas) - } - "insert_value" -> { - sexp.requireArityOrMalformed(IntRange(2, 4)) - val target = sexp.getRequired(0).transformExpect() - val value = sexp.getRequired(1).transformExpect() - val index = sexp.getOptional(2)?.transformExpect() - val onConflict = sexp.getOptional(3)?.transformExpect() - PartiqlAst.DmlOp.InsertValue( - target, - value, - index, - onConflict, - metas = sexp.metas) - } - "set" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val assignment = sexp.getRequired(0).transformExpect() - PartiqlAst.DmlOp.Set( - assignment, - metas = sexp.metas) - } - "remove" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val target = sexp.getRequired(0).transformExpect() - PartiqlAst.DmlOp.Remove( - target, - metas = sexp.metas) - } - "delete" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.DmlOp.Delete( - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'ConflictAction' - ////////////////////////////////////// - "do_nothing" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.ConflictAction.DoNothing( - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'DdlOp' - ////////////////////////////////////// - "create_table" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val tableName = sexp.getRequired(0).toSymbolPrimitive() - PartiqlAst.DdlOp.CreateTable( - tableName, - metas = sexp.metas) - } - "drop_table" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val tableName = sexp.getRequired(0).transformExpect() - PartiqlAst.DdlOp.DropTable( - tableName, - metas = sexp.metas) - } - "undrop_table" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val tableName = sexp.getRequired(0).toSymbolPrimitive() - PartiqlAst.DdlOp.UndropTable( - tableName, - metas = sexp.metas) - } - "create_index" -> { - sexp.requireArityOrMalformed(IntRange(1, 2147483647)) - val indexName = sexp.getRequired(0).transformExpect() - val fields = sexp.values.drop(2).map { it.transformExpect() } - PartiqlAst.DdlOp.CreateIndex( - indexName, - fields, - metas = sexp.metas) - } - "drop_index" -> { - val ir = sexp.transformToIntermediateRecord() - - val table = ir.processRequiredField("table") { it.transformExpect() } - val keys = ir.processRequiredField("keys") { it.transformExpect() } - - ir.malformedIfAnyUnprocessedFieldsRemain() - - DdlOp.DropIndex(table, keys, metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'ColumnComponent' - ////////////////////////////////////// - "returning_wildcard" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.ColumnComponent.ReturningWildcard( - metas = sexp.metas) - } - "returning_column" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val expr = sexp.getRequired(0).transformExpect() - PartiqlAst.ColumnComponent.ReturningColumn( - expr, - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'ReturningMapping' - ////////////////////////////////////// - "modified_new" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.ReturningMapping.ModifiedNew( - metas = sexp.metas) - } - "modified_old" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.ReturningMapping.ModifiedOld( - metas = sexp.metas) - } - "all_new" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.ReturningMapping.AllNew( - metas = sexp.metas) - } - "all_old" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.ReturningMapping.AllOld( - metas = sexp.metas) - } - ////////////////////////////////////// - // Variants for Sum Type 'Type' - ////////////////////////////////////// - "null_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.NullType( - metas = sexp.metas) - } - "boolean_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.BooleanType( - metas = sexp.metas) - } - "smallint_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.SmallintType( - metas = sexp.metas) - } - "integer4_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.Integer4Type( - metas = sexp.metas) - } - "integer8_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.Integer8Type( - metas = sexp.metas) - } - "integer_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.IntegerType( - metas = sexp.metas) - } - "float_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 1)) - val precision = sexp.getOptional(0)?.toLongPrimitive() - PartiqlAst.Type.FloatType( - precision, - metas = sexp.metas) - } - "real_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.RealType( - metas = sexp.metas) - } - "double_precision_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.DoublePrecisionType( - metas = sexp.metas) - } - "decimal_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 2)) - val precision = sexp.getOptional(0)?.toLongPrimitive() - val scale = sexp.getOptional(1)?.toLongPrimitive() - PartiqlAst.Type.DecimalType( - precision, - scale, - metas = sexp.metas) - } - "numeric_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 2)) - val precision = sexp.getOptional(0)?.toLongPrimitive() - val scale = sexp.getOptional(1)?.toLongPrimitive() - PartiqlAst.Type.NumericType( - precision, - scale, - metas = sexp.metas) - } - "timestamp_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.TimestampType( - metas = sexp.metas) - } - "character_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 1)) - val length = sexp.getOptional(0)?.toLongPrimitive() - PartiqlAst.Type.CharacterType( - length, - metas = sexp.metas) - } - "character_varying_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 1)) - val length = sexp.getOptional(0)?.toLongPrimitive() - PartiqlAst.Type.CharacterVaryingType( - length, - metas = sexp.metas) - } - "missing_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.MissingType( - metas = sexp.metas) - } - "string_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.StringType( - metas = sexp.metas) - } - "symbol_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.SymbolType( - metas = sexp.metas) - } - "blob_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.BlobType( - metas = sexp.metas) - } - "clob_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.ClobType( - metas = sexp.metas) - } - "date_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.DateType( - metas = sexp.metas) - } - "time_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 1)) - val precision = sexp.getOptional(0)?.toLongPrimitive() - PartiqlAst.Type.TimeType( - precision, - metas = sexp.metas) - } - "time_with_time_zone_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 1)) - val precision = sexp.getOptional(0)?.toLongPrimitive() - PartiqlAst.Type.TimeWithTimeZoneType( - precision, - metas = sexp.metas) - } - "struct_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.StructType( - metas = sexp.metas) - } - "tuple_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.TupleType( - metas = sexp.metas) - } - "list_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.ListType( - metas = sexp.metas) - } - "sexp_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.SexpType( - metas = sexp.metas) - } - "bag_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.BagType( - metas = sexp.metas) - } - "any_type" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.AnyType( - metas = sexp.metas) - } - "es_boolean" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.EsBoolean( - metas = sexp.metas) - } - "es_integer" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.EsInteger( - metas = sexp.metas) - } - "es_float" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.EsFloat( - metas = sexp.metas) - } - "es_text" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.EsText( - metas = sexp.metas) - } - "es_any" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.EsAny( - metas = sexp.metas) - } - "spark_short" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.SparkShort( - metas = sexp.metas) - } - "spark_integer" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.SparkInteger( - metas = sexp.metas) - } - "spark_long" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.SparkLong( - metas = sexp.metas) - } - "spark_double" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.SparkDouble( - metas = sexp.metas) - } - "spark_boolean" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.SparkBoolean( - metas = sexp.metas) - } - "spark_float" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.SparkFloat( - metas = sexp.metas) - } - "rs_varchar_max" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.RsVarcharMax( - metas = sexp.metas) - } - "rs_integer" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.RsInteger( - metas = sexp.metas) - } - "rs_bigint" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.RsBigint( - metas = sexp.metas) - } - "rs_boolean" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.RsBoolean( - metas = sexp.metas) - } - "rs_real" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.RsReal( - metas = sexp.metas) - } - "rs_double_precision" -> { - sexp.requireArityOrMalformed(IntRange(0, 0)) - PartiqlAst.Type.RsDoublePrecision( - metas = sexp.metas) - } - "custom_type" -> { - sexp.requireArityOrMalformed(IntRange(1, 1)) - val name = sexp.getRequired(0).toSymbolPrimitive() - PartiqlAst.Type.CustomType( - name, - metas = sexp.metas) - } - else -> errMalformed(sexp.head.metas.location, "Unknown tag '${sexp.tag}' for domain 'partiql_ast'") - } - } - } - - - open class Visitor : DomainVisitorBase() { - //////////////////////////////////////////////////////////////////////////// - // Visit Functions - //////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////// - // Tuple Types - ////////////////////////////////////// - open fun visitTimeValue(node: PartiqlAst.TimeValue) { } - open fun visitLet(node: PartiqlAst.Let) { } - open fun visitLetBinding(node: PartiqlAst.LetBinding) { } - open fun visitExprPair(node: PartiqlAst.ExprPair) { } - open fun visitExprPairList(node: PartiqlAst.ExprPairList) { } - open fun visitGroupBy(node: PartiqlAst.GroupBy) { } - open fun visitGroupKeyList(node: PartiqlAst.GroupKeyList) { } - open fun visitGroupKey(node: PartiqlAst.GroupKey) { } - open fun visitOrderBy(node: PartiqlAst.OrderBy) { } - open fun visitSortSpec(node: PartiqlAst.SortSpec) { } - open fun visitDmlOpList(node: PartiqlAst.DmlOpList) { } - open fun visitOnConflict(node: PartiqlAst.OnConflict) { } - open fun visitReturningExpr(node: PartiqlAst.ReturningExpr) { } - open fun visitReturningElem(node: PartiqlAst.ReturningElem) { } - open fun visitIdentifier(node: PartiqlAst.Identifier) { } - open fun visitAssignment(node: PartiqlAst.Assignment) { } - ////////////////////////////////////// - // Sum Type: Statement - ////////////////////////////////////// - protected open fun visitStatement(node: PartiqlAst.Statement) { } - protected open fun visitStatementQuery(node: PartiqlAst.Statement.Query) { } - protected open fun visitStatementDml(node: PartiqlAst.Statement.Dml) { } - protected open fun visitStatementDdl(node: PartiqlAst.Statement.Ddl) { } - protected open fun visitStatementExec(node: PartiqlAst.Statement.Exec) { } - ////////////////////////////////////// - // Sum Type: Expr - ////////////////////////////////////// - protected open fun visitExpr(node: PartiqlAst.Expr) { } - protected open fun visitExprMissing(node: PartiqlAst.Expr.Missing) { } - protected open fun visitExprLit(node: PartiqlAst.Expr.Lit) { } - protected open fun visitExprId(node: PartiqlAst.Expr.Id) { } - protected open fun visitExprParameter(node: PartiqlAst.Expr.Parameter) { } - protected open fun visitExprNot(node: PartiqlAst.Expr.Not) { } - protected open fun visitExprPos(node: PartiqlAst.Expr.Pos) { } - protected open fun visitExprNeg(node: PartiqlAst.Expr.Neg) { } - protected open fun visitExprPlus(node: PartiqlAst.Expr.Plus) { } - protected open fun visitExprMinus(node: PartiqlAst.Expr.Minus) { } - protected open fun visitExprTimes(node: PartiqlAst.Expr.Times) { } - protected open fun visitExprDivide(node: PartiqlAst.Expr.Divide) { } - protected open fun visitExprModulo(node: PartiqlAst.Expr.Modulo) { } - protected open fun visitExprConcat(node: PartiqlAst.Expr.Concat) { } - protected open fun visitExprAnd(node: PartiqlAst.Expr.And) { } - protected open fun visitExprOr(node: PartiqlAst.Expr.Or) { } - protected open fun visitExprEq(node: PartiqlAst.Expr.Eq) { } - protected open fun visitExprNe(node: PartiqlAst.Expr.Ne) { } - protected open fun visitExprGt(node: PartiqlAst.Expr.Gt) { } - protected open fun visitExprGte(node: PartiqlAst.Expr.Gte) { } - protected open fun visitExprLt(node: PartiqlAst.Expr.Lt) { } - protected open fun visitExprLte(node: PartiqlAst.Expr.Lte) { } - protected open fun visitExprLike(node: PartiqlAst.Expr.Like) { } - protected open fun visitExprBetween(node: PartiqlAst.Expr.Between) { } - protected open fun visitExprInCollection(node: PartiqlAst.Expr.InCollection) { } - protected open fun visitExprIsType(node: PartiqlAst.Expr.IsType) { } - protected open fun visitExprSimpleCase(node: PartiqlAst.Expr.SimpleCase) { } - protected open fun visitExprSearchedCase(node: PartiqlAst.Expr.SearchedCase) { } - protected open fun visitExprStruct(node: PartiqlAst.Expr.Struct) { } - protected open fun visitExprBag(node: PartiqlAst.Expr.Bag) { } - protected open fun visitExprList(node: PartiqlAst.Expr.List) { } - protected open fun visitExprSexp(node: PartiqlAst.Expr.Sexp) { } - protected open fun visitExprDate(node: PartiqlAst.Expr.Date) { } - protected open fun visitExprLitTime(node: PartiqlAst.Expr.LitTime) { } - protected open fun visitExprUnion(node: PartiqlAst.Expr.Union) { } - protected open fun visitExprExcept(node: PartiqlAst.Expr.Except) { } - protected open fun visitExprIntersect(node: PartiqlAst.Expr.Intersect) { } - protected open fun visitExprPath(node: PartiqlAst.Expr.Path) { } - protected open fun visitExprCall(node: PartiqlAst.Expr.Call) { } - protected open fun visitExprCallAgg(node: PartiqlAst.Expr.CallAgg) { } - protected open fun visitExprCast(node: PartiqlAst.Expr.Cast) { } - protected open fun visitExprCanCast(node: PartiqlAst.Expr.CanCast) { } - protected open fun visitExprCanLosslessCast(node: PartiqlAst.Expr.CanLosslessCast) { } - protected open fun visitExprNullIf(node: PartiqlAst.Expr.NullIf) { } - protected open fun visitExprCoalesce(node: PartiqlAst.Expr.Coalesce) { } - protected open fun visitExprSelect(node: PartiqlAst.Expr.Select) { } - ////////////////////////////////////// - // Sum Type: PathStep - ////////////////////////////////////// - protected open fun visitPathStep(node: PartiqlAst.PathStep) { } - protected open fun visitPathStepPathExpr(node: PartiqlAst.PathStep.PathExpr) { } - protected open fun visitPathStepPathWildcard(node: PartiqlAst.PathStep.PathWildcard) { } - protected open fun visitPathStepPathUnpivot(node: PartiqlAst.PathStep.PathUnpivot) { } - ////////////////////////////////////// - // Sum Type: Projection - ////////////////////////////////////// - protected open fun visitProjection(node: PartiqlAst.Projection) { } - protected open fun visitProjectionProjectStar(node: PartiqlAst.Projection.ProjectStar) { } - protected open fun visitProjectionProjectList(node: PartiqlAst.Projection.ProjectList) { } - protected open fun visitProjectionProjectPivot(node: PartiqlAst.Projection.ProjectPivot) { } - protected open fun visitProjectionProjectValue(node: PartiqlAst.Projection.ProjectValue) { } - ////////////////////////////////////// - // Sum Type: ProjectItem - ////////////////////////////////////// - protected open fun visitProjectItem(node: PartiqlAst.ProjectItem) { } - protected open fun visitProjectItemProjectAll(node: PartiqlAst.ProjectItem.ProjectAll) { } - protected open fun visitProjectItemProjectExpr(node: PartiqlAst.ProjectItem.ProjectExpr) { } - ////////////////////////////////////// - // Sum Type: FromSource - ////////////////////////////////////// - protected open fun visitFromSource(node: PartiqlAst.FromSource) { } - protected open fun visitFromSourceScan(node: PartiqlAst.FromSource.Scan) { } - protected open fun visitFromSourceUnpivot(node: PartiqlAst.FromSource.Unpivot) { } - protected open fun visitFromSourceJoin(node: PartiqlAst.FromSource.Join) { } - ////////////////////////////////////// - // Sum Type: JoinType - ////////////////////////////////////// - protected open fun visitJoinType(node: PartiqlAst.JoinType) { } - protected open fun visitJoinTypeInner(node: PartiqlAst.JoinType.Inner) { } - protected open fun visitJoinTypeLeft(node: PartiqlAst.JoinType.Left) { } - protected open fun visitJoinTypeRight(node: PartiqlAst.JoinType.Right) { } - protected open fun visitJoinTypeFull(node: PartiqlAst.JoinType.Full) { } - ////////////////////////////////////// - // Sum Type: GroupingStrategy - ////////////////////////////////////// - protected open fun visitGroupingStrategy(node: PartiqlAst.GroupingStrategy) { } - protected open fun visitGroupingStrategyGroupFull(node: PartiqlAst.GroupingStrategy.GroupFull) { } - protected open fun visitGroupingStrategyGroupPartial(node: PartiqlAst.GroupingStrategy.GroupPartial) { } - ////////////////////////////////////// - // Sum Type: OrderingSpec - ////////////////////////////////////// - protected open fun visitOrderingSpec(node: PartiqlAst.OrderingSpec) { } - protected open fun visitOrderingSpecAsc(node: PartiqlAst.OrderingSpec.Asc) { } - protected open fun visitOrderingSpecDesc(node: PartiqlAst.OrderingSpec.Desc) { } - ////////////////////////////////////// - // Sum Type: CaseSensitivity - ////////////////////////////////////// - protected open fun visitCaseSensitivity(node: PartiqlAst.CaseSensitivity) { } - protected open fun visitCaseSensitivityCaseSensitive(node: PartiqlAst.CaseSensitivity.CaseSensitive) { } - protected open fun visitCaseSensitivityCaseInsensitive(node: PartiqlAst.CaseSensitivity.CaseInsensitive) { } - ////////////////////////////////////// - // Sum Type: ScopeQualifier - ////////////////////////////////////// - protected open fun visitScopeQualifier(node: PartiqlAst.ScopeQualifier) { } - protected open fun visitScopeQualifierUnqualified(node: PartiqlAst.ScopeQualifier.Unqualified) { } - protected open fun visitScopeQualifierLocalsFirst(node: PartiqlAst.ScopeQualifier.LocalsFirst) { } - ////////////////////////////////////// - // Sum Type: SetQuantifier - ////////////////////////////////////// - protected open fun visitSetQuantifier(node: PartiqlAst.SetQuantifier) { } - protected open fun visitSetQuantifierAll(node: PartiqlAst.SetQuantifier.All) { } - protected open fun visitSetQuantifierDistinct(node: PartiqlAst.SetQuantifier.Distinct) { } - ////////////////////////////////////// - // Sum Type: DmlOp - ////////////////////////////////////// - protected open fun visitDmlOp(node: PartiqlAst.DmlOp) { } - protected open fun visitDmlOpInsert(node: PartiqlAst.DmlOp.Insert) { } - protected open fun visitDmlOpInsertValue(node: PartiqlAst.DmlOp.InsertValue) { } - protected open fun visitDmlOpSet(node: PartiqlAst.DmlOp.Set) { } - protected open fun visitDmlOpRemove(node: PartiqlAst.DmlOp.Remove) { } - protected open fun visitDmlOpDelete(node: PartiqlAst.DmlOp.Delete) { } - ////////////////////////////////////// - // Sum Type: ConflictAction - ////////////////////////////////////// - protected open fun visitConflictAction(node: PartiqlAst.ConflictAction) { } - protected open fun visitConflictActionDoNothing(node: PartiqlAst.ConflictAction.DoNothing) { } - ////////////////////////////////////// - // Sum Type: DdlOp - ////////////////////////////////////// - protected open fun visitDdlOp(node: PartiqlAst.DdlOp) { } - protected open fun visitDdlOpCreateTable(node: PartiqlAst.DdlOp.CreateTable) { } - protected open fun visitDdlOpDropTable(node: PartiqlAst.DdlOp.DropTable) { } - protected open fun visitDdlOpUndropTable(node: PartiqlAst.DdlOp.UndropTable) { } - protected open fun visitDdlOpCreateIndex(node: PartiqlAst.DdlOp.CreateIndex) { } - protected open fun visitDdlOpDropIndex(node: PartiqlAst.DdlOp.DropIndex) { } - ////////////////////////////////////// - // Sum Type: ColumnComponent - ////////////////////////////////////// - protected open fun visitColumnComponent(node: PartiqlAst.ColumnComponent) { } - protected open fun visitColumnComponentReturningWildcard(node: PartiqlAst.ColumnComponent.ReturningWildcard) { } - protected open fun visitColumnComponentReturningColumn(node: PartiqlAst.ColumnComponent.ReturningColumn) { } - ////////////////////////////////////// - // Sum Type: ReturningMapping - ////////////////////////////////////// - protected open fun visitReturningMapping(node: PartiqlAst.ReturningMapping) { } - protected open fun visitReturningMappingModifiedNew(node: PartiqlAst.ReturningMapping.ModifiedNew) { } - protected open fun visitReturningMappingModifiedOld(node: PartiqlAst.ReturningMapping.ModifiedOld) { } - protected open fun visitReturningMappingAllNew(node: PartiqlAst.ReturningMapping.AllNew) { } - protected open fun visitReturningMappingAllOld(node: PartiqlAst.ReturningMapping.AllOld) { } - ////////////////////////////////////// - // Sum Type: Type - ////////////////////////////////////// - protected open fun visitType(node: PartiqlAst.Type) { } - protected open fun visitTypeNullType(node: PartiqlAst.Type.NullType) { } - protected open fun visitTypeBooleanType(node: PartiqlAst.Type.BooleanType) { } - protected open fun visitTypeSmallintType(node: PartiqlAst.Type.SmallintType) { } - protected open fun visitTypeInteger4Type(node: PartiqlAst.Type.Integer4Type) { } - protected open fun visitTypeInteger8Type(node: PartiqlAst.Type.Integer8Type) { } - protected open fun visitTypeIntegerType(node: PartiqlAst.Type.IntegerType) { } - protected open fun visitTypeFloatType(node: PartiqlAst.Type.FloatType) { } - protected open fun visitTypeRealType(node: PartiqlAst.Type.RealType) { } - protected open fun visitTypeDoublePrecisionType(node: PartiqlAst.Type.DoublePrecisionType) { } - protected open fun visitTypeDecimalType(node: PartiqlAst.Type.DecimalType) { } - protected open fun visitTypeNumericType(node: PartiqlAst.Type.NumericType) { } - protected open fun visitTypeTimestampType(node: PartiqlAst.Type.TimestampType) { } - protected open fun visitTypeCharacterType(node: PartiqlAst.Type.CharacterType) { } - protected open fun visitTypeCharacterVaryingType(node: PartiqlAst.Type.CharacterVaryingType) { } - protected open fun visitTypeMissingType(node: PartiqlAst.Type.MissingType) { } - protected open fun visitTypeStringType(node: PartiqlAst.Type.StringType) { } - protected open fun visitTypeSymbolType(node: PartiqlAst.Type.SymbolType) { } - protected open fun visitTypeBlobType(node: PartiqlAst.Type.BlobType) { } - protected open fun visitTypeClobType(node: PartiqlAst.Type.ClobType) { } - protected open fun visitTypeDateType(node: PartiqlAst.Type.DateType) { } - protected open fun visitTypeTimeType(node: PartiqlAst.Type.TimeType) { } - protected open fun visitTypeTimeWithTimeZoneType(node: PartiqlAst.Type.TimeWithTimeZoneType) { } - protected open fun visitTypeStructType(node: PartiqlAst.Type.StructType) { } - protected open fun visitTypeTupleType(node: PartiqlAst.Type.TupleType) { } - protected open fun visitTypeListType(node: PartiqlAst.Type.ListType) { } - protected open fun visitTypeSexpType(node: PartiqlAst.Type.SexpType) { } - protected open fun visitTypeBagType(node: PartiqlAst.Type.BagType) { } - protected open fun visitTypeAnyType(node: PartiqlAst.Type.AnyType) { } - protected open fun visitTypeEsBoolean(node: PartiqlAst.Type.EsBoolean) { } - protected open fun visitTypeEsInteger(node: PartiqlAst.Type.EsInteger) { } - protected open fun visitTypeEsFloat(node: PartiqlAst.Type.EsFloat) { } - protected open fun visitTypeEsText(node: PartiqlAst.Type.EsText) { } - protected open fun visitTypeEsAny(node: PartiqlAst.Type.EsAny) { } - protected open fun visitTypeSparkShort(node: PartiqlAst.Type.SparkShort) { } - protected open fun visitTypeSparkInteger(node: PartiqlAst.Type.SparkInteger) { } - protected open fun visitTypeSparkLong(node: PartiqlAst.Type.SparkLong) { } - protected open fun visitTypeSparkDouble(node: PartiqlAst.Type.SparkDouble) { } - protected open fun visitTypeSparkBoolean(node: PartiqlAst.Type.SparkBoolean) { } - protected open fun visitTypeSparkFloat(node: PartiqlAst.Type.SparkFloat) { } - protected open fun visitTypeRsVarcharMax(node: PartiqlAst.Type.RsVarcharMax) { } - protected open fun visitTypeRsInteger(node: PartiqlAst.Type.RsInteger) { } - protected open fun visitTypeRsBigint(node: PartiqlAst.Type.RsBigint) { } - protected open fun visitTypeRsBoolean(node: PartiqlAst.Type.RsBoolean) { } - protected open fun visitTypeRsReal(node: PartiqlAst.Type.RsReal) { } - protected open fun visitTypeRsDoublePrecision(node: PartiqlAst.Type.RsDoublePrecision) { } - protected open fun visitTypeCustomType(node: PartiqlAst.Type.CustomType) { } - - //////////////////////////////////////////////////////////////////////////// - // Walk Functions - //////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////// - // Tuple Types - ////////////////////////////////////// - open fun walkTimeValue(node: PartiqlAst.TimeValue) { - visitTimeValue(node) - walkLongPrimitive(node.hour) - walkLongPrimitive(node.minute) - walkLongPrimitive(node.second) - walkLongPrimitive(node.nano) - walkLongPrimitive(node.precision) - node.tzMinutes?.let { walkLongPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkLet(node: PartiqlAst.Let) { - visitLet(node) - node.letBindings.map { walkLetBinding(it) } - walkMetas(node.metas) - } - - open fun walkLetBinding(node: PartiqlAst.LetBinding) { - visitLetBinding(node) - walkExpr(node.expr) - walkSymbolPrimitive(node.name) - walkMetas(node.metas) - } - - open fun walkExprPair(node: PartiqlAst.ExprPair) { - visitExprPair(node) - walkExpr(node.first) - walkExpr(node.second) - walkMetas(node.metas) - } - - open fun walkExprPairList(node: PartiqlAst.ExprPairList) { - visitExprPairList(node) - node.pairs.map { walkExprPair(it) } - walkMetas(node.metas) - } - - open fun walkGroupBy(node: PartiqlAst.GroupBy) { - visitGroupBy(node) - walkGroupingStrategy(node.strategy) - walkGroupKeyList(node.keyList) - node.groupAsAlias?.let { walkSymbolPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkGroupKeyList(node: PartiqlAst.GroupKeyList) { - visitGroupKeyList(node) - node.keys.map { walkGroupKey(it) } - walkMetas(node.metas) - } - - open fun walkGroupKey(node: PartiqlAst.GroupKey) { - visitGroupKey(node) - walkExpr(node.expr) - node.asAlias?.let { walkSymbolPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkOrderBy(node: PartiqlAst.OrderBy) { - visitOrderBy(node) - node.sortSpecs.map { walkSortSpec(it) } - walkMetas(node.metas) - } - - open fun walkSortSpec(node: PartiqlAst.SortSpec) { - visitSortSpec(node) - walkExpr(node.expr) - node.orderingSpec?.let { walkOrderingSpec(it) } - walkMetas(node.metas) - } - - open fun walkDmlOpList(node: PartiqlAst.DmlOpList) { - visitDmlOpList(node) - node.ops.map { walkDmlOp(it) } - walkMetas(node.metas) - } - - open fun walkOnConflict(node: PartiqlAst.OnConflict) { - visitOnConflict(node) - walkExpr(node.expr) - walkConflictAction(node.conflictAction) - walkMetas(node.metas) - } - - open fun walkReturningExpr(node: PartiqlAst.ReturningExpr) { - visitReturningExpr(node) - node.elems.map { walkReturningElem(it) } - walkMetas(node.metas) - } - - open fun walkReturningElem(node: PartiqlAst.ReturningElem) { - visitReturningElem(node) - walkReturningMapping(node.mapping) - walkColumnComponent(node.column) - walkMetas(node.metas) - } - - open fun walkIdentifier(node: PartiqlAst.Identifier) { - visitIdentifier(node) - walkSymbolPrimitive(node.name) - walkCaseSensitivity(node.case) - walkMetas(node.metas) - } - - open fun walkAssignment(node: PartiqlAst.Assignment) { - visitAssignment(node) - walkExpr(node.target) - walkExpr(node.value) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: Statement - ////////////////////////////////////// - open fun walkStatement(node: PartiqlAst.Statement) { - visitStatement(node) - when(node) { - is PartiqlAst.Statement.Query -> walkStatementQuery(node) - is PartiqlAst.Statement.Dml -> walkStatementDml(node) - is PartiqlAst.Statement.Ddl -> walkStatementDdl(node) - is PartiqlAst.Statement.Exec -> walkStatementExec(node) - } - } - - open fun walkStatementQuery(node: PartiqlAst.Statement.Query) { - visitStatementQuery(node) - walkExpr(node.expr) - walkMetas(node.metas) - } - - open fun walkStatementDml(node: PartiqlAst.Statement.Dml) { - visitStatementDml(node) - walkDmlOpList(node.operations) - node.from?.let { walkFromSource(it) } - node.where?.let { walkExpr(it) } - node.returning?.let { walkReturningExpr(it) } - walkMetas(node.metas) - } - - open fun walkStatementDdl(node: PartiqlAst.Statement.Ddl) { - visitStatementDdl(node) - walkDdlOp(node.op) - walkMetas(node.metas) - } - - open fun walkStatementExec(node: PartiqlAst.Statement.Exec) { - visitStatementExec(node) - walkSymbolPrimitive(node.procedureName) - node.args.map { walkExpr(it) } - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: Expr - ////////////////////////////////////// - open fun walkExpr(node: PartiqlAst.Expr) { - visitExpr(node) - when(node) { - is PartiqlAst.Expr.Missing -> walkExprMissing(node) - is PartiqlAst.Expr.Lit -> walkExprLit(node) - is PartiqlAst.Expr.Id -> walkExprId(node) - is PartiqlAst.Expr.Parameter -> walkExprParameter(node) - is PartiqlAst.Expr.Not -> walkExprNot(node) - is PartiqlAst.Expr.Pos -> walkExprPos(node) - is PartiqlAst.Expr.Neg -> walkExprNeg(node) - is PartiqlAst.Expr.Plus -> walkExprPlus(node) - is PartiqlAst.Expr.Minus -> walkExprMinus(node) - is PartiqlAst.Expr.Times -> walkExprTimes(node) - is PartiqlAst.Expr.Divide -> walkExprDivide(node) - is PartiqlAst.Expr.Modulo -> walkExprModulo(node) - is PartiqlAst.Expr.Concat -> walkExprConcat(node) - is PartiqlAst.Expr.And -> walkExprAnd(node) - is PartiqlAst.Expr.Or -> walkExprOr(node) - is PartiqlAst.Expr.Eq -> walkExprEq(node) - is PartiqlAst.Expr.Ne -> walkExprNe(node) - is PartiqlAst.Expr.Gt -> walkExprGt(node) - is PartiqlAst.Expr.Gte -> walkExprGte(node) - is PartiqlAst.Expr.Lt -> walkExprLt(node) - is PartiqlAst.Expr.Lte -> walkExprLte(node) - is PartiqlAst.Expr.Like -> walkExprLike(node) - is PartiqlAst.Expr.Between -> walkExprBetween(node) - is PartiqlAst.Expr.InCollection -> walkExprInCollection(node) - is PartiqlAst.Expr.IsType -> walkExprIsType(node) - is PartiqlAst.Expr.SimpleCase -> walkExprSimpleCase(node) - is PartiqlAst.Expr.SearchedCase -> walkExprSearchedCase(node) - is PartiqlAst.Expr.Struct -> walkExprStruct(node) - is PartiqlAst.Expr.Bag -> walkExprBag(node) - is PartiqlAst.Expr.List -> walkExprList(node) - is PartiqlAst.Expr.Sexp -> walkExprSexp(node) - is PartiqlAst.Expr.Date -> walkExprDate(node) - is PartiqlAst.Expr.LitTime -> walkExprLitTime(node) - is PartiqlAst.Expr.Union -> walkExprUnion(node) - is PartiqlAst.Expr.Except -> walkExprExcept(node) - is PartiqlAst.Expr.Intersect -> walkExprIntersect(node) - is PartiqlAst.Expr.Path -> walkExprPath(node) - is PartiqlAst.Expr.Call -> walkExprCall(node) - is PartiqlAst.Expr.CallAgg -> walkExprCallAgg(node) - is PartiqlAst.Expr.Cast -> walkExprCast(node) - is PartiqlAst.Expr.CanCast -> walkExprCanCast(node) - is PartiqlAst.Expr.CanLosslessCast -> walkExprCanLosslessCast(node) - is PartiqlAst.Expr.NullIf -> walkExprNullIf(node) - is PartiqlAst.Expr.Coalesce -> walkExprCoalesce(node) - is PartiqlAst.Expr.Select -> walkExprSelect(node) - } - } - - open fun walkExprMissing(node: PartiqlAst.Expr.Missing) { - visitExprMissing(node) - walkMetas(node.metas) - } - - open fun walkExprLit(node: PartiqlAst.Expr.Lit) { - visitExprLit(node) - walkAnyElement(node.value) - walkMetas(node.metas) - } - - open fun walkExprId(node: PartiqlAst.Expr.Id) { - visitExprId(node) - walkSymbolPrimitive(node.name) - walkCaseSensitivity(node.case) - walkScopeQualifier(node.qualifier) - walkMetas(node.metas) - } - - open fun walkExprParameter(node: PartiqlAst.Expr.Parameter) { - visitExprParameter(node) - walkLongPrimitive(node.index) - walkMetas(node.metas) - } - - open fun walkExprNot(node: PartiqlAst.Expr.Not) { - visitExprNot(node) - walkExpr(node.expr) - walkMetas(node.metas) - } - - open fun walkExprPos(node: PartiqlAst.Expr.Pos) { - visitExprPos(node) - walkExpr(node.expr) - walkMetas(node.metas) - } - - open fun walkExprNeg(node: PartiqlAst.Expr.Neg) { - visitExprNeg(node) - walkExpr(node.expr) - walkMetas(node.metas) - } - - open fun walkExprPlus(node: PartiqlAst.Expr.Plus) { - visitExprPlus(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprMinus(node: PartiqlAst.Expr.Minus) { - visitExprMinus(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprTimes(node: PartiqlAst.Expr.Times) { - visitExprTimes(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprDivide(node: PartiqlAst.Expr.Divide) { - visitExprDivide(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprModulo(node: PartiqlAst.Expr.Modulo) { - visitExprModulo(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprConcat(node: PartiqlAst.Expr.Concat) { - visitExprConcat(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprAnd(node: PartiqlAst.Expr.And) { - visitExprAnd(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprOr(node: PartiqlAst.Expr.Or) { - visitExprOr(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprEq(node: PartiqlAst.Expr.Eq) { - visitExprEq(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprNe(node: PartiqlAst.Expr.Ne) { - visitExprNe(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprGt(node: PartiqlAst.Expr.Gt) { - visitExprGt(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprGte(node: PartiqlAst.Expr.Gte) { - visitExprGte(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprLt(node: PartiqlAst.Expr.Lt) { - visitExprLt(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprLte(node: PartiqlAst.Expr.Lte) { - visitExprLte(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprLike(node: PartiqlAst.Expr.Like) { - visitExprLike(node) - walkExpr(node.value) - walkExpr(node.pattern) - node.escape?.let { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprBetween(node: PartiqlAst.Expr.Between) { - visitExprBetween(node) - walkExpr(node.value) - walkExpr(node.from) - walkExpr(node.to) - walkMetas(node.metas) - } - - open fun walkExprInCollection(node: PartiqlAst.Expr.InCollection) { - visitExprInCollection(node) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprIsType(node: PartiqlAst.Expr.IsType) { - visitExprIsType(node) - walkExpr(node.value) - walkType(node.type) - walkMetas(node.metas) - } - - open fun walkExprSimpleCase(node: PartiqlAst.Expr.SimpleCase) { - visitExprSimpleCase(node) - walkExpr(node.expr) - walkExprPairList(node.cases) - node.default?.let { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprSearchedCase(node: PartiqlAst.Expr.SearchedCase) { - visitExprSearchedCase(node) - walkExprPairList(node.cases) - node.default?.let { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprStruct(node: PartiqlAst.Expr.Struct) { - visitExprStruct(node) - node.fields.map { walkExprPair(it) } - walkMetas(node.metas) - } - - open fun walkExprBag(node: PartiqlAst.Expr.Bag) { - visitExprBag(node) - node.values.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprList(node: PartiqlAst.Expr.List) { - visitExprList(node) - node.values.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprSexp(node: PartiqlAst.Expr.Sexp) { - visitExprSexp(node) - node.values.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprDate(node: PartiqlAst.Expr.Date) { - visitExprDate(node) - walkLongPrimitive(node.year) - walkLongPrimitive(node.month) - walkLongPrimitive(node.day) - walkMetas(node.metas) - } - - open fun walkExprLitTime(node: PartiqlAst.Expr.LitTime) { - visitExprLitTime(node) - walkTimeValue(node.value) - walkMetas(node.metas) - } - - open fun walkExprUnion(node: PartiqlAst.Expr.Union) { - visitExprUnion(node) - walkSetQuantifier(node.setq) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprExcept(node: PartiqlAst.Expr.Except) { - visitExprExcept(node) - walkSetQuantifier(node.setq) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprIntersect(node: PartiqlAst.Expr.Intersect) { - visitExprIntersect(node) - walkSetQuantifier(node.setq) - node.operands.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprPath(node: PartiqlAst.Expr.Path) { - visitExprPath(node) - walkExpr(node.root) - node.steps.map { walkPathStep(it) } - walkMetas(node.metas) - } - - open fun walkExprCall(node: PartiqlAst.Expr.Call) { - visitExprCall(node) - walkSymbolPrimitive(node.funcName) - node.args.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprCallAgg(node: PartiqlAst.Expr.CallAgg) { - visitExprCallAgg(node) - walkSetQuantifier(node.setq) - walkSymbolPrimitive(node.funcName) - walkExpr(node.arg) - walkMetas(node.metas) - } - - open fun walkExprCast(node: PartiqlAst.Expr.Cast) { - visitExprCast(node) - walkExpr(node.value) - walkType(node.asType) - walkMetas(node.metas) - } - - open fun walkExprCanCast(node: PartiqlAst.Expr.CanCast) { - visitExprCanCast(node) - walkExpr(node.value) - walkType(node.asType) - walkMetas(node.metas) - } - - open fun walkExprCanLosslessCast(node: PartiqlAst.Expr.CanLosslessCast) { - visitExprCanLosslessCast(node) - walkExpr(node.value) - walkType(node.asType) - walkMetas(node.metas) - } - - open fun walkExprNullIf(node: PartiqlAst.Expr.NullIf) { - visitExprNullIf(node) - walkExpr(node.expr1) - walkExpr(node.expr2) - walkMetas(node.metas) - } - - open fun walkExprCoalesce(node: PartiqlAst.Expr.Coalesce) { - visitExprCoalesce(node) - node.args.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkExprSelect(node: PartiqlAst.Expr.Select) { - visitExprSelect(node) - node.setq?.let { walkSetQuantifier(it) } - walkProjection(node.project) - walkFromSource(node.from) - node.fromLet?.let { walkLet(it) } - node.where?.let { walkExpr(it) } - node.group?.let { walkGroupBy(it) } - node.having?.let { walkExpr(it) } - node.order?.let { walkOrderBy(it) } - node.limit?.let { walkExpr(it) } - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: PathStep - ////////////////////////////////////// - open fun walkPathStep(node: PartiqlAst.PathStep) { - visitPathStep(node) - when(node) { - is PartiqlAst.PathStep.PathExpr -> walkPathStepPathExpr(node) - is PartiqlAst.PathStep.PathWildcard -> walkPathStepPathWildcard(node) - is PartiqlAst.PathStep.PathUnpivot -> walkPathStepPathUnpivot(node) - } - } - - open fun walkPathStepPathExpr(node: PartiqlAst.PathStep.PathExpr) { - visitPathStepPathExpr(node) - walkExpr(node.index) - walkCaseSensitivity(node.case) - walkMetas(node.metas) - } - - open fun walkPathStepPathWildcard(node: PartiqlAst.PathStep.PathWildcard) { - visitPathStepPathWildcard(node) - walkMetas(node.metas) - } - - open fun walkPathStepPathUnpivot(node: PartiqlAst.PathStep.PathUnpivot) { - visitPathStepPathUnpivot(node) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: Projection - ////////////////////////////////////// - open fun walkProjection(node: PartiqlAst.Projection) { - visitProjection(node) - when(node) { - is PartiqlAst.Projection.ProjectStar -> walkProjectionProjectStar(node) - is PartiqlAst.Projection.ProjectList -> walkProjectionProjectList(node) - is PartiqlAst.Projection.ProjectPivot -> walkProjectionProjectPivot(node) - is PartiqlAst.Projection.ProjectValue -> walkProjectionProjectValue(node) - } - } - - open fun walkProjectionProjectStar(node: PartiqlAst.Projection.ProjectStar) { - visitProjectionProjectStar(node) - walkMetas(node.metas) - } - - open fun walkProjectionProjectList(node: PartiqlAst.Projection.ProjectList) { - visitProjectionProjectList(node) - node.projectItems.map { walkProjectItem(it) } - walkMetas(node.metas) - } - - open fun walkProjectionProjectPivot(node: PartiqlAst.Projection.ProjectPivot) { - visitProjectionProjectPivot(node) - walkExpr(node.value) - walkExpr(node.key) - walkMetas(node.metas) - } - - open fun walkProjectionProjectValue(node: PartiqlAst.Projection.ProjectValue) { - visitProjectionProjectValue(node) - walkExpr(node.value) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: ProjectItem - ////////////////////////////////////// - open fun walkProjectItem(node: PartiqlAst.ProjectItem) { - visitProjectItem(node) - when(node) { - is PartiqlAst.ProjectItem.ProjectAll -> walkProjectItemProjectAll(node) - is PartiqlAst.ProjectItem.ProjectExpr -> walkProjectItemProjectExpr(node) - } - } - - open fun walkProjectItemProjectAll(node: PartiqlAst.ProjectItem.ProjectAll) { - visitProjectItemProjectAll(node) - walkExpr(node.expr) - walkMetas(node.metas) - } - - open fun walkProjectItemProjectExpr(node: PartiqlAst.ProjectItem.ProjectExpr) { - visitProjectItemProjectExpr(node) - walkExpr(node.expr) - node.asAlias?.let { walkSymbolPrimitive(it) } - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: FromSource - ////////////////////////////////////// - open fun walkFromSource(node: PartiqlAst.FromSource) { - visitFromSource(node) - when(node) { - is PartiqlAst.FromSource.Scan -> walkFromSourceScan(node) - is PartiqlAst.FromSource.Unpivot -> walkFromSourceUnpivot(node) - is PartiqlAst.FromSource.Join -> walkFromSourceJoin(node) - } - } - - open fun walkFromSourceScan(node: PartiqlAst.FromSource.Scan) { - visitFromSourceScan(node) - walkExpr(node.expr) - node.asAlias?.let { walkSymbolPrimitive(it) } - node.atAlias?.let { walkSymbolPrimitive(it) } - node.byAlias?.let { walkSymbolPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkFromSourceUnpivot(node: PartiqlAst.FromSource.Unpivot) { - visitFromSourceUnpivot(node) - walkExpr(node.expr) - node.asAlias?.let { walkSymbolPrimitive(it) } - node.atAlias?.let { walkSymbolPrimitive(it) } - node.byAlias?.let { walkSymbolPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkFromSourceJoin(node: PartiqlAst.FromSource.Join) { - visitFromSourceJoin(node) - walkJoinType(node.type) - walkFromSource(node.left) - walkFromSource(node.right) - node.predicate?.let { walkExpr(it) } - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: JoinType - ////////////////////////////////////// - open fun walkJoinType(node: PartiqlAst.JoinType) { - visitJoinType(node) - when(node) { - is PartiqlAst.JoinType.Inner -> walkJoinTypeInner(node) - is PartiqlAst.JoinType.Left -> walkJoinTypeLeft(node) - is PartiqlAst.JoinType.Right -> walkJoinTypeRight(node) - is PartiqlAst.JoinType.Full -> walkJoinTypeFull(node) - } - } - - open fun walkJoinTypeInner(node: PartiqlAst.JoinType.Inner) { - visitJoinTypeInner(node) - walkMetas(node.metas) - } - - open fun walkJoinTypeLeft(node: PartiqlAst.JoinType.Left) { - visitJoinTypeLeft(node) - walkMetas(node.metas) - } - - open fun walkJoinTypeRight(node: PartiqlAst.JoinType.Right) { - visitJoinTypeRight(node) - walkMetas(node.metas) - } - - open fun walkJoinTypeFull(node: PartiqlAst.JoinType.Full) { - visitJoinTypeFull(node) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: GroupingStrategy - ////////////////////////////////////// - open fun walkGroupingStrategy(node: PartiqlAst.GroupingStrategy) { - visitGroupingStrategy(node) - when(node) { - is PartiqlAst.GroupingStrategy.GroupFull -> walkGroupingStrategyGroupFull(node) - is PartiqlAst.GroupingStrategy.GroupPartial -> walkGroupingStrategyGroupPartial(node) - } - } - - open fun walkGroupingStrategyGroupFull(node: PartiqlAst.GroupingStrategy.GroupFull) { - visitGroupingStrategyGroupFull(node) - walkMetas(node.metas) - } - - open fun walkGroupingStrategyGroupPartial(node: PartiqlAst.GroupingStrategy.GroupPartial) { - visitGroupingStrategyGroupPartial(node) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: OrderingSpec - ////////////////////////////////////// - open fun walkOrderingSpec(node: PartiqlAst.OrderingSpec) { - visitOrderingSpec(node) - when(node) { - is PartiqlAst.OrderingSpec.Asc -> walkOrderingSpecAsc(node) - is PartiqlAst.OrderingSpec.Desc -> walkOrderingSpecDesc(node) - } - } - - open fun walkOrderingSpecAsc(node: PartiqlAst.OrderingSpec.Asc) { - visitOrderingSpecAsc(node) - walkMetas(node.metas) - } - - open fun walkOrderingSpecDesc(node: PartiqlAst.OrderingSpec.Desc) { - visitOrderingSpecDesc(node) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: CaseSensitivity - ////////////////////////////////////// - open fun walkCaseSensitivity(node: PartiqlAst.CaseSensitivity) { - visitCaseSensitivity(node) - when(node) { - is PartiqlAst.CaseSensitivity.CaseSensitive -> walkCaseSensitivityCaseSensitive(node) - is PartiqlAst.CaseSensitivity.CaseInsensitive -> walkCaseSensitivityCaseInsensitive(node) - } - } - - open fun walkCaseSensitivityCaseSensitive(node: PartiqlAst.CaseSensitivity.CaseSensitive) { - visitCaseSensitivityCaseSensitive(node) - walkMetas(node.metas) - } - - open fun walkCaseSensitivityCaseInsensitive(node: PartiqlAst.CaseSensitivity.CaseInsensitive) { - visitCaseSensitivityCaseInsensitive(node) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: ScopeQualifier - ////////////////////////////////////// - open fun walkScopeQualifier(node: PartiqlAst.ScopeQualifier) { - visitScopeQualifier(node) - when(node) { - is PartiqlAst.ScopeQualifier.Unqualified -> walkScopeQualifierUnqualified(node) - is PartiqlAst.ScopeQualifier.LocalsFirst -> walkScopeQualifierLocalsFirst(node) - } - } - - open fun walkScopeQualifierUnqualified(node: PartiqlAst.ScopeQualifier.Unqualified) { - visitScopeQualifierUnqualified(node) - walkMetas(node.metas) - } - - open fun walkScopeQualifierLocalsFirst(node: PartiqlAst.ScopeQualifier.LocalsFirst) { - visitScopeQualifierLocalsFirst(node) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: SetQuantifier - ////////////////////////////////////// - open fun walkSetQuantifier(node: PartiqlAst.SetQuantifier) { - visitSetQuantifier(node) - when(node) { - is PartiqlAst.SetQuantifier.All -> walkSetQuantifierAll(node) - is PartiqlAst.SetQuantifier.Distinct -> walkSetQuantifierDistinct(node) - } - } - - open fun walkSetQuantifierAll(node: PartiqlAst.SetQuantifier.All) { - visitSetQuantifierAll(node) - walkMetas(node.metas) - } - - open fun walkSetQuantifierDistinct(node: PartiqlAst.SetQuantifier.Distinct) { - visitSetQuantifierDistinct(node) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: DmlOp - ////////////////////////////////////// - open fun walkDmlOp(node: PartiqlAst.DmlOp) { - visitDmlOp(node) - when(node) { - is PartiqlAst.DmlOp.Insert -> walkDmlOpInsert(node) - is PartiqlAst.DmlOp.InsertValue -> walkDmlOpInsertValue(node) - is PartiqlAst.DmlOp.Set -> walkDmlOpSet(node) - is PartiqlAst.DmlOp.Remove -> walkDmlOpRemove(node) - is PartiqlAst.DmlOp.Delete -> walkDmlOpDelete(node) - } - } - - open fun walkDmlOpInsert(node: PartiqlAst.DmlOp.Insert) { - visitDmlOpInsert(node) - walkExpr(node.target) - walkExpr(node.values) - walkMetas(node.metas) - } - - open fun walkDmlOpInsertValue(node: PartiqlAst.DmlOp.InsertValue) { - visitDmlOpInsertValue(node) - walkExpr(node.target) - walkExpr(node.value) - node.index?.let { walkExpr(it) } - node.onConflict?.let { walkOnConflict(it) } - walkMetas(node.metas) - } - - open fun walkDmlOpSet(node: PartiqlAst.DmlOp.Set) { - visitDmlOpSet(node) - walkAssignment(node.assignment) - walkMetas(node.metas) - } - - open fun walkDmlOpRemove(node: PartiqlAst.DmlOp.Remove) { - visitDmlOpRemove(node) - walkExpr(node.target) - walkMetas(node.metas) - } - - open fun walkDmlOpDelete(node: PartiqlAst.DmlOp.Delete) { - visitDmlOpDelete(node) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: ConflictAction - ////////////////////////////////////// - open fun walkConflictAction(node: PartiqlAst.ConflictAction) { - visitConflictAction(node) - when(node) { - is PartiqlAst.ConflictAction.DoNothing -> walkConflictActionDoNothing(node) - } - } - - open fun walkConflictActionDoNothing(node: PartiqlAst.ConflictAction.DoNothing) { - visitConflictActionDoNothing(node) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: DdlOp - ////////////////////////////////////// - open fun walkDdlOp(node: PartiqlAst.DdlOp) { - visitDdlOp(node) - when(node) { - is PartiqlAst.DdlOp.CreateTable -> walkDdlOpCreateTable(node) - is PartiqlAst.DdlOp.DropTable -> walkDdlOpDropTable(node) - is PartiqlAst.DdlOp.UndropTable -> walkDdlOpUndropTable(node) - is PartiqlAst.DdlOp.CreateIndex -> walkDdlOpCreateIndex(node) - is PartiqlAst.DdlOp.DropIndex -> walkDdlOpDropIndex(node) - } - } - - open fun walkDdlOpCreateTable(node: PartiqlAst.DdlOp.CreateTable) { - visitDdlOpCreateTable(node) - walkSymbolPrimitive(node.tableName) - walkMetas(node.metas) - } - - open fun walkDdlOpDropTable(node: PartiqlAst.DdlOp.DropTable) { - visitDdlOpDropTable(node) - walkIdentifier(node.tableName) - walkMetas(node.metas) - } - - open fun walkDdlOpUndropTable(node: PartiqlAst.DdlOp.UndropTable) { - visitDdlOpUndropTable(node) - walkSymbolPrimitive(node.tableName) - walkMetas(node.metas) - } - - open fun walkDdlOpCreateIndex(node: PartiqlAst.DdlOp.CreateIndex) { - visitDdlOpCreateIndex(node) - walkIdentifier(node.indexName) - node.fields.map { walkExpr(it) } - walkMetas(node.metas) - } - - open fun walkDdlOpDropIndex(node: PartiqlAst.DdlOp.DropIndex) { - visitDdlOpDropIndex(node) - walkIdentifier(node.table) - walkIdentifier(node.keys) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: ColumnComponent - ////////////////////////////////////// - open fun walkColumnComponent(node: PartiqlAst.ColumnComponent) { - visitColumnComponent(node) - when(node) { - is PartiqlAst.ColumnComponent.ReturningWildcard -> walkColumnComponentReturningWildcard(node) - is PartiqlAst.ColumnComponent.ReturningColumn -> walkColumnComponentReturningColumn(node) - } - } - - open fun walkColumnComponentReturningWildcard(node: PartiqlAst.ColumnComponent.ReturningWildcard) { - visitColumnComponentReturningWildcard(node) - walkMetas(node.metas) - } - - open fun walkColumnComponentReturningColumn(node: PartiqlAst.ColumnComponent.ReturningColumn) { - visitColumnComponentReturningColumn(node) - walkExpr(node.expr) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: ReturningMapping - ////////////////////////////////////// - open fun walkReturningMapping(node: PartiqlAst.ReturningMapping) { - visitReturningMapping(node) - when(node) { - is PartiqlAst.ReturningMapping.ModifiedNew -> walkReturningMappingModifiedNew(node) - is PartiqlAst.ReturningMapping.ModifiedOld -> walkReturningMappingModifiedOld(node) - is PartiqlAst.ReturningMapping.AllNew -> walkReturningMappingAllNew(node) - is PartiqlAst.ReturningMapping.AllOld -> walkReturningMappingAllOld(node) - } - } - - open fun walkReturningMappingModifiedNew(node: PartiqlAst.ReturningMapping.ModifiedNew) { - visitReturningMappingModifiedNew(node) - walkMetas(node.metas) - } - - open fun walkReturningMappingModifiedOld(node: PartiqlAst.ReturningMapping.ModifiedOld) { - visitReturningMappingModifiedOld(node) - walkMetas(node.metas) - } - - open fun walkReturningMappingAllNew(node: PartiqlAst.ReturningMapping.AllNew) { - visitReturningMappingAllNew(node) - walkMetas(node.metas) - } - - open fun walkReturningMappingAllOld(node: PartiqlAst.ReturningMapping.AllOld) { - visitReturningMappingAllOld(node) - walkMetas(node.metas) - } - - ////////////////////////////////////// - // Sum Type: Type - ////////////////////////////////////// - open fun walkType(node: PartiqlAst.Type) { - visitType(node) - when(node) { - is PartiqlAst.Type.NullType -> walkTypeNullType(node) - is PartiqlAst.Type.BooleanType -> walkTypeBooleanType(node) - is PartiqlAst.Type.SmallintType -> walkTypeSmallintType(node) - is PartiqlAst.Type.Integer4Type -> walkTypeInteger4Type(node) - is PartiqlAst.Type.Integer8Type -> walkTypeInteger8Type(node) - is PartiqlAst.Type.IntegerType -> walkTypeIntegerType(node) - is PartiqlAst.Type.FloatType -> walkTypeFloatType(node) - is PartiqlAst.Type.RealType -> walkTypeRealType(node) - is PartiqlAst.Type.DoublePrecisionType -> walkTypeDoublePrecisionType(node) - is PartiqlAst.Type.DecimalType -> walkTypeDecimalType(node) - is PartiqlAst.Type.NumericType -> walkTypeNumericType(node) - is PartiqlAst.Type.TimestampType -> walkTypeTimestampType(node) - is PartiqlAst.Type.CharacterType -> walkTypeCharacterType(node) - is PartiqlAst.Type.CharacterVaryingType -> walkTypeCharacterVaryingType(node) - is PartiqlAst.Type.MissingType -> walkTypeMissingType(node) - is PartiqlAst.Type.StringType -> walkTypeStringType(node) - is PartiqlAst.Type.SymbolType -> walkTypeSymbolType(node) - is PartiqlAst.Type.BlobType -> walkTypeBlobType(node) - is PartiqlAst.Type.ClobType -> walkTypeClobType(node) - is PartiqlAst.Type.DateType -> walkTypeDateType(node) - is PartiqlAst.Type.TimeType -> walkTypeTimeType(node) - is PartiqlAst.Type.TimeWithTimeZoneType -> walkTypeTimeWithTimeZoneType(node) - is PartiqlAst.Type.StructType -> walkTypeStructType(node) - is PartiqlAst.Type.TupleType -> walkTypeTupleType(node) - is PartiqlAst.Type.ListType -> walkTypeListType(node) - is PartiqlAst.Type.SexpType -> walkTypeSexpType(node) - is PartiqlAst.Type.BagType -> walkTypeBagType(node) - is PartiqlAst.Type.AnyType -> walkTypeAnyType(node) - is PartiqlAst.Type.EsBoolean -> walkTypeEsBoolean(node) - is PartiqlAst.Type.EsInteger -> walkTypeEsInteger(node) - is PartiqlAst.Type.EsFloat -> walkTypeEsFloat(node) - is PartiqlAst.Type.EsText -> walkTypeEsText(node) - is PartiqlAst.Type.EsAny -> walkTypeEsAny(node) - is PartiqlAst.Type.SparkShort -> walkTypeSparkShort(node) - is PartiqlAst.Type.SparkInteger -> walkTypeSparkInteger(node) - is PartiqlAst.Type.SparkLong -> walkTypeSparkLong(node) - is PartiqlAst.Type.SparkDouble -> walkTypeSparkDouble(node) - is PartiqlAst.Type.SparkBoolean -> walkTypeSparkBoolean(node) - is PartiqlAst.Type.SparkFloat -> walkTypeSparkFloat(node) - is PartiqlAst.Type.RsVarcharMax -> walkTypeRsVarcharMax(node) - is PartiqlAst.Type.RsInteger -> walkTypeRsInteger(node) - is PartiqlAst.Type.RsBigint -> walkTypeRsBigint(node) - is PartiqlAst.Type.RsBoolean -> walkTypeRsBoolean(node) - is PartiqlAst.Type.RsReal -> walkTypeRsReal(node) - is PartiqlAst.Type.RsDoublePrecision -> walkTypeRsDoublePrecision(node) - is PartiqlAst.Type.CustomType -> walkTypeCustomType(node) - } - } - - open fun walkTypeNullType(node: PartiqlAst.Type.NullType) { - visitTypeNullType(node) - walkMetas(node.metas) - } - - open fun walkTypeBooleanType(node: PartiqlAst.Type.BooleanType) { - visitTypeBooleanType(node) - walkMetas(node.metas) - } - - open fun walkTypeSmallintType(node: PartiqlAst.Type.SmallintType) { - visitTypeSmallintType(node) - walkMetas(node.metas) - } - - open fun walkTypeInteger4Type(node: PartiqlAst.Type.Integer4Type) { - visitTypeInteger4Type(node) - walkMetas(node.metas) - } - - open fun walkTypeInteger8Type(node: PartiqlAst.Type.Integer8Type) { - visitTypeInteger8Type(node) - walkMetas(node.metas) - } - - open fun walkTypeIntegerType(node: PartiqlAst.Type.IntegerType) { - visitTypeIntegerType(node) - walkMetas(node.metas) - } - - open fun walkTypeFloatType(node: PartiqlAst.Type.FloatType) { - visitTypeFloatType(node) - node.precision?.let { walkLongPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkTypeRealType(node: PartiqlAst.Type.RealType) { - visitTypeRealType(node) - walkMetas(node.metas) - } - - open fun walkTypeDoublePrecisionType(node: PartiqlAst.Type.DoublePrecisionType) { - visitTypeDoublePrecisionType(node) - walkMetas(node.metas) - } - - open fun walkTypeDecimalType(node: PartiqlAst.Type.DecimalType) { - visitTypeDecimalType(node) - node.precision?.let { walkLongPrimitive(it) } - node.scale?.let { walkLongPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkTypeNumericType(node: PartiqlAst.Type.NumericType) { - visitTypeNumericType(node) - node.precision?.let { walkLongPrimitive(it) } - node.scale?.let { walkLongPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkTypeTimestampType(node: PartiqlAst.Type.TimestampType) { - visitTypeTimestampType(node) - walkMetas(node.metas) - } - - open fun walkTypeCharacterType(node: PartiqlAst.Type.CharacterType) { - visitTypeCharacterType(node) - node.length?.let { walkLongPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkTypeCharacterVaryingType(node: PartiqlAst.Type.CharacterVaryingType) { - visitTypeCharacterVaryingType(node) - node.length?.let { walkLongPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkTypeMissingType(node: PartiqlAst.Type.MissingType) { - visitTypeMissingType(node) - walkMetas(node.metas) - } - - open fun walkTypeStringType(node: PartiqlAst.Type.StringType) { - visitTypeStringType(node) - walkMetas(node.metas) - } - - open fun walkTypeSymbolType(node: PartiqlAst.Type.SymbolType) { - visitTypeSymbolType(node) - walkMetas(node.metas) - } - - open fun walkTypeBlobType(node: PartiqlAst.Type.BlobType) { - visitTypeBlobType(node) - walkMetas(node.metas) - } - - open fun walkTypeClobType(node: PartiqlAst.Type.ClobType) { - visitTypeClobType(node) - walkMetas(node.metas) - } - - open fun walkTypeDateType(node: PartiqlAst.Type.DateType) { - visitTypeDateType(node) - walkMetas(node.metas) - } - - open fun walkTypeTimeType(node: PartiqlAst.Type.TimeType) { - visitTypeTimeType(node) - node.precision?.let { walkLongPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkTypeTimeWithTimeZoneType(node: PartiqlAst.Type.TimeWithTimeZoneType) { - visitTypeTimeWithTimeZoneType(node) - node.precision?.let { walkLongPrimitive(it) } - walkMetas(node.metas) - } - - open fun walkTypeStructType(node: PartiqlAst.Type.StructType) { - visitTypeStructType(node) - walkMetas(node.metas) - } - - open fun walkTypeTupleType(node: PartiqlAst.Type.TupleType) { - visitTypeTupleType(node) - walkMetas(node.metas) - } - - open fun walkTypeListType(node: PartiqlAst.Type.ListType) { - visitTypeListType(node) - walkMetas(node.metas) - } - - open fun walkTypeSexpType(node: PartiqlAst.Type.SexpType) { - visitTypeSexpType(node) - walkMetas(node.metas) - } - - open fun walkTypeBagType(node: PartiqlAst.Type.BagType) { - visitTypeBagType(node) - walkMetas(node.metas) - } - - open fun walkTypeAnyType(node: PartiqlAst.Type.AnyType) { - visitTypeAnyType(node) - walkMetas(node.metas) - } - - open fun walkTypeEsBoolean(node: PartiqlAst.Type.EsBoolean) { - visitTypeEsBoolean(node) - walkMetas(node.metas) - } - - open fun walkTypeEsInteger(node: PartiqlAst.Type.EsInteger) { - visitTypeEsInteger(node) - walkMetas(node.metas) - } - - open fun walkTypeEsFloat(node: PartiqlAst.Type.EsFloat) { - visitTypeEsFloat(node) - walkMetas(node.metas) - } - - open fun walkTypeEsText(node: PartiqlAst.Type.EsText) { - visitTypeEsText(node) - walkMetas(node.metas) - } - - open fun walkTypeEsAny(node: PartiqlAst.Type.EsAny) { - visitTypeEsAny(node) - walkMetas(node.metas) - } - - open fun walkTypeSparkShort(node: PartiqlAst.Type.SparkShort) { - visitTypeSparkShort(node) - walkMetas(node.metas) - } - - open fun walkTypeSparkInteger(node: PartiqlAst.Type.SparkInteger) { - visitTypeSparkInteger(node) - walkMetas(node.metas) - } - - open fun walkTypeSparkLong(node: PartiqlAst.Type.SparkLong) { - visitTypeSparkLong(node) - walkMetas(node.metas) - } - - open fun walkTypeSparkDouble(node: PartiqlAst.Type.SparkDouble) { - visitTypeSparkDouble(node) - walkMetas(node.metas) - } - - open fun walkTypeSparkBoolean(node: PartiqlAst.Type.SparkBoolean) { - visitTypeSparkBoolean(node) - walkMetas(node.metas) - } - - open fun walkTypeSparkFloat(node: PartiqlAst.Type.SparkFloat) { - visitTypeSparkFloat(node) - walkMetas(node.metas) - } - - open fun walkTypeRsVarcharMax(node: PartiqlAst.Type.RsVarcharMax) { - visitTypeRsVarcharMax(node) - walkMetas(node.metas) - } - - open fun walkTypeRsInteger(node: PartiqlAst.Type.RsInteger) { - visitTypeRsInteger(node) - walkMetas(node.metas) - } - - open fun walkTypeRsBigint(node: PartiqlAst.Type.RsBigint) { - visitTypeRsBigint(node) - walkMetas(node.metas) - } - - open fun walkTypeRsBoolean(node: PartiqlAst.Type.RsBoolean) { - visitTypeRsBoolean(node) - walkMetas(node.metas) - } - - open fun walkTypeRsReal(node: PartiqlAst.Type.RsReal) { - visitTypeRsReal(node) - walkMetas(node.metas) - } - - open fun walkTypeRsDoublePrecision(node: PartiqlAst.Type.RsDoublePrecision) { - visitTypeRsDoublePrecision(node) - walkMetas(node.metas) - } - - open fun walkTypeCustomType(node: PartiqlAst.Type.CustomType) { - visitTypeCustomType(node) - walkSymbolPrimitive(node.name) - walkMetas(node.metas) - } - - } - - - open class VisitorFold : DomainVisitorFoldBase() { - //////////////////////////////////////////////////////////////////////////// - // Visit Functions - //////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////// - // Tuple Types - ////////////////////////////////////// - open protected fun visitTimeValue(node: PartiqlAst.TimeValue, accumulator: T): T = accumulator - open protected fun visitLet(node: PartiqlAst.Let, accumulator: T): T = accumulator - open protected fun visitLetBinding(node: PartiqlAst.LetBinding, accumulator: T): T = accumulator - open protected fun visitExprPair(node: PartiqlAst.ExprPair, accumulator: T): T = accumulator - open protected fun visitExprPairList(node: PartiqlAst.ExprPairList, accumulator: T): T = accumulator - open protected fun visitGroupBy(node: PartiqlAst.GroupBy, accumulator: T): T = accumulator - open protected fun visitGroupKeyList(node: PartiqlAst.GroupKeyList, accumulator: T): T = accumulator - open protected fun visitGroupKey(node: PartiqlAst.GroupKey, accumulator: T): T = accumulator - open protected fun visitOrderBy(node: PartiqlAst.OrderBy, accumulator: T): T = accumulator - open protected fun visitSortSpec(node: PartiqlAst.SortSpec, accumulator: T): T = accumulator - open protected fun visitDmlOpList(node: PartiqlAst.DmlOpList, accumulator: T): T = accumulator - open protected fun visitOnConflict(node: PartiqlAst.OnConflict, accumulator: T): T = accumulator - open protected fun visitReturningExpr(node: PartiqlAst.ReturningExpr, accumulator: T): T = accumulator - open protected fun visitReturningElem(node: PartiqlAst.ReturningElem, accumulator: T): T = accumulator - open protected fun visitIdentifier(node: PartiqlAst.Identifier, accumulator: T): T = accumulator - open protected fun visitAssignment(node: PartiqlAst.Assignment, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: Statement - ////////////////////////////////////// - open protected fun visitStatement(node: PartiqlAst.Statement, accumulator: T): T = accumulator - open protected fun visitStatementQuery(node: PartiqlAst.Statement.Query, accumulator: T): T = accumulator - open protected fun visitStatementDml(node: PartiqlAst.Statement.Dml, accumulator: T): T = accumulator - open protected fun visitStatementDdl(node: PartiqlAst.Statement.Ddl, accumulator: T): T = accumulator - open protected fun visitStatementExec(node: PartiqlAst.Statement.Exec, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: Expr - ////////////////////////////////////// - open protected fun visitExpr(node: PartiqlAst.Expr, accumulator: T): T = accumulator - open protected fun visitExprMissing(node: PartiqlAst.Expr.Missing, accumulator: T): T = accumulator - open protected fun visitExprLit(node: PartiqlAst.Expr.Lit, accumulator: T): T = accumulator - open protected fun visitExprId(node: PartiqlAst.Expr.Id, accumulator: T): T = accumulator - open protected fun visitExprParameter(node: PartiqlAst.Expr.Parameter, accumulator: T): T = accumulator - open protected fun visitExprNot(node: PartiqlAst.Expr.Not, accumulator: T): T = accumulator - open protected fun visitExprPos(node: PartiqlAst.Expr.Pos, accumulator: T): T = accumulator - open protected fun visitExprNeg(node: PartiqlAst.Expr.Neg, accumulator: T): T = accumulator - open protected fun visitExprPlus(node: PartiqlAst.Expr.Plus, accumulator: T): T = accumulator - open protected fun visitExprMinus(node: PartiqlAst.Expr.Minus, accumulator: T): T = accumulator - open protected fun visitExprTimes(node: PartiqlAst.Expr.Times, accumulator: T): T = accumulator - open protected fun visitExprDivide(node: PartiqlAst.Expr.Divide, accumulator: T): T = accumulator - open protected fun visitExprModulo(node: PartiqlAst.Expr.Modulo, accumulator: T): T = accumulator - open protected fun visitExprConcat(node: PartiqlAst.Expr.Concat, accumulator: T): T = accumulator - open protected fun visitExprAnd(node: PartiqlAst.Expr.And, accumulator: T): T = accumulator - open protected fun visitExprOr(node: PartiqlAst.Expr.Or, accumulator: T): T = accumulator - open protected fun visitExprEq(node: PartiqlAst.Expr.Eq, accumulator: T): T = accumulator - open protected fun visitExprNe(node: PartiqlAst.Expr.Ne, accumulator: T): T = accumulator - open protected fun visitExprGt(node: PartiqlAst.Expr.Gt, accumulator: T): T = accumulator - open protected fun visitExprGte(node: PartiqlAst.Expr.Gte, accumulator: T): T = accumulator - open protected fun visitExprLt(node: PartiqlAst.Expr.Lt, accumulator: T): T = accumulator - open protected fun visitExprLte(node: PartiqlAst.Expr.Lte, accumulator: T): T = accumulator - open protected fun visitExprLike(node: PartiqlAst.Expr.Like, accumulator: T): T = accumulator - open protected fun visitExprBetween(node: PartiqlAst.Expr.Between, accumulator: T): T = accumulator - open protected fun visitExprInCollection(node: PartiqlAst.Expr.InCollection, accumulator: T): T = accumulator - open protected fun visitExprIsType(node: PartiqlAst.Expr.IsType, accumulator: T): T = accumulator - open protected fun visitExprSimpleCase(node: PartiqlAst.Expr.SimpleCase, accumulator: T): T = accumulator - open protected fun visitExprSearchedCase(node: PartiqlAst.Expr.SearchedCase, accumulator: T): T = accumulator - open protected fun visitExprStruct(node: PartiqlAst.Expr.Struct, accumulator: T): T = accumulator - open protected fun visitExprBag(node: PartiqlAst.Expr.Bag, accumulator: T): T = accumulator - open protected fun visitExprList(node: PartiqlAst.Expr.List, accumulator: T): T = accumulator - open protected fun visitExprSexp(node: PartiqlAst.Expr.Sexp, accumulator: T): T = accumulator - open protected fun visitExprDate(node: PartiqlAst.Expr.Date, accumulator: T): T = accumulator - open protected fun visitExprLitTime(node: PartiqlAst.Expr.LitTime, accumulator: T): T = accumulator - open protected fun visitExprUnion(node: PartiqlAst.Expr.Union, accumulator: T): T = accumulator - open protected fun visitExprExcept(node: PartiqlAst.Expr.Except, accumulator: T): T = accumulator - open protected fun visitExprIntersect(node: PartiqlAst.Expr.Intersect, accumulator: T): T = accumulator - open protected fun visitExprPath(node: PartiqlAst.Expr.Path, accumulator: T): T = accumulator - open protected fun visitExprCall(node: PartiqlAst.Expr.Call, accumulator: T): T = accumulator - open protected fun visitExprCallAgg(node: PartiqlAst.Expr.CallAgg, accumulator: T): T = accumulator - open protected fun visitExprCast(node: PartiqlAst.Expr.Cast, accumulator: T): T = accumulator - open protected fun visitExprCanCast(node: PartiqlAst.Expr.CanCast, accumulator: T): T = accumulator - open protected fun visitExprCanLosslessCast(node: PartiqlAst.Expr.CanLosslessCast, accumulator: T): T = accumulator - open protected fun visitExprNullIf(node: PartiqlAst.Expr.NullIf, accumulator: T): T = accumulator - open protected fun visitExprCoalesce(node: PartiqlAst.Expr.Coalesce, accumulator: T): T = accumulator - open protected fun visitExprSelect(node: PartiqlAst.Expr.Select, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: PathStep - ////////////////////////////////////// - open protected fun visitPathStep(node: PartiqlAst.PathStep, accumulator: T): T = accumulator - open protected fun visitPathStepPathExpr(node: PartiqlAst.PathStep.PathExpr, accumulator: T): T = accumulator - open protected fun visitPathStepPathWildcard(node: PartiqlAst.PathStep.PathWildcard, accumulator: T): T = accumulator - open protected fun visitPathStepPathUnpivot(node: PartiqlAst.PathStep.PathUnpivot, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: Projection - ////////////////////////////////////// - open protected fun visitProjection(node: PartiqlAst.Projection, accumulator: T): T = accumulator - open protected fun visitProjectionProjectStar(node: PartiqlAst.Projection.ProjectStar, accumulator: T): T = accumulator - open protected fun visitProjectionProjectList(node: PartiqlAst.Projection.ProjectList, accumulator: T): T = accumulator - open protected fun visitProjectionProjectPivot(node: PartiqlAst.Projection.ProjectPivot, accumulator: T): T = accumulator - open protected fun visitProjectionProjectValue(node: PartiqlAst.Projection.ProjectValue, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: ProjectItem - ////////////////////////////////////// - open protected fun visitProjectItem(node: PartiqlAst.ProjectItem, accumulator: T): T = accumulator - open protected fun visitProjectItemProjectAll(node: PartiqlAst.ProjectItem.ProjectAll, accumulator: T): T = accumulator - open protected fun visitProjectItemProjectExpr(node: PartiqlAst.ProjectItem.ProjectExpr, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: FromSource - ////////////////////////////////////// - open protected fun visitFromSource(node: PartiqlAst.FromSource, accumulator: T): T = accumulator - open protected fun visitFromSourceScan(node: PartiqlAst.FromSource.Scan, accumulator: T): T = accumulator - open protected fun visitFromSourceUnpivot(node: PartiqlAst.FromSource.Unpivot, accumulator: T): T = accumulator - open protected fun visitFromSourceJoin(node: PartiqlAst.FromSource.Join, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: JoinType - ////////////////////////////////////// - open protected fun visitJoinType(node: PartiqlAst.JoinType, accumulator: T): T = accumulator - open protected fun visitJoinTypeInner(node: PartiqlAst.JoinType.Inner, accumulator: T): T = accumulator - open protected fun visitJoinTypeLeft(node: PartiqlAst.JoinType.Left, accumulator: T): T = accumulator - open protected fun visitJoinTypeRight(node: PartiqlAst.JoinType.Right, accumulator: T): T = accumulator - open protected fun visitJoinTypeFull(node: PartiqlAst.JoinType.Full, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: GroupingStrategy - ////////////////////////////////////// - open protected fun visitGroupingStrategy(node: PartiqlAst.GroupingStrategy, accumulator: T): T = accumulator - open protected fun visitGroupingStrategyGroupFull(node: PartiqlAst.GroupingStrategy.GroupFull, accumulator: T): T = accumulator - open protected fun visitGroupingStrategyGroupPartial(node: PartiqlAst.GroupingStrategy.GroupPartial, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: OrderingSpec - ////////////////////////////////////// - open protected fun visitOrderingSpec(node: PartiqlAst.OrderingSpec, accumulator: T): T = accumulator - open protected fun visitOrderingSpecAsc(node: PartiqlAst.OrderingSpec.Asc, accumulator: T): T = accumulator - open protected fun visitOrderingSpecDesc(node: PartiqlAst.OrderingSpec.Desc, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: CaseSensitivity - ////////////////////////////////////// - open protected fun visitCaseSensitivity(node: PartiqlAst.CaseSensitivity, accumulator: T): T = accumulator - open protected fun visitCaseSensitivityCaseSensitive(node: PartiqlAst.CaseSensitivity.CaseSensitive, accumulator: T): T = accumulator - open protected fun visitCaseSensitivityCaseInsensitive(node: PartiqlAst.CaseSensitivity.CaseInsensitive, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: ScopeQualifier - ////////////////////////////////////// - open protected fun visitScopeQualifier(node: PartiqlAst.ScopeQualifier, accumulator: T): T = accumulator - open protected fun visitScopeQualifierUnqualified(node: PartiqlAst.ScopeQualifier.Unqualified, accumulator: T): T = accumulator - open protected fun visitScopeQualifierLocalsFirst(node: PartiqlAst.ScopeQualifier.LocalsFirst, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: SetQuantifier - ////////////////////////////////////// - open protected fun visitSetQuantifier(node: PartiqlAst.SetQuantifier, accumulator: T): T = accumulator - open protected fun visitSetQuantifierAll(node: PartiqlAst.SetQuantifier.All, accumulator: T): T = accumulator - open protected fun visitSetQuantifierDistinct(node: PartiqlAst.SetQuantifier.Distinct, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: DmlOp - ////////////////////////////////////// - open protected fun visitDmlOp(node: PartiqlAst.DmlOp, accumulator: T): T = accumulator - open protected fun visitDmlOpInsert(node: PartiqlAst.DmlOp.Insert, accumulator: T): T = accumulator - open protected fun visitDmlOpInsertValue(node: PartiqlAst.DmlOp.InsertValue, accumulator: T): T = accumulator - open protected fun visitDmlOpSet(node: PartiqlAst.DmlOp.Set, accumulator: T): T = accumulator - open protected fun visitDmlOpRemove(node: PartiqlAst.DmlOp.Remove, accumulator: T): T = accumulator - open protected fun visitDmlOpDelete(node: PartiqlAst.DmlOp.Delete, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: ConflictAction - ////////////////////////////////////// - open protected fun visitConflictAction(node: PartiqlAst.ConflictAction, accumulator: T): T = accumulator - open protected fun visitConflictActionDoNothing(node: PartiqlAst.ConflictAction.DoNothing, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: DdlOp - ////////////////////////////////////// - open protected fun visitDdlOp(node: PartiqlAst.DdlOp, accumulator: T): T = accumulator - open protected fun visitDdlOpCreateTable(node: PartiqlAst.DdlOp.CreateTable, accumulator: T): T = accumulator - open protected fun visitDdlOpDropTable(node: PartiqlAst.DdlOp.DropTable, accumulator: T): T = accumulator - open protected fun visitDdlOpUndropTable(node: PartiqlAst.DdlOp.UndropTable, accumulator: T): T = accumulator - open protected fun visitDdlOpCreateIndex(node: PartiqlAst.DdlOp.CreateIndex, accumulator: T): T = accumulator - open protected fun visitDdlOpDropIndex(node: PartiqlAst.DdlOp.DropIndex, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: ColumnComponent - ////////////////////////////////////// - open protected fun visitColumnComponent(node: PartiqlAst.ColumnComponent, accumulator: T): T = accumulator - open protected fun visitColumnComponentReturningWildcard(node: PartiqlAst.ColumnComponent.ReturningWildcard, accumulator: T): T = accumulator - open protected fun visitColumnComponentReturningColumn(node: PartiqlAst.ColumnComponent.ReturningColumn, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: ReturningMapping - ////////////////////////////////////// - open protected fun visitReturningMapping(node: PartiqlAst.ReturningMapping, accumulator: T): T = accumulator - open protected fun visitReturningMappingModifiedNew(node: PartiqlAst.ReturningMapping.ModifiedNew, accumulator: T): T = accumulator - open protected fun visitReturningMappingModifiedOld(node: PartiqlAst.ReturningMapping.ModifiedOld, accumulator: T): T = accumulator - open protected fun visitReturningMappingAllNew(node: PartiqlAst.ReturningMapping.AllNew, accumulator: T): T = accumulator - open protected fun visitReturningMappingAllOld(node: PartiqlAst.ReturningMapping.AllOld, accumulator: T): T = accumulator - ////////////////////////////////////// - // Sum Type: Type - ////////////////////////////////////// - open protected fun visitType(node: PartiqlAst.Type, accumulator: T): T = accumulator - open protected fun visitTypeNullType(node: PartiqlAst.Type.NullType, accumulator: T): T = accumulator - open protected fun visitTypeBooleanType(node: PartiqlAst.Type.BooleanType, accumulator: T): T = accumulator - open protected fun visitTypeSmallintType(node: PartiqlAst.Type.SmallintType, accumulator: T): T = accumulator - open protected fun visitTypeInteger4Type(node: PartiqlAst.Type.Integer4Type, accumulator: T): T = accumulator - open protected fun visitTypeInteger8Type(node: PartiqlAst.Type.Integer8Type, accumulator: T): T = accumulator - open protected fun visitTypeIntegerType(node: PartiqlAst.Type.IntegerType, accumulator: T): T = accumulator - open protected fun visitTypeFloatType(node: PartiqlAst.Type.FloatType, accumulator: T): T = accumulator - open protected fun visitTypeRealType(node: PartiqlAst.Type.RealType, accumulator: T): T = accumulator - open protected fun visitTypeDoublePrecisionType(node: PartiqlAst.Type.DoublePrecisionType, accumulator: T): T = accumulator - open protected fun visitTypeDecimalType(node: PartiqlAst.Type.DecimalType, accumulator: T): T = accumulator - open protected fun visitTypeNumericType(node: PartiqlAst.Type.NumericType, accumulator: T): T = accumulator - open protected fun visitTypeTimestampType(node: PartiqlAst.Type.TimestampType, accumulator: T): T = accumulator - open protected fun visitTypeCharacterType(node: PartiqlAst.Type.CharacterType, accumulator: T): T = accumulator - open protected fun visitTypeCharacterVaryingType(node: PartiqlAst.Type.CharacterVaryingType, accumulator: T): T = accumulator - open protected fun visitTypeMissingType(node: PartiqlAst.Type.MissingType, accumulator: T): T = accumulator - open protected fun visitTypeStringType(node: PartiqlAst.Type.StringType, accumulator: T): T = accumulator - open protected fun visitTypeSymbolType(node: PartiqlAst.Type.SymbolType, accumulator: T): T = accumulator - open protected fun visitTypeBlobType(node: PartiqlAst.Type.BlobType, accumulator: T): T = accumulator - open protected fun visitTypeClobType(node: PartiqlAst.Type.ClobType, accumulator: T): T = accumulator - open protected fun visitTypeDateType(node: PartiqlAst.Type.DateType, accumulator: T): T = accumulator - open protected fun visitTypeTimeType(node: PartiqlAst.Type.TimeType, accumulator: T): T = accumulator - open protected fun visitTypeTimeWithTimeZoneType(node: PartiqlAst.Type.TimeWithTimeZoneType, accumulator: T): T = accumulator - open protected fun visitTypeStructType(node: PartiqlAst.Type.StructType, accumulator: T): T = accumulator - open protected fun visitTypeTupleType(node: PartiqlAst.Type.TupleType, accumulator: T): T = accumulator - open protected fun visitTypeListType(node: PartiqlAst.Type.ListType, accumulator: T): T = accumulator - open protected fun visitTypeSexpType(node: PartiqlAst.Type.SexpType, accumulator: T): T = accumulator - open protected fun visitTypeBagType(node: PartiqlAst.Type.BagType, accumulator: T): T = accumulator - open protected fun visitTypeAnyType(node: PartiqlAst.Type.AnyType, accumulator: T): T = accumulator - open protected fun visitTypeEsBoolean(node: PartiqlAst.Type.EsBoolean, accumulator: T): T = accumulator - open protected fun visitTypeEsInteger(node: PartiqlAst.Type.EsInteger, accumulator: T): T = accumulator - open protected fun visitTypeEsFloat(node: PartiqlAst.Type.EsFloat, accumulator: T): T = accumulator - open protected fun visitTypeEsText(node: PartiqlAst.Type.EsText, accumulator: T): T = accumulator - open protected fun visitTypeEsAny(node: PartiqlAst.Type.EsAny, accumulator: T): T = accumulator - open protected fun visitTypeSparkShort(node: PartiqlAst.Type.SparkShort, accumulator: T): T = accumulator - open protected fun visitTypeSparkInteger(node: PartiqlAst.Type.SparkInteger, accumulator: T): T = accumulator - open protected fun visitTypeSparkLong(node: PartiqlAst.Type.SparkLong, accumulator: T): T = accumulator - open protected fun visitTypeSparkDouble(node: PartiqlAst.Type.SparkDouble, accumulator: T): T = accumulator - open protected fun visitTypeSparkBoolean(node: PartiqlAst.Type.SparkBoolean, accumulator: T): T = accumulator - open protected fun visitTypeSparkFloat(node: PartiqlAst.Type.SparkFloat, accumulator: T): T = accumulator - open protected fun visitTypeRsVarcharMax(node: PartiqlAst.Type.RsVarcharMax, accumulator: T): T = accumulator - open protected fun visitTypeRsInteger(node: PartiqlAst.Type.RsInteger, accumulator: T): T = accumulator - open protected fun visitTypeRsBigint(node: PartiqlAst.Type.RsBigint, accumulator: T): T = accumulator - open protected fun visitTypeRsBoolean(node: PartiqlAst.Type.RsBoolean, accumulator: T): T = accumulator - open protected fun visitTypeRsReal(node: PartiqlAst.Type.RsReal, accumulator: T): T = accumulator - open protected fun visitTypeRsDoublePrecision(node: PartiqlAst.Type.RsDoublePrecision, accumulator: T): T = accumulator - open protected fun visitTypeCustomType(node: PartiqlAst.Type.CustomType, accumulator: T): T = accumulator - - //////////////////////////////////////////////////////////////////////////// - // Walk Functions - //////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////// - // Tuple Types - ////////////////////////////////////// - open fun walkTimeValue(node: PartiqlAst.TimeValue, accumulator: T): T { - var current = accumulator - current = visitTimeValue(node, current) - current = walkLongPrimitive(node.hour, current) - current = walkLongPrimitive(node.minute, current) - current = walkLongPrimitive(node.second, current) - current = walkLongPrimitive(node.nano, current) - current = walkLongPrimitive(node.precision, current) - node.tzMinutes?.let { current = walkLongPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkLet(node: PartiqlAst.Let, accumulator: T): T { - var current = accumulator - current = visitLet(node, current) - node.letBindings.map { current = walkLetBinding(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkLetBinding(node: PartiqlAst.LetBinding, accumulator: T): T { - var current = accumulator - current = visitLetBinding(node, current) - current = walkExpr(node.expr, current) - current = walkSymbolPrimitive(node.name, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprPair(node: PartiqlAst.ExprPair, accumulator: T): T { - var current = accumulator - current = visitExprPair(node, current) - current = walkExpr(node.first, current) - current = walkExpr(node.second, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprPairList(node: PartiqlAst.ExprPairList, accumulator: T): T { - var current = accumulator - current = visitExprPairList(node, current) - node.pairs.map { current = walkExprPair(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkGroupBy(node: PartiqlAst.GroupBy, accumulator: T): T { - var current = accumulator - current = visitGroupBy(node, current) - current = walkGroupingStrategy(node.strategy, current) - current = walkGroupKeyList(node.keyList, current) - node.groupAsAlias?.let { current = walkSymbolPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkGroupKeyList(node: PartiqlAst.GroupKeyList, accumulator: T): T { - var current = accumulator - current = visitGroupKeyList(node, current) - node.keys.map { current = walkGroupKey(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkGroupKey(node: PartiqlAst.GroupKey, accumulator: T): T { - var current = accumulator - current = visitGroupKey(node, current) - current = walkExpr(node.expr, current) - node.asAlias?.let { current = walkSymbolPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkOrderBy(node: PartiqlAst.OrderBy, accumulator: T): T { - var current = accumulator - current = visitOrderBy(node, current) - node.sortSpecs.map { current = walkSortSpec(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkSortSpec(node: PartiqlAst.SortSpec, accumulator: T): T { - var current = accumulator - current = visitSortSpec(node, current) - current = walkExpr(node.expr, current) - node.orderingSpec?.let { current = walkOrderingSpec(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkDmlOpList(node: PartiqlAst.DmlOpList, accumulator: T): T { - var current = accumulator - current = visitDmlOpList(node, current) - node.ops.map { current = walkDmlOp(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkOnConflict(node: PartiqlAst.OnConflict, accumulator: T): T { - var current = accumulator - current = visitOnConflict(node, current) - current = walkExpr(node.expr, current) - current = walkConflictAction(node.conflictAction, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkReturningExpr(node: PartiqlAst.ReturningExpr, accumulator: T): T { - var current = accumulator - current = visitReturningExpr(node, current) - node.elems.map { current = walkReturningElem(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkReturningElem(node: PartiqlAst.ReturningElem, accumulator: T): T { - var current = accumulator - current = visitReturningElem(node, current) - current = walkReturningMapping(node.mapping, current) - current = walkColumnComponent(node.column, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkIdentifier(node: PartiqlAst.Identifier, accumulator: T): T { - var current = accumulator - current = visitIdentifier(node, current) - current = walkSymbolPrimitive(node.name, current) - current = walkCaseSensitivity(node.case, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkAssignment(node: PartiqlAst.Assignment, accumulator: T): T { - var current = accumulator - current = visitAssignment(node, current) - current = walkExpr(node.target, current) - current = walkExpr(node.value, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: Statement - ////////////////////////////////////// - open fun walkStatement(node: PartiqlAst.Statement, accumulator: T): T { - val current = visitStatement(node, accumulator) - return when(node) { - is PartiqlAst.Statement.Query -> walkStatementQuery(node, current) - is PartiqlAst.Statement.Dml -> walkStatementDml(node, current) - is PartiqlAst.Statement.Ddl -> walkStatementDdl(node, current) - is PartiqlAst.Statement.Exec -> walkStatementExec(node, current) - } - } - - open fun walkStatementQuery(node: PartiqlAst.Statement.Query, accumulator: T): T { - var current = accumulator - current = visitStatementQuery(node, current) - current = walkExpr(node.expr, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkStatementDml(node: PartiqlAst.Statement.Dml, accumulator: T): T { - var current = accumulator - current = visitStatementDml(node, current) - current = walkDmlOpList(node.operations, current) - node.from?.let { current = walkFromSource(it, current) } - node.where?.let { current = walkExpr(it, current) } - node.returning?.let { current = walkReturningExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkStatementDdl(node: PartiqlAst.Statement.Ddl, accumulator: T): T { - var current = accumulator - current = visitStatementDdl(node, current) - current = walkDdlOp(node.op, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkStatementExec(node: PartiqlAst.Statement.Exec, accumulator: T): T { - var current = accumulator - current = visitStatementExec(node, current) - current = walkSymbolPrimitive(node.procedureName, current) - node.args.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: Expr - ////////////////////////////////////// - open fun walkExpr(node: PartiqlAst.Expr, accumulator: T): T { - val current = visitExpr(node, accumulator) - return when(node) { - is PartiqlAst.Expr.Missing -> walkExprMissing(node, current) - is PartiqlAst.Expr.Lit -> walkExprLit(node, current) - is PartiqlAst.Expr.Id -> walkExprId(node, current) - is PartiqlAst.Expr.Parameter -> walkExprParameter(node, current) - is PartiqlAst.Expr.Not -> walkExprNot(node, current) - is PartiqlAst.Expr.Pos -> walkExprPos(node, current) - is PartiqlAst.Expr.Neg -> walkExprNeg(node, current) - is PartiqlAst.Expr.Plus -> walkExprPlus(node, current) - is PartiqlAst.Expr.Minus -> walkExprMinus(node, current) - is PartiqlAst.Expr.Times -> walkExprTimes(node, current) - is PartiqlAst.Expr.Divide -> walkExprDivide(node, current) - is PartiqlAst.Expr.Modulo -> walkExprModulo(node, current) - is PartiqlAst.Expr.Concat -> walkExprConcat(node, current) - is PartiqlAst.Expr.And -> walkExprAnd(node, current) - is PartiqlAst.Expr.Or -> walkExprOr(node, current) - is PartiqlAst.Expr.Eq -> walkExprEq(node, current) - is PartiqlAst.Expr.Ne -> walkExprNe(node, current) - is PartiqlAst.Expr.Gt -> walkExprGt(node, current) - is PartiqlAst.Expr.Gte -> walkExprGte(node, current) - is PartiqlAst.Expr.Lt -> walkExprLt(node, current) - is PartiqlAst.Expr.Lte -> walkExprLte(node, current) - is PartiqlAst.Expr.Like -> walkExprLike(node, current) - is PartiqlAst.Expr.Between -> walkExprBetween(node, current) - is PartiqlAst.Expr.InCollection -> walkExprInCollection(node, current) - is PartiqlAst.Expr.IsType -> walkExprIsType(node, current) - is PartiqlAst.Expr.SimpleCase -> walkExprSimpleCase(node, current) - is PartiqlAst.Expr.SearchedCase -> walkExprSearchedCase(node, current) - is PartiqlAst.Expr.Struct -> walkExprStruct(node, current) - is PartiqlAst.Expr.Bag -> walkExprBag(node, current) - is PartiqlAst.Expr.List -> walkExprList(node, current) - is PartiqlAst.Expr.Sexp -> walkExprSexp(node, current) - is PartiqlAst.Expr.Date -> walkExprDate(node, current) - is PartiqlAst.Expr.LitTime -> walkExprLitTime(node, current) - is PartiqlAst.Expr.Union -> walkExprUnion(node, current) - is PartiqlAst.Expr.Except -> walkExprExcept(node, current) - is PartiqlAst.Expr.Intersect -> walkExprIntersect(node, current) - is PartiqlAst.Expr.Path -> walkExprPath(node, current) - is PartiqlAst.Expr.Call -> walkExprCall(node, current) - is PartiqlAst.Expr.CallAgg -> walkExprCallAgg(node, current) - is PartiqlAst.Expr.Cast -> walkExprCast(node, current) - is PartiqlAst.Expr.CanCast -> walkExprCanCast(node, current) - is PartiqlAst.Expr.CanLosslessCast -> walkExprCanLosslessCast(node, current) - is PartiqlAst.Expr.NullIf -> walkExprNullIf(node, current) - is PartiqlAst.Expr.Coalesce -> walkExprCoalesce(node, current) - is PartiqlAst.Expr.Select -> walkExprSelect(node, current) - } - } - - open fun walkExprMissing(node: PartiqlAst.Expr.Missing, accumulator: T): T { - var current = accumulator - current = visitExprMissing(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprLit(node: PartiqlAst.Expr.Lit, accumulator: T): T { - var current = accumulator - current = visitExprLit(node, current) - current = walkAnyElement(node.value, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprId(node: PartiqlAst.Expr.Id, accumulator: T): T { - var current = accumulator - current = visitExprId(node, current) - current = walkSymbolPrimitive(node.name, current) - current = walkCaseSensitivity(node.case, current) - current = walkScopeQualifier(node.qualifier, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprParameter(node: PartiqlAst.Expr.Parameter, accumulator: T): T { - var current = accumulator - current = visitExprParameter(node, current) - current = walkLongPrimitive(node.index, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprNot(node: PartiqlAst.Expr.Not, accumulator: T): T { - var current = accumulator - current = visitExprNot(node, current) - current = walkExpr(node.expr, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprPos(node: PartiqlAst.Expr.Pos, accumulator: T): T { - var current = accumulator - current = visitExprPos(node, current) - current = walkExpr(node.expr, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprNeg(node: PartiqlAst.Expr.Neg, accumulator: T): T { - var current = accumulator - current = visitExprNeg(node, current) - current = walkExpr(node.expr, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprPlus(node: PartiqlAst.Expr.Plus, accumulator: T): T { - var current = accumulator - current = visitExprPlus(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprMinus(node: PartiqlAst.Expr.Minus, accumulator: T): T { - var current = accumulator - current = visitExprMinus(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprTimes(node: PartiqlAst.Expr.Times, accumulator: T): T { - var current = accumulator - current = visitExprTimes(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprDivide(node: PartiqlAst.Expr.Divide, accumulator: T): T { - var current = accumulator - current = visitExprDivide(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprModulo(node: PartiqlAst.Expr.Modulo, accumulator: T): T { - var current = accumulator - current = visitExprModulo(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprConcat(node: PartiqlAst.Expr.Concat, accumulator: T): T { - var current = accumulator - current = visitExprConcat(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprAnd(node: PartiqlAst.Expr.And, accumulator: T): T { - var current = accumulator - current = visitExprAnd(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprOr(node: PartiqlAst.Expr.Or, accumulator: T): T { - var current = accumulator - current = visitExprOr(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprEq(node: PartiqlAst.Expr.Eq, accumulator: T): T { - var current = accumulator - current = visitExprEq(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprNe(node: PartiqlAst.Expr.Ne, accumulator: T): T { - var current = accumulator - current = visitExprNe(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprGt(node: PartiqlAst.Expr.Gt, accumulator: T): T { - var current = accumulator - current = visitExprGt(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprGte(node: PartiqlAst.Expr.Gte, accumulator: T): T { - var current = accumulator - current = visitExprGte(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprLt(node: PartiqlAst.Expr.Lt, accumulator: T): T { - var current = accumulator - current = visitExprLt(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprLte(node: PartiqlAst.Expr.Lte, accumulator: T): T { - var current = accumulator - current = visitExprLte(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprLike(node: PartiqlAst.Expr.Like, accumulator: T): T { - var current = accumulator - current = visitExprLike(node, current) - current = walkExpr(node.value, current) - current = walkExpr(node.pattern, current) - node.escape?.let { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprBetween(node: PartiqlAst.Expr.Between, accumulator: T): T { - var current = accumulator - current = visitExprBetween(node, current) - current = walkExpr(node.value, current) - current = walkExpr(node.from, current) - current = walkExpr(node.to, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprInCollection(node: PartiqlAst.Expr.InCollection, accumulator: T): T { - var current = accumulator - current = visitExprInCollection(node, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprIsType(node: PartiqlAst.Expr.IsType, accumulator: T): T { - var current = accumulator - current = visitExprIsType(node, current) - current = walkExpr(node.value, current) - current = walkType(node.type, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprSimpleCase(node: PartiqlAst.Expr.SimpleCase, accumulator: T): T { - var current = accumulator - current = visitExprSimpleCase(node, current) - current = walkExpr(node.expr, current) - current = walkExprPairList(node.cases, current) - node.default?.let { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprSearchedCase(node: PartiqlAst.Expr.SearchedCase, accumulator: T): T { - var current = accumulator - current = visitExprSearchedCase(node, current) - current = walkExprPairList(node.cases, current) - node.default?.let { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprStruct(node: PartiqlAst.Expr.Struct, accumulator: T): T { - var current = accumulator - current = visitExprStruct(node, current) - node.fields.map { current = walkExprPair(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprBag(node: PartiqlAst.Expr.Bag, accumulator: T): T { - var current = accumulator - current = visitExprBag(node, current) - node.values.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprList(node: PartiqlAst.Expr.List, accumulator: T): T { - var current = accumulator - current = visitExprList(node, current) - node.values.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprSexp(node: PartiqlAst.Expr.Sexp, accumulator: T): T { - var current = accumulator - current = visitExprSexp(node, current) - node.values.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprDate(node: PartiqlAst.Expr.Date, accumulator: T): T { - var current = accumulator - current = visitExprDate(node, current) - current = walkLongPrimitive(node.year, current) - current = walkLongPrimitive(node.month, current) - current = walkLongPrimitive(node.day, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprLitTime(node: PartiqlAst.Expr.LitTime, accumulator: T): T { - var current = accumulator - current = visitExprLitTime(node, current) - current = walkTimeValue(node.value, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprUnion(node: PartiqlAst.Expr.Union, accumulator: T): T { - var current = accumulator - current = visitExprUnion(node, current) - current = walkSetQuantifier(node.setq, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprExcept(node: PartiqlAst.Expr.Except, accumulator: T): T { - var current = accumulator - current = visitExprExcept(node, current) - current = walkSetQuantifier(node.setq, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprIntersect(node: PartiqlAst.Expr.Intersect, accumulator: T): T { - var current = accumulator - current = visitExprIntersect(node, current) - current = walkSetQuantifier(node.setq, current) - node.operands.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprPath(node: PartiqlAst.Expr.Path, accumulator: T): T { - var current = accumulator - current = visitExprPath(node, current) - current = walkExpr(node.root, current) - node.steps.map { current = walkPathStep(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprCall(node: PartiqlAst.Expr.Call, accumulator: T): T { - var current = accumulator - current = visitExprCall(node, current) - current = walkSymbolPrimitive(node.funcName, current) - node.args.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprCallAgg(node: PartiqlAst.Expr.CallAgg, accumulator: T): T { - var current = accumulator - current = visitExprCallAgg(node, current) - current = walkSetQuantifier(node.setq, current) - current = walkSymbolPrimitive(node.funcName, current) - current = walkExpr(node.arg, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprCast(node: PartiqlAst.Expr.Cast, accumulator: T): T { - var current = accumulator - current = visitExprCast(node, current) - current = walkExpr(node.value, current) - current = walkType(node.asType, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprCanCast(node: PartiqlAst.Expr.CanCast, accumulator: T): T { - var current = accumulator - current = visitExprCanCast(node, current) - current = walkExpr(node.value, current) - current = walkType(node.asType, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprCanLosslessCast(node: PartiqlAst.Expr.CanLosslessCast, accumulator: T): T { - var current = accumulator - current = visitExprCanLosslessCast(node, current) - current = walkExpr(node.value, current) - current = walkType(node.asType, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprNullIf(node: PartiqlAst.Expr.NullIf, accumulator: T): T { - var current = accumulator - current = visitExprNullIf(node, current) - current = walkExpr(node.expr1, current) - current = walkExpr(node.expr2, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprCoalesce(node: PartiqlAst.Expr.Coalesce, accumulator: T): T { - var current = accumulator - current = visitExprCoalesce(node, current) - node.args.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkExprSelect(node: PartiqlAst.Expr.Select, accumulator: T): T { - var current = accumulator - current = visitExprSelect(node, current) - node.setq?.let { current = walkSetQuantifier(it, current) } - current = walkProjection(node.project, current) - current = walkFromSource(node.from, current) - node.fromLet?.let { current = walkLet(it, current) } - node.where?.let { current = walkExpr(it, current) } - node.group?.let { current = walkGroupBy(it, current) } - node.having?.let { current = walkExpr(it, current) } - node.order?.let { current = walkOrderBy(it, current) } - node.limit?.let { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: PathStep - ////////////////////////////////////// - open fun walkPathStep(node: PartiqlAst.PathStep, accumulator: T): T { - val current = visitPathStep(node, accumulator) - return when(node) { - is PartiqlAst.PathStep.PathExpr -> walkPathStepPathExpr(node, current) - is PartiqlAst.PathStep.PathWildcard -> walkPathStepPathWildcard(node, current) - is PartiqlAst.PathStep.PathUnpivot -> walkPathStepPathUnpivot(node, current) - } - } - - open fun walkPathStepPathExpr(node: PartiqlAst.PathStep.PathExpr, accumulator: T): T { - var current = accumulator - current = visitPathStepPathExpr(node, current) - current = walkExpr(node.index, current) - current = walkCaseSensitivity(node.case, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkPathStepPathWildcard(node: PartiqlAst.PathStep.PathWildcard, accumulator: T): T { - var current = accumulator - current = visitPathStepPathWildcard(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkPathStepPathUnpivot(node: PartiqlAst.PathStep.PathUnpivot, accumulator: T): T { - var current = accumulator - current = visitPathStepPathUnpivot(node, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: Projection - ////////////////////////////////////// - open fun walkProjection(node: PartiqlAst.Projection, accumulator: T): T { - val current = visitProjection(node, accumulator) - return when(node) { - is PartiqlAst.Projection.ProjectStar -> walkProjectionProjectStar(node, current) - is PartiqlAst.Projection.ProjectList -> walkProjectionProjectList(node, current) - is PartiqlAst.Projection.ProjectPivot -> walkProjectionProjectPivot(node, current) - is PartiqlAst.Projection.ProjectValue -> walkProjectionProjectValue(node, current) - } - } - - open fun walkProjectionProjectStar(node: PartiqlAst.Projection.ProjectStar, accumulator: T): T { - var current = accumulator - current = visitProjectionProjectStar(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkProjectionProjectList(node: PartiqlAst.Projection.ProjectList, accumulator: T): T { - var current = accumulator - current = visitProjectionProjectList(node, current) - node.projectItems.map { current = walkProjectItem(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkProjectionProjectPivot(node: PartiqlAst.Projection.ProjectPivot, accumulator: T): T { - var current = accumulator - current = visitProjectionProjectPivot(node, current) - current = walkExpr(node.value, current) - current = walkExpr(node.key, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkProjectionProjectValue(node: PartiqlAst.Projection.ProjectValue, accumulator: T): T { - var current = accumulator - current = visitProjectionProjectValue(node, current) - current = walkExpr(node.value, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: ProjectItem - ////////////////////////////////////// - open fun walkProjectItem(node: PartiqlAst.ProjectItem, accumulator: T): T { - val current = visitProjectItem(node, accumulator) - return when(node) { - is PartiqlAst.ProjectItem.ProjectAll -> walkProjectItemProjectAll(node, current) - is PartiqlAst.ProjectItem.ProjectExpr -> walkProjectItemProjectExpr(node, current) - } - } - - open fun walkProjectItemProjectAll(node: PartiqlAst.ProjectItem.ProjectAll, accumulator: T): T { - var current = accumulator - current = visitProjectItemProjectAll(node, current) - current = walkExpr(node.expr, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkProjectItemProjectExpr(node: PartiqlAst.ProjectItem.ProjectExpr, accumulator: T): T { - var current = accumulator - current = visitProjectItemProjectExpr(node, current) - current = walkExpr(node.expr, current) - node.asAlias?.let { current = walkSymbolPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: FromSource - ////////////////////////////////////// - open fun walkFromSource(node: PartiqlAst.FromSource, accumulator: T): T { - val current = visitFromSource(node, accumulator) - return when(node) { - is PartiqlAst.FromSource.Scan -> walkFromSourceScan(node, current) - is PartiqlAst.FromSource.Unpivot -> walkFromSourceUnpivot(node, current) - is PartiqlAst.FromSource.Join -> walkFromSourceJoin(node, current) - } - } - - open fun walkFromSourceScan(node: PartiqlAst.FromSource.Scan, accumulator: T): T { - var current = accumulator - current = visitFromSourceScan(node, current) - current = walkExpr(node.expr, current) - node.asAlias?.let { current = walkSymbolPrimitive(it, current) } - node.atAlias?.let { current = walkSymbolPrimitive(it, current) } - node.byAlias?.let { current = walkSymbolPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkFromSourceUnpivot(node: PartiqlAst.FromSource.Unpivot, accumulator: T): T { - var current = accumulator - current = visitFromSourceUnpivot(node, current) - current = walkExpr(node.expr, current) - node.asAlias?.let { current = walkSymbolPrimitive(it, current) } - node.atAlias?.let { current = walkSymbolPrimitive(it, current) } - node.byAlias?.let { current = walkSymbolPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkFromSourceJoin(node: PartiqlAst.FromSource.Join, accumulator: T): T { - var current = accumulator - current = visitFromSourceJoin(node, current) - current = walkJoinType(node.type, current) - current = walkFromSource(node.left, current) - current = walkFromSource(node.right, current) - node.predicate?.let { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: JoinType - ////////////////////////////////////// - open fun walkJoinType(node: PartiqlAst.JoinType, accumulator: T): T { - val current = visitJoinType(node, accumulator) - return when(node) { - is PartiqlAst.JoinType.Inner -> walkJoinTypeInner(node, current) - is PartiqlAst.JoinType.Left -> walkJoinTypeLeft(node, current) - is PartiqlAst.JoinType.Right -> walkJoinTypeRight(node, current) - is PartiqlAst.JoinType.Full -> walkJoinTypeFull(node, current) - } - } - - open fun walkJoinTypeInner(node: PartiqlAst.JoinType.Inner, accumulator: T): T { - var current = accumulator - current = visitJoinTypeInner(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkJoinTypeLeft(node: PartiqlAst.JoinType.Left, accumulator: T): T { - var current = accumulator - current = visitJoinTypeLeft(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkJoinTypeRight(node: PartiqlAst.JoinType.Right, accumulator: T): T { - var current = accumulator - current = visitJoinTypeRight(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkJoinTypeFull(node: PartiqlAst.JoinType.Full, accumulator: T): T { - var current = accumulator - current = visitJoinTypeFull(node, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: GroupingStrategy - ////////////////////////////////////// - open fun walkGroupingStrategy(node: PartiqlAst.GroupingStrategy, accumulator: T): T { - val current = visitGroupingStrategy(node, accumulator) - return when(node) { - is PartiqlAst.GroupingStrategy.GroupFull -> walkGroupingStrategyGroupFull(node, current) - is PartiqlAst.GroupingStrategy.GroupPartial -> walkGroupingStrategyGroupPartial(node, current) - } - } - - open fun walkGroupingStrategyGroupFull(node: PartiqlAst.GroupingStrategy.GroupFull, accumulator: T): T { - var current = accumulator - current = visitGroupingStrategyGroupFull(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkGroupingStrategyGroupPartial(node: PartiqlAst.GroupingStrategy.GroupPartial, accumulator: T): T { - var current = accumulator - current = visitGroupingStrategyGroupPartial(node, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: OrderingSpec - ////////////////////////////////////// - open fun walkOrderingSpec(node: PartiqlAst.OrderingSpec, accumulator: T): T { - val current = visitOrderingSpec(node, accumulator) - return when(node) { - is PartiqlAst.OrderingSpec.Asc -> walkOrderingSpecAsc(node, current) - is PartiqlAst.OrderingSpec.Desc -> walkOrderingSpecDesc(node, current) - } - } - - open fun walkOrderingSpecAsc(node: PartiqlAst.OrderingSpec.Asc, accumulator: T): T { - var current = accumulator - current = visitOrderingSpecAsc(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkOrderingSpecDesc(node: PartiqlAst.OrderingSpec.Desc, accumulator: T): T { - var current = accumulator - current = visitOrderingSpecDesc(node, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: CaseSensitivity - ////////////////////////////////////// - open fun walkCaseSensitivity(node: PartiqlAst.CaseSensitivity, accumulator: T): T { - val current = visitCaseSensitivity(node, accumulator) - return when(node) { - is PartiqlAst.CaseSensitivity.CaseSensitive -> walkCaseSensitivityCaseSensitive(node, current) - is PartiqlAst.CaseSensitivity.CaseInsensitive -> walkCaseSensitivityCaseInsensitive(node, current) - } - } - - open fun walkCaseSensitivityCaseSensitive(node: PartiqlAst.CaseSensitivity.CaseSensitive, accumulator: T): T { - var current = accumulator - current = visitCaseSensitivityCaseSensitive(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkCaseSensitivityCaseInsensitive(node: PartiqlAst.CaseSensitivity.CaseInsensitive, accumulator: T): T { - var current = accumulator - current = visitCaseSensitivityCaseInsensitive(node, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: ScopeQualifier - ////////////////////////////////////// - open fun walkScopeQualifier(node: PartiqlAst.ScopeQualifier, accumulator: T): T { - val current = visitScopeQualifier(node, accumulator) - return when(node) { - is PartiqlAst.ScopeQualifier.Unqualified -> walkScopeQualifierUnqualified(node, current) - is PartiqlAst.ScopeQualifier.LocalsFirst -> walkScopeQualifierLocalsFirst(node, current) - } - } - - open fun walkScopeQualifierUnqualified(node: PartiqlAst.ScopeQualifier.Unqualified, accumulator: T): T { - var current = accumulator - current = visitScopeQualifierUnqualified(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkScopeQualifierLocalsFirst(node: PartiqlAst.ScopeQualifier.LocalsFirst, accumulator: T): T { - var current = accumulator - current = visitScopeQualifierLocalsFirst(node, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: SetQuantifier - ////////////////////////////////////// - open fun walkSetQuantifier(node: PartiqlAst.SetQuantifier, accumulator: T): T { - val current = visitSetQuantifier(node, accumulator) - return when(node) { - is PartiqlAst.SetQuantifier.All -> walkSetQuantifierAll(node, current) - is PartiqlAst.SetQuantifier.Distinct -> walkSetQuantifierDistinct(node, current) - } - } - - open fun walkSetQuantifierAll(node: PartiqlAst.SetQuantifier.All, accumulator: T): T { - var current = accumulator - current = visitSetQuantifierAll(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkSetQuantifierDistinct(node: PartiqlAst.SetQuantifier.Distinct, accumulator: T): T { - var current = accumulator - current = visitSetQuantifierDistinct(node, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: DmlOp - ////////////////////////////////////// - open fun walkDmlOp(node: PartiqlAst.DmlOp, accumulator: T): T { - val current = visitDmlOp(node, accumulator) - return when(node) { - is PartiqlAst.DmlOp.Insert -> walkDmlOpInsert(node, current) - is PartiqlAst.DmlOp.InsertValue -> walkDmlOpInsertValue(node, current) - is PartiqlAst.DmlOp.Set -> walkDmlOpSet(node, current) - is PartiqlAst.DmlOp.Remove -> walkDmlOpRemove(node, current) - is PartiqlAst.DmlOp.Delete -> walkDmlOpDelete(node, current) - } - } - - open fun walkDmlOpInsert(node: PartiqlAst.DmlOp.Insert, accumulator: T): T { - var current = accumulator - current = visitDmlOpInsert(node, current) - current = walkExpr(node.target, current) - current = walkExpr(node.values, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkDmlOpInsertValue(node: PartiqlAst.DmlOp.InsertValue, accumulator: T): T { - var current = accumulator - current = visitDmlOpInsertValue(node, current) - current = walkExpr(node.target, current) - current = walkExpr(node.value, current) - node.index?.let { current = walkExpr(it, current) } - node.onConflict?.let { current = walkOnConflict(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkDmlOpSet(node: PartiqlAst.DmlOp.Set, accumulator: T): T { - var current = accumulator - current = visitDmlOpSet(node, current) - current = walkAssignment(node.assignment, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkDmlOpRemove(node: PartiqlAst.DmlOp.Remove, accumulator: T): T { - var current = accumulator - current = visitDmlOpRemove(node, current) - current = walkExpr(node.target, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkDmlOpDelete(node: PartiqlAst.DmlOp.Delete, accumulator: T): T { - var current = accumulator - current = visitDmlOpDelete(node, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: ConflictAction - ////////////////////////////////////// - open fun walkConflictAction(node: PartiqlAst.ConflictAction, accumulator: T): T { - val current = visitConflictAction(node, accumulator) - return when(node) { - is PartiqlAst.ConflictAction.DoNothing -> walkConflictActionDoNothing(node, current) - } - } - - open fun walkConflictActionDoNothing(node: PartiqlAst.ConflictAction.DoNothing, accumulator: T): T { - var current = accumulator - current = visitConflictActionDoNothing(node, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: DdlOp - ////////////////////////////////////// - open fun walkDdlOp(node: PartiqlAst.DdlOp, accumulator: T): T { - val current = visitDdlOp(node, accumulator) - return when(node) { - is PartiqlAst.DdlOp.CreateTable -> walkDdlOpCreateTable(node, current) - is PartiqlAst.DdlOp.DropTable -> walkDdlOpDropTable(node, current) - is PartiqlAst.DdlOp.UndropTable -> walkDdlOpUndropTable(node, current) - is PartiqlAst.DdlOp.CreateIndex -> walkDdlOpCreateIndex(node, current) - is PartiqlAst.DdlOp.DropIndex -> walkDdlOpDropIndex(node, current) - } - } - - open fun walkDdlOpCreateTable(node: PartiqlAst.DdlOp.CreateTable, accumulator: T): T { - var current = accumulator - current = visitDdlOpCreateTable(node, current) - current = walkSymbolPrimitive(node.tableName, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkDdlOpDropTable(node: PartiqlAst.DdlOp.DropTable, accumulator: T): T { - var current = accumulator - current = visitDdlOpDropTable(node, current) - current = walkIdentifier(node.tableName, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkDdlOpUndropTable(node: PartiqlAst.DdlOp.UndropTable, accumulator: T): T { - var current = accumulator - current = visitDdlOpUndropTable(node, current) - current = walkSymbolPrimitive(node.tableName, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkDdlOpCreateIndex(node: PartiqlAst.DdlOp.CreateIndex, accumulator: T): T { - var current = accumulator - current = visitDdlOpCreateIndex(node, current) - current = walkIdentifier(node.indexName, current) - node.fields.map { current = walkExpr(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkDdlOpDropIndex(node: PartiqlAst.DdlOp.DropIndex, accumulator: T): T { - var current = accumulator - current = visitDdlOpDropIndex(node, current) - current = walkIdentifier(node.table, current) - current = walkIdentifier(node.keys, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: ColumnComponent - ////////////////////////////////////// - open fun walkColumnComponent(node: PartiqlAst.ColumnComponent, accumulator: T): T { - val current = visitColumnComponent(node, accumulator) - return when(node) { - is PartiqlAst.ColumnComponent.ReturningWildcard -> walkColumnComponentReturningWildcard(node, current) - is PartiqlAst.ColumnComponent.ReturningColumn -> walkColumnComponentReturningColumn(node, current) - } - } - - open fun walkColumnComponentReturningWildcard(node: PartiqlAst.ColumnComponent.ReturningWildcard, accumulator: T): T { - var current = accumulator - current = visitColumnComponentReturningWildcard(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkColumnComponentReturningColumn(node: PartiqlAst.ColumnComponent.ReturningColumn, accumulator: T): T { - var current = accumulator - current = visitColumnComponentReturningColumn(node, current) - current = walkExpr(node.expr, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: ReturningMapping - ////////////////////////////////////// - open fun walkReturningMapping(node: PartiqlAst.ReturningMapping, accumulator: T): T { - val current = visitReturningMapping(node, accumulator) - return when(node) { - is PartiqlAst.ReturningMapping.ModifiedNew -> walkReturningMappingModifiedNew(node, current) - is PartiqlAst.ReturningMapping.ModifiedOld -> walkReturningMappingModifiedOld(node, current) - is PartiqlAst.ReturningMapping.AllNew -> walkReturningMappingAllNew(node, current) - is PartiqlAst.ReturningMapping.AllOld -> walkReturningMappingAllOld(node, current) - } - } - - open fun walkReturningMappingModifiedNew(node: PartiqlAst.ReturningMapping.ModifiedNew, accumulator: T): T { - var current = accumulator - current = visitReturningMappingModifiedNew(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkReturningMappingModifiedOld(node: PartiqlAst.ReturningMapping.ModifiedOld, accumulator: T): T { - var current = accumulator - current = visitReturningMappingModifiedOld(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkReturningMappingAllNew(node: PartiqlAst.ReturningMapping.AllNew, accumulator: T): T { - var current = accumulator - current = visitReturningMappingAllNew(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkReturningMappingAllOld(node: PartiqlAst.ReturningMapping.AllOld, accumulator: T): T { - var current = accumulator - current = visitReturningMappingAllOld(node, current) - current = walkMetas(node.metas, current) - return current - } - - ////////////////////////////////////// - // Sum Type: Type - ////////////////////////////////////// - open fun walkType(node: PartiqlAst.Type, accumulator: T): T { - val current = visitType(node, accumulator) - return when(node) { - is PartiqlAst.Type.NullType -> walkTypeNullType(node, current) - is PartiqlAst.Type.BooleanType -> walkTypeBooleanType(node, current) - is PartiqlAst.Type.SmallintType -> walkTypeSmallintType(node, current) - is PartiqlAst.Type.Integer4Type -> walkTypeInteger4Type(node, current) - is PartiqlAst.Type.Integer8Type -> walkTypeInteger8Type(node, current) - is PartiqlAst.Type.IntegerType -> walkTypeIntegerType(node, current) - is PartiqlAst.Type.FloatType -> walkTypeFloatType(node, current) - is PartiqlAst.Type.RealType -> walkTypeRealType(node, current) - is PartiqlAst.Type.DoublePrecisionType -> walkTypeDoublePrecisionType(node, current) - is PartiqlAst.Type.DecimalType -> walkTypeDecimalType(node, current) - is PartiqlAst.Type.NumericType -> walkTypeNumericType(node, current) - is PartiqlAst.Type.TimestampType -> walkTypeTimestampType(node, current) - is PartiqlAst.Type.CharacterType -> walkTypeCharacterType(node, current) - is PartiqlAst.Type.CharacterVaryingType -> walkTypeCharacterVaryingType(node, current) - is PartiqlAst.Type.MissingType -> walkTypeMissingType(node, current) - is PartiqlAst.Type.StringType -> walkTypeStringType(node, current) - is PartiqlAst.Type.SymbolType -> walkTypeSymbolType(node, current) - is PartiqlAst.Type.BlobType -> walkTypeBlobType(node, current) - is PartiqlAst.Type.ClobType -> walkTypeClobType(node, current) - is PartiqlAst.Type.DateType -> walkTypeDateType(node, current) - is PartiqlAst.Type.TimeType -> walkTypeTimeType(node, current) - is PartiqlAst.Type.TimeWithTimeZoneType -> walkTypeTimeWithTimeZoneType(node, current) - is PartiqlAst.Type.StructType -> walkTypeStructType(node, current) - is PartiqlAst.Type.TupleType -> walkTypeTupleType(node, current) - is PartiqlAst.Type.ListType -> walkTypeListType(node, current) - is PartiqlAst.Type.SexpType -> walkTypeSexpType(node, current) - is PartiqlAst.Type.BagType -> walkTypeBagType(node, current) - is PartiqlAst.Type.AnyType -> walkTypeAnyType(node, current) - is PartiqlAst.Type.EsBoolean -> walkTypeEsBoolean(node, current) - is PartiqlAst.Type.EsInteger -> walkTypeEsInteger(node, current) - is PartiqlAst.Type.EsFloat -> walkTypeEsFloat(node, current) - is PartiqlAst.Type.EsText -> walkTypeEsText(node, current) - is PartiqlAst.Type.EsAny -> walkTypeEsAny(node, current) - is PartiqlAst.Type.SparkShort -> walkTypeSparkShort(node, current) - is PartiqlAst.Type.SparkInteger -> walkTypeSparkInteger(node, current) - is PartiqlAst.Type.SparkLong -> walkTypeSparkLong(node, current) - is PartiqlAst.Type.SparkDouble -> walkTypeSparkDouble(node, current) - is PartiqlAst.Type.SparkBoolean -> walkTypeSparkBoolean(node, current) - is PartiqlAst.Type.SparkFloat -> walkTypeSparkFloat(node, current) - is PartiqlAst.Type.RsVarcharMax -> walkTypeRsVarcharMax(node, current) - is PartiqlAst.Type.RsInteger -> walkTypeRsInteger(node, current) - is PartiqlAst.Type.RsBigint -> walkTypeRsBigint(node, current) - is PartiqlAst.Type.RsBoolean -> walkTypeRsBoolean(node, current) - is PartiqlAst.Type.RsReal -> walkTypeRsReal(node, current) - is PartiqlAst.Type.RsDoublePrecision -> walkTypeRsDoublePrecision(node, current) - is PartiqlAst.Type.CustomType -> walkTypeCustomType(node, current) - } - } - - open fun walkTypeNullType(node: PartiqlAst.Type.NullType, accumulator: T): T { - var current = accumulator - current = visitTypeNullType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeBooleanType(node: PartiqlAst.Type.BooleanType, accumulator: T): T { - var current = accumulator - current = visitTypeBooleanType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeSmallintType(node: PartiqlAst.Type.SmallintType, accumulator: T): T { - var current = accumulator - current = visitTypeSmallintType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeInteger4Type(node: PartiqlAst.Type.Integer4Type, accumulator: T): T { - var current = accumulator - current = visitTypeInteger4Type(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeInteger8Type(node: PartiqlAst.Type.Integer8Type, accumulator: T): T { - var current = accumulator - current = visitTypeInteger8Type(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeIntegerType(node: PartiqlAst.Type.IntegerType, accumulator: T): T { - var current = accumulator - current = visitTypeIntegerType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeFloatType(node: PartiqlAst.Type.FloatType, accumulator: T): T { - var current = accumulator - current = visitTypeFloatType(node, current) - node.precision?.let { current = walkLongPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeRealType(node: PartiqlAst.Type.RealType, accumulator: T): T { - var current = accumulator - current = visitTypeRealType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeDoublePrecisionType(node: PartiqlAst.Type.DoublePrecisionType, accumulator: T): T { - var current = accumulator - current = visitTypeDoublePrecisionType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeDecimalType(node: PartiqlAst.Type.DecimalType, accumulator: T): T { - var current = accumulator - current = visitTypeDecimalType(node, current) - node.precision?.let { current = walkLongPrimitive(it, current) } - node.scale?.let { current = walkLongPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeNumericType(node: PartiqlAst.Type.NumericType, accumulator: T): T { - var current = accumulator - current = visitTypeNumericType(node, current) - node.precision?.let { current = walkLongPrimitive(it, current) } - node.scale?.let { current = walkLongPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeTimestampType(node: PartiqlAst.Type.TimestampType, accumulator: T): T { - var current = accumulator - current = visitTypeTimestampType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeCharacterType(node: PartiqlAst.Type.CharacterType, accumulator: T): T { - var current = accumulator - current = visitTypeCharacterType(node, current) - node.length?.let { current = walkLongPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeCharacterVaryingType(node: PartiqlAst.Type.CharacterVaryingType, accumulator: T): T { - var current = accumulator - current = visitTypeCharacterVaryingType(node, current) - node.length?.let { current = walkLongPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeMissingType(node: PartiqlAst.Type.MissingType, accumulator: T): T { - var current = accumulator - current = visitTypeMissingType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeStringType(node: PartiqlAst.Type.StringType, accumulator: T): T { - var current = accumulator - current = visitTypeStringType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeSymbolType(node: PartiqlAst.Type.SymbolType, accumulator: T): T { - var current = accumulator - current = visitTypeSymbolType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeBlobType(node: PartiqlAst.Type.BlobType, accumulator: T): T { - var current = accumulator - current = visitTypeBlobType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeClobType(node: PartiqlAst.Type.ClobType, accumulator: T): T { - var current = accumulator - current = visitTypeClobType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeDateType(node: PartiqlAst.Type.DateType, accumulator: T): T { - var current = accumulator - current = visitTypeDateType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeTimeType(node: PartiqlAst.Type.TimeType, accumulator: T): T { - var current = accumulator - current = visitTypeTimeType(node, current) - node.precision?.let { current = walkLongPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeTimeWithTimeZoneType(node: PartiqlAst.Type.TimeWithTimeZoneType, accumulator: T): T { - var current = accumulator - current = visitTypeTimeWithTimeZoneType(node, current) - node.precision?.let { current = walkLongPrimitive(it, current) } - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeStructType(node: PartiqlAst.Type.StructType, accumulator: T): T { - var current = accumulator - current = visitTypeStructType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeTupleType(node: PartiqlAst.Type.TupleType, accumulator: T): T { - var current = accumulator - current = visitTypeTupleType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeListType(node: PartiqlAst.Type.ListType, accumulator: T): T { - var current = accumulator - current = visitTypeListType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeSexpType(node: PartiqlAst.Type.SexpType, accumulator: T): T { - var current = accumulator - current = visitTypeSexpType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeBagType(node: PartiqlAst.Type.BagType, accumulator: T): T { - var current = accumulator - current = visitTypeBagType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeAnyType(node: PartiqlAst.Type.AnyType, accumulator: T): T { - var current = accumulator - current = visitTypeAnyType(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeEsBoolean(node: PartiqlAst.Type.EsBoolean, accumulator: T): T { - var current = accumulator - current = visitTypeEsBoolean(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeEsInteger(node: PartiqlAst.Type.EsInteger, accumulator: T): T { - var current = accumulator - current = visitTypeEsInteger(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeEsFloat(node: PartiqlAst.Type.EsFloat, accumulator: T): T { - var current = accumulator - current = visitTypeEsFloat(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeEsText(node: PartiqlAst.Type.EsText, accumulator: T): T { - var current = accumulator - current = visitTypeEsText(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeEsAny(node: PartiqlAst.Type.EsAny, accumulator: T): T { - var current = accumulator - current = visitTypeEsAny(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeSparkShort(node: PartiqlAst.Type.SparkShort, accumulator: T): T { - var current = accumulator - current = visitTypeSparkShort(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeSparkInteger(node: PartiqlAst.Type.SparkInteger, accumulator: T): T { - var current = accumulator - current = visitTypeSparkInteger(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeSparkLong(node: PartiqlAst.Type.SparkLong, accumulator: T): T { - var current = accumulator - current = visitTypeSparkLong(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeSparkDouble(node: PartiqlAst.Type.SparkDouble, accumulator: T): T { - var current = accumulator - current = visitTypeSparkDouble(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeSparkBoolean(node: PartiqlAst.Type.SparkBoolean, accumulator: T): T { - var current = accumulator - current = visitTypeSparkBoolean(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeSparkFloat(node: PartiqlAst.Type.SparkFloat, accumulator: T): T { - var current = accumulator - current = visitTypeSparkFloat(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeRsVarcharMax(node: PartiqlAst.Type.RsVarcharMax, accumulator: T): T { - var current = accumulator - current = visitTypeRsVarcharMax(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeRsInteger(node: PartiqlAst.Type.RsInteger, accumulator: T): T { - var current = accumulator - current = visitTypeRsInteger(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeRsBigint(node: PartiqlAst.Type.RsBigint, accumulator: T): T { - var current = accumulator - current = visitTypeRsBigint(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeRsBoolean(node: PartiqlAst.Type.RsBoolean, accumulator: T): T { - var current = accumulator - current = visitTypeRsBoolean(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeRsReal(node: PartiqlAst.Type.RsReal, accumulator: T): T { - var current = accumulator - current = visitTypeRsReal(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeRsDoublePrecision(node: PartiqlAst.Type.RsDoublePrecision, accumulator: T): T { - var current = accumulator - current = visitTypeRsDoublePrecision(node, current) - current = walkMetas(node.metas, current) - return current - } - - open fun walkTypeCustomType(node: PartiqlAst.Type.CustomType, accumulator: T): T { - var current = accumulator - current = visitTypeCustomType(node, current) - current = walkSymbolPrimitive(node.name, current) - current = walkMetas(node.metas, current) - return current - } - - } - abstract class VisitorTransform : DomainVisitorTransformBase() { - ////////////////////////////////////// - // Tuple Types - ////////////////////////////////////// - // Tuple TimeValue - open fun transformTimeValue(node: PartiqlAst.TimeValue): PartiqlAst.TimeValue { - val new_hour = transformTimeValue_hour(node) - val new_minute = transformTimeValue_minute(node) - val new_second = transformTimeValue_second(node) - val new_nano = transformTimeValue_nano(node) - val new_precision = transformTimeValue_precision(node) - val new_tzMinutes = transformTimeValue_tzMinutes(node) - val new_metas = transformTimeValue_metas(node) - return if ( - node.hour !== new_hour || - node.minute !== new_minute || - node.second !== new_second || - node.nano !== new_nano || - node.precision !== new_precision || - node.tzMinutes !== new_tzMinutes || - node.metas !== new_metas - ) { - PartiqlAst.TimeValue( - hour = new_hour, - minute = new_minute, - second = new_second, - nano = new_nano, - precision = new_precision, - tzMinutes = new_tzMinutes, - metas = new_metas - ) - } else { - node - } - } - open fun transformTimeValue_hour(node: PartiqlAst.TimeValue) = - transformLongPrimitive(node.hour) - open fun transformTimeValue_minute(node: PartiqlAst.TimeValue) = - transformLongPrimitive(node.minute) - open fun transformTimeValue_second(node: PartiqlAst.TimeValue) = - transformLongPrimitive(node.second) - open fun transformTimeValue_nano(node: PartiqlAst.TimeValue) = - transformLongPrimitive(node.nano) - open fun transformTimeValue_precision(node: PartiqlAst.TimeValue) = - transformLongPrimitive(node.precision) - open fun transformTimeValue_tzMinutes(node: PartiqlAst.TimeValue) = - node.tzMinutes?.let { transformLongPrimitive(it) } - open fun transformTimeValue_metas(node: PartiqlAst.TimeValue) = - transformMetas(node.metas) - - // Tuple Let - open fun transformLet(node: PartiqlAst.Let): PartiqlAst.Let { - val new_letBindings = transformLet_letBindings(node) - val new_metas = transformLet_metas(node) - return if ( - node.letBindings !== new_letBindings || - node.metas !== new_metas - ) { - PartiqlAst.Let( - letBindings = new_letBindings, - metas = new_metas - ) - } else { - node - } - } - open fun transformLet_letBindings(node: PartiqlAst.Let) = - node.letBindings.map { transformLetBinding(it) } - open fun transformLet_metas(node: PartiqlAst.Let) = - transformMetas(node.metas) - - // Tuple LetBinding - open fun transformLetBinding(node: PartiqlAst.LetBinding): PartiqlAst.LetBinding { - val new_expr = transformLetBinding_expr(node) - val new_name = transformLetBinding_name(node) - val new_metas = transformLetBinding_metas(node) - return if ( - node.expr !== new_expr || - node.name !== new_name || - node.metas !== new_metas - ) { - PartiqlAst.LetBinding( - expr = new_expr, - name = new_name, - metas = new_metas - ) - } else { - node - } - } - open fun transformLetBinding_expr(node: PartiqlAst.LetBinding) = - transformExpr(node.expr) - open fun transformLetBinding_name(node: PartiqlAst.LetBinding) = - transformSymbolPrimitive(node.name) - open fun transformLetBinding_metas(node: PartiqlAst.LetBinding) = - transformMetas(node.metas) - - // Tuple ExprPair - open fun transformExprPair(node: PartiqlAst.ExprPair): PartiqlAst.ExprPair { - val new_first = transformExprPair_first(node) - val new_second = transformExprPair_second(node) - val new_metas = transformExprPair_metas(node) - return if ( - node.first !== new_first || - node.second !== new_second || - node.metas !== new_metas - ) { - PartiqlAst.ExprPair( - first = new_first, - second = new_second, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprPair_first(node: PartiqlAst.ExprPair) = - transformExpr(node.first) - open fun transformExprPair_second(node: PartiqlAst.ExprPair) = - transformExpr(node.second) - open fun transformExprPair_metas(node: PartiqlAst.ExprPair) = - transformMetas(node.metas) - - // Tuple ExprPairList - open fun transformExprPairList(node: PartiqlAst.ExprPairList): PartiqlAst.ExprPairList { - val new_pairs = transformExprPairList_pairs(node) - val new_metas = transformExprPairList_metas(node) - return if ( - node.pairs !== new_pairs || - node.metas !== new_metas - ) { - PartiqlAst.ExprPairList( - pairs = new_pairs, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprPairList_pairs(node: PartiqlAst.ExprPairList) = - node.pairs.map { transformExprPair(it) } - open fun transformExprPairList_metas(node: PartiqlAst.ExprPairList) = - transformMetas(node.metas) - - // Tuple GroupBy - open fun transformGroupBy(node: PartiqlAst.GroupBy): PartiqlAst.GroupBy { - val new_strategy = transformGroupBy_strategy(node) - val new_keyList = transformGroupBy_keyList(node) - val new_groupAsAlias = transformGroupBy_groupAsAlias(node) - val new_metas = transformGroupBy_metas(node) - return if ( - node.strategy !== new_strategy || - node.keyList !== new_keyList || - node.groupAsAlias !== new_groupAsAlias || - node.metas !== new_metas - ) { - PartiqlAst.GroupBy( - strategy = new_strategy, - keyList = new_keyList, - groupAsAlias = new_groupAsAlias, - metas = new_metas - ) - } else { - node - } - } - open fun transformGroupBy_strategy(node: PartiqlAst.GroupBy) = - transformGroupingStrategy(node.strategy) - open fun transformGroupBy_keyList(node: PartiqlAst.GroupBy) = - transformGroupKeyList(node.keyList) - open fun transformGroupBy_groupAsAlias(node: PartiqlAst.GroupBy) = - node.groupAsAlias?.let { transformSymbolPrimitive(it) } - open fun transformGroupBy_metas(node: PartiqlAst.GroupBy) = - transformMetas(node.metas) - - // Tuple GroupKeyList - open fun transformGroupKeyList(node: PartiqlAst.GroupKeyList): PartiqlAst.GroupKeyList { - val new_keys = transformGroupKeyList_keys(node) - val new_metas = transformGroupKeyList_metas(node) - return if ( - node.keys !== new_keys || - node.metas !== new_metas - ) { - PartiqlAst.GroupKeyList( - keys = new_keys, - metas = new_metas - ) - } else { - node - } - } - open fun transformGroupKeyList_keys(node: PartiqlAst.GroupKeyList) = - node.keys.map { transformGroupKey(it) } - open fun transformGroupKeyList_metas(node: PartiqlAst.GroupKeyList) = - transformMetas(node.metas) - - // Tuple GroupKey - open fun transformGroupKey(node: PartiqlAst.GroupKey): PartiqlAst.GroupKey { - val new_expr = transformGroupKey_expr(node) - val new_asAlias = transformGroupKey_asAlias(node) - val new_metas = transformGroupKey_metas(node) - return if ( - node.expr !== new_expr || - node.asAlias !== new_asAlias || - node.metas !== new_metas - ) { - PartiqlAst.GroupKey( - expr = new_expr, - asAlias = new_asAlias, - metas = new_metas - ) - } else { - node - } - } - open fun transformGroupKey_expr(node: PartiqlAst.GroupKey) = - transformExpr(node.expr) - open fun transformGroupKey_asAlias(node: PartiqlAst.GroupKey) = - node.asAlias?.let { transformSymbolPrimitive(it) } - open fun transformGroupKey_metas(node: PartiqlAst.GroupKey) = - transformMetas(node.metas) - - // Tuple OrderBy - open fun transformOrderBy(node: PartiqlAst.OrderBy): PartiqlAst.OrderBy { - val new_sortSpecs = transformOrderBy_sortSpecs(node) - val new_metas = transformOrderBy_metas(node) - return if ( - node.sortSpecs !== new_sortSpecs || - node.metas !== new_metas - ) { - PartiqlAst.OrderBy( - sortSpecs = new_sortSpecs, - metas = new_metas - ) - } else { - node - } - } - open fun transformOrderBy_sortSpecs(node: PartiqlAst.OrderBy) = - node.sortSpecs.map { transformSortSpec(it) } - open fun transformOrderBy_metas(node: PartiqlAst.OrderBy) = - transformMetas(node.metas) - - // Tuple SortSpec - open fun transformSortSpec(node: PartiqlAst.SortSpec): PartiqlAst.SortSpec { - val new_expr = transformSortSpec_expr(node) - val new_orderingSpec = transformSortSpec_orderingSpec(node) - val new_metas = transformSortSpec_metas(node) - return if ( - node.expr !== new_expr || - node.orderingSpec !== new_orderingSpec || - node.metas !== new_metas - ) { - PartiqlAst.SortSpec( - expr = new_expr, - orderingSpec = new_orderingSpec, - metas = new_metas - ) - } else { - node - } - } - open fun transformSortSpec_expr(node: PartiqlAst.SortSpec) = - transformExpr(node.expr) - open fun transformSortSpec_orderingSpec(node: PartiqlAst.SortSpec) = - node.orderingSpec?.let { transformOrderingSpec(it) } - open fun transformSortSpec_metas(node: PartiqlAst.SortSpec) = - transformMetas(node.metas) - - // Tuple DmlOpList - open fun transformDmlOpList(node: PartiqlAst.DmlOpList): PartiqlAst.DmlOpList { - val new_ops = transformDmlOpList_ops(node) - val new_metas = transformDmlOpList_metas(node) - return if ( - node.ops !== new_ops || - node.metas !== new_metas - ) { - PartiqlAst.DmlOpList( - ops = new_ops, - metas = new_metas - ) - } else { - node - } - } - open fun transformDmlOpList_ops(node: PartiqlAst.DmlOpList) = - node.ops.map { transformDmlOp(it) } - open fun transformDmlOpList_metas(node: PartiqlAst.DmlOpList) = - transformMetas(node.metas) - - // Tuple OnConflict - open fun transformOnConflict(node: PartiqlAst.OnConflict): PartiqlAst.OnConflict { - val new_expr = transformOnConflict_expr(node) - val new_conflictAction = transformOnConflict_conflictAction(node) - val new_metas = transformOnConflict_metas(node) - return if ( - node.expr !== new_expr || - node.conflictAction !== new_conflictAction || - node.metas !== new_metas - ) { - PartiqlAst.OnConflict( - expr = new_expr, - conflictAction = new_conflictAction, - metas = new_metas - ) - } else { - node - } - } - open fun transformOnConflict_expr(node: PartiqlAst.OnConflict) = - transformExpr(node.expr) - open fun transformOnConflict_conflictAction(node: PartiqlAst.OnConflict) = - transformConflictAction(node.conflictAction) - open fun transformOnConflict_metas(node: PartiqlAst.OnConflict) = - transformMetas(node.metas) - - // Tuple ReturningExpr - open fun transformReturningExpr(node: PartiqlAst.ReturningExpr): PartiqlAst.ReturningExpr { - val new_elems = transformReturningExpr_elems(node) - val new_metas = transformReturningExpr_metas(node) - return if ( - node.elems !== new_elems || - node.metas !== new_metas - ) { - PartiqlAst.ReturningExpr( - elems = new_elems, - metas = new_metas - ) - } else { - node - } - } - open fun transformReturningExpr_elems(node: PartiqlAst.ReturningExpr) = - node.elems.map { transformReturningElem(it) } - open fun transformReturningExpr_metas(node: PartiqlAst.ReturningExpr) = - transformMetas(node.metas) - - // Tuple ReturningElem - open fun transformReturningElem(node: PartiqlAst.ReturningElem): PartiqlAst.ReturningElem { - val new_mapping = transformReturningElem_mapping(node) - val new_column = transformReturningElem_column(node) - val new_metas = transformReturningElem_metas(node) - return if ( - node.mapping !== new_mapping || - node.column !== new_column || - node.metas !== new_metas - ) { - PartiqlAst.ReturningElem( - mapping = new_mapping, - column = new_column, - metas = new_metas - ) - } else { - node - } - } - open fun transformReturningElem_mapping(node: PartiqlAst.ReturningElem) = - transformReturningMapping(node.mapping) - open fun transformReturningElem_column(node: PartiqlAst.ReturningElem) = - transformColumnComponent(node.column) - open fun transformReturningElem_metas(node: PartiqlAst.ReturningElem) = - transformMetas(node.metas) - - // Tuple Identifier - open fun transformIdentifier(node: PartiqlAst.Identifier): PartiqlAst.Identifier { - val new_name = transformIdentifier_name(node) - val new_case = transformIdentifier_case(node) - val new_metas = transformIdentifier_metas(node) - return if ( - node.name !== new_name || - node.case !== new_case || - node.metas !== new_metas - ) { - PartiqlAst.Identifier( - name = new_name, - case = new_case, - metas = new_metas - ) - } else { - node - } - } - open fun transformIdentifier_name(node: PartiqlAst.Identifier) = - transformSymbolPrimitive(node.name) - open fun transformIdentifier_case(node: PartiqlAst.Identifier) = - transformCaseSensitivity(node.case) - open fun transformIdentifier_metas(node: PartiqlAst.Identifier) = - transformMetas(node.metas) - - // Tuple Assignment - open fun transformAssignment(node: PartiqlAst.Assignment): PartiqlAst.Assignment { - val new_target = transformAssignment_target(node) - val new_value = transformAssignment_value(node) - val new_metas = transformAssignment_metas(node) - return if ( - node.target !== new_target || - node.value !== new_value || - node.metas !== new_metas - ) { - PartiqlAst.Assignment( - target = new_target, - value = new_value, - metas = new_metas - ) - } else { - node - } - } - open fun transformAssignment_target(node: PartiqlAst.Assignment) = - transformExpr(node.target) - open fun transformAssignment_value(node: PartiqlAst.Assignment) = - transformExpr(node.value) - open fun transformAssignment_metas(node: PartiqlAst.Assignment) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: Statement - ////////////////////////////////////// - open fun transformStatement(node: PartiqlAst.Statement): PartiqlAst.Statement = - when(node) { - is PartiqlAst.Statement.Query -> transformStatementQuery(node) - is PartiqlAst.Statement.Dml -> transformStatementDml(node) - is PartiqlAst.Statement.Ddl -> transformStatementDdl(node) - is PartiqlAst.Statement.Exec -> transformStatementExec(node) - } - // Variant StatementQuery - open fun transformStatementQuery(node: PartiqlAst.Statement.Query): PartiqlAst.Statement { - val new_expr = transformStatementQuery_expr(node) - val new_metas = transformStatementQuery_metas(node) - return if ( - node.expr !== new_expr || - node.metas !== new_metas - ) { - PartiqlAst.Statement.Query( - expr = new_expr, - metas = new_metas - ) - } else { - node - } - } - open fun transformStatementQuery_expr(node: PartiqlAst.Statement.Query) = - transformExpr(node.expr) - open fun transformStatementQuery_metas(node: PartiqlAst.Statement.Query) = - transformMetas(node.metas) - - // Variant StatementDml - open fun transformStatementDml(node: PartiqlAst.Statement.Dml): PartiqlAst.Statement { - val new_operations = transformStatementDml_operations(node) - val new_from = transformStatementDml_from(node) - val new_where = transformStatementDml_where(node) - val new_returning = transformStatementDml_returning(node) - val new_metas = transformStatementDml_metas(node) - return if ( - node.operations !== new_operations || - node.from !== new_from || - node.where !== new_where || - node.returning !== new_returning || - node.metas !== new_metas - ) { - PartiqlAst.Statement.Dml( - operations = new_operations, - from = new_from, - where = new_where, - returning = new_returning, - metas = new_metas - ) - } else { - node - } - } - open fun transformStatementDml_operations(node: PartiqlAst.Statement.Dml) = - transformDmlOpList(node.operations) - open fun transformStatementDml_from(node: PartiqlAst.Statement.Dml) = - node.from?.let { transformFromSource(it) } - open fun transformStatementDml_where(node: PartiqlAst.Statement.Dml) = - node.where?.let { transformExpr(it) } - open fun transformStatementDml_returning(node: PartiqlAst.Statement.Dml) = - node.returning?.let { transformReturningExpr(it) } - open fun transformStatementDml_metas(node: PartiqlAst.Statement.Dml) = - transformMetas(node.metas) - - // Variant StatementDdl - open fun transformStatementDdl(node: PartiqlAst.Statement.Ddl): PartiqlAst.Statement { - val new_op = transformStatementDdl_op(node) - val new_metas = transformStatementDdl_metas(node) - return if ( - node.op !== new_op || - node.metas !== new_metas - ) { - PartiqlAst.Statement.Ddl( - op = new_op, - metas = new_metas - ) - } else { - node - } - } - open fun transformStatementDdl_op(node: PartiqlAst.Statement.Ddl) = - transformDdlOp(node.op) - open fun transformStatementDdl_metas(node: PartiqlAst.Statement.Ddl) = - transformMetas(node.metas) - - // Variant StatementExec - open fun transformStatementExec(node: PartiqlAst.Statement.Exec): PartiqlAst.Statement { - val new_procedureName = transformStatementExec_procedureName(node) - val new_args = transformStatementExec_args(node) - val new_metas = transformStatementExec_metas(node) - return if ( - node.procedureName !== new_procedureName || - node.args !== new_args || - node.metas !== new_metas - ) { - PartiqlAst.Statement.Exec( - procedureName = new_procedureName, - args = new_args, - metas = new_metas - ) - } else { - node - } - } - open fun transformStatementExec_procedureName(node: PartiqlAst.Statement.Exec) = - transformSymbolPrimitive(node.procedureName) - open fun transformStatementExec_args(node: PartiqlAst.Statement.Exec) = - node.args.map { transformExpr(it) } - open fun transformStatementExec_metas(node: PartiqlAst.Statement.Exec) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: Expr - ////////////////////////////////////// - open fun transformExpr(node: PartiqlAst.Expr): PartiqlAst.Expr = - when(node) { - is PartiqlAst.Expr.Missing -> transformExprMissing(node) - is PartiqlAst.Expr.Lit -> transformExprLit(node) - is PartiqlAst.Expr.Id -> transformExprId(node) - is PartiqlAst.Expr.Parameter -> transformExprParameter(node) - is PartiqlAst.Expr.Not -> transformExprNot(node) - is PartiqlAst.Expr.Pos -> transformExprPos(node) - is PartiqlAst.Expr.Neg -> transformExprNeg(node) - is PartiqlAst.Expr.Plus -> transformExprPlus(node) - is PartiqlAst.Expr.Minus -> transformExprMinus(node) - is PartiqlAst.Expr.Times -> transformExprTimes(node) - is PartiqlAst.Expr.Divide -> transformExprDivide(node) - is PartiqlAst.Expr.Modulo -> transformExprModulo(node) - is PartiqlAst.Expr.Concat -> transformExprConcat(node) - is PartiqlAst.Expr.And -> transformExprAnd(node) - is PartiqlAst.Expr.Or -> transformExprOr(node) - is PartiqlAst.Expr.Eq -> transformExprEq(node) - is PartiqlAst.Expr.Ne -> transformExprNe(node) - is PartiqlAst.Expr.Gt -> transformExprGt(node) - is PartiqlAst.Expr.Gte -> transformExprGte(node) - is PartiqlAst.Expr.Lt -> transformExprLt(node) - is PartiqlAst.Expr.Lte -> transformExprLte(node) - is PartiqlAst.Expr.Like -> transformExprLike(node) - is PartiqlAst.Expr.Between -> transformExprBetween(node) - is PartiqlAst.Expr.InCollection -> transformExprInCollection(node) - is PartiqlAst.Expr.IsType -> transformExprIsType(node) - is PartiqlAst.Expr.SimpleCase -> transformExprSimpleCase(node) - is PartiqlAst.Expr.SearchedCase -> transformExprSearchedCase(node) - is PartiqlAst.Expr.Struct -> transformExprStruct(node) - is PartiqlAst.Expr.Bag -> transformExprBag(node) - is PartiqlAst.Expr.List -> transformExprList(node) - is PartiqlAst.Expr.Sexp -> transformExprSexp(node) - is PartiqlAst.Expr.Date -> transformExprDate(node) - is PartiqlAst.Expr.LitTime -> transformExprLitTime(node) - is PartiqlAst.Expr.Union -> transformExprUnion(node) - is PartiqlAst.Expr.Except -> transformExprExcept(node) - is PartiqlAst.Expr.Intersect -> transformExprIntersect(node) - is PartiqlAst.Expr.Path -> transformExprPath(node) - is PartiqlAst.Expr.Call -> transformExprCall(node) - is PartiqlAst.Expr.CallAgg -> transformExprCallAgg(node) - is PartiqlAst.Expr.Cast -> transformExprCast(node) - is PartiqlAst.Expr.CanCast -> transformExprCanCast(node) - is PartiqlAst.Expr.CanLosslessCast -> transformExprCanLosslessCast(node) - is PartiqlAst.Expr.NullIf -> transformExprNullIf(node) - is PartiqlAst.Expr.Coalesce -> transformExprCoalesce(node) - is PartiqlAst.Expr.Select -> transformExprSelect(node) - } - // Variant ExprMissing - open fun transformExprMissing(node: PartiqlAst.Expr.Missing): PartiqlAst.Expr { - val new_metas = transformExprMissing_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Expr.Missing( - metas = new_metas - ) - } else { - node - } - } - open fun transformExprMissing_metas(node: PartiqlAst.Expr.Missing) = - transformMetas(node.metas) - - // Variant ExprLit - open fun transformExprLit(node: PartiqlAst.Expr.Lit): PartiqlAst.Expr { - val new_value = transformExprLit_value(node) - val new_metas = transformExprLit_metas(node) - return if ( - node.value !== new_value || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Lit( - value = new_value, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprLit_value(node: PartiqlAst.Expr.Lit) = - transformAnyElement(node.value) - open fun transformExprLit_metas(node: PartiqlAst.Expr.Lit) = - transformMetas(node.metas) - - // Variant ExprId - open fun transformExprId(node: PartiqlAst.Expr.Id): PartiqlAst.Expr { - val new_name = transformExprId_name(node) - val new_case = transformExprId_case(node) - val new_qualifier = transformExprId_qualifier(node) - val new_metas = transformExprId_metas(node) - return if ( - node.name !== new_name || - node.case !== new_case || - node.qualifier !== new_qualifier || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Id( - name = new_name, - case = new_case, - qualifier = new_qualifier, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprId_name(node: PartiqlAst.Expr.Id) = - transformSymbolPrimitive(node.name) - open fun transformExprId_case(node: PartiqlAst.Expr.Id) = - transformCaseSensitivity(node.case) - open fun transformExprId_qualifier(node: PartiqlAst.Expr.Id) = - transformScopeQualifier(node.qualifier) - open fun transformExprId_metas(node: PartiqlAst.Expr.Id) = - transformMetas(node.metas) - - // Variant ExprParameter - open fun transformExprParameter(node: PartiqlAst.Expr.Parameter): PartiqlAst.Expr { - val new_index = transformExprParameter_index(node) - val new_metas = transformExprParameter_metas(node) - return if ( - node.index !== new_index || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Parameter( - index = new_index, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprParameter_index(node: PartiqlAst.Expr.Parameter) = - transformLongPrimitive(node.index) - open fun transformExprParameter_metas(node: PartiqlAst.Expr.Parameter) = - transformMetas(node.metas) - - // Variant ExprNot - open fun transformExprNot(node: PartiqlAst.Expr.Not): PartiqlAst.Expr { - val new_expr = transformExprNot_expr(node) - val new_metas = transformExprNot_metas(node) - return if ( - node.expr !== new_expr || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Not( - expr = new_expr, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprNot_expr(node: PartiqlAst.Expr.Not) = - transformExpr(node.expr) - open fun transformExprNot_metas(node: PartiqlAst.Expr.Not) = - transformMetas(node.metas) - - // Variant ExprPos - open fun transformExprPos(node: PartiqlAst.Expr.Pos): PartiqlAst.Expr { - val new_expr = transformExprPos_expr(node) - val new_metas = transformExprPos_metas(node) - return if ( - node.expr !== new_expr || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Pos( - expr = new_expr, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprPos_expr(node: PartiqlAst.Expr.Pos) = - transformExpr(node.expr) - open fun transformExprPos_metas(node: PartiqlAst.Expr.Pos) = - transformMetas(node.metas) - - // Variant ExprNeg - open fun transformExprNeg(node: PartiqlAst.Expr.Neg): PartiqlAst.Expr { - val new_expr = transformExprNeg_expr(node) - val new_metas = transformExprNeg_metas(node) - return if ( - node.expr !== new_expr || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Neg( - expr = new_expr, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprNeg_expr(node: PartiqlAst.Expr.Neg) = - transformExpr(node.expr) - open fun transformExprNeg_metas(node: PartiqlAst.Expr.Neg) = - transformMetas(node.metas) - - // Variant ExprPlus - open fun transformExprPlus(node: PartiqlAst.Expr.Plus): PartiqlAst.Expr { - val new_operands = transformExprPlus_operands(node) - val new_metas = transformExprPlus_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Plus( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprPlus_operands(node: PartiqlAst.Expr.Plus) = - node.operands.map { transformExpr(it) } - open fun transformExprPlus_metas(node: PartiqlAst.Expr.Plus) = - transformMetas(node.metas) - - // Variant ExprMinus - open fun transformExprMinus(node: PartiqlAst.Expr.Minus): PartiqlAst.Expr { - val new_operands = transformExprMinus_operands(node) - val new_metas = transformExprMinus_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Minus( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprMinus_operands(node: PartiqlAst.Expr.Minus) = - node.operands.map { transformExpr(it) } - open fun transformExprMinus_metas(node: PartiqlAst.Expr.Minus) = - transformMetas(node.metas) - - // Variant ExprTimes - open fun transformExprTimes(node: PartiqlAst.Expr.Times): PartiqlAst.Expr { - val new_operands = transformExprTimes_operands(node) - val new_metas = transformExprTimes_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Times( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprTimes_operands(node: PartiqlAst.Expr.Times) = - node.operands.map { transformExpr(it) } - open fun transformExprTimes_metas(node: PartiqlAst.Expr.Times) = - transformMetas(node.metas) - - // Variant ExprDivide - open fun transformExprDivide(node: PartiqlAst.Expr.Divide): PartiqlAst.Expr { - val new_operands = transformExprDivide_operands(node) - val new_metas = transformExprDivide_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Divide( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprDivide_operands(node: PartiqlAst.Expr.Divide) = - node.operands.map { transformExpr(it) } - open fun transformExprDivide_metas(node: PartiqlAst.Expr.Divide) = - transformMetas(node.metas) - - // Variant ExprModulo - open fun transformExprModulo(node: PartiqlAst.Expr.Modulo): PartiqlAst.Expr { - val new_operands = transformExprModulo_operands(node) - val new_metas = transformExprModulo_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Modulo( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprModulo_operands(node: PartiqlAst.Expr.Modulo) = - node.operands.map { transformExpr(it) } - open fun transformExprModulo_metas(node: PartiqlAst.Expr.Modulo) = - transformMetas(node.metas) - - // Variant ExprConcat - open fun transformExprConcat(node: PartiqlAst.Expr.Concat): PartiqlAst.Expr { - val new_operands = transformExprConcat_operands(node) - val new_metas = transformExprConcat_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Concat( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprConcat_operands(node: PartiqlAst.Expr.Concat) = - node.operands.map { transformExpr(it) } - open fun transformExprConcat_metas(node: PartiqlAst.Expr.Concat) = - transformMetas(node.metas) - - // Variant ExprAnd - open fun transformExprAnd(node: PartiqlAst.Expr.And): PartiqlAst.Expr { - val new_operands = transformExprAnd_operands(node) - val new_metas = transformExprAnd_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.And( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprAnd_operands(node: PartiqlAst.Expr.And) = - node.operands.map { transformExpr(it) } - open fun transformExprAnd_metas(node: PartiqlAst.Expr.And) = - transformMetas(node.metas) - - // Variant ExprOr - open fun transformExprOr(node: PartiqlAst.Expr.Or): PartiqlAst.Expr { - val new_operands = transformExprOr_operands(node) - val new_metas = transformExprOr_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Or( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprOr_operands(node: PartiqlAst.Expr.Or) = - node.operands.map { transformExpr(it) } - open fun transformExprOr_metas(node: PartiqlAst.Expr.Or) = - transformMetas(node.metas) - - // Variant ExprEq - open fun transformExprEq(node: PartiqlAst.Expr.Eq): PartiqlAst.Expr { - val new_operands = transformExprEq_operands(node) - val new_metas = transformExprEq_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Eq( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprEq_operands(node: PartiqlAst.Expr.Eq) = - node.operands.map { transformExpr(it) } - open fun transformExprEq_metas(node: PartiqlAst.Expr.Eq) = - transformMetas(node.metas) - - // Variant ExprNe - open fun transformExprNe(node: PartiqlAst.Expr.Ne): PartiqlAst.Expr { - val new_operands = transformExprNe_operands(node) - val new_metas = transformExprNe_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Ne( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprNe_operands(node: PartiqlAst.Expr.Ne) = - node.operands.map { transformExpr(it) } - open fun transformExprNe_metas(node: PartiqlAst.Expr.Ne) = - transformMetas(node.metas) - - // Variant ExprGt - open fun transformExprGt(node: PartiqlAst.Expr.Gt): PartiqlAst.Expr { - val new_operands = transformExprGt_operands(node) - val new_metas = transformExprGt_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Gt( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprGt_operands(node: PartiqlAst.Expr.Gt) = - node.operands.map { transformExpr(it) } - open fun transformExprGt_metas(node: PartiqlAst.Expr.Gt) = - transformMetas(node.metas) - - // Variant ExprGte - open fun transformExprGte(node: PartiqlAst.Expr.Gte): PartiqlAst.Expr { - val new_operands = transformExprGte_operands(node) - val new_metas = transformExprGte_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Gte( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprGte_operands(node: PartiqlAst.Expr.Gte) = - node.operands.map { transformExpr(it) } - open fun transformExprGte_metas(node: PartiqlAst.Expr.Gte) = - transformMetas(node.metas) - - // Variant ExprLt - open fun transformExprLt(node: PartiqlAst.Expr.Lt): PartiqlAst.Expr { - val new_operands = transformExprLt_operands(node) - val new_metas = transformExprLt_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Lt( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprLt_operands(node: PartiqlAst.Expr.Lt) = - node.operands.map { transformExpr(it) } - open fun transformExprLt_metas(node: PartiqlAst.Expr.Lt) = - transformMetas(node.metas) - - // Variant ExprLte - open fun transformExprLte(node: PartiqlAst.Expr.Lte): PartiqlAst.Expr { - val new_operands = transformExprLte_operands(node) - val new_metas = transformExprLte_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Lte( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprLte_operands(node: PartiqlAst.Expr.Lte) = - node.operands.map { transformExpr(it) } - open fun transformExprLte_metas(node: PartiqlAst.Expr.Lte) = - transformMetas(node.metas) - - // Variant ExprLike - open fun transformExprLike(node: PartiqlAst.Expr.Like): PartiqlAst.Expr { - val new_value = transformExprLike_value(node) - val new_pattern = transformExprLike_pattern(node) - val new_escape = transformExprLike_escape(node) - val new_metas = transformExprLike_metas(node) - return if ( - node.value !== new_value || - node.pattern !== new_pattern || - node.escape !== new_escape || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Like( - value = new_value, - pattern = new_pattern, - escape = new_escape, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprLike_value(node: PartiqlAst.Expr.Like) = - transformExpr(node.value) - open fun transformExprLike_pattern(node: PartiqlAst.Expr.Like) = - transformExpr(node.pattern) - open fun transformExprLike_escape(node: PartiqlAst.Expr.Like) = - node.escape?.let { transformExpr(it) } - open fun transformExprLike_metas(node: PartiqlAst.Expr.Like) = - transformMetas(node.metas) - - // Variant ExprBetween - open fun transformExprBetween(node: PartiqlAst.Expr.Between): PartiqlAst.Expr { - val new_value = transformExprBetween_value(node) - val new_from = transformExprBetween_from(node) - val new_to = transformExprBetween_to(node) - val new_metas = transformExprBetween_metas(node) - return if ( - node.value !== new_value || - node.from !== new_from || - node.to !== new_to || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Between( - value = new_value, - from = new_from, - to = new_to, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprBetween_value(node: PartiqlAst.Expr.Between) = - transformExpr(node.value) - open fun transformExprBetween_from(node: PartiqlAst.Expr.Between) = - transformExpr(node.from) - open fun transformExprBetween_to(node: PartiqlAst.Expr.Between) = - transformExpr(node.to) - open fun transformExprBetween_metas(node: PartiqlAst.Expr.Between) = - transformMetas(node.metas) - - // Variant ExprInCollection - open fun transformExprInCollection(node: PartiqlAst.Expr.InCollection): PartiqlAst.Expr { - val new_operands = transformExprInCollection_operands(node) - val new_metas = transformExprInCollection_metas(node) - return if ( - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.InCollection( - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprInCollection_operands(node: PartiqlAst.Expr.InCollection) = - node.operands.map { transformExpr(it) } - open fun transformExprInCollection_metas(node: PartiqlAst.Expr.InCollection) = - transformMetas(node.metas) - - // Variant ExprIsType - open fun transformExprIsType(node: PartiqlAst.Expr.IsType): PartiqlAst.Expr { - val new_value = transformExprIsType_value(node) - val new_type = transformExprIsType_type(node) - val new_metas = transformExprIsType_metas(node) - return if ( - node.value !== new_value || - node.type !== new_type || - node.metas !== new_metas - ) { - PartiqlAst.Expr.IsType( - value = new_value, - type = new_type, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprIsType_value(node: PartiqlAst.Expr.IsType) = - transformExpr(node.value) - open fun transformExprIsType_type(node: PartiqlAst.Expr.IsType) = - transformType(node.type) - open fun transformExprIsType_metas(node: PartiqlAst.Expr.IsType) = - transformMetas(node.metas) - - // Variant ExprSimpleCase - open fun transformExprSimpleCase(node: PartiqlAst.Expr.SimpleCase): PartiqlAst.Expr { - val new_expr = transformExprSimpleCase_expr(node) - val new_cases = transformExprSimpleCase_cases(node) - val new_default = transformExprSimpleCase_default(node) - val new_metas = transformExprSimpleCase_metas(node) - return if ( - node.expr !== new_expr || - node.cases !== new_cases || - node.default !== new_default || - node.metas !== new_metas - ) { - PartiqlAst.Expr.SimpleCase( - expr = new_expr, - cases = new_cases, - default = new_default, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprSimpleCase_expr(node: PartiqlAst.Expr.SimpleCase) = - transformExpr(node.expr) - open fun transformExprSimpleCase_cases(node: PartiqlAst.Expr.SimpleCase) = - transformExprPairList(node.cases) - open fun transformExprSimpleCase_default(node: PartiqlAst.Expr.SimpleCase) = - node.default?.let { transformExpr(it) } - open fun transformExprSimpleCase_metas(node: PartiqlAst.Expr.SimpleCase) = - transformMetas(node.metas) - - // Variant ExprSearchedCase - open fun transformExprSearchedCase(node: PartiqlAst.Expr.SearchedCase): PartiqlAst.Expr { - val new_cases = transformExprSearchedCase_cases(node) - val new_default = transformExprSearchedCase_default(node) - val new_metas = transformExprSearchedCase_metas(node) - return if ( - node.cases !== new_cases || - node.default !== new_default || - node.metas !== new_metas - ) { - PartiqlAst.Expr.SearchedCase( - cases = new_cases, - default = new_default, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprSearchedCase_cases(node: PartiqlAst.Expr.SearchedCase) = - transformExprPairList(node.cases) - open fun transformExprSearchedCase_default(node: PartiqlAst.Expr.SearchedCase) = - node.default?.let { transformExpr(it) } - open fun transformExprSearchedCase_metas(node: PartiqlAst.Expr.SearchedCase) = - transformMetas(node.metas) - - // Variant ExprStruct - open fun transformExprStruct(node: PartiqlAst.Expr.Struct): PartiqlAst.Expr { - val new_fields = transformExprStruct_fields(node) - val new_metas = transformExprStruct_metas(node) - return if ( - node.fields !== new_fields || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Struct( - fields = new_fields, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprStruct_fields(node: PartiqlAst.Expr.Struct) = - node.fields.map { transformExprPair(it) } - open fun transformExprStruct_metas(node: PartiqlAst.Expr.Struct) = - transformMetas(node.metas) - - // Variant ExprBag - open fun transformExprBag(node: PartiqlAst.Expr.Bag): PartiqlAst.Expr { - val new_values = transformExprBag_values(node) - val new_metas = transformExprBag_metas(node) - return if ( - node.values !== new_values || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Bag( - values = new_values, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprBag_values(node: PartiqlAst.Expr.Bag) = - node.values.map { transformExpr(it) } - open fun transformExprBag_metas(node: PartiqlAst.Expr.Bag) = - transformMetas(node.metas) - - // Variant ExprList - open fun transformExprList(node: PartiqlAst.Expr.List): PartiqlAst.Expr { - val new_values = transformExprList_values(node) - val new_metas = transformExprList_metas(node) - return if ( - node.values !== new_values || - node.metas !== new_metas - ) { - PartiqlAst.Expr.List( - values = new_values, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprList_values(node: PartiqlAst.Expr.List) = - node.values.map { transformExpr(it) } - open fun transformExprList_metas(node: PartiqlAst.Expr.List) = - transformMetas(node.metas) - - // Variant ExprSexp - open fun transformExprSexp(node: PartiqlAst.Expr.Sexp): PartiqlAst.Expr { - val new_values = transformExprSexp_values(node) - val new_metas = transformExprSexp_metas(node) - return if ( - node.values !== new_values || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Sexp( - values = new_values, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprSexp_values(node: PartiqlAst.Expr.Sexp) = - node.values.map { transformExpr(it) } - open fun transformExprSexp_metas(node: PartiqlAst.Expr.Sexp) = - transformMetas(node.metas) - - // Variant ExprDate - open fun transformExprDate(node: PartiqlAst.Expr.Date): PartiqlAst.Expr { - val new_year = transformExprDate_year(node) - val new_month = transformExprDate_month(node) - val new_day = transformExprDate_day(node) - val new_metas = transformExprDate_metas(node) - return if ( - node.year !== new_year || - node.month !== new_month || - node.day !== new_day || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Date( - year = new_year, - month = new_month, - day = new_day, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprDate_year(node: PartiqlAst.Expr.Date) = - transformLongPrimitive(node.year) - open fun transformExprDate_month(node: PartiqlAst.Expr.Date) = - transformLongPrimitive(node.month) - open fun transformExprDate_day(node: PartiqlAst.Expr.Date) = - transformLongPrimitive(node.day) - open fun transformExprDate_metas(node: PartiqlAst.Expr.Date) = - transformMetas(node.metas) - - // Variant ExprLitTime - open fun transformExprLitTime(node: PartiqlAst.Expr.LitTime): PartiqlAst.Expr { - val new_value = transformExprLitTime_value(node) - val new_metas = transformExprLitTime_metas(node) - return if ( - node.value !== new_value || - node.metas !== new_metas - ) { - PartiqlAst.Expr.LitTime( - value = new_value, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprLitTime_value(node: PartiqlAst.Expr.LitTime) = - transformTimeValue(node.value) - open fun transformExprLitTime_metas(node: PartiqlAst.Expr.LitTime) = - transformMetas(node.metas) - - // Variant ExprUnion - open fun transformExprUnion(node: PartiqlAst.Expr.Union): PartiqlAst.Expr { - val new_setq = transformExprUnion_setq(node) - val new_operands = transformExprUnion_operands(node) - val new_metas = transformExprUnion_metas(node) - return if ( - node.setq !== new_setq || - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Union( - setq = new_setq, - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprUnion_setq(node: PartiqlAst.Expr.Union) = - transformSetQuantifier(node.setq) - open fun transformExprUnion_operands(node: PartiqlAst.Expr.Union) = - node.operands.map { transformExpr(it) } - open fun transformExprUnion_metas(node: PartiqlAst.Expr.Union) = - transformMetas(node.metas) - - // Variant ExprExcept - open fun transformExprExcept(node: PartiqlAst.Expr.Except): PartiqlAst.Expr { - val new_setq = transformExprExcept_setq(node) - val new_operands = transformExprExcept_operands(node) - val new_metas = transformExprExcept_metas(node) - return if ( - node.setq !== new_setq || - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Except( - setq = new_setq, - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprExcept_setq(node: PartiqlAst.Expr.Except) = - transformSetQuantifier(node.setq) - open fun transformExprExcept_operands(node: PartiqlAst.Expr.Except) = - node.operands.map { transformExpr(it) } - open fun transformExprExcept_metas(node: PartiqlAst.Expr.Except) = - transformMetas(node.metas) - - // Variant ExprIntersect - open fun transformExprIntersect(node: PartiqlAst.Expr.Intersect): PartiqlAst.Expr { - val new_setq = transformExprIntersect_setq(node) - val new_operands = transformExprIntersect_operands(node) - val new_metas = transformExprIntersect_metas(node) - return if ( - node.setq !== new_setq || - node.operands !== new_operands || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Intersect( - setq = new_setq, - operands = new_operands, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprIntersect_setq(node: PartiqlAst.Expr.Intersect) = - transformSetQuantifier(node.setq) - open fun transformExprIntersect_operands(node: PartiqlAst.Expr.Intersect) = - node.operands.map { transformExpr(it) } - open fun transformExprIntersect_metas(node: PartiqlAst.Expr.Intersect) = - transformMetas(node.metas) - - // Variant ExprPath - open fun transformExprPath(node: PartiqlAst.Expr.Path): PartiqlAst.Expr { - val new_root = transformExprPath_root(node) - val new_steps = transformExprPath_steps(node) - val new_metas = transformExprPath_metas(node) - return if ( - node.root !== new_root || - node.steps !== new_steps || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Path( - root = new_root, - steps = new_steps, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprPath_root(node: PartiqlAst.Expr.Path) = - transformExpr(node.root) - open fun transformExprPath_steps(node: PartiqlAst.Expr.Path) = - node.steps.map { transformPathStep(it) } - open fun transformExprPath_metas(node: PartiqlAst.Expr.Path) = - transformMetas(node.metas) - - // Variant ExprCall - open fun transformExprCall(node: PartiqlAst.Expr.Call): PartiqlAst.Expr { - val new_funcName = transformExprCall_funcName(node) - val new_args = transformExprCall_args(node) - val new_metas = transformExprCall_metas(node) - return if ( - node.funcName !== new_funcName || - node.args !== new_args || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Call( - funcName = new_funcName, - args = new_args, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprCall_funcName(node: PartiqlAst.Expr.Call) = - transformSymbolPrimitive(node.funcName) - open fun transformExprCall_args(node: PartiqlAst.Expr.Call) = - node.args.map { transformExpr(it) } - open fun transformExprCall_metas(node: PartiqlAst.Expr.Call) = - transformMetas(node.metas) - - // Variant ExprCallAgg - open fun transformExprCallAgg(node: PartiqlAst.Expr.CallAgg): PartiqlAst.Expr { - val new_setq = transformExprCallAgg_setq(node) - val new_funcName = transformExprCallAgg_funcName(node) - val new_arg = transformExprCallAgg_arg(node) - val new_metas = transformExprCallAgg_metas(node) - return if ( - node.setq !== new_setq || - node.funcName !== new_funcName || - node.arg !== new_arg || - node.metas !== new_metas - ) { - PartiqlAst.Expr.CallAgg( - setq = new_setq, - funcName = new_funcName, - arg = new_arg, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprCallAgg_setq(node: PartiqlAst.Expr.CallAgg) = - transformSetQuantifier(node.setq) - open fun transformExprCallAgg_funcName(node: PartiqlAst.Expr.CallAgg) = - transformSymbolPrimitive(node.funcName) - open fun transformExprCallAgg_arg(node: PartiqlAst.Expr.CallAgg) = - transformExpr(node.arg) - open fun transformExprCallAgg_metas(node: PartiqlAst.Expr.CallAgg) = - transformMetas(node.metas) - - // Variant ExprCast - open fun transformExprCast(node: PartiqlAst.Expr.Cast): PartiqlAst.Expr { - val new_value = transformExprCast_value(node) - val new_asType = transformExprCast_asType(node) - val new_metas = transformExprCast_metas(node) - return if ( - node.value !== new_value || - node.asType !== new_asType || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Cast( - value = new_value, - asType = new_asType, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprCast_value(node: PartiqlAst.Expr.Cast) = - transformExpr(node.value) - open fun transformExprCast_asType(node: PartiqlAst.Expr.Cast) = - transformType(node.asType) - open fun transformExprCast_metas(node: PartiqlAst.Expr.Cast) = - transformMetas(node.metas) - - // Variant ExprCanCast - open fun transformExprCanCast(node: PartiqlAst.Expr.CanCast): PartiqlAst.Expr { - val new_value = transformExprCanCast_value(node) - val new_asType = transformExprCanCast_asType(node) - val new_metas = transformExprCanCast_metas(node) - return if ( - node.value !== new_value || - node.asType !== new_asType || - node.metas !== new_metas - ) { - PartiqlAst.Expr.CanCast( - value = new_value, - asType = new_asType, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprCanCast_value(node: PartiqlAst.Expr.CanCast) = - transformExpr(node.value) - open fun transformExprCanCast_asType(node: PartiqlAst.Expr.CanCast) = - transformType(node.asType) - open fun transformExprCanCast_metas(node: PartiqlAst.Expr.CanCast) = - transformMetas(node.metas) - - // Variant ExprCanLosslessCast - open fun transformExprCanLosslessCast(node: PartiqlAst.Expr.CanLosslessCast): PartiqlAst.Expr { - val new_value = transformExprCanLosslessCast_value(node) - val new_asType = transformExprCanLosslessCast_asType(node) - val new_metas = transformExprCanLosslessCast_metas(node) - return if ( - node.value !== new_value || - node.asType !== new_asType || - node.metas !== new_metas - ) { - PartiqlAst.Expr.CanLosslessCast( - value = new_value, - asType = new_asType, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprCanLosslessCast_value(node: PartiqlAst.Expr.CanLosslessCast) = - transformExpr(node.value) - open fun transformExprCanLosslessCast_asType(node: PartiqlAst.Expr.CanLosslessCast) = - transformType(node.asType) - open fun transformExprCanLosslessCast_metas(node: PartiqlAst.Expr.CanLosslessCast) = - transformMetas(node.metas) - - // Variant ExprNullIf - open fun transformExprNullIf(node: PartiqlAst.Expr.NullIf): PartiqlAst.Expr { - val new_expr1 = transformExprNullIf_expr1(node) - val new_expr2 = transformExprNullIf_expr2(node) - val new_metas = transformExprNullIf_metas(node) - return if ( - node.expr1 !== new_expr1 || - node.expr2 !== new_expr2 || - node.metas !== new_metas - ) { - PartiqlAst.Expr.NullIf( - expr1 = new_expr1, - expr2 = new_expr2, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprNullIf_expr1(node: PartiqlAst.Expr.NullIf) = - transformExpr(node.expr1) - open fun transformExprNullIf_expr2(node: PartiqlAst.Expr.NullIf) = - transformExpr(node.expr2) - open fun transformExprNullIf_metas(node: PartiqlAst.Expr.NullIf) = - transformMetas(node.metas) - - // Variant ExprCoalesce - open fun transformExprCoalesce(node: PartiqlAst.Expr.Coalesce): PartiqlAst.Expr { - val new_args = transformExprCoalesce_args(node) - val new_metas = transformExprCoalesce_metas(node) - return if ( - node.args !== new_args || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Coalesce( - args = new_args, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprCoalesce_args(node: PartiqlAst.Expr.Coalesce) = - node.args.map { transformExpr(it) } - open fun transformExprCoalesce_metas(node: PartiqlAst.Expr.Coalesce) = - transformMetas(node.metas) - - // Variant ExprSelect - open fun transformExprSelect(node: PartiqlAst.Expr.Select): PartiqlAst.Expr { - val new_setq = transformExprSelect_setq(node) - val new_project = transformExprSelect_project(node) - val new_from = transformExprSelect_from(node) - val new_fromLet = transformExprSelect_fromLet(node) - val new_where = transformExprSelect_where(node) - val new_group = transformExprSelect_group(node) - val new_having = transformExprSelect_having(node) - val new_order = transformExprSelect_order(node) - val new_limit = transformExprSelect_limit(node) - val new_metas = transformExprSelect_metas(node) - return if ( - node.setq !== new_setq || - node.project !== new_project || - node.from !== new_from || - node.fromLet !== new_fromLet || - node.where !== new_where || - node.group !== new_group || - node.having !== new_having || - node.order !== new_order || - node.limit !== new_limit || - node.metas !== new_metas - ) { - PartiqlAst.Expr.Select( - setq = new_setq, - project = new_project, - from = new_from, - fromLet = new_fromLet, - where = new_where, - group = new_group, - having = new_having, - order = new_order, - limit = new_limit, - metas = new_metas - ) - } else { - node - } - } - open fun transformExprSelect_setq(node: PartiqlAst.Expr.Select) = - node.setq?.let { transformSetQuantifier(it) } - open fun transformExprSelect_project(node: PartiqlAst.Expr.Select) = - transformProjection(node.project) - open fun transformExprSelect_from(node: PartiqlAst.Expr.Select) = - transformFromSource(node.from) - open fun transformExprSelect_fromLet(node: PartiqlAst.Expr.Select) = - node.fromLet?.let { transformLet(it) } - open fun transformExprSelect_where(node: PartiqlAst.Expr.Select) = - node.where?.let { transformExpr(it) } - open fun transformExprSelect_group(node: PartiqlAst.Expr.Select) = - node.group?.let { transformGroupBy(it) } - open fun transformExprSelect_having(node: PartiqlAst.Expr.Select) = - node.having?.let { transformExpr(it) } - open fun transformExprSelect_order(node: PartiqlAst.Expr.Select) = - node.order?.let { transformOrderBy(it) } - open fun transformExprSelect_limit(node: PartiqlAst.Expr.Select) = - node.limit?.let { transformExpr(it) } - open fun transformExprSelect_metas(node: PartiqlAst.Expr.Select) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: PathStep - ////////////////////////////////////// - open fun transformPathStep(node: PartiqlAst.PathStep): PartiqlAst.PathStep = - when(node) { - is PartiqlAst.PathStep.PathExpr -> transformPathStepPathExpr(node) - is PartiqlAst.PathStep.PathWildcard -> transformPathStepPathWildcard(node) - is PartiqlAst.PathStep.PathUnpivot -> transformPathStepPathUnpivot(node) - } - // Variant PathStepPathExpr - open fun transformPathStepPathExpr(node: PartiqlAst.PathStep.PathExpr): PartiqlAst.PathStep { - val new_index = transformPathStepPathExpr_index(node) - val new_case = transformPathStepPathExpr_case(node) - val new_metas = transformPathStepPathExpr_metas(node) - return if ( - node.index !== new_index || - node.case !== new_case || - node.metas !== new_metas - ) { - PartiqlAst.PathStep.PathExpr( - index = new_index, - case = new_case, - metas = new_metas - ) - } else { - node - } - } - open fun transformPathStepPathExpr_index(node: PartiqlAst.PathStep.PathExpr) = - transformExpr(node.index) - open fun transformPathStepPathExpr_case(node: PartiqlAst.PathStep.PathExpr) = - transformCaseSensitivity(node.case) - open fun transformPathStepPathExpr_metas(node: PartiqlAst.PathStep.PathExpr) = - transformMetas(node.metas) - - // Variant PathStepPathWildcard - open fun transformPathStepPathWildcard(node: PartiqlAst.PathStep.PathWildcard): PartiqlAst.PathStep { - val new_metas = transformPathStepPathWildcard_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.PathStep.PathWildcard( - metas = new_metas - ) - } else { - node - } - } - open fun transformPathStepPathWildcard_metas(node: PartiqlAst.PathStep.PathWildcard) = - transformMetas(node.metas) - - // Variant PathStepPathUnpivot - open fun transformPathStepPathUnpivot(node: PartiqlAst.PathStep.PathUnpivot): PartiqlAst.PathStep { - val new_metas = transformPathStepPathUnpivot_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.PathStep.PathUnpivot( - metas = new_metas - ) - } else { - node - } - } - open fun transformPathStepPathUnpivot_metas(node: PartiqlAst.PathStep.PathUnpivot) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: Projection - ////////////////////////////////////// - open fun transformProjection(node: PartiqlAst.Projection): PartiqlAst.Projection = - when(node) { - is PartiqlAst.Projection.ProjectStar -> transformProjectionProjectStar(node) - is PartiqlAst.Projection.ProjectList -> transformProjectionProjectList(node) - is PartiqlAst.Projection.ProjectPivot -> transformProjectionProjectPivot(node) - is PartiqlAst.Projection.ProjectValue -> transformProjectionProjectValue(node) - } - // Variant ProjectionProjectStar - open fun transformProjectionProjectStar(node: PartiqlAst.Projection.ProjectStar): PartiqlAst.Projection { - val new_metas = transformProjectionProjectStar_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Projection.ProjectStar( - metas = new_metas - ) - } else { - node - } - } - open fun transformProjectionProjectStar_metas(node: PartiqlAst.Projection.ProjectStar) = - transformMetas(node.metas) - - // Variant ProjectionProjectList - open fun transformProjectionProjectList(node: PartiqlAst.Projection.ProjectList): PartiqlAst.Projection { - val new_projectItems = transformProjectionProjectList_projectItems(node) - val new_metas = transformProjectionProjectList_metas(node) - return if ( - node.projectItems !== new_projectItems || - node.metas !== new_metas - ) { - PartiqlAst.Projection.ProjectList( - projectItems = new_projectItems, - metas = new_metas - ) - } else { - node - } - } - open fun transformProjectionProjectList_projectItems(node: PartiqlAst.Projection.ProjectList) = - node.projectItems.map { transformProjectItem(it) } - open fun transformProjectionProjectList_metas(node: PartiqlAst.Projection.ProjectList) = - transformMetas(node.metas) - - // Variant ProjectionProjectPivot - open fun transformProjectionProjectPivot(node: PartiqlAst.Projection.ProjectPivot): PartiqlAst.Projection { - val new_value = transformProjectionProjectPivot_value(node) - val new_key = transformProjectionProjectPivot_key(node) - val new_metas = transformProjectionProjectPivot_metas(node) - return if ( - node.value !== new_value || - node.key !== new_key || - node.metas !== new_metas - ) { - PartiqlAst.Projection.ProjectPivot( - value = new_value, - key = new_key, - metas = new_metas - ) - } else { - node - } - } - open fun transformProjectionProjectPivot_value(node: PartiqlAst.Projection.ProjectPivot) = - transformExpr(node.value) - open fun transformProjectionProjectPivot_key(node: PartiqlAst.Projection.ProjectPivot) = - transformExpr(node.key) - open fun transformProjectionProjectPivot_metas(node: PartiqlAst.Projection.ProjectPivot) = - transformMetas(node.metas) - - // Variant ProjectionProjectValue - open fun transformProjectionProjectValue(node: PartiqlAst.Projection.ProjectValue): PartiqlAst.Projection { - val new_value = transformProjectionProjectValue_value(node) - val new_metas = transformProjectionProjectValue_metas(node) - return if ( - node.value !== new_value || - node.metas !== new_metas - ) { - PartiqlAst.Projection.ProjectValue( - value = new_value, - metas = new_metas - ) - } else { - node - } - } - open fun transformProjectionProjectValue_value(node: PartiqlAst.Projection.ProjectValue) = - transformExpr(node.value) - open fun transformProjectionProjectValue_metas(node: PartiqlAst.Projection.ProjectValue) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: ProjectItem - ////////////////////////////////////// - open fun transformProjectItem(node: PartiqlAst.ProjectItem): PartiqlAst.ProjectItem = - when(node) { - is PartiqlAst.ProjectItem.ProjectAll -> transformProjectItemProjectAll(node) - is PartiqlAst.ProjectItem.ProjectExpr -> transformProjectItemProjectExpr(node) - } - // Variant ProjectItemProjectAll - open fun transformProjectItemProjectAll(node: PartiqlAst.ProjectItem.ProjectAll): PartiqlAst.ProjectItem { - val new_expr = transformProjectItemProjectAll_expr(node) - val new_metas = transformProjectItemProjectAll_metas(node) - return if ( - node.expr !== new_expr || - node.metas !== new_metas - ) { - PartiqlAst.ProjectItem.ProjectAll( - expr = new_expr, - metas = new_metas - ) - } else { - node - } - } - open fun transformProjectItemProjectAll_expr(node: PartiqlAst.ProjectItem.ProjectAll) = - transformExpr(node.expr) - open fun transformProjectItemProjectAll_metas(node: PartiqlAst.ProjectItem.ProjectAll) = - transformMetas(node.metas) - - // Variant ProjectItemProjectExpr - open fun transformProjectItemProjectExpr(node: PartiqlAst.ProjectItem.ProjectExpr): PartiqlAst.ProjectItem { - val new_expr = transformProjectItemProjectExpr_expr(node) - val new_asAlias = transformProjectItemProjectExpr_asAlias(node) - val new_metas = transformProjectItemProjectExpr_metas(node) - return if ( - node.expr !== new_expr || - node.asAlias !== new_asAlias || - node.metas !== new_metas - ) { - PartiqlAst.ProjectItem.ProjectExpr( - expr = new_expr, - asAlias = new_asAlias, - metas = new_metas - ) - } else { - node - } - } - open fun transformProjectItemProjectExpr_expr(node: PartiqlAst.ProjectItem.ProjectExpr) = - transformExpr(node.expr) - open fun transformProjectItemProjectExpr_asAlias(node: PartiqlAst.ProjectItem.ProjectExpr) = - node.asAlias?.let { transformSymbolPrimitive(it) } - open fun transformProjectItemProjectExpr_metas(node: PartiqlAst.ProjectItem.ProjectExpr) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: FromSource - ////////////////////////////////////// - open fun transformFromSource(node: PartiqlAst.FromSource): PartiqlAst.FromSource = - when(node) { - is PartiqlAst.FromSource.Scan -> transformFromSourceScan(node) - is PartiqlAst.FromSource.Unpivot -> transformFromSourceUnpivot(node) - is PartiqlAst.FromSource.Join -> transformFromSourceJoin(node) - } - // Variant FromSourceScan - open fun transformFromSourceScan(node: PartiqlAst.FromSource.Scan): PartiqlAst.FromSource { - val new_expr = transformFromSourceScan_expr(node) - val new_asAlias = transformFromSourceScan_asAlias(node) - val new_atAlias = transformFromSourceScan_atAlias(node) - val new_byAlias = transformFromSourceScan_byAlias(node) - val new_metas = transformFromSourceScan_metas(node) - return if ( - node.expr !== new_expr || - node.asAlias !== new_asAlias || - node.atAlias !== new_atAlias || - node.byAlias !== new_byAlias || - node.metas !== new_metas - ) { - PartiqlAst.FromSource.Scan( - expr = new_expr, - asAlias = new_asAlias, - atAlias = new_atAlias, - byAlias = new_byAlias, - metas = new_metas - ) - } else { - node - } - } - open fun transformFromSourceScan_expr(node: PartiqlAst.FromSource.Scan) = - transformExpr(node.expr) - open fun transformFromSourceScan_asAlias(node: PartiqlAst.FromSource.Scan) = - node.asAlias?.let { transformSymbolPrimitive(it) } - open fun transformFromSourceScan_atAlias(node: PartiqlAst.FromSource.Scan) = - node.atAlias?.let { transformSymbolPrimitive(it) } - open fun transformFromSourceScan_byAlias(node: PartiqlAst.FromSource.Scan) = - node.byAlias?.let { transformSymbolPrimitive(it) } - open fun transformFromSourceScan_metas(node: PartiqlAst.FromSource.Scan) = - transformMetas(node.metas) - - // Variant FromSourceUnpivot - open fun transformFromSourceUnpivot(node: PartiqlAst.FromSource.Unpivot): PartiqlAst.FromSource { - val new_expr = transformFromSourceUnpivot_expr(node) - val new_asAlias = transformFromSourceUnpivot_asAlias(node) - val new_atAlias = transformFromSourceUnpivot_atAlias(node) - val new_byAlias = transformFromSourceUnpivot_byAlias(node) - val new_metas = transformFromSourceUnpivot_metas(node) - return if ( - node.expr !== new_expr || - node.asAlias !== new_asAlias || - node.atAlias !== new_atAlias || - node.byAlias !== new_byAlias || - node.metas !== new_metas - ) { - PartiqlAst.FromSource.Unpivot( - expr = new_expr, - asAlias = new_asAlias, - atAlias = new_atAlias, - byAlias = new_byAlias, - metas = new_metas - ) - } else { - node - } - } - open fun transformFromSourceUnpivot_expr(node: PartiqlAst.FromSource.Unpivot) = - transformExpr(node.expr) - open fun transformFromSourceUnpivot_asAlias(node: PartiqlAst.FromSource.Unpivot) = - node.asAlias?.let { transformSymbolPrimitive(it) } - open fun transformFromSourceUnpivot_atAlias(node: PartiqlAst.FromSource.Unpivot) = - node.atAlias?.let { transformSymbolPrimitive(it) } - open fun transformFromSourceUnpivot_byAlias(node: PartiqlAst.FromSource.Unpivot) = - node.byAlias?.let { transformSymbolPrimitive(it) } - open fun transformFromSourceUnpivot_metas(node: PartiqlAst.FromSource.Unpivot) = - transformMetas(node.metas) - - // Variant FromSourceJoin - open fun transformFromSourceJoin(node: PartiqlAst.FromSource.Join): PartiqlAst.FromSource { - val new_type = transformFromSourceJoin_type(node) - val new_left = transformFromSourceJoin_left(node) - val new_right = transformFromSourceJoin_right(node) - val new_predicate = transformFromSourceJoin_predicate(node) - val new_metas = transformFromSourceJoin_metas(node) - return if ( - node.type !== new_type || - node.left !== new_left || - node.right !== new_right || - node.predicate !== new_predicate || - node.metas !== new_metas - ) { - PartiqlAst.FromSource.Join( - type = new_type, - left = new_left, - right = new_right, - predicate = new_predicate, - metas = new_metas - ) - } else { - node - } - } - open fun transformFromSourceJoin_type(node: PartiqlAst.FromSource.Join) = - transformJoinType(node.type) - open fun transformFromSourceJoin_left(node: PartiqlAst.FromSource.Join) = - transformFromSource(node.left) - open fun transformFromSourceJoin_right(node: PartiqlAst.FromSource.Join) = - transformFromSource(node.right) - open fun transformFromSourceJoin_predicate(node: PartiqlAst.FromSource.Join) = - node.predicate?.let { transformExpr(it) } - open fun transformFromSourceJoin_metas(node: PartiqlAst.FromSource.Join) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: JoinType - ////////////////////////////////////// - open fun transformJoinType(node: PartiqlAst.JoinType): PartiqlAst.JoinType = - when(node) { - is PartiqlAst.JoinType.Inner -> transformJoinTypeInner(node) - is PartiqlAst.JoinType.Left -> transformJoinTypeLeft(node) - is PartiqlAst.JoinType.Right -> transformJoinTypeRight(node) - is PartiqlAst.JoinType.Full -> transformJoinTypeFull(node) - } - // Variant JoinTypeInner - open fun transformJoinTypeInner(node: PartiqlAst.JoinType.Inner): PartiqlAst.JoinType { - val new_metas = transformJoinTypeInner_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.JoinType.Inner( - metas = new_metas - ) - } else { - node - } - } - open fun transformJoinTypeInner_metas(node: PartiqlAst.JoinType.Inner) = - transformMetas(node.metas) - - // Variant JoinTypeLeft - open fun transformJoinTypeLeft(node: PartiqlAst.JoinType.Left): PartiqlAst.JoinType { - val new_metas = transformJoinTypeLeft_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.JoinType.Left( - metas = new_metas - ) - } else { - node - } - } - open fun transformJoinTypeLeft_metas(node: PartiqlAst.JoinType.Left) = - transformMetas(node.metas) - - // Variant JoinTypeRight - open fun transformJoinTypeRight(node: PartiqlAst.JoinType.Right): PartiqlAst.JoinType { - val new_metas = transformJoinTypeRight_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.JoinType.Right( - metas = new_metas - ) - } else { - node - } - } - open fun transformJoinTypeRight_metas(node: PartiqlAst.JoinType.Right) = - transformMetas(node.metas) - - // Variant JoinTypeFull - open fun transformJoinTypeFull(node: PartiqlAst.JoinType.Full): PartiqlAst.JoinType { - val new_metas = transformJoinTypeFull_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.JoinType.Full( - metas = new_metas - ) - } else { - node - } - } - open fun transformJoinTypeFull_metas(node: PartiqlAst.JoinType.Full) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: GroupingStrategy - ////////////////////////////////////// - open fun transformGroupingStrategy(node: PartiqlAst.GroupingStrategy): PartiqlAst.GroupingStrategy = - when(node) { - is PartiqlAst.GroupingStrategy.GroupFull -> transformGroupingStrategyGroupFull(node) - is PartiqlAst.GroupingStrategy.GroupPartial -> transformGroupingStrategyGroupPartial(node) - } - // Variant GroupingStrategyGroupFull - open fun transformGroupingStrategyGroupFull(node: PartiqlAst.GroupingStrategy.GroupFull): PartiqlAst.GroupingStrategy { - val new_metas = transformGroupingStrategyGroupFull_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.GroupingStrategy.GroupFull( - metas = new_metas - ) - } else { - node - } - } - open fun transformGroupingStrategyGroupFull_metas(node: PartiqlAst.GroupingStrategy.GroupFull) = - transformMetas(node.metas) - - // Variant GroupingStrategyGroupPartial - open fun transformGroupingStrategyGroupPartial(node: PartiqlAst.GroupingStrategy.GroupPartial): PartiqlAst.GroupingStrategy { - val new_metas = transformGroupingStrategyGroupPartial_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.GroupingStrategy.GroupPartial( - metas = new_metas - ) - } else { - node - } - } - open fun transformGroupingStrategyGroupPartial_metas(node: PartiqlAst.GroupingStrategy.GroupPartial) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: OrderingSpec - ////////////////////////////////////// - open fun transformOrderingSpec(node: PartiqlAst.OrderingSpec): PartiqlAst.OrderingSpec = - when(node) { - is PartiqlAst.OrderingSpec.Asc -> transformOrderingSpecAsc(node) - is PartiqlAst.OrderingSpec.Desc -> transformOrderingSpecDesc(node) - } - // Variant OrderingSpecAsc - open fun transformOrderingSpecAsc(node: PartiqlAst.OrderingSpec.Asc): PartiqlAst.OrderingSpec { - val new_metas = transformOrderingSpecAsc_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.OrderingSpec.Asc( - metas = new_metas - ) - } else { - node - } - } - open fun transformOrderingSpecAsc_metas(node: PartiqlAst.OrderingSpec.Asc) = - transformMetas(node.metas) - - // Variant OrderingSpecDesc - open fun transformOrderingSpecDesc(node: PartiqlAst.OrderingSpec.Desc): PartiqlAst.OrderingSpec { - val new_metas = transformOrderingSpecDesc_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.OrderingSpec.Desc( - metas = new_metas - ) - } else { - node - } - } - open fun transformOrderingSpecDesc_metas(node: PartiqlAst.OrderingSpec.Desc) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: CaseSensitivity - ////////////////////////////////////// - open fun transformCaseSensitivity(node: PartiqlAst.CaseSensitivity): PartiqlAst.CaseSensitivity = - when(node) { - is PartiqlAst.CaseSensitivity.CaseSensitive -> transformCaseSensitivityCaseSensitive(node) - is PartiqlAst.CaseSensitivity.CaseInsensitive -> transformCaseSensitivityCaseInsensitive(node) - } - // Variant CaseSensitivityCaseSensitive - open fun transformCaseSensitivityCaseSensitive(node: PartiqlAst.CaseSensitivity.CaseSensitive): PartiqlAst.CaseSensitivity { - val new_metas = transformCaseSensitivityCaseSensitive_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.CaseSensitivity.CaseSensitive( - metas = new_metas - ) - } else { - node - } - } - open fun transformCaseSensitivityCaseSensitive_metas(node: PartiqlAst.CaseSensitivity.CaseSensitive) = - transformMetas(node.metas) - - // Variant CaseSensitivityCaseInsensitive - open fun transformCaseSensitivityCaseInsensitive(node: PartiqlAst.CaseSensitivity.CaseInsensitive): PartiqlAst.CaseSensitivity { - val new_metas = transformCaseSensitivityCaseInsensitive_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.CaseSensitivity.CaseInsensitive( - metas = new_metas - ) - } else { - node - } - } - open fun transformCaseSensitivityCaseInsensitive_metas(node: PartiqlAst.CaseSensitivity.CaseInsensitive) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: ScopeQualifier - ////////////////////////////////////// - open fun transformScopeQualifier(node: PartiqlAst.ScopeQualifier): PartiqlAst.ScopeQualifier = - when(node) { - is PartiqlAst.ScopeQualifier.Unqualified -> transformScopeQualifierUnqualified(node) - is PartiqlAst.ScopeQualifier.LocalsFirst -> transformScopeQualifierLocalsFirst(node) - } - // Variant ScopeQualifierUnqualified - open fun transformScopeQualifierUnqualified(node: PartiqlAst.ScopeQualifier.Unqualified): PartiqlAst.ScopeQualifier { - val new_metas = transformScopeQualifierUnqualified_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.ScopeQualifier.Unqualified( - metas = new_metas - ) - } else { - node - } - } - open fun transformScopeQualifierUnqualified_metas(node: PartiqlAst.ScopeQualifier.Unqualified) = - transformMetas(node.metas) - - // Variant ScopeQualifierLocalsFirst - open fun transformScopeQualifierLocalsFirst(node: PartiqlAst.ScopeQualifier.LocalsFirst): PartiqlAst.ScopeQualifier { - val new_metas = transformScopeQualifierLocalsFirst_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.ScopeQualifier.LocalsFirst( - metas = new_metas - ) - } else { - node - } - } - open fun transformScopeQualifierLocalsFirst_metas(node: PartiqlAst.ScopeQualifier.LocalsFirst) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: SetQuantifier - ////////////////////////////////////// - open fun transformSetQuantifier(node: PartiqlAst.SetQuantifier): PartiqlAst.SetQuantifier = - when(node) { - is PartiqlAst.SetQuantifier.All -> transformSetQuantifierAll(node) - is PartiqlAst.SetQuantifier.Distinct -> transformSetQuantifierDistinct(node) - } - // Variant SetQuantifierAll - open fun transformSetQuantifierAll(node: PartiqlAst.SetQuantifier.All): PartiqlAst.SetQuantifier { - val new_metas = transformSetQuantifierAll_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.SetQuantifier.All( - metas = new_metas - ) - } else { - node - } - } - open fun transformSetQuantifierAll_metas(node: PartiqlAst.SetQuantifier.All) = - transformMetas(node.metas) - - // Variant SetQuantifierDistinct - open fun transformSetQuantifierDistinct(node: PartiqlAst.SetQuantifier.Distinct): PartiqlAst.SetQuantifier { - val new_metas = transformSetQuantifierDistinct_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.SetQuantifier.Distinct( - metas = new_metas - ) - } else { - node - } - } - open fun transformSetQuantifierDistinct_metas(node: PartiqlAst.SetQuantifier.Distinct) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: DmlOp - ////////////////////////////////////// - open fun transformDmlOp(node: PartiqlAst.DmlOp): PartiqlAst.DmlOp = - when(node) { - is PartiqlAst.DmlOp.Insert -> transformDmlOpInsert(node) - is PartiqlAst.DmlOp.InsertValue -> transformDmlOpInsertValue(node) - is PartiqlAst.DmlOp.Set -> transformDmlOpSet(node) - is PartiqlAst.DmlOp.Remove -> transformDmlOpRemove(node) - is PartiqlAst.DmlOp.Delete -> transformDmlOpDelete(node) - } - // Variant DmlOpInsert - open fun transformDmlOpInsert(node: PartiqlAst.DmlOp.Insert): PartiqlAst.DmlOp { - val new_target = transformDmlOpInsert_target(node) - val new_values = transformDmlOpInsert_values(node) - val new_metas = transformDmlOpInsert_metas(node) - return if ( - node.target !== new_target || - node.values !== new_values || - node.metas !== new_metas - ) { - PartiqlAst.DmlOp.Insert( - target = new_target, - values = new_values, - metas = new_metas - ) - } else { - node - } - } - open fun transformDmlOpInsert_target(node: PartiqlAst.DmlOp.Insert) = - transformExpr(node.target) - open fun transformDmlOpInsert_values(node: PartiqlAst.DmlOp.Insert) = - transformExpr(node.values) - open fun transformDmlOpInsert_metas(node: PartiqlAst.DmlOp.Insert) = - transformMetas(node.metas) - - // Variant DmlOpInsertValue - open fun transformDmlOpInsertValue(node: PartiqlAst.DmlOp.InsertValue): PartiqlAst.DmlOp { - val new_target = transformDmlOpInsertValue_target(node) - val new_value = transformDmlOpInsertValue_value(node) - val new_index = transformDmlOpInsertValue_index(node) - val new_onConflict = transformDmlOpInsertValue_onConflict(node) - val new_metas = transformDmlOpInsertValue_metas(node) - return if ( - node.target !== new_target || - node.value !== new_value || - node.index !== new_index || - node.onConflict !== new_onConflict || - node.metas !== new_metas - ) { - PartiqlAst.DmlOp.InsertValue( - target = new_target, - value = new_value, - index = new_index, - onConflict = new_onConflict, - metas = new_metas - ) - } else { - node - } - } - open fun transformDmlOpInsertValue_target(node: PartiqlAst.DmlOp.InsertValue) = - transformExpr(node.target) - open fun transformDmlOpInsertValue_value(node: PartiqlAst.DmlOp.InsertValue) = - transformExpr(node.value) - open fun transformDmlOpInsertValue_index(node: PartiqlAst.DmlOp.InsertValue) = - node.index?.let { transformExpr(it) } - open fun transformDmlOpInsertValue_onConflict(node: PartiqlAst.DmlOp.InsertValue) = - node.onConflict?.let { transformOnConflict(it) } - open fun transformDmlOpInsertValue_metas(node: PartiqlAst.DmlOp.InsertValue) = - transformMetas(node.metas) - - // Variant DmlOpSet - open fun transformDmlOpSet(node: PartiqlAst.DmlOp.Set): PartiqlAst.DmlOp { - val new_assignment = transformDmlOpSet_assignment(node) - val new_metas = transformDmlOpSet_metas(node) - return if ( - node.assignment !== new_assignment || - node.metas !== new_metas - ) { - PartiqlAst.DmlOp.Set( - assignment = new_assignment, - metas = new_metas - ) - } else { - node - } - } - open fun transformDmlOpSet_assignment(node: PartiqlAst.DmlOp.Set) = - transformAssignment(node.assignment) - open fun transformDmlOpSet_metas(node: PartiqlAst.DmlOp.Set) = - transformMetas(node.metas) - - // Variant DmlOpRemove - open fun transformDmlOpRemove(node: PartiqlAst.DmlOp.Remove): PartiqlAst.DmlOp { - val new_target = transformDmlOpRemove_target(node) - val new_metas = transformDmlOpRemove_metas(node) - return if ( - node.target !== new_target || - node.metas !== new_metas - ) { - PartiqlAst.DmlOp.Remove( - target = new_target, - metas = new_metas - ) - } else { - node - } - } - open fun transformDmlOpRemove_target(node: PartiqlAst.DmlOp.Remove) = - transformExpr(node.target) - open fun transformDmlOpRemove_metas(node: PartiqlAst.DmlOp.Remove) = - transformMetas(node.metas) - - // Variant DmlOpDelete - open fun transformDmlOpDelete(node: PartiqlAst.DmlOp.Delete): PartiqlAst.DmlOp { - val new_metas = transformDmlOpDelete_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.DmlOp.Delete( - metas = new_metas - ) - } else { - node - } - } - open fun transformDmlOpDelete_metas(node: PartiqlAst.DmlOp.Delete) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: ConflictAction - ////////////////////////////////////// - open fun transformConflictAction(node: PartiqlAst.ConflictAction): PartiqlAst.ConflictAction = - when(node) { - is PartiqlAst.ConflictAction.DoNothing -> transformConflictActionDoNothing(node) - } - // Variant ConflictActionDoNothing - open fun transformConflictActionDoNothing(node: PartiqlAst.ConflictAction.DoNothing): PartiqlAst.ConflictAction { - val new_metas = transformConflictActionDoNothing_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.ConflictAction.DoNothing( - metas = new_metas - ) - } else { - node - } - } - open fun transformConflictActionDoNothing_metas(node: PartiqlAst.ConflictAction.DoNothing) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: DdlOp - ////////////////////////////////////// - open fun transformDdlOp(node: PartiqlAst.DdlOp): PartiqlAst.DdlOp = - when(node) { - is PartiqlAst.DdlOp.CreateTable -> transformDdlOpCreateTable(node) - is PartiqlAst.DdlOp.DropTable -> transformDdlOpDropTable(node) - is PartiqlAst.DdlOp.UndropTable -> transformDdlOpUndropTable(node) - is PartiqlAst.DdlOp.CreateIndex -> transformDdlOpCreateIndex(node) - is PartiqlAst.DdlOp.DropIndex -> transformDdlOpDropIndex(node) - } - // Variant DdlOpCreateTable - open fun transformDdlOpCreateTable(node: PartiqlAst.DdlOp.CreateTable): PartiqlAst.DdlOp { - val new_tableName = transformDdlOpCreateTable_tableName(node) - val new_metas = transformDdlOpCreateTable_metas(node) - return if ( - node.tableName !== new_tableName || - node.metas !== new_metas - ) { - PartiqlAst.DdlOp.CreateTable( - tableName = new_tableName, - metas = new_metas - ) - } else { - node - } - } - open fun transformDdlOpCreateTable_tableName(node: PartiqlAst.DdlOp.CreateTable) = - transformSymbolPrimitive(node.tableName) - open fun transformDdlOpCreateTable_metas(node: PartiqlAst.DdlOp.CreateTable) = - transformMetas(node.metas) - - // Variant DdlOpDropTable - open fun transformDdlOpDropTable(node: PartiqlAst.DdlOp.DropTable): PartiqlAst.DdlOp { - val new_tableName = transformDdlOpDropTable_tableName(node) - val new_metas = transformDdlOpDropTable_metas(node) - return if ( - node.tableName !== new_tableName || - node.metas !== new_metas - ) { - PartiqlAst.DdlOp.DropTable( - tableName = new_tableName, - metas = new_metas - ) - } else { - node - } - } - open fun transformDdlOpDropTable_tableName(node: PartiqlAst.DdlOp.DropTable) = - transformIdentifier(node.tableName) - open fun transformDdlOpDropTable_metas(node: PartiqlAst.DdlOp.DropTable) = - transformMetas(node.metas) - - // Variant DdlOpUndropTable - open fun transformDdlOpUndropTable(node: PartiqlAst.DdlOp.UndropTable): PartiqlAst.DdlOp { - val new_tableName = transformDdlOpUndropTable_tableName(node) - val new_metas = transformDdlOpUndropTable_metas(node) - return if ( - node.tableName !== new_tableName || - node.metas !== new_metas - ) { - PartiqlAst.DdlOp.UndropTable( - tableName = new_tableName, - metas = new_metas - ) - } else { - node - } - } - open fun transformDdlOpUndropTable_tableName(node: PartiqlAst.DdlOp.UndropTable) = - transformSymbolPrimitive(node.tableName) - open fun transformDdlOpUndropTable_metas(node: PartiqlAst.DdlOp.UndropTable) = - transformMetas(node.metas) - - // Variant DdlOpCreateIndex - open fun transformDdlOpCreateIndex(node: PartiqlAst.DdlOp.CreateIndex): PartiqlAst.DdlOp { - val new_indexName = transformDdlOpCreateIndex_indexName(node) - val new_fields = transformDdlOpCreateIndex_fields(node) - val new_metas = transformDdlOpCreateIndex_metas(node) - return if ( - node.indexName !== new_indexName || - node.fields !== new_fields || - node.metas !== new_metas - ) { - PartiqlAst.DdlOp.CreateIndex( - indexName = new_indexName, - fields = new_fields, - metas = new_metas - ) - } else { - node - } - } - open fun transformDdlOpCreateIndex_indexName(node: PartiqlAst.DdlOp.CreateIndex) = - transformIdentifier(node.indexName) - open fun transformDdlOpCreateIndex_fields(node: PartiqlAst.DdlOp.CreateIndex) = - node.fields.map { transformExpr(it) } - open fun transformDdlOpCreateIndex_metas(node: PartiqlAst.DdlOp.CreateIndex) = - transformMetas(node.metas) - - // Variant DdlOpDropIndex - open fun transformDdlOpDropIndex(node: PartiqlAst.DdlOp.DropIndex): PartiqlAst.DdlOp { - val new_table = transformDdlOpDropIndex_table(node) - val new_keys = transformDdlOpDropIndex_keys(node) - val new_metas = transformDdlOpDropIndex_metas(node) - return if ( - node.table !== new_table || - node.keys !== new_keys || - node.metas !== new_metas - ) { - PartiqlAst.DdlOp.DropIndex( - table = new_table, - keys = new_keys, - metas = new_metas - ) - } else { - node - } - } - open fun transformDdlOpDropIndex_table(node: PartiqlAst.DdlOp.DropIndex) = - transformIdentifier(node.table) - open fun transformDdlOpDropIndex_keys(node: PartiqlAst.DdlOp.DropIndex) = - transformIdentifier(node.keys) - open fun transformDdlOpDropIndex_metas(node: PartiqlAst.DdlOp.DropIndex) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: ColumnComponent - ////////////////////////////////////// - open fun transformColumnComponent(node: PartiqlAst.ColumnComponent): PartiqlAst.ColumnComponent = - when(node) { - is PartiqlAst.ColumnComponent.ReturningWildcard -> transformColumnComponentReturningWildcard(node) - is PartiqlAst.ColumnComponent.ReturningColumn -> transformColumnComponentReturningColumn(node) - } - // Variant ColumnComponentReturningWildcard - open fun transformColumnComponentReturningWildcard(node: PartiqlAst.ColumnComponent.ReturningWildcard): PartiqlAst.ColumnComponent { - val new_metas = transformColumnComponentReturningWildcard_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.ColumnComponent.ReturningWildcard( - metas = new_metas - ) - } else { - node - } - } - open fun transformColumnComponentReturningWildcard_metas(node: PartiqlAst.ColumnComponent.ReturningWildcard) = - transformMetas(node.metas) - - // Variant ColumnComponentReturningColumn - open fun transformColumnComponentReturningColumn(node: PartiqlAst.ColumnComponent.ReturningColumn): PartiqlAst.ColumnComponent { - val new_expr = transformColumnComponentReturningColumn_expr(node) - val new_metas = transformColumnComponentReturningColumn_metas(node) - return if ( - node.expr !== new_expr || - node.metas !== new_metas - ) { - PartiqlAst.ColumnComponent.ReturningColumn( - expr = new_expr, - metas = new_metas - ) - } else { - node - } - } - open fun transformColumnComponentReturningColumn_expr(node: PartiqlAst.ColumnComponent.ReturningColumn) = - transformExpr(node.expr) - open fun transformColumnComponentReturningColumn_metas(node: PartiqlAst.ColumnComponent.ReturningColumn) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: ReturningMapping - ////////////////////////////////////// - open fun transformReturningMapping(node: PartiqlAst.ReturningMapping): PartiqlAst.ReturningMapping = - when(node) { - is PartiqlAst.ReturningMapping.ModifiedNew -> transformReturningMappingModifiedNew(node) - is PartiqlAst.ReturningMapping.ModifiedOld -> transformReturningMappingModifiedOld(node) - is PartiqlAst.ReturningMapping.AllNew -> transformReturningMappingAllNew(node) - is PartiqlAst.ReturningMapping.AllOld -> transformReturningMappingAllOld(node) - } - // Variant ReturningMappingModifiedNew - open fun transformReturningMappingModifiedNew(node: PartiqlAst.ReturningMapping.ModifiedNew): PartiqlAst.ReturningMapping { - val new_metas = transformReturningMappingModifiedNew_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.ReturningMapping.ModifiedNew( - metas = new_metas - ) - } else { - node - } - } - open fun transformReturningMappingModifiedNew_metas(node: PartiqlAst.ReturningMapping.ModifiedNew) = - transformMetas(node.metas) - - // Variant ReturningMappingModifiedOld - open fun transformReturningMappingModifiedOld(node: PartiqlAst.ReturningMapping.ModifiedOld): PartiqlAst.ReturningMapping { - val new_metas = transformReturningMappingModifiedOld_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.ReturningMapping.ModifiedOld( - metas = new_metas - ) - } else { - node - } - } - open fun transformReturningMappingModifiedOld_metas(node: PartiqlAst.ReturningMapping.ModifiedOld) = - transformMetas(node.metas) - - // Variant ReturningMappingAllNew - open fun transformReturningMappingAllNew(node: PartiqlAst.ReturningMapping.AllNew): PartiqlAst.ReturningMapping { - val new_metas = transformReturningMappingAllNew_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.ReturningMapping.AllNew( - metas = new_metas - ) - } else { - node - } - } - open fun transformReturningMappingAllNew_metas(node: PartiqlAst.ReturningMapping.AllNew) = - transformMetas(node.metas) - - // Variant ReturningMappingAllOld - open fun transformReturningMappingAllOld(node: PartiqlAst.ReturningMapping.AllOld): PartiqlAst.ReturningMapping { - val new_metas = transformReturningMappingAllOld_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.ReturningMapping.AllOld( - metas = new_metas - ) - } else { - node - } - } - open fun transformReturningMappingAllOld_metas(node: PartiqlAst.ReturningMapping.AllOld) = - transformMetas(node.metas) - - ////////////////////////////////////// - // Sum Type: Type - ////////////////////////////////////// - open fun transformType(node: PartiqlAst.Type): PartiqlAst.Type = - when(node) { - is PartiqlAst.Type.NullType -> transformTypeNullType(node) - is PartiqlAst.Type.BooleanType -> transformTypeBooleanType(node) - is PartiqlAst.Type.SmallintType -> transformTypeSmallintType(node) - is PartiqlAst.Type.Integer4Type -> transformTypeInteger4Type(node) - is PartiqlAst.Type.Integer8Type -> transformTypeInteger8Type(node) - is PartiqlAst.Type.IntegerType -> transformTypeIntegerType(node) - is PartiqlAst.Type.FloatType -> transformTypeFloatType(node) - is PartiqlAst.Type.RealType -> transformTypeRealType(node) - is PartiqlAst.Type.DoublePrecisionType -> transformTypeDoublePrecisionType(node) - is PartiqlAst.Type.DecimalType -> transformTypeDecimalType(node) - is PartiqlAst.Type.NumericType -> transformTypeNumericType(node) - is PartiqlAst.Type.TimestampType -> transformTypeTimestampType(node) - is PartiqlAst.Type.CharacterType -> transformTypeCharacterType(node) - is PartiqlAst.Type.CharacterVaryingType -> transformTypeCharacterVaryingType(node) - is PartiqlAst.Type.MissingType -> transformTypeMissingType(node) - is PartiqlAst.Type.StringType -> transformTypeStringType(node) - is PartiqlAst.Type.SymbolType -> transformTypeSymbolType(node) - is PartiqlAst.Type.BlobType -> transformTypeBlobType(node) - is PartiqlAst.Type.ClobType -> transformTypeClobType(node) - is PartiqlAst.Type.DateType -> transformTypeDateType(node) - is PartiqlAst.Type.TimeType -> transformTypeTimeType(node) - is PartiqlAst.Type.TimeWithTimeZoneType -> transformTypeTimeWithTimeZoneType(node) - is PartiqlAst.Type.StructType -> transformTypeStructType(node) - is PartiqlAst.Type.TupleType -> transformTypeTupleType(node) - is PartiqlAst.Type.ListType -> transformTypeListType(node) - is PartiqlAst.Type.SexpType -> transformTypeSexpType(node) - is PartiqlAst.Type.BagType -> transformTypeBagType(node) - is PartiqlAst.Type.AnyType -> transformTypeAnyType(node) - is PartiqlAst.Type.EsBoolean -> transformTypeEsBoolean(node) - is PartiqlAst.Type.EsInteger -> transformTypeEsInteger(node) - is PartiqlAst.Type.EsFloat -> transformTypeEsFloat(node) - is PartiqlAst.Type.EsText -> transformTypeEsText(node) - is PartiqlAst.Type.EsAny -> transformTypeEsAny(node) - is PartiqlAst.Type.SparkShort -> transformTypeSparkShort(node) - is PartiqlAst.Type.SparkInteger -> transformTypeSparkInteger(node) - is PartiqlAst.Type.SparkLong -> transformTypeSparkLong(node) - is PartiqlAst.Type.SparkDouble -> transformTypeSparkDouble(node) - is PartiqlAst.Type.SparkBoolean -> transformTypeSparkBoolean(node) - is PartiqlAst.Type.SparkFloat -> transformTypeSparkFloat(node) - is PartiqlAst.Type.RsVarcharMax -> transformTypeRsVarcharMax(node) - is PartiqlAst.Type.RsInteger -> transformTypeRsInteger(node) - is PartiqlAst.Type.RsBigint -> transformTypeRsBigint(node) - is PartiqlAst.Type.RsBoolean -> transformTypeRsBoolean(node) - is PartiqlAst.Type.RsReal -> transformTypeRsReal(node) - is PartiqlAst.Type.RsDoublePrecision -> transformTypeRsDoublePrecision(node) - is PartiqlAst.Type.CustomType -> transformTypeCustomType(node) - } - // Variant TypeNullType - open fun transformTypeNullType(node: PartiqlAst.Type.NullType): PartiqlAst.Type { - val new_metas = transformTypeNullType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.NullType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeNullType_metas(node: PartiqlAst.Type.NullType) = - transformMetas(node.metas) - - // Variant TypeBooleanType - open fun transformTypeBooleanType(node: PartiqlAst.Type.BooleanType): PartiqlAst.Type { - val new_metas = transformTypeBooleanType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.BooleanType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeBooleanType_metas(node: PartiqlAst.Type.BooleanType) = - transformMetas(node.metas) - - // Variant TypeSmallintType - open fun transformTypeSmallintType(node: PartiqlAst.Type.SmallintType): PartiqlAst.Type { - val new_metas = transformTypeSmallintType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.SmallintType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeSmallintType_metas(node: PartiqlAst.Type.SmallintType) = - transformMetas(node.metas) - - // Variant TypeInteger4Type - open fun transformTypeInteger4Type(node: PartiqlAst.Type.Integer4Type): PartiqlAst.Type { - val new_metas = transformTypeInteger4Type_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.Integer4Type( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeInteger4Type_metas(node: PartiqlAst.Type.Integer4Type) = - transformMetas(node.metas) - - // Variant TypeInteger8Type - open fun transformTypeInteger8Type(node: PartiqlAst.Type.Integer8Type): PartiqlAst.Type { - val new_metas = transformTypeInteger8Type_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.Integer8Type( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeInteger8Type_metas(node: PartiqlAst.Type.Integer8Type) = - transformMetas(node.metas) - - // Variant TypeIntegerType - open fun transformTypeIntegerType(node: PartiqlAst.Type.IntegerType): PartiqlAst.Type { - val new_metas = transformTypeIntegerType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.IntegerType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeIntegerType_metas(node: PartiqlAst.Type.IntegerType) = - transformMetas(node.metas) - - // Variant TypeFloatType - open fun transformTypeFloatType(node: PartiqlAst.Type.FloatType): PartiqlAst.Type { - val new_precision = transformTypeFloatType_precision(node) - val new_metas = transformTypeFloatType_metas(node) - return if ( - node.precision !== new_precision || - node.metas !== new_metas - ) { - PartiqlAst.Type.FloatType( - precision = new_precision, - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeFloatType_precision(node: PartiqlAst.Type.FloatType) = - node.precision?.let { transformLongPrimitive(it) } - open fun transformTypeFloatType_metas(node: PartiqlAst.Type.FloatType) = - transformMetas(node.metas) - - // Variant TypeRealType - open fun transformTypeRealType(node: PartiqlAst.Type.RealType): PartiqlAst.Type { - val new_metas = transformTypeRealType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.RealType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeRealType_metas(node: PartiqlAst.Type.RealType) = - transformMetas(node.metas) - - // Variant TypeDoublePrecisionType - open fun transformTypeDoublePrecisionType(node: PartiqlAst.Type.DoublePrecisionType): PartiqlAst.Type { - val new_metas = transformTypeDoublePrecisionType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.DoublePrecisionType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeDoublePrecisionType_metas(node: PartiqlAst.Type.DoublePrecisionType) = - transformMetas(node.metas) - - // Variant TypeDecimalType - open fun transformTypeDecimalType(node: PartiqlAst.Type.DecimalType): PartiqlAst.Type { - val new_precision = transformTypeDecimalType_precision(node) - val new_scale = transformTypeDecimalType_scale(node) - val new_metas = transformTypeDecimalType_metas(node) - return if ( - node.precision !== new_precision || - node.scale !== new_scale || - node.metas !== new_metas - ) { - PartiqlAst.Type.DecimalType( - precision = new_precision, - scale = new_scale, - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeDecimalType_precision(node: PartiqlAst.Type.DecimalType) = - node.precision?.let { transformLongPrimitive(it) } - open fun transformTypeDecimalType_scale(node: PartiqlAst.Type.DecimalType) = - node.scale?.let { transformLongPrimitive(it) } - open fun transformTypeDecimalType_metas(node: PartiqlAst.Type.DecimalType) = - transformMetas(node.metas) - - // Variant TypeNumericType - open fun transformTypeNumericType(node: PartiqlAst.Type.NumericType): PartiqlAst.Type { - val new_precision = transformTypeNumericType_precision(node) - val new_scale = transformTypeNumericType_scale(node) - val new_metas = transformTypeNumericType_metas(node) - return if ( - node.precision !== new_precision || - node.scale !== new_scale || - node.metas !== new_metas - ) { - PartiqlAst.Type.NumericType( - precision = new_precision, - scale = new_scale, - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeNumericType_precision(node: PartiqlAst.Type.NumericType) = - node.precision?.let { transformLongPrimitive(it) } - open fun transformTypeNumericType_scale(node: PartiqlAst.Type.NumericType) = - node.scale?.let { transformLongPrimitive(it) } - open fun transformTypeNumericType_metas(node: PartiqlAst.Type.NumericType) = - transformMetas(node.metas) - - // Variant TypeTimestampType - open fun transformTypeTimestampType(node: PartiqlAst.Type.TimestampType): PartiqlAst.Type { - val new_metas = transformTypeTimestampType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.TimestampType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeTimestampType_metas(node: PartiqlAst.Type.TimestampType) = - transformMetas(node.metas) - - // Variant TypeCharacterType - open fun transformTypeCharacterType(node: PartiqlAst.Type.CharacterType): PartiqlAst.Type { - val new_length = transformTypeCharacterType_length(node) - val new_metas = transformTypeCharacterType_metas(node) - return if ( - node.length !== new_length || - node.metas !== new_metas - ) { - PartiqlAst.Type.CharacterType( - length = new_length, - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeCharacterType_length(node: PartiqlAst.Type.CharacterType) = - node.length?.let { transformLongPrimitive(it) } - open fun transformTypeCharacterType_metas(node: PartiqlAst.Type.CharacterType) = - transformMetas(node.metas) - - // Variant TypeCharacterVaryingType - open fun transformTypeCharacterVaryingType(node: PartiqlAst.Type.CharacterVaryingType): PartiqlAst.Type { - val new_length = transformTypeCharacterVaryingType_length(node) - val new_metas = transformTypeCharacterVaryingType_metas(node) - return if ( - node.length !== new_length || - node.metas !== new_metas - ) { - PartiqlAst.Type.CharacterVaryingType( - length = new_length, - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeCharacterVaryingType_length(node: PartiqlAst.Type.CharacterVaryingType) = - node.length?.let { transformLongPrimitive(it) } - open fun transformTypeCharacterVaryingType_metas(node: PartiqlAst.Type.CharacterVaryingType) = - transformMetas(node.metas) - - // Variant TypeMissingType - open fun transformTypeMissingType(node: PartiqlAst.Type.MissingType): PartiqlAst.Type { - val new_metas = transformTypeMissingType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.MissingType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeMissingType_metas(node: PartiqlAst.Type.MissingType) = - transformMetas(node.metas) - - // Variant TypeStringType - open fun transformTypeStringType(node: PartiqlAst.Type.StringType): PartiqlAst.Type { - val new_metas = transformTypeStringType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.StringType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeStringType_metas(node: PartiqlAst.Type.StringType) = - transformMetas(node.metas) - - // Variant TypeSymbolType - open fun transformTypeSymbolType(node: PartiqlAst.Type.SymbolType): PartiqlAst.Type { - val new_metas = transformTypeSymbolType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.SymbolType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeSymbolType_metas(node: PartiqlAst.Type.SymbolType) = - transformMetas(node.metas) - - // Variant TypeBlobType - open fun transformTypeBlobType(node: PartiqlAst.Type.BlobType): PartiqlAst.Type { - val new_metas = transformTypeBlobType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.BlobType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeBlobType_metas(node: PartiqlAst.Type.BlobType) = - transformMetas(node.metas) - - // Variant TypeClobType - open fun transformTypeClobType(node: PartiqlAst.Type.ClobType): PartiqlAst.Type { - val new_metas = transformTypeClobType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.ClobType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeClobType_metas(node: PartiqlAst.Type.ClobType) = - transformMetas(node.metas) - - // Variant TypeDateType - open fun transformTypeDateType(node: PartiqlAst.Type.DateType): PartiqlAst.Type { - val new_metas = transformTypeDateType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.DateType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeDateType_metas(node: PartiqlAst.Type.DateType) = - transformMetas(node.metas) - - // Variant TypeTimeType - open fun transformTypeTimeType(node: PartiqlAst.Type.TimeType): PartiqlAst.Type { - val new_precision = transformTypeTimeType_precision(node) - val new_metas = transformTypeTimeType_metas(node) - return if ( - node.precision !== new_precision || - node.metas !== new_metas - ) { - PartiqlAst.Type.TimeType( - precision = new_precision, - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeTimeType_precision(node: PartiqlAst.Type.TimeType) = - node.precision?.let { transformLongPrimitive(it) } - open fun transformTypeTimeType_metas(node: PartiqlAst.Type.TimeType) = - transformMetas(node.metas) - - // Variant TypeTimeWithTimeZoneType - open fun transformTypeTimeWithTimeZoneType(node: PartiqlAst.Type.TimeWithTimeZoneType): PartiqlAst.Type { - val new_precision = transformTypeTimeWithTimeZoneType_precision(node) - val new_metas = transformTypeTimeWithTimeZoneType_metas(node) - return if ( - node.precision !== new_precision || - node.metas !== new_metas - ) { - PartiqlAst.Type.TimeWithTimeZoneType( - precision = new_precision, - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeTimeWithTimeZoneType_precision(node: PartiqlAst.Type.TimeWithTimeZoneType) = - node.precision?.let { transformLongPrimitive(it) } - open fun transformTypeTimeWithTimeZoneType_metas(node: PartiqlAst.Type.TimeWithTimeZoneType) = - transformMetas(node.metas) - - // Variant TypeStructType - open fun transformTypeStructType(node: PartiqlAst.Type.StructType): PartiqlAst.Type { - val new_metas = transformTypeStructType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.StructType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeStructType_metas(node: PartiqlAst.Type.StructType) = - transformMetas(node.metas) - - // Variant TypeTupleType - open fun transformTypeTupleType(node: PartiqlAst.Type.TupleType): PartiqlAst.Type { - val new_metas = transformTypeTupleType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.TupleType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeTupleType_metas(node: PartiqlAst.Type.TupleType) = - transformMetas(node.metas) - - // Variant TypeListType - open fun transformTypeListType(node: PartiqlAst.Type.ListType): PartiqlAst.Type { - val new_metas = transformTypeListType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.ListType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeListType_metas(node: PartiqlAst.Type.ListType) = - transformMetas(node.metas) - - // Variant TypeSexpType - open fun transformTypeSexpType(node: PartiqlAst.Type.SexpType): PartiqlAst.Type { - val new_metas = transformTypeSexpType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.SexpType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeSexpType_metas(node: PartiqlAst.Type.SexpType) = - transformMetas(node.metas) - - // Variant TypeBagType - open fun transformTypeBagType(node: PartiqlAst.Type.BagType): PartiqlAst.Type { - val new_metas = transformTypeBagType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.BagType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeBagType_metas(node: PartiqlAst.Type.BagType) = - transformMetas(node.metas) - - // Variant TypeAnyType - open fun transformTypeAnyType(node: PartiqlAst.Type.AnyType): PartiqlAst.Type { - val new_metas = transformTypeAnyType_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.AnyType( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeAnyType_metas(node: PartiqlAst.Type.AnyType) = - transformMetas(node.metas) - - // Variant TypeEsBoolean - open fun transformTypeEsBoolean(node: PartiqlAst.Type.EsBoolean): PartiqlAst.Type { - val new_metas = transformTypeEsBoolean_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.EsBoolean( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeEsBoolean_metas(node: PartiqlAst.Type.EsBoolean) = - transformMetas(node.metas) - - // Variant TypeEsInteger - open fun transformTypeEsInteger(node: PartiqlAst.Type.EsInteger): PartiqlAst.Type { - val new_metas = transformTypeEsInteger_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.EsInteger( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeEsInteger_metas(node: PartiqlAst.Type.EsInteger) = - transformMetas(node.metas) - - // Variant TypeEsFloat - open fun transformTypeEsFloat(node: PartiqlAst.Type.EsFloat): PartiqlAst.Type { - val new_metas = transformTypeEsFloat_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.EsFloat( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeEsFloat_metas(node: PartiqlAst.Type.EsFloat) = - transformMetas(node.metas) - - // Variant TypeEsText - open fun transformTypeEsText(node: PartiqlAst.Type.EsText): PartiqlAst.Type { - val new_metas = transformTypeEsText_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.EsText( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeEsText_metas(node: PartiqlAst.Type.EsText) = - transformMetas(node.metas) - - // Variant TypeEsAny - open fun transformTypeEsAny(node: PartiqlAst.Type.EsAny): PartiqlAst.Type { - val new_metas = transformTypeEsAny_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.EsAny( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeEsAny_metas(node: PartiqlAst.Type.EsAny) = - transformMetas(node.metas) - - // Variant TypeSparkShort - open fun transformTypeSparkShort(node: PartiqlAst.Type.SparkShort): PartiqlAst.Type { - val new_metas = transformTypeSparkShort_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.SparkShort( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeSparkShort_metas(node: PartiqlAst.Type.SparkShort) = - transformMetas(node.metas) - - // Variant TypeSparkInteger - open fun transformTypeSparkInteger(node: PartiqlAst.Type.SparkInteger): PartiqlAst.Type { - val new_metas = transformTypeSparkInteger_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.SparkInteger( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeSparkInteger_metas(node: PartiqlAst.Type.SparkInteger) = - transformMetas(node.metas) - - // Variant TypeSparkLong - open fun transformTypeSparkLong(node: PartiqlAst.Type.SparkLong): PartiqlAst.Type { - val new_metas = transformTypeSparkLong_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.SparkLong( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeSparkLong_metas(node: PartiqlAst.Type.SparkLong) = - transformMetas(node.metas) - - // Variant TypeSparkDouble - open fun transformTypeSparkDouble(node: PartiqlAst.Type.SparkDouble): PartiqlAst.Type { - val new_metas = transformTypeSparkDouble_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.SparkDouble( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeSparkDouble_metas(node: PartiqlAst.Type.SparkDouble) = - transformMetas(node.metas) - - // Variant TypeSparkBoolean - open fun transformTypeSparkBoolean(node: PartiqlAst.Type.SparkBoolean): PartiqlAst.Type { - val new_metas = transformTypeSparkBoolean_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.SparkBoolean( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeSparkBoolean_metas(node: PartiqlAst.Type.SparkBoolean) = - transformMetas(node.metas) - - // Variant TypeSparkFloat - open fun transformTypeSparkFloat(node: PartiqlAst.Type.SparkFloat): PartiqlAst.Type { - val new_metas = transformTypeSparkFloat_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.SparkFloat( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeSparkFloat_metas(node: PartiqlAst.Type.SparkFloat) = - transformMetas(node.metas) - - // Variant TypeRsVarcharMax - open fun transformTypeRsVarcharMax(node: PartiqlAst.Type.RsVarcharMax): PartiqlAst.Type { - val new_metas = transformTypeRsVarcharMax_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.RsVarcharMax( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeRsVarcharMax_metas(node: PartiqlAst.Type.RsVarcharMax) = - transformMetas(node.metas) - - // Variant TypeRsInteger - open fun transformTypeRsInteger(node: PartiqlAst.Type.RsInteger): PartiqlAst.Type { - val new_metas = transformTypeRsInteger_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.RsInteger( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeRsInteger_metas(node: PartiqlAst.Type.RsInteger) = - transformMetas(node.metas) - - // Variant TypeRsBigint - open fun transformTypeRsBigint(node: PartiqlAst.Type.RsBigint): PartiqlAst.Type { - val new_metas = transformTypeRsBigint_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.RsBigint( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeRsBigint_metas(node: PartiqlAst.Type.RsBigint) = - transformMetas(node.metas) - - // Variant TypeRsBoolean - open fun transformTypeRsBoolean(node: PartiqlAst.Type.RsBoolean): PartiqlAst.Type { - val new_metas = transformTypeRsBoolean_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.RsBoolean( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeRsBoolean_metas(node: PartiqlAst.Type.RsBoolean) = - transformMetas(node.metas) - - // Variant TypeRsReal - open fun transformTypeRsReal(node: PartiqlAst.Type.RsReal): PartiqlAst.Type { - val new_metas = transformTypeRsReal_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.RsReal( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeRsReal_metas(node: PartiqlAst.Type.RsReal) = - transformMetas(node.metas) - - // Variant TypeRsDoublePrecision - open fun transformTypeRsDoublePrecision(node: PartiqlAst.Type.RsDoublePrecision): PartiqlAst.Type { - val new_metas = transformTypeRsDoublePrecision_metas(node) - return if ( - node.metas !== new_metas - ) { - PartiqlAst.Type.RsDoublePrecision( - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeRsDoublePrecision_metas(node: PartiqlAst.Type.RsDoublePrecision) = - transformMetas(node.metas) - - // Variant TypeCustomType - open fun transformTypeCustomType(node: PartiqlAst.Type.CustomType): PartiqlAst.Type { - val new_name = transformTypeCustomType_name(node) - val new_metas = transformTypeCustomType_metas(node) - return if ( - node.name !== new_name || - node.metas !== new_metas - ) { - PartiqlAst.Type.CustomType( - name = new_name, - metas = new_metas - ) - } else { - node - } - } - open fun transformTypeCustomType_name(node: PartiqlAst.Type.CustomType) = - transformSymbolPrimitive(node.name) - open fun transformTypeCustomType_metas(node: PartiqlAst.Type.CustomType) = - transformMetas(node.metas) - - } -} - - - -////////////////////////////////////// -// Cross domain transforms -////////////////////////////////////// - diff --git a/lang/src/org/partiql/lang/errors/ErrorAndErrorContexts.kt b/lang/src/org/partiql/lang/errors/ErrorAndErrorContexts.kt index 0a14713977..5202e48177 100644 --- a/lang/src/org/partiql/lang/errors/ErrorAndErrorContexts.kt +++ b/lang/src/org/partiql/lang/errors/ErrorAndErrorContexts.kt @@ -15,9 +15,8 @@ package org.partiql.lang.errors import com.amazon.ion.IonValue -import org.partiql.lang.errors.PropertyType.* -import org.partiql.lang.syntax.* -import java.util.* +import org.partiql.lang.syntax.TokenType +import java.util.EnumMap internal const val UNKNOWN: String = "" @@ -26,10 +25,10 @@ internal const val UNKNOWN: String = "" * Categories for errors. Should map to stages in the Compiler and Evaluator. */ enum class ErrorCategory(val message: String) { - LEXER ("Lexer Error"), - PARSER ("Parser Error"), - SEMANTIC ("Semantic Error"), - EVALUATOR ("Evaluator Error"); + LEXER("Lexer Error"), + PARSER("Parser Error"), + SEMANTIC("Semantic Error"), + EVALUATOR("Evaluator Error"); override fun toString() = message } @@ -47,42 +46,42 @@ enum class ErrorCategory(val message: String) { * */ enum class Property(val propertyName: String, val propertyType: PropertyType) { - LINE_NUMBER("line_no", LONG_CLASS), - COLUMN_NUMBER("column_no", LONG_CLASS), - TOKEN_STRING("token_string", STRING_CLASS), - CAST_TO("cast_to", STRING_CLASS), - CAST_FROM("cast_from", STRING_CLASS), - KEYWORD("keyword", STRING_CLASS), - TOKEN_TYPE("token_type", TOKEN_CLASS), - EXPECTED_TOKEN_TYPE("expected_token_type", TOKEN_CLASS), - EXPECTED_TOKEN_TYPE_1_OF_2("expected_token_type_1_of_2", TOKEN_CLASS), - EXPECTED_TOKEN_TYPE_2_OF_2("expected_token_type_2_of_2", TOKEN_CLASS), - TOKEN_VALUE("token_value", ION_VALUE_CLASS), - EXPECTED_ARITY_MIN("arity_min", INTEGER_CLASS), - EXPECTED_ARITY_MAX("arity_max", INTEGER_CLASS), - ACTUAL_ARITY("actual_arity", INTEGER_CLASS), - EXPECTED_PARAMETER_ORDINAL("expected_parameter_ordinal", INTEGER_CLASS), - BOUND_PARAMETER_COUNT("bound_parameter_count", INTEGER_CLASS), - TIMESTAMP_FORMAT_PATTERN("timestamp_format_pattern", STRING_CLASS), - TIMESTAMP_FORMAT_PATTERN_FIELDS("timestamp_format_pattern_fields", STRING_CLASS), - TIMESTAMP_STRING("timestamp_string", STRING_CLASS), - BINDING_NAME("binding_name", STRING_CLASS), - BINDING_NAME_MATCHES("binding_name_matches", STRING_CLASS), - LIKE_VALUE("value_to_match", STRING_CLASS), - LIKE_PATTERN("pattern", STRING_CLASS), - LIKE_ESCAPE("escape_char", STRING_CLASS), - FUNCTION_NAME("function_name", STRING_CLASS), - ARGUMENT_POSITION("argument_position", INTEGER_CLASS), - NARY_OP("nary_op", STRING_CLASS), - PROCEDURE_NAME("procedure_name", STRING_CLASS), - EXPECTED_ARGUMENT_TYPES("expected_types", STRING_CLASS), - ACTUAL_ARGUMENT_TYPES("actual_types", STRING_CLASS), - FEATURE_NAME("FEATURE_NAME", STRING_CLASS), - ACTUAL_TYPE("ACTUAL_TYPE", STRING_CLASS), - INT_SIZE_IN_BYTES("INT_SIZE", INTEGER_CLASS), - EXPECTED_STATIC_TYPE("EXPECTED_STATIC_TYPE", STRING_CLASS), - CONSTANT("CONSTANT", STRING_CLASS), - MESSAGE("MESSAGE", STRING_CLASS) + LINE_NUMBER("line_no", PropertyType.LONG_CLASS), + COLUMN_NUMBER("column_no", PropertyType.LONG_CLASS), + TOKEN_STRING("token_string", PropertyType.STRING_CLASS), + CAST_TO("cast_to", PropertyType.STRING_CLASS), + CAST_FROM("cast_from", PropertyType.STRING_CLASS), + KEYWORD("keyword", PropertyType.STRING_CLASS), + TOKEN_TYPE("token_type", PropertyType.TOKEN_CLASS), + EXPECTED_TOKEN_TYPE("expected_token_type", PropertyType.TOKEN_CLASS), + EXPECTED_TOKEN_TYPE_1_OF_2("expected_token_type_1_of_2", PropertyType.TOKEN_CLASS), + EXPECTED_TOKEN_TYPE_2_OF_2("expected_token_type_2_of_2", PropertyType.TOKEN_CLASS), + TOKEN_VALUE("token_value", PropertyType.ION_VALUE_CLASS), + EXPECTED_ARITY_MIN("arity_min", PropertyType.INTEGER_CLASS), + EXPECTED_ARITY_MAX("arity_max", PropertyType.INTEGER_CLASS), + ACTUAL_ARITY("actual_arity", PropertyType.INTEGER_CLASS), + EXPECTED_PARAMETER_ORDINAL("expected_parameter_ordinal", PropertyType.INTEGER_CLASS), + BOUND_PARAMETER_COUNT("bound_parameter_count", PropertyType.INTEGER_CLASS), + TIMESTAMP_FORMAT_PATTERN("timestamp_format_pattern", PropertyType.STRING_CLASS), + TIMESTAMP_FORMAT_PATTERN_FIELDS("timestamp_format_pattern_fields", PropertyType.STRING_CLASS), + TIMESTAMP_STRING("timestamp_string", PropertyType.STRING_CLASS), + BINDING_NAME("binding_name", PropertyType.STRING_CLASS), + BINDING_NAME_MATCHES("binding_name_matches", PropertyType.STRING_CLASS), + LIKE_VALUE("value_to_match", PropertyType.STRING_CLASS), + LIKE_PATTERN("pattern", PropertyType.STRING_CLASS), + LIKE_ESCAPE("escape_char", PropertyType.STRING_CLASS), + FUNCTION_NAME("function_name", PropertyType.STRING_CLASS), + ARGUMENT_POSITION("argument_position", PropertyType.INTEGER_CLASS), + NARY_OP("nary_op", PropertyType.STRING_CLASS), + PROCEDURE_NAME("procedure_name", PropertyType.STRING_CLASS), + EXPECTED_ARGUMENT_TYPES("expected_types", PropertyType.STRING_CLASS), + ACTUAL_ARGUMENT_TYPES("actual_types", PropertyType.STRING_CLASS), + FEATURE_NAME("FEATURE_NAME", PropertyType.STRING_CLASS), + ACTUAL_TYPE("ACTUAL_TYPE", PropertyType.STRING_CLASS), + INT_SIZE_IN_BYTES("INT_SIZE", PropertyType.INTEGER_CLASS), + EXPECTED_STATIC_TYPE("EXPECTED_STATIC_TYPE", PropertyType.STRING_CLASS), + CONSTANT("CONSTANT", PropertyType.STRING_CLASS), + MESSAGE("MESSAGE", PropertyType.STRING_CLASS) } /** @@ -99,29 +98,27 @@ abstract class PropertyValue(val type: PropertyType) { val value: Any get() = when (type) { - LONG_CLASS -> longValue() - STRING_CLASS -> stringValue() - INTEGER_CLASS -> integerValue() - TOKEN_CLASS -> tokenTypeValue() - ION_VALUE_CLASS -> ionValue() + PropertyType.LONG_CLASS -> longValue() + PropertyType.STRING_CLASS -> stringValue() + PropertyType.INTEGER_CLASS -> integerValue() + PropertyType.TOKEN_CLASS -> tokenTypeValue() + PropertyType.ION_VALUE_CLASS -> ionValue() } override fun toString(): String = when (type) { - ION_VALUE_CLASS -> (value as IonValue).toPrettyString() + PropertyType.ION_VALUE_CLASS -> (value as IonValue).toPrettyString() else -> value.toString() } } - - /** * A [PropertyType] is a top level type for all types of values that appear as properties in error codes. * Clients can access the type (as a `Class<*>`) of a property's value through [getType()]. * */ -enum class PropertyType(private val type: Class<*>){ - LONG_CLASS (Long::class.javaObjectType), +enum class PropertyType(private val type: Class<*>) { + LONG_CLASS(Long::class.javaObjectType), STRING_CLASS(String::class.javaObjectType), INTEGER_CLASS(Int::class.javaObjectType), TOKEN_CLASS(TokenType::class.javaObjectType), @@ -157,7 +154,7 @@ class PropertyValueMap(private val map: EnumMap = EnumM operator fun get(key: Property): PropertyValue? = map[key] - private fun verifyTypeAndSet(prop: Property, expectedType: PropertyType, value : T, pValue: PropertyValue) { + private fun verifyTypeAndSet(prop: Property, expectedType: PropertyType, value: T, pValue: PropertyValue) { if (prop.propertyType == expectedType) { map[prop] = pValue } else { @@ -174,10 +171,10 @@ class PropertyValueMap(private val map: EnumMap = EnumM * @throws [IllegalArgumentException] if the [Property] used as `key` requires values of type **other than** [String] */ operator fun set(key: Property, strValue: String) { - val o = object : PropertyValue(STRING_CLASS) { + val o = object : PropertyValue(PropertyType.STRING_CLASS) { override fun stringValue(): String = strValue } - verifyTypeAndSet(key, STRING_CLASS, strValue ,o) + verifyTypeAndSet(key, PropertyType.STRING_CLASS, strValue, o) } @@ -190,10 +187,10 @@ class PropertyValueMap(private val map: EnumMap = EnumM * @throws [IllegalArgumentException] if the [Property] used as `key` requires values of type **other than** [Long] */ operator fun set(key: Property, longValue: Long) { - val o = object : PropertyValue(LONG_CLASS) { + val o = object : PropertyValue(PropertyType.LONG_CLASS) { override fun longValue(): Long = longValue } - verifyTypeAndSet(key, LONG_CLASS, longValue, o) + verifyTypeAndSet(key, PropertyType.LONG_CLASS, longValue, o) } @@ -206,10 +203,10 @@ class PropertyValueMap(private val map: EnumMap = EnumM * @throws [IllegalArgumentException] if the [Property] used as `key` requires values of type **other than** [Int] */ operator fun set(key: Property, intValue: Int) { - val o = object : PropertyValue(INTEGER_CLASS) { + val o = object : PropertyValue(PropertyType.INTEGER_CLASS) { override fun integerValue(): Int = intValue } - verifyTypeAndSet(key, INTEGER_CLASS, intValue, o) + verifyTypeAndSet(key, PropertyType.INTEGER_CLASS, intValue, o) } @@ -222,10 +219,10 @@ class PropertyValueMap(private val map: EnumMap = EnumM * @throws [IllegalArgumentException] if the [Property] used as `key` requires values of type **other than** [IonValue] */ operator fun set(key: Property, ionValue: IonValue) { - val o = object : PropertyValue(ION_VALUE_CLASS) { + val o = object : PropertyValue(PropertyType.ION_VALUE_CLASS) { override fun ionValue(): IonValue = ionValue } - verifyTypeAndSet(key, ION_VALUE_CLASS, ionValue, o) + verifyTypeAndSet(key, PropertyType.ION_VALUE_CLASS, ionValue, o) } @@ -238,10 +235,10 @@ class PropertyValueMap(private val map: EnumMap = EnumM * @throws [IllegalArgumentException] if the [Property] used as `key` requires values of type **other than** [TokenType] */ operator fun set(key: Property, tokenTypeValue: TokenType) { - val o = object : PropertyValue(TOKEN_CLASS) { + val o = object : PropertyValue(PropertyType.TOKEN_CLASS) { override fun tokenTypeValue(): TokenType = tokenTypeValue } - verifyTypeAndSet(key, TOKEN_CLASS, tokenTypeValue, o) + verifyTypeAndSet(key, PropertyType.TOKEN_CLASS, tokenTypeValue, o) } diff --git a/lang/src/org/partiql/lang/eval/AnyOfCastTable.kt b/lang/src/org/partiql/lang/eval/AnyOfCastTable.kt index 380baf4bcc..443cb7ef80 100644 --- a/lang/src/org/partiql/lang/eval/AnyOfCastTable.kt +++ b/lang/src/org/partiql/lang/eval/AnyOfCastTable.kt @@ -11,7 +11,6 @@ import org.partiql.lang.types.CollectionType import org.partiql.lang.types.SingleType import org.partiql.lang.types.StaticType import org.partiql.lang.types.StructType -import java.lang.IllegalStateException /** * The template table that encodes the type conversion precedence for a source type to target type. diff --git a/lang/src/org/partiql/lang/eval/Bindings.kt b/lang/src/org/partiql/lang/eval/Bindings.kt index 2f76eacbee..3e9dabbdbb 100644 --- a/lang/src/org/partiql/lang/eval/Bindings.kt +++ b/lang/src/org/partiql/lang/eval/Bindings.kt @@ -13,10 +13,14 @@ */ package org.partiql.lang.eval -import com.amazon.ion.* +import com.amazon.ion.IonStruct +import com.amazon.ion.IonSystem +import com.amazon.ion.IonValue import org.partiql.lang.ast.CaseSensitivity import org.partiql.lang.errors.ErrorCode -import org.partiql.lang.util.* +import org.partiql.lang.util.errAmbiguousBinding +import org.partiql.lang.util.isBindingNameEquivalent +import org.partiql.lang.util.stringValue /** Indicates if the lookup of a particular binding should be case-sensitive or not. */ enum class BindingCase { diff --git a/lang/src/org/partiql/lang/eval/CompileOptions.kt b/lang/src/org/partiql/lang/eval/CompileOptions.kt index fa90442921..e7ddb132cc 100644 --- a/lang/src/org/partiql/lang/eval/CompileOptions.kt +++ b/lang/src/org/partiql/lang/eval/CompileOptions.kt @@ -15,6 +15,11 @@ package org.partiql.lang.eval import org.partiql.lang.domains.PartiqlAst +import org.partiql.lang.eval.ProjectionIterationBehavior.FILTER_MISSING +import org.partiql.lang.eval.ProjectionIterationBehavior.UNFILTERED +import org.partiql.lang.eval.ThunkReturnTypeAssertions.ENABLED +import org.partiql.lang.eval.VisitorTransformMode.DEFAULT +import org.partiql.lang.eval.VisitorTransformMode.NONE import org.partiql.lang.eval.visitors.IDENTITY_VISITOR_TRANSFORM import org.partiql.lang.eval.visitors.basicVisitorTransforms import java.time.ZoneOffset diff --git a/lang/src/org/partiql/lang/eval/Environment.kt b/lang/src/org/partiql/lang/eval/Environment.kt index 25b3373657..7a8e7d9a45 100644 --- a/lang/src/org/partiql/lang/eval/Environment.kt +++ b/lang/src/org/partiql/lang/eval/Environment.kt @@ -14,7 +14,7 @@ package org.partiql.lang.eval -import java.util.* +import java.util.TreeMap /** * The environment for execution. diff --git a/lang/src/org/partiql/lang/eval/EvaluatingCompiler.kt b/lang/src/org/partiql/lang/eval/EvaluatingCompiler.kt index ada02daa0f..2dd4ebf2ad 100644 --- a/lang/src/org/partiql/lang/eval/EvaluatingCompiler.kt +++ b/lang/src/org/partiql/lang/eval/EvaluatingCompiler.kt @@ -14,12 +14,85 @@ package org.partiql.lang.eval - -import com.amazon.ion.* -import org.partiql.lang.ast.* +import com.amazon.ion.IntegerSize +import com.amazon.ion.IonInt +import com.amazon.ion.IonSexp +import com.amazon.ion.IonString +import com.amazon.ion.IonValue +import com.amazon.ion.Timestamp +import org.partiql.lang.ast.AggregateCallSiteListMeta +import org.partiql.lang.ast.AggregateRegisterIdMeta +import org.partiql.lang.ast.AstDeserializerBuilder +import org.partiql.lang.ast.AstVersion +import org.partiql.lang.ast.CallAgg +import org.partiql.lang.ast.CaseSensitivity +import org.partiql.lang.ast.Coalesce +import org.partiql.lang.ast.CreateIndex +import org.partiql.lang.ast.CreateTable +import org.partiql.lang.ast.DataManipulation +import org.partiql.lang.ast.DateLiteral +import org.partiql.lang.ast.DropIndex +import org.partiql.lang.ast.DropTable +import org.partiql.lang.ast.Exec +import org.partiql.lang.ast.ExprNode +import org.partiql.lang.ast.FromSource +import org.partiql.lang.ast.FromSourceExpr +import org.partiql.lang.ast.FromSourceJoin +import org.partiql.lang.ast.FromSourceLet +import org.partiql.lang.ast.FromSourceUnpivot +import org.partiql.lang.ast.GroupBy +import org.partiql.lang.ast.GroupByItem +import org.partiql.lang.ast.GroupingStrategy +import org.partiql.lang.ast.IsCountStarMeta +import org.partiql.lang.ast.JoinOp +import org.partiql.lang.ast.LetSource +import org.partiql.lang.ast.Literal +import org.partiql.lang.ast.LiteralMissing +import org.partiql.lang.ast.MetaContainer +import org.partiql.lang.ast.NAry +import org.partiql.lang.ast.NAryOp +import org.partiql.lang.ast.NullIf +import org.partiql.lang.ast.Parameter +import org.partiql.lang.ast.Path +import org.partiql.lang.ast.PathComponent +import org.partiql.lang.ast.PathComponentExpr +import org.partiql.lang.ast.PathComponentUnpivot +import org.partiql.lang.ast.PathComponentWildcard +import org.partiql.lang.ast.ScopeQualifier +import org.partiql.lang.ast.SearchedCase +import org.partiql.lang.ast.Select +import org.partiql.lang.ast.SelectListItemExpr +import org.partiql.lang.ast.SelectListItemProjectAll +import org.partiql.lang.ast.SelectListItemStar +import org.partiql.lang.ast.SelectProjectionList +import org.partiql.lang.ast.SelectProjectionPivot +import org.partiql.lang.ast.SelectProjectionValue +import org.partiql.lang.ast.Seq +import org.partiql.lang.ast.SeqType +import org.partiql.lang.ast.SetQuantifier +import org.partiql.lang.ast.SimpleCase +import org.partiql.lang.ast.SourceLocationMeta +import org.partiql.lang.ast.Struct +import org.partiql.lang.ast.SymbolicName +import org.partiql.lang.ast.TimeLiteral +import org.partiql.lang.ast.Typed +import org.partiql.lang.ast.TypedOp +import org.partiql.lang.ast.UniqueNameMeta +import org.partiql.lang.ast.VariableReference +import org.partiql.lang.ast.staticType +import org.partiql.lang.ast.toAstExpr +import org.partiql.lang.ast.toAstStatement +import org.partiql.lang.ast.toAstType +import org.partiql.lang.ast.toExprNode +import org.partiql.lang.ast.toExprNodeSetQuantifier +import org.partiql.lang.ast.toPartiQlMetaContainer import org.partiql.lang.domains.PartiqlAst -import org.partiql.lang.errors.* -import org.partiql.lang.eval.binding.* +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.errors.PropertyValueMap +import org.partiql.lang.errors.UNBOUND_QUOTED_IDENTIFIER_HINT +import org.partiql.lang.eval.binding.Alias +import org.partiql.lang.eval.binding.localsBinder import org.partiql.lang.eval.builtins.storedprocedure.StoredProcedure import org.partiql.lang.eval.like.PatternPart import org.partiql.lang.eval.like.executePattern @@ -38,10 +111,28 @@ import org.partiql.lang.types.TypedOpParameter import org.partiql.lang.types.UnknownArguments import org.partiql.lang.types.UnsupportedTypeCheckException import org.partiql.lang.types.toTypedOpParameter -import org.partiql.lang.util.* -import java.math.* -import java.util.* -import kotlin.collections.* +import org.partiql.lang.util.bigDecimalOf +import org.partiql.lang.util.case +import org.partiql.lang.util.checkThreadInterrupted +import org.partiql.lang.util.codePointSequence +import org.partiql.lang.util.compareTo +import org.partiql.lang.util.div +import org.partiql.lang.util.drop +import org.partiql.lang.util.foldLeftProduct +import org.partiql.lang.util.isZero +import org.partiql.lang.util.minus +import org.partiql.lang.util.plus +import org.partiql.lang.util.rem +import org.partiql.lang.util.stringValue +import org.partiql.lang.util.take +import org.partiql.lang.util.times +import org.partiql.lang.util.timestampValue +import org.partiql.lang.util.totalMinutes +import org.partiql.lang.util.unaryMinus +import java.math.BigDecimal +import java.util.LinkedList +import java.util.Stack +import java.util.TreeSet /** * A basic compiler that converts an instance of [ExprNode] to an [Expression]. @@ -88,24 +179,23 @@ internal class EvaluatingCompiler( compilationContextStack.push( when { compilationContextStack.empty() -> CompilationContext(expressionContext, fromSourceNames) - else -> compilationContextStack.peek().createNested(expressionContext, - fromSourceNames) + else -> compilationContextStack.peek().createNested(expressionContext, + fromSourceNames) }) try { return block() - } - finally { + } finally { compilationContextStack.pop() } } private fun Number.exprValue(): ExprValue = when (this) { - is Int -> valueFactory.newInt(this) - is Long -> valueFactory.newInt(this) - is Double -> valueFactory.newFloat(this) + is Int -> valueFactory.newInt(this) + is Long -> valueFactory.newInt(this) + is Double -> valueFactory.newFloat(this) is BigDecimal -> valueFactory.newDecimal(this) - else -> errNoContext("Cannot convert number to expression value: $this", errorCode = ErrorCode.EVALUATOR_INVALID_CONVERSION, internal = true) + else -> errNoContext("Cannot convert number to expression value: $this", errorCode = ErrorCode.EVALUATOR_INVALID_CONVERSION, internal = true) } private fun Boolean.exprValue(): ExprValue = valueFactory.newBoolean(this) @@ -126,7 +216,7 @@ internal class EvaluatingCompiler( private inner class Accumulator( var current: Number? = 0L, val nextFunc: (Number?, ExprValue) -> Number, - val valueFilter: (ExprValue) -> Boolean = { _ -> true} + val valueFilter: (ExprValue) -> Boolean = { _ -> true } ) : ExprAggregator { override fun next(value: ExprValue) { @@ -145,7 +235,7 @@ internal class EvaluatingCompiler( null -> nextNum else -> when { cmpFunc(nextNum, curr) -> nextNum - else -> curr + else -> curr } } } @@ -153,7 +243,9 @@ internal class EvaluatingCompiler( /** Dispatch table for built-in aggregate functions. */ private val builtinAggregates: Map, ExprAggregatorFactory> = { val countAccFunc: (Number?, ExprValue) -> Number = { curr, _ -> curr!! + 1L } - val sumAccFunc: (Number?, ExprValue) -> Number = { curr, next -> curr?.let { it + next.numberValue() } ?: next.numberValue() } + val sumAccFunc: (Number?, ExprValue) -> Number = { curr, next -> + curr?.let { it + next.numberValue() } ?: next.numberValue() + } val minAccFunc = comparisonAccumulator { left, right -> left < right } val maxAccFunc = comparisonAccumulator { left, right -> left > right } @@ -163,11 +255,12 @@ internal class EvaluatingCompiler( var count = 0L override fun next(value: ExprValue) { - if(value.isNotUnknown() && filter.invoke(value)) { + if (value.isNotUnknown() && filter.invoke(value)) { sum = sum?.let { it + value.numberValue() } ?: value.numberValue() count++ } } + override fun compute() = sum?.let { (it / bigDecimalOf(count)).exprValue() } ?: valueFactory.nullValue } } @@ -284,22 +377,22 @@ internal class EvaluatingCompiler( private fun compileExprNode(expr: ExprNode): ThunkEnv { checkThreadInterrupted() return when (expr) { - is Literal -> compileLiteral(expr) - is LiteralMissing -> compileLiteralMissing(expr) + is Literal -> compileLiteral(expr) + is LiteralMissing -> compileLiteralMissing(expr) is VariableReference -> compileVariableReference(expr) - is NAry -> compileNAry(expr) - is Typed -> compileTyped(expr) - is SimpleCase -> compileSimpleCase(expr) - is SearchedCase -> compileSearchedCase(expr) - is Path -> compilePath(expr) - is Struct -> compileStruct(expr) - is Seq -> compileSeq(expr) - is Select -> compileSelect(expr) - is CallAgg -> compileCallAgg(expr) - is Parameter -> compileParameter(expr) - is NullIf -> compileNullIf(expr) - is Coalesce -> compileCoalesce(expr) - is DataManipulation -> err( + is NAry -> compileNAry(expr) + is Typed -> compileTyped(expr) + is SimpleCase -> compileSimpleCase(expr) + is SearchedCase -> compileSearchedCase(expr) + is Path -> compilePath(expr) + is Struct -> compileStruct(expr) + is Seq -> compileSeq(expr) + is Select -> compileSelect(expr) + is CallAgg -> compileCallAgg(expr) + is Parameter -> compileParameter(expr) + is NullIf -> compileNullIf(expr) + is Coalesce -> compileCoalesce(expr) + is DataManipulation -> err( "DML operations are not supported yet", ErrorCode.EVALUATOR_FEATURE_NOT_SUPPORTED_YET, errorContextFrom(expr.metas).also { @@ -403,7 +496,7 @@ internal class EvaluatingCompiler( // No staticType, can't validate integer size. null -> computeThunk else -> { - when(compileOptions.typingMode) { + when (compileOptions.typingMode) { TypingMode.LEGACY -> { // integer size constraints have not been tested under [TypingMode.LEGACY] because the // [StaticTypeInferenceVisitorTransform] doesn't support being used with legacy mode yet. @@ -412,7 +505,7 @@ internal class EvaluatingCompiler( val hasConstrainedInteger = staticTypes.any { it is IntType && it.rangeConstraint != IntType.IntRangeConstraint.UNCONSTRAINED } - if(hasConstrainedInteger) { + if (hasConstrainedInteger) { TODO("Legacy mode doesn't support integer size constraints yet.") } else { computeThunk @@ -452,7 +545,7 @@ internal class EvaluatingCompiler( private fun integerValueValidator( range: LongRange ): (ExprValue) -> Boolean = { value -> - when(value.type) { + when (value.type) { ExprValueType.NULL, ExprValueType.MISSING -> true ExprValueType.INT -> { val longValue: Long = value.scalar.numberValue()?.toLong() @@ -465,7 +558,7 @@ internal class EvaluatingCompiler( range.contains(longValue) } else -> error( - "The expression's static type was supposed to be INT but instead it was ${value.type}" + + "The expression's static type was supposed to be INT but instead it was ${value.type}" + "This may indicate the presence of a bug in the type inferencer.") } } @@ -495,15 +588,15 @@ internal class EvaluatingCompiler( argThunks: List, metas: MetaContainer): ThunkEnv { return when (argThunks.size) { - //Unary - - 1 -> { + //Unary - + 1 -> { val firstThunk = argThunks[0] thunkFactory.thunkEnvOperands(metas, firstThunk) { _, value -> (-value.numberValue()).exprValue() } } - //N-ary - + //N-ary - else -> thunkFactory.thunkFold(metas, argThunks) { lValue, rValue -> (lValue.numberValue() - rValue.numberValue()).exprValue() } @@ -576,7 +669,7 @@ internal class EvaluatingCompiler( private fun compileNAryLte( argThunks: List, metas: MetaContainer - ): ThunkEnv = + ): ThunkEnv = thunkFactory.thunkAndMap(metas, argThunks) { lValue, rValue -> lValue <= rValue } private fun compileNAryGt( @@ -706,22 +799,22 @@ internal class EvaluatingCompiler( } private fun compileNAryAnd(argThunks: List, metas: MetaContainer): ThunkEnv = - // can't use the null propagation supplied by [ThunkFactory.thunkEnv] here because AND short-circuits on + // can't use the null propagation supplied by [ThunkFactory.thunkEnv] here because AND short-circuits on // false values and *NOT* on NULL or MISSING - when(compileOptions.typingMode) { + when (compileOptions.typingMode) { TypingMode.LEGACY -> thunkFactory.thunkEnv(metas) thunk@{ env -> var hasUnknowns = false argThunks.forEach { currThunk -> val currValue = currThunk(env) when { - currValue.isUnknown() -> hasUnknowns = true + currValue.isUnknown() -> hasUnknowns = true //Short circuit only if we encounter a known false value. !currValue.booleanValue() -> return@thunk valueFactory.newBoolean(false) } } when (hasUnknowns) { - true -> valueFactory.nullValue + true -> valueFactory.nullValue false -> valueFactory.newBoolean(true) } } @@ -730,9 +823,9 @@ internal class EvaluatingCompiler( var hasMissing = false argThunks.forEach { currThunk -> val currValue = currThunk(env) - when(currValue.type) { + when (currValue.type) { //Short circuit only if we encounter a known false value. - ExprValueType.BOOL -> if(!currValue.booleanValue()) return@thunk valueFactory.newBoolean(false) + ExprValueType.BOOL -> if (!currValue.booleanValue()) return@thunk valueFactory.newBoolean(false) ExprValueType.NULL -> hasNull = true // type mismatch, return missing else -> hasMissing = true @@ -741,7 +834,7 @@ internal class EvaluatingCompiler( when { hasMissing -> valueFactory.missingValue - hasNull -> valueFactory.nullValue + hasNull -> valueFactory.nullValue else -> valueFactory.newBoolean(true) } } @@ -751,9 +844,9 @@ internal class EvaluatingCompiler( argThunks: List, metas: MetaContainer ): ThunkEnv = - // can't use the null propagation supplied by [ThunkFactory.thunkEnv] here because OR short-circuits on + // can't use the null propagation supplied by [ThunkFactory.thunkEnv] here because OR short-circuits on // true values and *NOT* on NULL or MISSING - when(compileOptions.typingMode) { + when (compileOptions.typingMode) { TypingMode.LEGACY -> thunkFactory.thunkEnv(metas) thunk@{ env -> var hasUnknowns = false @@ -805,11 +898,10 @@ internal class EvaluatingCompiler( val lType = lValue.type val rType = rValue.type - if(lType.isText && rType.isText) { + if (lType.isText && rType.isText) { // null/missing propagation is handled before getting here (lValue.stringValue() + rValue.stringValue()).exprValue() - } - else { + } else { err( "Wrong argument type for ||", ErrorCode.EVALUATOR_CONCAT_FAILED_DUE_TO_INCOMPATIBLE_TYPE, @@ -845,7 +937,7 @@ internal class EvaluatingCompiler( val funcArgs = args.drop(1) // Check arity - if(funcArgs.size !in func.signature.arity) { + if (funcArgs.size !in func.signature.arity) { val errorContext = errorContextFrom(metas).also { it[Property.FUNCTION_NAME] = func.signature.name it[Property.EXPECTED_ARITY_MIN] = func.signature.arity.first @@ -872,7 +964,7 @@ internal class EvaluatingCompiler( // Compile the arguments val argThunks = funcArgs.map { compileExprNode(it) } - fun checkArgumentTypes(signature: FunctionSignature, args: List) : Arguments { + fun checkArgumentTypes(signature: FunctionSignature, args: List): Arguments { fun checkArgumentType(formalStaticType: StaticType, actualArg: ExprValue, position: Int) { val formalExprValueTypeDomain = formalStaticType.typeDomain @@ -894,16 +986,16 @@ internal class EvaluatingCompiler( val rest = args.drop(signature.requiredParameters.size) signature.requiredParameters.zip(required).forEachIndexed() { idx, (expected, actual) -> - checkArgumentType(expected, actual, idx+1) + checkArgumentType(expected, actual, idx + 1) } return if (signature.optionalParameter != null && !rest.isEmpty()) { val opt = rest.last() - checkArgumentType(signature.optionalParameter, opt, required.size+1) + checkArgumentType(signature.optionalParameter, opt, required.size + 1) RequiredWithOptional(required, opt) } else if (signature.variadicParameter != null) { rest.forEachIndexed() { idx, arg -> - checkArgumentType(signature.variadicParameter.type, arg, required.size+1+idx) + checkArgumentType(signature.variadicParameter.type, arg, required.size + 1 + idx) } RequiredWithVariadic(required, rest) } else { @@ -911,10 +1003,10 @@ internal class EvaluatingCompiler( } } - return when(func.signature.unknownArguments) { - UnknownArguments.PROPAGATE -> thunkFactory.thunkEnvOperands(metas, argThunks) { env, values -> - val checkedArgs = checkArgumentTypes(func.signature, values) - func.call(env, checkedArgs) + return when (func.signature.unknownArguments) { + UnknownArguments.PROPAGATE -> thunkFactory.thunkEnvOperands(metas, argThunks) { env, values -> + val checkedArgs = checkArgumentTypes(func.signature, values) + func.call(env, checkedArgs) } UnknownArguments.PASS_THRU -> thunkFactory.thunkEnv(metas) { env -> val funcArgValues = argThunks.map { it(env) } @@ -941,22 +1033,22 @@ internal class EvaluatingCompiler( val fromSourceNames = currentCompilationContext.fromSourceNames - return when(uniqueNameMeta) { + return when (uniqueNameMeta) { null -> { val bindingName = BindingName(id, case.toBindingCase()) val evalVariableReference = when (compileOptions.undefinedVariable) { - UndefinedVariableBehavior.ERROR -> + UndefinedVariableBehavior.ERROR -> thunkFactory.thunkEnv(metas) { env -> - when(val value = env.current[bindingName]) { + when (val value = env.current[bindingName]) { null -> { if (fromSourceNames.any { bindingName.isEquivalentTo(it) }) { throw EvaluationException( - "Variable not in GROUP BY or aggregation function: ${bindingName.name}", - ErrorCode.EVALUATOR_VARIABLE_NOT_INCLUDED_IN_GROUP_BY, - errorContextFrom(metas).also { it[Property.BINDING_NAME] = bindingName.name }, - internal = false) + "Variable not in GROUP BY or aggregation function: ${bindingName.name}", + ErrorCode.EVALUATOR_VARIABLE_NOT_INCLUDED_IN_GROUP_BY, + errorContextFrom(metas).also { it[Property.BINDING_NAME] = bindingName.name }, + internal = false) } else { - val (errorCode, hint) = when(expr.case) { + val (errorCode, hint) = when (expr.case) { CaseSensitivity.SENSITIVE -> Pair(ErrorCode.EVALUATOR_QUOTED_BINDING_DOES_NOT_EXIST, " $UNBOUND_QUOTED_IDENTIFIER_HINT") @@ -981,7 +1073,7 @@ internal class EvaluatingCompiler( when (lookupStrategy) { ScopeQualifier.UNQUALIFIED -> evalVariableReference - ScopeQualifier.LEXICAL -> thunkFactory.thunkEnv(metas) { env -> + ScopeQualifier.LEXICAL -> thunkFactory.thunkEnv(metas) { env -> evalVariableReference(env.flipToLocals()) } } @@ -1010,13 +1102,13 @@ internal class EvaluatingCompiler( val params = env.session.parameters if (params.size <= index) { throw EvaluationException( - "Unbound parameter for ordinal: ${ordinal}", - ErrorCode.EVALUATOR_UNBOUND_PARAMETER, - errorContextFrom(metas).also { - it[Property.EXPECTED_PARAMETER_ORDINAL] = ordinal - it[Property.BOUND_PARAMETER_COUNT] = params.size - }, - internal = false + "Unbound parameter for ordinal: ${ordinal}", + ErrorCode.EVALUATOR_UNBOUND_PARAMETER, + errorContextFrom(metas).also { + it[Property.EXPECTED_PARAMETER_ORDINAL] = ordinal + it[Property.BOUND_PARAMETER_COUNT] = params.size + }, + internal = false ) } @@ -1030,7 +1122,8 @@ internal class EvaluatingCompiler( val typedOpParameter = dataType.toAstType().toTypedOpParameter(customTypedOpParameters) when (typedOpParameter.staticType) { - is SingleType -> {} + is SingleType -> { + } is AnyType -> { // return trivial results for operations against ANY return when (op) { @@ -1046,10 +1139,10 @@ internal class EvaluatingCompiler( // no validation needed since type parameters are not honored in this mode anyway } TypedOpBehavior.HONOR_PARAMETERS -> { - when(typedOpParameter.staticType) { + when (typedOpParameter.staticType) { is FloatType -> // check if FLOAT has been given an argument--throw exception since we do not honor it. - if(expr.type.args.any()) { + if (expr.type.args.any()) { err( "FLOAT precision parameter is unsupported", ErrorCode.SEMANTIC_FLOAT_PRECISION_UNSUPPORTED, @@ -1073,7 +1166,8 @@ internal class EvaluatingCompiler( } } is AnyOfType, - is SingleType -> {} + is SingleType -> { + } } fun typeOpValidate(value: ExprValue, @@ -1118,7 +1212,7 @@ internal class EvaluatingCompiler( } } - fun compileCast(type: StaticType): ThunkEnv = when(type) { + fun compileCast(type: StaticType): ThunkEnv = when (type) { is SingleType -> compileSingleTypeCast(type) is AnyOfType -> { val locationMeta = metas.sourceLocationMeta @@ -1141,7 +1235,7 @@ internal class EvaluatingCompiler( } return when (op) { - TypedOp.IS -> compileTypedIs(metas, expThunk, typedOpParameter) + TypedOp.IS -> compileTypedIs(metas, expThunk, typedOpParameter) // using thunkFactory here includes the optional evaluation-time type check TypedOp.CAST -> thunkFactory.thunkEnv(metas, compileCast(typedOpParameter.staticType)) @@ -1187,6 +1281,7 @@ internal class EvaluatingCompiler( val locationMeta = metas.sourceLocationMeta fun castFunc(singleType: SingleType) = { value: ExprValue -> value.cast(singleType, valueFactory, compileOptions.typedOpBehavior, locationMeta, compileOptions.defaultTimezoneOffset) } + val roundTripped = when (sourceType) { is SingleType -> castFunc(sourceType)(castedValue) is AnyOfType -> { @@ -1208,10 +1303,10 @@ internal class EvaluatingCompiler( // Short-circuit timestamp -> date roundtrip if precision isn't [Timestamp.Precision.DAY] or // [Timestamp.Precision.MONTH] or [Timestamp.Precision.YEAR] - ExprValueType.TIMESTAMP -> when(typedOpParameter.staticType) { + ExprValueType.TIMESTAMP -> when (typedOpParameter.staticType) { StaticType.DATE -> when (sourceValue.ionValue.timestampValue().precision) { - Timestamp.Precision.DAY, Timestamp.Precision.MONTH, Timestamp.Precision.YEAR -> roundTrip() - else -> valueFactory.newBoolean(false) + Timestamp.Precision.DAY, Timestamp.Precision.MONTH, Timestamp.Precision.YEAR -> roundTrip() + else -> valueFactory.newBoolean(false) } StaticType.TIME -> valueFactory.newBoolean(false) else -> roundTrip() @@ -1280,7 +1375,7 @@ internal class EvaluatingCompiler( } private fun compileTypedIs(metas: MetaContainer, expThunk: ThunkEnv, typedOpParameter: TypedOpParameter): ThunkEnv { - val typeMatchFunc = when (val staticType = typedOpParameter.staticType){ + val typeMatchFunc = when (val staticType = typedOpParameter.staticType) { is SingleType -> makeIsCheck(staticType, typedOpParameter, metas) is AnyOfType -> staticType.types.map { childType -> when (childType) { @@ -1310,7 +1405,7 @@ internal class EvaluatingCompiler( val elseThunk = when { elseExpr != null -> compileExprNode(elseExpr) - else -> thunkFactory.thunkEnv(metas) { _ -> valueFactory.nullValue } + else -> thunkFactory.thunkEnv(metas) { _ -> valueFactory.nullValue } } val branchThunks = branches.map { Pair(compileExprNode(it.valueExpr), compileExprNode(it.thenExpr)) } @@ -1324,7 +1419,8 @@ internal class EvaluatingCompiler( val branchValue = bt.first(env) // Just skip any branch values that are unknown, which we consider the same as false here. when { - branchValue.isUnknown() -> { /* intentionally blank */ } + branchValue.isUnknown() -> { /* intentionally blank */ + } else -> { if (caseValue.exprEquals(branchValue)) { val thenValue = bt.second(env) @@ -1427,7 +1523,7 @@ internal class EvaluatingCompiler( val type = when (seqType) { SeqType.SEXP -> ExprValueType.SEXP SeqType.LIST -> ExprValueType.LIST - SeqType.BAG -> ExprValueType.BAG + SeqType.BAG -> ExprValueType.BAG } val makeItemThunkSequence = when (type) { @@ -1536,7 +1632,7 @@ internal class EvaluatingCompiler( err("ORDER BY is not supported in evaluator yet", ErrorCode.EVALUATOR_FEATURE_NOT_SUPPORTED_YET, errorContextFrom(selectExpr.metas).also { it[Property.FEATURE_NAME] = "ORDER BY" }, - internal = false ) + internal = false) } // Get all the FROM source aliases and LET bindings for binding error checks @@ -1574,8 +1670,8 @@ internal class EvaluatingCompiler( val limitThunk = limit?.let { compileExprNode(it) } val limitLocationMeta = limit?.metas?.sourceLocationMeta - fun rowsWithOffsetAndLimit (rows: Sequence, env: Environment): Sequence { - val rowsWithOffset = when (offsetThunk){ + fun rowsWithOffsetAndLimit(rows: Sequence, env: Environment): Sequence { + val rowsWithOffset = when (offsetThunk) { null -> rows else -> rows.drop(evalOffset(offsetThunk, env, offsetLocationMeta)) } @@ -1601,7 +1697,7 @@ internal class EvaluatingCompiler( selectProjectionThunk(projectEnv, joinedValues) } - val quantifiedRows = when(setQuantifier) { + val quantifiedRows = when (setQuantifier) { // wrap the ExprValue to use ExprValue.equals as the equality SetQuantifier.DISTINCT -> projectedRows.filter(createUniqueExprValueFilter()) SetQuantifier.ALL -> projectedRows @@ -1613,7 +1709,7 @@ internal class EvaluatingCompiler( it.unnamedValue() }) } - else -> { + else -> { // Grouping is needed class CompiledAggregate(val factory: ExprAggregatorFactory, val argThunk: ThunkEnv) @@ -1761,14 +1857,14 @@ internal class EvaluatingCompiler( thunkFactory.thunkEnv(metas) { env -> val sourceValue = rowsWithOffsetAndLimit(sourceThunks(env).asSequence(), env) val seq = sourceValue - .map { (_, env) -> Pair(asThunk(env), atThunk(env)) } - .filter { (name, _) -> name.type.isText } - .map { (name, value) -> value.namedValue(name) } + .map { (_, env) -> Pair(asThunk(env), atThunk(env)) } + .filter { (name, _) -> name.type.isText } + .map { (name, value) -> value.namedValue(name) } createStructExprValue(seq, StructOrdering.UNORDERED) } } } - is SelectProjectionList -> { + is SelectProjectionList -> { val (items) = projection nestCompilationContext(ExpressionContext.SELECT_LIST, allFromSourceAliases) { val projectionThunk: ThunkEnvValue> = @@ -1805,7 +1901,7 @@ internal class EvaluatingCompiler( val name = syntheticColumnName(columns.size).exprValue() columns.add(value.namedValue(name)) } else { - val valuesToProject = when(compileOptions.projectionIteration) { + val valuesToProject = when (compileOptions.projectionIteration) { ProjectionIterationBehavior.FILTER_MISSING -> { value.filter { it.type != ExprValueType.MISSING } } @@ -1835,7 +1931,8 @@ internal class EvaluatingCompiler( private fun compileGroupByExpressions(groupByItems: List): List = groupByItems.map { - val alias = it.asName ?: errNoContext("GroupByItem.asName was not specified", errorCode = ErrorCode.INTERNAL_ERROR, internal = true) + val alias = it.asName + ?: errNoContext("GroupByItem.asName was not specified", errorCode = ErrorCode.INTERNAL_ERROR, internal = true) val uniqueName = (alias.metas.find(UniqueNameMeta.TAG) as UniqueNameMeta?)?.uniqueName CompiledGroupByItem(alias.name.exprValue(), uniqueName, compileExprNode(it.expr)) @@ -1875,7 +1972,7 @@ internal class EvaluatingCompiler( .nest(groupAsBindings) } - else -> { groupByEnv, currentGroup -> + else -> { groupByEnv, currentGroup -> groupByEnv.nest(currentGroup.key.bindings, newGroup = currentGroup) } } @@ -1896,12 +1993,11 @@ internal class EvaluatingCompiler( val havingClauseResult = havingThunk(groupByEnv) if (havingClauseResult.isNotUnknown() && havingClauseResult.booleanValue()) { selectProjectionThunk(groupByEnv, listOf(currentGroup.key)) - } - else { + } else { null } } - else -> { groupByEnv, currentGroup -> + else -> { groupByEnv, currentGroup -> //Create a closure that simply performs the final projection and // returns the result. selectProjectionThunk(groupByEnv, listOf(currentGroup.key)) @@ -1911,7 +2007,7 @@ internal class EvaluatingCompiler( private fun compileCallAgg(expr: CallAgg): ThunkEnv { val (funcExpr, setQuantifier, argExpr, metas: MetaContainer) = expr - if(metas.hasMeta(IsCountStarMeta.TAG) && currentCompilationContext.expressionContext != ExpressionContext.SELECT_LIST) { + if (metas.hasMeta(IsCountStarMeta.TAG) && currentCompilationContext.expressionContext != ExpressionContext.SELECT_LIST) { err("COUNT(*) is not allowed in this context", ErrorCode.EVALUATOR_COUNT_START_NOT_ALLOWED, errorContextFrom(metas), internal = false) } @@ -1924,13 +2020,13 @@ internal class EvaluatingCompiler( } return when (currentCompilationContext.expressionContext) { - ExpressionContext.AGG_ARG -> { + ExpressionContext.AGG_ARG -> { err("The arguments of an aggregate function cannot contain aggregate functions", ErrorCode.EVALUATOR_INVALID_ARGUMENTS_FOR_AGG_FUNCTION, errorContextFrom(metas), internal = false) } - ExpressionContext.NORMAL -> + ExpressionContext.NORMAL -> thunkFactory.thunkEnv(metas) { env -> val aggregator = aggFactory.create() val argValue = argThunk(env) @@ -1942,10 +2038,11 @@ internal class EvaluatingCompiler( val registerId = registerIdMeta.registerId thunkFactory.thunkEnv(metas) { env -> // Note: env.currentGroup must be set by caller. - val registers = env.currentGroup?.registers ?: err("No current group or current group has no registers", - ErrorCode.INTERNAL_ERROR, - errorContextFrom(metas), - internal = true) + val registers = env.currentGroup?.registers + ?: err("No current group or current group has no registers", + ErrorCode.INTERNAL_ERROR, + errorContextFrom(metas), + internal = true) registers[registerId].aggregator.compute() } @@ -1953,13 +2050,13 @@ internal class EvaluatingCompiler( } } - fun getAggregatorFactory(funcName: String, setQuantifier: SetQuantifier, metas: MetaContainer): ExprAggregatorFactory { - val key = funcName.toLowerCase() to setQuantifier + fun getAggregatorFactory(funcName: String, setQuantifier: SetQuantifier, metas: MetaContainer): ExprAggregatorFactory { + val key = funcName.toLowerCase() to setQuantifier - return builtinAggregates[key] ?: err("No such function: $funcName", - ErrorCode.EVALUATOR_NO_SUCH_FUNCTION, - errorContextFrom(metas).also { it[Property.FUNCTION_NAME] = funcName }, - internal = false) + return builtinAggregates[key] ?: err("No such function: $funcName", + ErrorCode.EVALUATOR_NO_SUCH_FUNCTION, + errorContextFrom(metas).also { it[Property.FUNCTION_NAME] = funcName }, + internal = false) } private fun compileFromSources( @@ -1985,17 +2082,17 @@ internal class EvaluatingCompiler( sources.add( CompiledFromSource( alias = Alias( - asName = fromSource.variables.asName?.name ?: - err("FromSourceExpr.variables.asName was null", - ErrorCode.INTERNAL_ERROR, - errorContextFrom(fromSource.expr.metas), internal = true), + asName = fromSource.variables.asName?.name + ?: err("FromSourceExpr.variables.asName was null", + ErrorCode.INTERNAL_ERROR, + errorContextFrom(fromSource.expr.metas), internal = true), atName = fromSource.variables.atName?.name, byName = fromSource.variables.byName?.name), thunk = thunk, joinExpansion = joinExpansion, filter = conditionThunk)) } - is FromSourceJoin -> case { + is FromSourceJoin -> case { val (joinOp, left, right, condition, _: MetaContainer) = fromSource @@ -2003,14 +2100,14 @@ internal class EvaluatingCompiler( sources.addAll(leftSources) val joinExpansionInner = when (joinOp) { - JoinOp.INNER -> JoinExpansion.INNER - JoinOp.LEFT -> JoinExpansion.OUTER + JoinOp.INNER -> JoinExpansion.INNER + JoinOp.LEFT -> JoinExpansion.OUTER JoinOp.RIGHT, JoinOp.OUTER -> err("RIGHT and FULL JOIN not supported", - ErrorCode.EVALUATOR_FEATURE_NOT_SUPPORTED_YET, - errorContextFrom(metas).also { - it[Property.FEATURE_NAME] = "RIGHT and FULL JOIN" - }, - internal = false) + ErrorCode.EVALUATOR_FEATURE_NOT_SUPPORTED_YET, + errorContextFrom(metas).also { + it[Property.FEATURE_NAME] = "RIGHT and FULL JOIN" + }, + internal = false) } val conditionThunkInner = compileExprNode(condition) @@ -2066,11 +2163,11 @@ internal class EvaluatingCompiler( childEnv.nest( Bindings.buildLazyBindings { addBinding(alias.asName) { value } - if(alias.atName != null) + if (alias.atName != null) addBinding(alias.atName) { value.name ?: valueFactory.missingValue } - if(alias.byName != null) + if (alias.byName != null) addBinding(alias.byName) { value.address ?: valueFactory.missingValue } @@ -2141,7 +2238,7 @@ internal class EvaluatingCompiler( seq = seq.filter { (_, env) -> val whereClauseResult = whereThunk(env) when (whereClauseResult.isUnknown()) { - true -> false + true -> false false -> whereClauseResult.booleanValue() } } @@ -2155,12 +2252,12 @@ internal class EvaluatingCompiler( ): List = selectList.items.mapIndexed { idx, it -> when (it) { - is SelectListItemStar -> { + is SelectListItemStar -> { errNoContext("Encountered a SelectListItemStar--did SelectStarVisitorTransform execute?", errorCode = ErrorCode.INTERNAL_ERROR, internal = true) } - is SelectListItemExpr -> { + is SelectListItemExpr -> { val (itemExpr, asName) = it val alias = asName?.name ?: itemExpr.extractColumnAlias(idx) val thunk = compileExprNode(itemExpr) @@ -2198,7 +2295,7 @@ internal class EvaluatingCompiler( val componentMetas = pathComponent.metas componentThunks.add( when (pathComponent) { - is PathComponentExpr -> { + is PathComponentExpr -> { val (indexExpr, caseSensitivity) = pathComponent when { //If indexExpr is a literal string, there is no need to evaluate it--just compile a @@ -2209,7 +2306,7 @@ internal class EvaluatingCompiler( componentValue.bindings[lookupName] ?: valueFactory.missingValue } } - else -> { + else -> { val indexThunk = compileExprNode(indexExpr) thunkFactory.thunkEnvValue(componentMetas) { env, componentValue -> val indexValue = indexThunk(env) @@ -2217,11 +2314,11 @@ internal class EvaluatingCompiler( indexValue.type == ExprValueType.INT -> { componentValue.ordinalBindings[indexValue.numberValue().toInt()] } - indexValue.type.isText -> { + indexValue.type.isText -> { val lookupName = BindingName(indexValue.stringValue(), caseSensitivity.toBindingCase()) componentValue.bindings[lookupName] } - else -> { + else -> { when (compileOptions.typingMode) { TypingMode.LEGACY -> err("Cannot convert index to int/string: $indexValue", ErrorCode.EVALUATOR_INVALID_CONVERSION, @@ -2236,7 +2333,7 @@ internal class EvaluatingCompiler( } } } - is PathComponentUnpivot -> { + is PathComponentUnpivot -> { when { !remainingComponents.isEmpty() -> { val tempThunk = compilePathComponents(pathMetas, remainingComponents) @@ -2247,7 +2344,7 @@ internal class EvaluatingCompiler( valueFactory.newBag(mapped) } } - else -> + else -> thunkFactory.thunkEnvValue(componentMetas) { _, componentValue -> valueFactory.newBag(componentValue.unpivot().asSequence()) } @@ -2269,7 +2366,7 @@ internal class EvaluatingCompiler( valueFactory.newBag(mapped) } - else -> thunkFactory.thunkEnvValue(componentMetas) { env, componentValue -> + else -> thunkFactory.thunkEnvValue(componentMetas) { env, componentValue -> val mapped = componentValue .rangeOver() .flatMap { @@ -2282,7 +2379,7 @@ internal class EvaluatingCompiler( } } } - else -> { + else -> { thunkFactory.thunkEnvValue(componentMetas) { _, componentValue -> val mapped = componentValue.rangeOver().asSequence() valueFactory.newBag(mapped) @@ -2293,7 +2390,7 @@ internal class EvaluatingCompiler( }) } return when (componentThunks.size) { - 1 -> componentThunks.first() + 1 -> componentThunks.first() else -> thunkFactory.thunkEnvValue(pathMetas) { env, rootValue -> componentThunks.fold(rootValue) { componentValue, componentThunk -> componentThunk(env, componentValue) @@ -2322,7 +2419,7 @@ internal class EvaluatingCompiler( val patternExpr = argExprs[1] val escapeExpr = when { argExprs.size > 2 -> argExprs[2] - else -> null + else -> null } val patternLocationMeta = patternExpr.metas.sourceLocationMeta @@ -2335,7 +2432,7 @@ internal class EvaluatingCompiler( val patternArgs = listOfNotNull(pattern, escape) when { patternArgs.any { it.type.isUnknown } -> return null - patternArgs.any { !it.type.isText } -> return { + patternArgs.any { !it.type.isText } -> return { err("LIKE expression must be given non-null strings as input", ErrorCode.EVALUATOR_LIKE_INVALID_INPUTS, errorContextFrom(operatorMetas).also { @@ -2344,7 +2441,7 @@ internal class EvaluatingCompiler( }, internal = false) } - else -> { + else -> { val (patternString: String, escapeChar: Int?) = checkPattern(pattern.ionValue, patternLocationMeta, escape?.ionValue, escapeLocationMeta) @@ -2353,7 +2450,7 @@ internal class EvaluatingCompiler( else -> parsePattern(patternString, escapeChar) } - return { patternParts } + return { patternParts } } } } @@ -2387,8 +2484,7 @@ internal class EvaluatingCompiler( if (valueExpr is Literal) { val resultValue = runPatternParts(valueFactory.newFromIonValue(valueExpr.ionValue), patternParts) return thunkFactory.thunkEnv(operatorMetas) { resultValue } - } - else { + } else { thunkFactory.thunkEnvOperands(operatorMetas, valueThunk) { _, value -> runPatternParts(value, patternParts) } @@ -2449,10 +2545,10 @@ internal class EvaluatingCompiler( ): Pair { val patternString = pattern.stringValue() - ?: err("Must provide a non-null value for PATTERN in a LIKE predicate: $pattern", - ErrorCode.EVALUATOR_LIKE_PATTERN_INVALID_ESCAPE_SEQUENCE, - errorContextFrom(patternLocationMeta), - internal = false) + ?: err("Must provide a non-null value for PATTERN in a LIKE predicate: $pattern", + ErrorCode.EVALUATOR_LIKE_PATTERN_INVALID_ESCAPE_SEQUENCE, + errorContextFrom(patternLocationMeta), + internal = false) escape?.let { val escapeCharString = checkEscapeChar(escape, escapeLocationMeta) @@ -2464,12 +2560,12 @@ internal class EvaluatingCompiler( val current = iter.next() if (current == escapeCharCodePoint && (!iter.hasNext() || !validEscapedChars.contains(iter.next()))) { err("Invalid escape sequence : $patternString", - ErrorCode.EVALUATOR_LIKE_PATTERN_INVALID_ESCAPE_SEQUENCE, - errorContextFrom(patternLocationMeta).apply { - set(Property.LIKE_PATTERN, patternString) - set(Property.LIKE_ESCAPE, escapeCharString) - }, - internal = false) + ErrorCode.EVALUATOR_LIKE_PATTERN_INVALID_ESCAPE_SEQUENCE, + errorContextFrom(patternLocationMeta).apply { + set(Property.LIKE_PATTERN, patternString) + set(Property.LIKE_ESCAPE, escapeCharString) + }, + internal = false) } } return Pair(patternString, escapeCharCodePoint) @@ -2492,13 +2588,13 @@ internal class EvaluatingCompiler( */ private fun checkEscapeChar(escape: IonValue, locationMeta: SourceLocationMeta?): String { val escapeChar = escape.stringValue()?.let { it } - ?: err( - "Must provide a value when using ESCAPE in a LIKE predicate: $escape", - ErrorCode.EVALUATOR_LIKE_PATTERN_INVALID_ESCAPE_SEQUENCE, - errorContextFrom(locationMeta), - internal = false) + ?: err( + "Must provide a value when using ESCAPE in a LIKE predicate: $escape", + ErrorCode.EVALUATOR_LIKE_PATTERN_INVALID_ESCAPE_SEQUENCE, + errorContextFrom(locationMeta), + internal = false) when (escapeChar) { - "" -> { + "" -> { err( "Cannot use empty character as ESCAPE character in a LIKE predicate: $escape", ErrorCode.EVALUATOR_LIKE_PATTERN_INVALID_ESCAPE_SEQUENCE, @@ -2521,11 +2617,11 @@ internal class EvaluatingCompiler( private fun compileDdl(node: ExprNode): ThunkEnv { return { _ -> err( - "DDL operations are not supported yet", - ErrorCode.EVALUATOR_FEATURE_NOT_SUPPORTED_YET, - errorContextFrom(node.metas).also { - it[Property.FEATURE_NAME] = "DDL Operations" - }, internal = false + "DDL operations are not supported yet", + ErrorCode.EVALUATOR_FEATURE_NOT_SUPPORTED_YET, + errorContextFrom(node.metas).also { + it[Property.FEATURE_NAME] = "DDL Operations" + }, internal = false ) } } @@ -2578,7 +2674,7 @@ internal class EvaluatingCompiler( return thunkFactory.thunkEnv(metas) { value } } - private fun compileTimeLiteral(node: TimeLiteral) : ThunkEnv { + private fun compileTimeLiteral(node: TimeLiteral): ThunkEnv { val (hour, minute, second, nano, precision, with_time_zone, tz_minutes, metas) = node return thunkFactory.thunkEnv(metas) { // Add the default time zone if the type "TIME WITH TIME ZONE" does not have an explicitly specified time zone. @@ -2608,11 +2704,11 @@ internal class EvaluatingCompiler( /** Unpivots a `struct`, and synthesizes a synthetic singleton `struct` for other [ExprValue]. */ internal fun ExprValue.unpivot(): ExprValue = when { // special case for our special UNPIVOT value to avoid double wrapping - this is UnpivotedExprValue -> this + this is UnpivotedExprValue -> this // Wrap into a pseudo-BAG type == ExprValueType.STRUCT || type == ExprValueType.MISSING -> UnpivotedExprValue(this) // for non-struct, this wraps any value into a BAG with a synthetic name - else -> UnpivotedExprValue( + else -> UnpivotedExprValue( listOf( this.namedValue(valueFactory.newString(syntheticColumnName(0))) ) @@ -2621,9 +2717,9 @@ internal class EvaluatingCompiler( private fun createStructExprValue(seq: Sequence, ordering: StructOrdering) = valueFactory.newStruct( - when(compileOptions.projectionIteration) { + when (compileOptions.projectionIteration) { ProjectionIterationBehavior.FILTER_MISSING -> seq.filter { it.type != ExprValueType.MISSING } - ProjectionIterationBehavior.UNFILTERED -> seq + ProjectionIterationBehavior.UNFILTERED -> seq }, ordering ) @@ -2653,6 +2749,7 @@ private data class FromProduction( private enum class JoinExpansion { /** Default for non-joined values, CROSS and INNER JOIN. */ INNER, + /** Expansion mode for LEFT/RIGHT/FULL JOIN. */ OUTER } @@ -2667,10 +2764,12 @@ private enum class ExpressionContext { * contexts). */ NORMAL, + /** * Indicates that the compiler is compiling an expression in a select list. */ SELECT_LIST, + /** * Indicates that the compiler is compiling an expression that is the argument to an aggregate function. */ @@ -2684,8 +2783,7 @@ private enum class ExpressionContext { * @param expressionContext Indicates what part of the grammar is currently being compiled. * @param fromSourceNames Set of all FROM source aliases for binding error checks. */ -private class CompilationContext(val expressionContext: ExpressionContext, val fromSourceNames: Set) -{ +private class CompilationContext(val expressionContext: ExpressionContext, val fromSourceNames: Set) { fun createNested(expressionContext: ExpressionContext, fromSourceNames: Set) = CompilationContext(expressionContext, fromSourceNames) } @@ -2718,7 +2816,7 @@ private class MultipleProjectionElement(val thunks: List) : Projection private val MetaContainer.sourceLocationMeta get() = (this.find(SourceLocationMeta.TAG) as? SourceLocationMeta) -private fun StaticType.getTypes() = when(val flattened = this.flatten()) { +private fun StaticType.getTypes() = when (val flattened = this.flatten()) { is AnyOfType -> flattened.types else -> listOf(this) } \ No newline at end of file diff --git a/lang/src/org/partiql/lang/eval/EvaluationSession.kt b/lang/src/org/partiql/lang/eval/EvaluationSession.kt index e9406d3151..59dad25066 100644 --- a/lang/src/org/partiql/lang/eval/EvaluationSession.kt +++ b/lang/src/org/partiql/lang/eval/EvaluationSession.kt @@ -14,7 +14,7 @@ package org.partiql.lang.eval -import com.amazon.ion.* +import com.amazon.ion.Timestamp /** * Evaluation Session. Holds user defined constants used during evaluation. Each value has a default value that can diff --git a/lang/src/org/partiql/lang/eval/ExprNodeExtensions.kt b/lang/src/org/partiql/lang/eval/ExprNodeExtensions.kt index 53ad584d8a..38ac0c97ac 100644 --- a/lang/src/org/partiql/lang/eval/ExprNodeExtensions.kt +++ b/lang/src/org/partiql/lang/eval/ExprNodeExtensions.kt @@ -66,7 +66,7 @@ private fun Path.extractColumnAlias(idx: Int): String { else -> syntheticColumnName(idx) } } - else -> syntheticColumnName(idx) + else -> syntheticColumnName(idx) } } diff --git a/lang/src/org/partiql/lang/eval/ExprValueExtensions.kt b/lang/src/org/partiql/lang/eval/ExprValueExtensions.kt index 92ef6996c2..bea22e497d 100644 --- a/lang/src/org/partiql/lang/eval/ExprValueExtensions.kt +++ b/lang/src/org/partiql/lang/eval/ExprValueExtensions.kt @@ -14,13 +14,17 @@ package org.partiql.lang.eval -import com.amazon.ion.* -import org.partiql.lang.ast.* -import org.partiql.lang.errors.* -import org.partiql.lang.eval.ExprValueType.* +import com.amazon.ion.IntegerSize +import com.amazon.ion.IonInt +import com.amazon.ion.Timestamp +import org.partiql.lang.ast.SourceLocationMeta +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.errors.PropertyValueMap import org.partiql.lang.eval.time.NANOS_PER_SECOND import org.partiql.lang.eval.time.Time -import org.partiql.lang.syntax.* +import org.partiql.lang.syntax.DATE_TIME_PART_KEYWORDS +import org.partiql.lang.syntax.DateTimePart import org.partiql.lang.types.BagType import org.partiql.lang.types.BlobType import org.partiql.lang.types.BoolType @@ -39,14 +43,22 @@ import org.partiql.lang.types.StringType import org.partiql.lang.types.SymbolType import org.partiql.lang.types.TimeType import org.partiql.lang.types.TimestampType -import org.partiql.lang.util.* -import java.math.* +import org.partiql.lang.util.ConfigurableExprValueFormatter +import org.partiql.lang.util.bigDecimalOf +import org.partiql.lang.util.coerce +import org.partiql.lang.util.compareTo +import org.partiql.lang.util.downcast +import org.partiql.lang.util.getPrecisionFromTimeString +import org.partiql.lang.util.ionValue +import java.math.BigDecimal +import java.math.MathContext +import java.math.RoundingMode import java.time.LocalDate import java.time.LocalTime import java.time.ZoneOffset import java.time.format.DateTimeFormatter import java.time.format.DateTimeParseException -import java.util.* +import java.util.TreeSet import kotlin.math.round /** @@ -180,12 +192,13 @@ internal fun ExprValue.isDirectlyComparableTo(other: ExprValue): Boolean = when { // The ExprValue type for TIME and TIME WITH TIME ZONE is same // and thus needs to be checked explicitly for the timezone values. - type == TIME && other.type == TIME -> timeValue().isDirectlyComparableTo(other.timeValue()) + type == ExprValueType.TIME && other.type == ExprValueType.TIME -> + timeValue().isDirectlyComparableTo(other.timeValue()) else -> type.isDirectlyComparableTo(other.type) } /** Types that are cast to the [ExprValueType.isText] types by calling `IonValue.toString()`. */ -private val ION_TEXT_STRING_CAST_TYPES = setOf(BOOL, TIMESTAMP) +private val ION_TEXT_STRING_CAST_TYPES = setOf(ExprValueType.BOOL, ExprValueType.TIMESTAMP) /** Regex to match DATE strings of the format yyyy-MM-dd */ private val datePatternRegex = Regex("\\d\\d\\d\\d-\\d\\d-\\d\\d") @@ -336,7 +349,6 @@ fun ExprValue.cast( } it.toLong() } - valueFactory.newInt(result) } is FloatType -> valueFactory.newFloat(this.toDouble()) @@ -400,7 +412,7 @@ fun ExprValue.cast( type.isUnknown -> return this // Note that the ExprValueType for TIME and TIME WITH TIME ZONE is the same i.e. ExprValueType.TIME. // We further need to check for the time zone and hence we do not short circuit here when the type is TIME. - type == targetType.runtimeType && type != TIME -> { + type == targetType.runtimeType && type != ExprValueType.TIME -> { return when (targetType) { is IntType, is FloatType, is DecimalType-> numberValue().exprValue(targetType) is StringType -> stringValue().exprValue(targetType) @@ -421,7 +433,7 @@ fun ExprValue.cast( } } is IntType -> when { - type == BOOL -> return if(booleanValue()) 1L.exprValue(targetType) else 0L.exprValue(targetType) + type == ExprValueType.BOOL -> return if(booleanValue()) 1L.exprValue(targetType) else 0L.exprValue(targetType) type.isNumber -> return numberValue().exprValue(targetType) type.isText -> { val value = try { @@ -439,7 +451,7 @@ fun ExprValue.cast( } } is FloatType -> when { - type == BOOL -> return if (booleanValue()) 1.0.exprValue(targetType) else 0.0.exprValue(targetType) + type == ExprValueType.BOOL -> return if (booleanValue()) 1.0.exprValue(targetType) else 0.0.exprValue(targetType) type.isNumber -> return numberValue().toDouble().exprValue(targetType) type.isText -> try { @@ -449,7 +461,7 @@ fun ExprValue.cast( } } is DecimalType -> when { - type == BOOL -> return if (booleanValue()) { + type == ExprValueType.BOOL -> return if (booleanValue()) { BigDecimal.ONE.exprValue(targetType) } else { BigDecimal.ZERO.exprValue(targetType) @@ -471,7 +483,7 @@ fun ExprValue.cast( } } is DateType -> when { - type == TIMESTAMP -> { + type == ExprValueType.TIMESTAMP -> { val ts = timestampValue() return valueFactory.newDate(LocalDate.of(ts.year, ts.month, ts.day)) } @@ -493,7 +505,7 @@ fun ExprValue.cast( is TimeType -> { val precision = targetType.precision when { - type == TIME -> { + type == ExprValueType.TIME -> { val time = timeValue() val timeZoneOffset = when (targetType.withTimeZone) { true -> time.zoneOffset?: defaultTimezoneOffset @@ -506,7 +518,7 @@ fun ExprValue.cast( timeZoneOffset )) } - type == TIMESTAMP -> { + type == ExprValueType.TIMESTAMP -> { val ts = timestampValue() val timeZoneOffset = when (targetType.withTimeZone) { true -> ts.localOffset?: castFailedErr( @@ -561,8 +573,8 @@ fun ExprValue.cast( is StringType, is SymbolType -> when { type.isNumber -> return numberValue().toString().exprValue(targetType) type.isText -> return stringValue().exprValue(targetType) - type == DATE -> return dateValue().toString().exprValue(targetType) - type == TIME -> return timeValue().toString().exprValue(targetType) + type == ExprValueType.DATE -> return dateValue().toString().exprValue(targetType) + type == ExprValueType.TIME -> return timeValue().toString().exprValue(targetType) type in ION_TEXT_STRING_CAST_TYPES -> return ionValue.toString().exprValue(targetType) } is ClobType -> when { diff --git a/lang/src/org/partiql/lang/eval/ExprValueFactory.kt b/lang/src/org/partiql/lang/eval/ExprValueFactory.kt index e3f61e63b9..a4bb882688 100644 --- a/lang/src/org/partiql/lang/eval/ExprValueFactory.kt +++ b/lang/src/org/partiql/lang/eval/ExprValueFactory.kt @@ -14,11 +14,30 @@ package org.partiql.lang.eval -import com.amazon.ion.* +import com.amazon.ion.IonBool +import com.amazon.ion.IonContainer +import com.amazon.ion.IonNull +import com.amazon.ion.IonReader +import com.amazon.ion.IonSequence +import com.amazon.ion.IonStruct +import com.amazon.ion.IonSystem +import com.amazon.ion.IonType +import com.amazon.ion.IonValue +import com.amazon.ion.Timestamp import org.partiql.lang.errors.ErrorCode import org.partiql.lang.eval.time.Time -import org.partiql.lang.util.* -import java.math.* +import org.partiql.lang.util.booleanValueOrNull +import org.partiql.lang.util.bytesValueOrNull +import org.partiql.lang.util.isBag +import org.partiql.lang.util.isMissing +import org.partiql.lang.util.numberValueOrNull +import org.partiql.lang.util.ordinal +import org.partiql.lang.util.propertyValueMapOf +import org.partiql.lang.util.seal +import org.partiql.lang.util.stringValueOrNull +import org.partiql.lang.util.timestampValueOrNull +import java.math.BigDecimal +import java.math.BigInteger import java.time.LocalDate internal const val MISSING_ANNOTATION = "\$partiql_missing" diff --git a/lang/src/org/partiql/lang/eval/ExprValueType.kt b/lang/src/org/partiql/lang/eval/ExprValueType.kt index 8bce9bce35..e1d46f225e 100644 --- a/lang/src/org/partiql/lang/eval/ExprValueType.kt +++ b/lang/src/org/partiql/lang/eval/ExprValueType.kt @@ -15,12 +15,10 @@ package org.partiql.lang.eval import com.amazon.ion.IonType -import org.partiql.lang.ast.* import org.partiql.lang.domains.PartiqlAst -import org.partiql.lang.domains.PartiqlAst.Type.* import org.partiql.lang.errors.ErrorCode -import org.partiql.lang.syntax.TYPE_ALIASES import org.partiql.lang.syntax.CORE_TYPE_NAME_ARITY_MAP +import org.partiql.lang.syntax.TYPE_ALIASES /** * The core types of [ExprValue] that exist within the type system of the evaluator. @@ -49,7 +47,7 @@ enum class ExprValueType(val typeNames: List, ), INT( typeNames = listOf("int", "smallint", "integer2", "int2", "integer", "integer4", "int4", "integer8", "int8", - "bigint"), + "bigint"), isNumber = true ), FLOAT( @@ -141,7 +139,7 @@ enum class ExprValueType(val typeNames: List, .map { val ourType = when (it) { IonType.DATAGRAM -> BAG - else -> valueOf(it.name) + else -> valueOf(it.name) } Pair(it, ourType) }.toMap() @@ -156,14 +154,14 @@ enum class ExprValueType(val typeNames: List, } catch (e: IllegalArgumentException) { // no direct type mapping when (it) { - "boolean" -> BOOL + "boolean" -> BOOL "smallint", "integer", "integer4", - "integer8" -> INT - "real", "double_precision" -> FLOAT - "numeric" -> DECIMAL - "character", "character_varying" -> STRING - "tuple" -> STRUCT - else -> throw IllegalStateException("No ExprValueType handler for $it") + "integer8" -> INT + "real", "double_precision" -> FLOAT + "numeric" -> DECIMAL + "character", "character_varying" -> STRING + "tuple" -> STRUCT + else -> throw IllegalStateException("No ExprValueType handler for $it") } } @@ -173,10 +171,10 @@ enum class ExprValueType(val typeNames: List, fun fromTypeName(name: String): ExprValueType = LEX_TYPE_MAP[name] - ?: throw EvaluationException( - "No such value type for $name", - ErrorCode.LEXER_INVALID_NAME, - internal = true) + ?: throw EvaluationException( + "No such value type for $name", + ErrorCode.LEXER_INVALID_NAME, + internal = true) fun fromSqlDataType(sqlDataType: PartiqlAst.Type) = fromSqlDataTypeOrNull(sqlDataType) ?: throw EvaluationException( @@ -186,53 +184,53 @@ enum class ExprValueType(val typeNames: List, ) fun fromSqlDataTypeOrNull(sqlDataType: PartiqlAst.Type) = when (sqlDataType) { - is BooleanType -> BOOL - is MissingType -> MISSING - is NullType -> NULL - is SmallintType -> INT - is Integer4Type -> INT - is Integer8Type -> INT - is IntegerType -> INT - is FloatType -> FLOAT - is RealType -> FLOAT - is DoublePrecisionType -> FLOAT - is DecimalType -> DECIMAL - is NumericType -> DECIMAL - is TimestampType -> TIMESTAMP - is CharacterType -> STRING - is CharacterVaryingType -> STRING - is StringType -> STRING - is SymbolType -> SYMBOL - is ClobType -> CLOB - is BlobType -> BLOB - is StructType -> STRUCT - is TupleType -> STRUCT - is ListType -> LIST - is SexpType -> SEXP - is BagType -> BAG - is AnyType -> null - is DateType -> DATE - is TimeType, - is TimeWithTimeZoneType -> TIME - is CustomType -> null + is PartiqlAst.Type.BooleanType -> BOOL + is PartiqlAst.Type.MissingType -> MISSING + is PartiqlAst.Type.NullType -> NULL + is PartiqlAst.Type.SmallintType -> INT + is PartiqlAst.Type.Integer4Type -> INT + is PartiqlAst.Type.Integer8Type -> INT + is PartiqlAst.Type.IntegerType -> INT + is PartiqlAst.Type.FloatType -> FLOAT + is PartiqlAst.Type.RealType -> FLOAT + is PartiqlAst.Type.DoublePrecisionType -> FLOAT + is PartiqlAst.Type.DecimalType -> DECIMAL + is PartiqlAst.Type.NumericType -> DECIMAL + is PartiqlAst.Type.TimestampType -> TIMESTAMP + is PartiqlAst.Type.CharacterType -> STRING + is PartiqlAst.Type.CharacterVaryingType -> STRING + is PartiqlAst.Type.StringType -> STRING + is PartiqlAst.Type.SymbolType -> SYMBOL + is PartiqlAst.Type.ClobType -> CLOB + is PartiqlAst.Type.BlobType -> BLOB + is PartiqlAst.Type.StructType -> STRUCT + is PartiqlAst.Type.TupleType -> STRUCT + is PartiqlAst.Type.ListType -> LIST + is PartiqlAst.Type.SexpType -> SEXP + is PartiqlAst.Type.BagType -> BAG + is PartiqlAst.Type.AnyType -> null + is PartiqlAst.Type.DateType -> DATE + is PartiqlAst.Type.TimeType, + is PartiqlAst.Type.TimeWithTimeZoneType -> TIME + is PartiqlAst.Type.CustomType -> null // TODO: Remove these hardcoded nodes from the PIG domain once [https://github.com/partiql/partiql-lang-kotlin/issues/510] is resolved. - is EsBoolean, - is EsInteger, - is EsText, - is EsAny, - is EsFloat, - is RsBigint, - is RsBoolean, - is RsDoublePrecision, - is RsInteger, - is RsReal, - is RsVarcharMax, - is SparkBoolean, - is SparkDouble, - is SparkFloat, - is SparkInteger, - is SparkLong, - is SparkShort -> error("$this node should not be present in PartiQLAST. Consider transforming the AST using CustomTypeVisitorTransform.") + is PartiqlAst.Type.EsBoolean, + is PartiqlAst.Type.EsInteger, + is PartiqlAst.Type.EsText, + is PartiqlAst.Type.EsAny, + is PartiqlAst.Type.EsFloat, + is PartiqlAst.Type.RsBigint, + is PartiqlAst.Type.RsBoolean, + is PartiqlAst.Type.RsDoublePrecision, + is PartiqlAst.Type.RsInteger, + is PartiqlAst.Type.RsReal, + is PartiqlAst.Type.RsVarcharMax, + is PartiqlAst.Type.SparkBoolean, + is PartiqlAst.Type.SparkDouble, + is PartiqlAst.Type.SparkFloat, + is PartiqlAst.Type.SparkInteger, + is PartiqlAst.Type.SparkLong, + is PartiqlAst.Type.SparkShort -> error("$this node should not be present in PartiQLAST. Consider transforming the AST using CustomTypeVisitorTransform.") } } -} +} \ No newline at end of file diff --git a/lang/src/org/partiql/lang/eval/GroupKeyExprValue.kt b/lang/src/org/partiql/lang/eval/GroupKeyExprValue.kt index 7ab677dcb5..95455ce45a 100644 --- a/lang/src/org/partiql/lang/eval/GroupKeyExprValue.kt +++ b/lang/src/org/partiql/lang/eval/GroupKeyExprValue.kt @@ -14,7 +14,7 @@ package org.partiql.lang.eval -import com.amazon.ion.* +import com.amazon.ion.IonSystem import org.partiql.lang.eval.visitors.GroupByItemAliasVisitorTransform diff --git a/lang/src/org/partiql/lang/eval/IonStructBindings.kt b/lang/src/org/partiql/lang/eval/IonStructBindings.kt index 417a63c25c..fc59271d2e 100644 --- a/lang/src/org/partiql/lang/eval/IonStructBindings.kt +++ b/lang/src/org/partiql/lang/eval/IonStructBindings.kt @@ -14,8 +14,9 @@ package org.partiql.lang.eval -import com.amazon.ion.* -import org.partiql.lang.util.* +import com.amazon.ion.IonStruct +import com.amazon.ion.IonValue +import org.partiql.lang.util.errAmbiguousBinding /** * Custom implementation of [Bindings] that lazily computes case sensitive or insensitive hash tables which diff --git a/lang/src/org/partiql/lang/eval/NaturalExprValueComparators.kt b/lang/src/org/partiql/lang/eval/NaturalExprValueComparators.kt index a2966ab6db..6169f96c99 100644 --- a/lang/src/org/partiql/lang/eval/NaturalExprValueComparators.kt +++ b/lang/src/org/partiql/lang/eval/NaturalExprValueComparators.kt @@ -15,7 +15,7 @@ package org.partiql.lang.eval import org.partiql.lang.errors.ErrorCode -import org.partiql.lang.eval.ExprValueType.* +import org.partiql.lang.eval.NaturalExprValueComparators.NullOrder import org.partiql.lang.util.* /** @@ -159,7 +159,7 @@ enum class NaturalExprValueComparators(private val nullOrder: NullOrder) : Compa // Bool ifCompared( - handle(lType == BOOL, rType == BOOL) { + handle(lType == ExprValueType.BOOL, rType == ExprValueType.BOOL) { val lVal = left.booleanValue() val rVal = right.booleanValue() @@ -193,7 +193,7 @@ enum class NaturalExprValueComparators(private val nullOrder: NullOrder) : Compa // Date ifCompared( - handle(lType == DATE, rType == DATE) { + handle(lType == ExprValueType.DATE, rType == ExprValueType.DATE) { val lVal = left.dateValue() val rVal = right.dateValue() @@ -203,7 +203,7 @@ enum class NaturalExprValueComparators(private val nullOrder: NullOrder) : Compa // Time ifCompared( - handle(lType == TIME, rType == TIME) { + handle(lType == ExprValueType.TIME, rType == ExprValueType.TIME) { val lVal = left.timeValue() val rVal = right.timeValue() @@ -213,7 +213,7 @@ enum class NaturalExprValueComparators(private val nullOrder: NullOrder) : Compa // Timestamp ifCompared( - handle(lType == TIMESTAMP, rType == TIMESTAMP) { + handle(lType == ExprValueType.TIMESTAMP, rType == ExprValueType.TIMESTAMP) { val lVal = left.timestampValue() val rVal = right.timestampValue() @@ -252,28 +252,28 @@ enum class NaturalExprValueComparators(private val nullOrder: NullOrder) : Compa // List ifCompared( - handle(lType == LIST, rType == LIST) { + handle(lType == ExprValueType.LIST, rType == ExprValueType.LIST) { return compareOrdered(left, right, this) } ) { return it } // Sexp ifCompared( - handle(lType == SEXP, rType == SEXP) { + handle(lType == ExprValueType.SEXP, rType == ExprValueType.SEXP) { return compareOrdered(left, right, this) } ) { return it } // Struct ifCompared( - handle(lType == STRUCT, rType == STRUCT) { + handle(lType == ExprValueType.STRUCT, rType == ExprValueType.STRUCT) { compareUnordered(left, right, structFieldComparator) } ) { return it } // Bag ifCompared( - handle(lType == BAG, rType == BAG) { + handle(lType == ExprValueType.BAG, rType == ExprValueType.BAG) { compareUnordered(left, right, this) } ) { return it } diff --git a/lang/src/org/partiql/lang/eval/NodeMetadata.kt b/lang/src/org/partiql/lang/eval/NodeMetadata.kt index e557f1faf6..5d2a9182f3 100644 --- a/lang/src/org/partiql/lang/eval/NodeMetadata.kt +++ b/lang/src/org/partiql/lang/eval/NodeMetadata.kt @@ -14,9 +14,10 @@ package org.partiql.lang.eval -import com.amazon.ion.* -import org.partiql.lang.errors.* -import org.partiql.lang.util.* +import com.amazon.ion.IonStruct +import org.partiql.lang.errors.Property +import org.partiql.lang.errors.PropertyValueMap +import org.partiql.lang.util.longValue /* * WARNING: This whole file is intended as a non intrusive way to preserve the meta nodes information during diff --git a/lang/src/org/partiql/lang/eval/OrdinalBindings.kt b/lang/src/org/partiql/lang/eval/OrdinalBindings.kt index e0b3a01cd0..fe2ae976e2 100644 --- a/lang/src/org/partiql/lang/eval/OrdinalBindings.kt +++ b/lang/src/org/partiql/lang/eval/OrdinalBindings.kt @@ -14,7 +14,7 @@ package org.partiql.lang.eval -import com.amazon.ion.* +import com.amazon.ion.IonSequence /** A simple mapping of ordinal index to [ExprValue]. */ interface OrdinalBindings { diff --git a/lang/src/org/partiql/lang/eval/StructExprValue.kt b/lang/src/org/partiql/lang/eval/StructExprValue.kt index 480db70718..1d95de8463 100644 --- a/lang/src/org/partiql/lang/eval/StructExprValue.kt +++ b/lang/src/org/partiql/lang/eval/StructExprValue.kt @@ -14,11 +14,10 @@ package org.partiql.lang.eval -import com.amazon.ion.* +import com.amazon.ion.IonStruct +import com.amazon.ion.IonSystem import org.partiql.lang.errors.ErrorCode -import org.partiql.lang.util.* -import java.util.* - +import org.partiql.lang.util.seal /** Indicates if a struct is ordered or not. */ enum class StructOrdering { diff --git a/lang/src/org/partiql/lang/eval/Thunk.kt b/lang/src/org/partiql/lang/eval/Thunk.kt index f655f4abea..6dd757413c 100644 --- a/lang/src/org/partiql/lang/eval/Thunk.kt +++ b/lang/src/org/partiql/lang/eval/Thunk.kt @@ -14,8 +14,12 @@ package org.partiql.lang.eval -import org.partiql.lang.ast.* -import org.partiql.lang.errors.* +import org.partiql.lang.ast.MetaContainer +import org.partiql.lang.ast.SourceLocationMeta +import org.partiql.lang.ast.staticType +import org.partiql.lang.errors.ErrorBehaviorInPermissiveMode +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property /** diff --git a/lang/src/org/partiql/lang/eval/binding/LocalsBinder.kt b/lang/src/org/partiql/lang/eval/binding/LocalsBinder.kt index a9aa9f0bdc..4e05e297f5 100644 --- a/lang/src/org/partiql/lang/eval/binding/LocalsBinder.kt +++ b/lang/src/org/partiql/lang/eval/binding/LocalsBinder.kt @@ -14,8 +14,13 @@ package org.partiql.lang.eval.binding -import org.partiql.lang.eval.* -import org.partiql.lang.util.* +import org.partiql.lang.eval.BindingCase +import org.partiql.lang.eval.BindingName +import org.partiql.lang.eval.Bindings +import org.partiql.lang.eval.ExprValue +import org.partiql.lang.eval.address +import org.partiql.lang.eval.name +import org.partiql.lang.util.errAmbiguousBinding /** * Creates a list of bindings from a list of locals. diff --git a/lang/src/org/partiql/lang/eval/builtins/DateAddExprFunction.kt b/lang/src/org/partiql/lang/eval/builtins/DateAddExprFunction.kt index 22d56f92f2..301e39cb7f 100644 --- a/lang/src/org/partiql/lang/eval/builtins/DateAddExprFunction.kt +++ b/lang/src/org/partiql/lang/eval/builtins/DateAddExprFunction.kt @@ -38,12 +38,11 @@ internal class DateAddExprFunction(val valueFactory: ExprValueFactory) : ExprFun ) companion object { - @JvmStatic private val precisionOrder = listOf(Precision.YEAR, - Precision.MONTH, - Precision.DAY, - Precision.MINUTE, - Precision.SECOND) - + @JvmStatic private val precisionOrder = listOf(Timestamp.Precision.YEAR, + Timestamp.Precision.MONTH, + Timestamp.Precision.DAY, + Timestamp.Precision.MINUTE, + Timestamp.Precision.SECOND) @JvmStatic private val dateTimePartToPrecision = mapOf(DateTimePart.YEAR to Precision.YEAR, DateTimePart.MONTH to Precision.MONTH, DateTimePart.DAY to Precision.DAY, @@ -52,7 +51,7 @@ internal class DateAddExprFunction(val valueFactory: ExprValueFactory) : ExprFun DateTimePart.SECOND to Precision.SECOND) } - private fun Timestamp.hasSufficientPrecisionFor(requiredPrecision: Precision): Boolean { + private fun Timestamp.hasSufficientPrecisionFor(requiredPrecision: Timestamp.Precision): Boolean { val requiredPrecisionPos = precisionOrder.indexOf(requiredPrecision) val precisionPos = precisionOrder.indexOf(precision) @@ -67,17 +66,17 @@ internal class DateAddExprFunction(val valueFactory: ExprValueFactory) : ExprFun } return when (requiredPrecision) { - Precision.YEAR -> Timestamp.forYear(this.year) - Precision.MONTH -> Timestamp.forMonth(this.year, this.month) - Precision.DAY -> Timestamp.forDay(this.year, this.month, this.day) - Precision.SECOND -> Timestamp.forSecond(this.year, + Timestamp.Precision.YEAR -> Timestamp.forYear(this.year) + Timestamp.Precision.MONTH -> Timestamp.forMonth(this.year, this.month) + Timestamp.Precision.DAY -> Timestamp.forDay(this.year, this.month, this.day) + Timestamp.Precision.SECOND -> Timestamp.forSecond(this.year, this.month, this.day, this.hour, this.minute, this.second, this.localOffset) - Precision.MINUTE -> Timestamp.forMinute(this.year, + Timestamp.Precision.MINUTE -> Timestamp.forMinute(this.year, this.month, this.day, this.hour, diff --git a/lang/src/org/partiql/lang/eval/builtins/SubstringExprFunction.kt b/lang/src/org/partiql/lang/eval/builtins/SubstringExprFunction.kt index 471107f546..c1d28e15bd 100644 --- a/lang/src/org/partiql/lang/eval/builtins/SubstringExprFunction.kt +++ b/lang/src/org/partiql/lang/eval/builtins/SubstringExprFunction.kt @@ -24,8 +24,6 @@ import org.partiql.lang.eval.intValue import org.partiql.lang.eval.stringValue import org.partiql.lang.types.FunctionSignature import org.partiql.lang.types.StaticType -import java.lang.Integer.max -import java.lang.Integer.min /** * Built in function to return the substring of an existing string. This function @@ -129,11 +127,11 @@ internal class SubstringExprFunction(private val valueFactory: ExprValueFactory) // calculate this before adjusting start position to account for negative startPosition val endPosition = when (quantity) { null -> codePointCount - else -> min(codePointCount, startPosition + quantity - 1) + else -> Integer.min(codePointCount, startPosition + quantity - 1) } // Clamp start indexes to values that make sense for java substring - val adjustedStartPosition = max(0, startPosition - 1) + val adjustedStartPosition = Integer.max(0, startPosition - 1) if (endPosition < adjustedStartPosition) { return valueFactory.newString("") diff --git a/lang/src/org/partiql/lang/eval/builtins/TimestampParser.kt b/lang/src/org/partiql/lang/eval/builtins/TimestampParser.kt index 82227237c8..2788ffb965 100644 --- a/lang/src/org/partiql/lang/eval/builtins/TimestampParser.kt +++ b/lang/src/org/partiql/lang/eval/builtins/TimestampParser.kt @@ -14,15 +14,19 @@ package org.partiql.lang.eval.builtins -import com.amazon.ion.* -import org.partiql.lang.errors.* -import org.partiql.lang.eval.* -import org.partiql.lang.eval.builtins.timestamp.* -import org.partiql.lang.util.* -import java.math.* -import java.time.* -import java.time.format.* -import java.time.temporal.* +import com.amazon.ion.Timestamp +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.eval.EvaluationException +import org.partiql.lang.eval.builtins.timestamp.FormatPattern +import org.partiql.lang.eval.builtins.timestamp.TimestampField +import org.partiql.lang.eval.errNoContext +import org.partiql.lang.util.propertyValueMapOf +import java.math.BigDecimal +import java.time.DateTimeException +import java.time.format.DateTimeFormatterBuilder +import java.time.temporal.ChronoField +import java.time.temporal.TemporalAccessor /** * Uses Java 8's DateTimeFormatter to parse an Ion Timestamp value. diff --git a/lang/src/org/partiql/lang/eval/builtins/TimestampTemporalAccessor.kt b/lang/src/org/partiql/lang/eval/builtins/TimestampTemporalAccessor.kt index 1a61024fb6..1e96ffc2d5 100644 --- a/lang/src/org/partiql/lang/eval/builtins/TimestampTemporalAccessor.kt +++ b/lang/src/org/partiql/lang/eval/builtins/TimestampTemporalAccessor.kt @@ -14,9 +14,13 @@ package org.partiql.lang.eval.builtins -import com.amazon.ion.* -import java.math.* -import java.time.temporal.* +import com.amazon.ion.Timestamp +import java.math.BigDecimal +import java.time.temporal.ChronoField +import java.time.temporal.IsoFields +import java.time.temporal.TemporalAccessor +import java.time.temporal.TemporalField +import java.time.temporal.UnsupportedTemporalTypeException private val NANOS_PER_SECOND = 1_000_000_000L private val MILLIS_PER_SECOND = 1_000L diff --git a/lang/src/org/partiql/lang/eval/builtins/ToTimestampExprFunction.kt b/lang/src/org/partiql/lang/eval/builtins/ToTimestampExprFunction.kt index ba06df1450..92b9686a8e 100644 --- a/lang/src/org/partiql/lang/eval/builtins/ToTimestampExprFunction.kt +++ b/lang/src/org/partiql/lang/eval/builtins/ToTimestampExprFunction.kt @@ -26,7 +26,6 @@ import org.partiql.lang.types.FunctionSignature import org.partiql.lang.types.StaticType import org.partiql.lang.util.stringValue - /** * PartiQL function to convert a formatted string into an Ion Timestamp. */ diff --git a/lang/src/org/partiql/lang/eval/builtins/TrimExprFunction.kt b/lang/src/org/partiql/lang/eval/builtins/TrimExprFunction.kt index a757a8c4df..dd954cab89 100644 --- a/lang/src/org/partiql/lang/eval/builtins/TrimExprFunction.kt +++ b/lang/src/org/partiql/lang/eval/builtins/TrimExprFunction.kt @@ -69,7 +69,7 @@ internal class TrimExprFunction(private val valueFactory: ExprValueFactory) : Ex ) private val DEFAULT_TO_REMOVE = " ".codePoints().toArray() - private val DEFAULT_SPECIFICATION = BOTH + private val DEFAULT_SPECIFICATION = TrimSpecification.BOTH private fun IntArray.leadingTrimOffset(toRemove: IntArray): Int { var offset = 0 @@ -145,7 +145,6 @@ internal class TrimExprFunction(private val valueFactory: ExprValueFactory) : Ex } override fun callWithRequired(env: Environment, required: List) = trim1Arg(required[0]) - override fun callWithVariadic(env: Environment, required: List, variadic: List): ExprValue { return when (variadic.size) { 0 -> trim1Arg(required[0]) diff --git a/lang/src/org/partiql/lang/eval/builtins/timestamp/FormatItem.kt b/lang/src/org/partiql/lang/eval/builtins/timestamp/FormatItem.kt index 2168dd4511..be3df8c2fd 100644 --- a/lang/src/org/partiql/lang/eval/builtins/timestamp/FormatItem.kt +++ b/lang/src/org/partiql/lang/eval/builtins/timestamp/FormatItem.kt @@ -14,8 +14,6 @@ package org.partiql.lang.eval.builtins.timestamp -import org.partiql.lang.eval.builtins.timestamp.TimestampField.* - /** * A item that is parsed from the format pattern. i.e. text or one of many symbols corresponding to a * field and its formatting options. diff --git a/lang/src/org/partiql/lang/eval/builtins/timestamp/FormatPattern.kt b/lang/src/org/partiql/lang/eval/builtins/timestamp/FormatPattern.kt index 91b2758964..394d747091 100644 --- a/lang/src/org/partiql/lang/eval/builtins/timestamp/FormatPattern.kt +++ b/lang/src/org/partiql/lang/eval/builtins/timestamp/FormatPattern.kt @@ -14,11 +14,10 @@ package org.partiql.lang.eval.builtins.timestamp -import org.partiql.lang.errors.* -import org.partiql.lang.eval.* -import org.partiql.lang.util.* - -import org.partiql.lang.eval.builtins.timestamp.TimestampField.* +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.eval.EvaluationException +import org.partiql.lang.util.propertyValueMapOf /** * Represents a parsed timestamp format pattern. @@ -170,7 +169,8 @@ internal class FormatPattern(val formatPatternString: String, val formatItems: L //NOTE: HOUR is not a valid precision for an Ion timestamp but when a format pattern's //leastSignificantField is HOUR, the minute field defaults to 00. if(hasOffset || hasAmPm) { - errIfMissingTimestampFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH, HOUR_OF_DAY) + errIfMissingTimestampFields(TimestampField.YEAR, TimestampField.MONTH_OF_YEAR, TimestampField.DAY_OF_MONTH, + TimestampField.HOUR_OF_DAY) } when (leastSignificantField) { @@ -178,18 +178,24 @@ internal class FormatPattern(val formatPatternString: String, val formatItems: L //If most precise field is null there are no format symbols corresponding to any timestamp fields. err("YEAR") } - YEAR -> { + TimestampField.YEAR -> { // the year field is the most coarse of the timestamp fields // it does not require any other fields to make a complete timestamp } - MONTH_OF_YEAR -> errIfMissingTimestampFields(YEAR) - DAY_OF_MONTH -> errIfMissingTimestampFields(YEAR, MONTH_OF_YEAR) - HOUR_OF_DAY -> errIfMissingTimestampFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH) - MINUTE_OF_HOUR -> errIfMissingTimestampFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH, HOUR_OF_DAY) - SECOND_OF_MINUTE -> errIfMissingTimestampFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE_OF_HOUR) - FRACTION_OF_SECOND -> errIfMissingTimestampFields(YEAR, MONTH_OF_YEAR, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE_OF_HOUR, SECOND_OF_MINUTE) - - OFFSET, AM_PM -> { + TimestampField.MONTH_OF_YEAR -> errIfMissingTimestampFields(TimestampField.YEAR) + TimestampField.DAY_OF_MONTH -> errIfMissingTimestampFields(TimestampField.YEAR, TimestampField.MONTH_OF_YEAR) + TimestampField.HOUR_OF_DAY -> errIfMissingTimestampFields(TimestampField.YEAR, + TimestampField.MONTH_OF_YEAR, TimestampField.DAY_OF_MONTH) + TimestampField.MINUTE_OF_HOUR -> errIfMissingTimestampFields(TimestampField.YEAR, + TimestampField.MONTH_OF_YEAR, TimestampField.DAY_OF_MONTH, TimestampField.HOUR_OF_DAY) + TimestampField.SECOND_OF_MINUTE -> errIfMissingTimestampFields(TimestampField.YEAR, + TimestampField.MONTH_OF_YEAR, TimestampField.DAY_OF_MONTH, TimestampField.HOUR_OF_DAY, + TimestampField.MINUTE_OF_HOUR) + TimestampField. FRACTION_OF_SECOND -> errIfMissingTimestampFields(TimestampField.YEAR, + TimestampField.MONTH_OF_YEAR, TimestampField.DAY_OF_MONTH, TimestampField.HOUR_OF_DAY, + TimestampField.MINUTE_OF_HOUR, TimestampField.SECOND_OF_MINUTE) + + TimestampField.OFFSET, TimestampField.AM_PM -> { throw IllegalStateException("OFFSET, AM_PM should never be the least significant field!") } } diff --git a/lang/src/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternLexer.kt b/lang/src/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternLexer.kt index 652a895e14..56889a5254 100644 --- a/lang/src/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternLexer.kt +++ b/lang/src/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternLexer.kt @@ -14,9 +14,11 @@ package org.partiql.lang.eval.builtins.timestamp -import org.partiql.lang.errors.* -import org.partiql.lang.eval.* -import org.partiql.lang.util.* +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.eval.EvaluationException +import org.partiql.lang.util.codePointSequence +import org.partiql.lang.util.propertyValueMapOf private const val NON_ESCAPED_TEXT = " /-,:." private const val SINGLE_QUOTE_CP = '\''.toInt() diff --git a/lang/src/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternParser.kt b/lang/src/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternParser.kt index cf140d98ed..dfbf19625b 100644 --- a/lang/src/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternParser.kt +++ b/lang/src/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternParser.kt @@ -14,9 +14,10 @@ package org.partiql.lang.eval.builtins.timestamp -import org.partiql.lang.errors.* -import org.partiql.lang.eval.* -import org.partiql.lang.util.* +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.eval.EvaluationException +import org.partiql.lang.util.propertyValueMapOf internal class TimestampFormatPatternParser { diff --git a/lang/src/org/partiql/lang/eval/io/DelimitedValues.kt b/lang/src/org/partiql/lang/eval/io/DelimitedValues.kt index ed33a6914d..d66bf8cb47 100644 --- a/lang/src/org/partiql/lang/eval/io/DelimitedValues.kt +++ b/lang/src/org/partiql/lang/eval/io/DelimitedValues.kt @@ -14,12 +14,26 @@ package org.partiql.lang.eval.io -import com.amazon.ion.* +import com.amazon.ion.IonDecimal +import com.amazon.ion.IonException +import com.amazon.ion.IonFloat +import com.amazon.ion.IonInt +import com.amazon.ion.IonSystem +import com.amazon.ion.IonTimestamp +import com.amazon.ion.IonType +import com.amazon.ion.IonValue import org.apache.commons.csv.CSVFormat import org.apache.commons.csv.CSVParser import org.apache.commons.csv.CSVPrinter -import org.partiql.lang.eval.* -import org.partiql.lang.util.* +import org.partiql.lang.eval.BindingCase +import org.partiql.lang.eval.BindingName +import org.partiql.lang.eval.ExprValue +import org.partiql.lang.eval.ExprValueFactory +import org.partiql.lang.eval.StructOrdering +import org.partiql.lang.eval.namedValue +import org.partiql.lang.eval.orderedNames +import org.partiql.lang.eval.syntheticColumnName +import org.partiql.lang.util.stringValue import java.io.BufferedReader import java.io.Reader import java.io.Writer diff --git a/lang/src/org/partiql/lang/eval/time/Time.kt b/lang/src/org/partiql/lang/eval/time/Time.kt index 31dfa8d14d..2d9df71c86 100644 --- a/lang/src/org/partiql/lang/eval/time/Time.kt +++ b/lang/src/org/partiql/lang/eval/time/Time.kt @@ -5,10 +5,8 @@ import com.amazon.ion.IonSystem import org.partiql.lang.errors.ErrorCode import org.partiql.lang.eval.EvaluationException import org.partiql.lang.eval.err -import org.partiql.lang.eval.errNoContext import org.partiql.lang.util.getOffsetHHmm import org.partiql.lang.util.propertyValueMapOf -import org.partiql.lang.util.times import java.math.BigDecimal import java.math.RoundingMode import java.time.DateTimeException diff --git a/lang/src/org/partiql/lang/eval/time/TimeExtensions.kt b/lang/src/org/partiql/lang/eval/time/TimeExtensions.kt index 61689ec3de..68a80afd78 100644 --- a/lang/src/org/partiql/lang/eval/time/TimeExtensions.kt +++ b/lang/src/org/partiql/lang/eval/time/TimeExtensions.kt @@ -3,8 +3,6 @@ package org.partiql.lang.util import org.partiql.lang.errors.ErrorCode import org.partiql.lang.eval.time.SECONDS_PER_HOUR import org.partiql.lang.eval.time.SECONDS_PER_MINUTE -import java.time.DateTimeException -import java.time.Instant import java.time.ZoneOffset import kotlin.math.absoluteValue diff --git a/lang/src/org/partiql/lang/eval/visitors/FromSourceAliasVisitorTransform.kt b/lang/src/org/partiql/lang/eval/visitors/FromSourceAliasVisitorTransform.kt index 777685e3e3..84f953f30c 100644 --- a/lang/src/org/partiql/lang/eval/visitors/FromSourceAliasVisitorTransform.kt +++ b/lang/src/org/partiql/lang/eval/visitors/FromSourceAliasVisitorTransform.kt @@ -1,8 +1,7 @@ package org.partiql.lang.eval.visitors -import org.partiql.lang.domains.extractSourceLocation - import org.partiql.lang.domains.PartiqlAst +import org.partiql.lang.domains.extractSourceLocation import org.partiql.lang.eval.extractColumnAlias import org.partiql.pig.runtime.SymbolPrimitive diff --git a/lang/src/org/partiql/lang/eval/visitors/StaticTypeInferenceVisitorTransform.kt b/lang/src/org/partiql/lang/eval/visitors/StaticTypeInferenceVisitorTransform.kt index 864a5f8715..0589eff99f 100644 --- a/lang/src/org/partiql/lang/eval/visitors/StaticTypeInferenceVisitorTransform.kt +++ b/lang/src/org/partiql/lang/eval/visitors/StaticTypeInferenceVisitorTransform.kt @@ -23,7 +23,6 @@ import org.partiql.lang.domains.PartiqlAst import org.partiql.lang.domains.staticType import org.partiql.lang.domains.toBindingCase import org.partiql.lang.errors.Problem -import org.partiql.lang.types.toTypedOpParameter import org.partiql.lang.errors.ProblemHandler import org.partiql.lang.errors.ProblemSeverity import org.partiql.lang.errors.ProblemThrower @@ -31,13 +30,11 @@ import org.partiql.lang.eval.BindingCase import org.partiql.lang.eval.BindingName import org.partiql.lang.eval.Bindings import org.partiql.lang.eval.ExprValueType -import org.partiql.lang.eval.TypingMode import org.partiql.lang.eval.builtins.createBuiltinFunctionSignatures import org.partiql.lang.eval.delegate import org.partiql.lang.eval.getStartingSourceLocationMeta import org.partiql.lang.types.* import org.partiql.lang.util.cartesianProduct -import java.lang.IllegalStateException /** * A [PartiqlAst.VisitorTransform] that annotates nodes with their static type. diff --git a/lang/src/org/partiql/lang/eval/visitors/StaticTypeVisitorTransform.kt b/lang/src/org/partiql/lang/eval/visitors/StaticTypeVisitorTransform.kt index 885c647e6a..c3399571f8 100644 --- a/lang/src/org/partiql/lang/eval/visitors/StaticTypeVisitorTransform.kt +++ b/lang/src/org/partiql/lang/eval/visitors/StaticTypeVisitorTransform.kt @@ -8,10 +8,8 @@ import com.amazon.ion.IonSystem import com.amazon.ionelement.api.MetaContainer import com.amazon.ionelement.api.metaContainerOf import com.amazon.ionelement.api.toIonElement -import org.partiql.lang.ast.LetBinding import org.partiql.lang.ast.StaticTypeMeta import org.partiql.lang.ast.passes.SemanticException -import org.partiql.lang.ast.sourceLocation import org.partiql.lang.domains.PartiqlAst import org.partiql.lang.domains.addSourceLocation import org.partiql.lang.domains.extractSourceLocation diff --git a/lang/src/org/partiql/lang/mappers/Exceptions.kt b/lang/src/org/partiql/lang/mappers/Exceptions.kt index 37de9cf97e..5349f314f9 100644 --- a/lang/src/org/partiql/lang/mappers/Exceptions.kt +++ b/lang/src/org/partiql/lang/mappers/Exceptions.kt @@ -1,7 +1,5 @@ package org.partiql.lang.mappers -import java.lang.RuntimeException - /** * General exception class for ISL and StaticType mappers. */ diff --git a/lang/src/org/partiql/lang/schemadiscovery/ConstraintUtils.kt b/lang/src/org/partiql/lang/schemadiscovery/ConstraintUtils.kt index 727c568f2b..304f70700c 100644 --- a/lang/src/org/partiql/lang/schemadiscovery/ConstraintUtils.kt +++ b/lang/src/org/partiql/lang/schemadiscovery/ConstraintUtils.kt @@ -3,7 +3,6 @@ package org.partiql.lang.schemadiscovery import com.amazon.ionelement.api.ionBool import com.amazon.ionelement.api.ionInt import org.partiql.ionschema.model.IonSchemaModel -import java.lang.IllegalStateException import kotlin.math.max import kotlin.math.min diff --git a/lang/src/org/partiql/lang/schemadiscovery/DiscoveredConstraintUnifier.kt b/lang/src/org/partiql/lang/schemadiscovery/DiscoveredConstraintUnifier.kt index df9635ff27..55a2075b05 100644 --- a/lang/src/org/partiql/lang/schemadiscovery/DiscoveredConstraintUnifier.kt +++ b/lang/src/org/partiql/lang/schemadiscovery/DiscoveredConstraintUnifier.kt @@ -1,7 +1,6 @@ package org.partiql.lang.schemadiscovery import org.partiql.ionschema.model.IonSchemaModel -import java.lang.IllegalArgumentException /** * For two conflicting [IonSchemaModel.ConstraintList]s with the same type constraint, unifies the constraint diff --git a/lang/src/org/partiql/lang/syntax/Parser.kt b/lang/src/org/partiql/lang/syntax/Parser.kt index d7106a0070..0e39368369 100644 --- a/lang/src/org/partiql/lang/syntax/Parser.kt +++ b/lang/src/org/partiql/lang/syntax/Parser.kt @@ -14,8 +14,8 @@ package org.partiql.lang.syntax -import com.amazon.ion.* -import org.partiql.lang.ast.* +import com.amazon.ion.IonSexp +import org.partiql.lang.ast.ExprNode import org.partiql.lang.domains.PartiqlAst /** diff --git a/lang/src/org/partiql/lang/syntax/SqlLexer.kt b/lang/src/org/partiql/lang/syntax/SqlLexer.kt index c77da3e06a..924ba86180 100644 --- a/lang/src/org/partiql/lang/syntax/SqlLexer.kt +++ b/lang/src/org/partiql/lang/syntax/SqlLexer.kt @@ -14,17 +14,15 @@ package org.partiql.lang.syntax -import com.amazon.ion.* -import org.partiql.lang.errors.* -import org.partiql.lang.errors.ErrorCode.* -import org.partiql.lang.errors.Property.* -import org.partiql.lang.syntax.SqlLexer.LexType.* -import org.partiql.lang.syntax.SqlLexer.StateType.* -import org.partiql.lang.syntax.TokenType.* -import org.partiql.lang.syntax.TokenType.KEYWORD -import org.partiql.lang.util.* -import java.math.* - +import com.amazon.ion.IonException +import com.amazon.ion.IonSystem +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.errors.PropertyValueMap +import org.partiql.lang.util.bigDecimalOf +import org.partiql.lang.util.codePointSequence +import org.partiql.lang.util.seal +import java.math.BigInteger /** * Simple tokenizer for PartiQL. @@ -73,7 +71,7 @@ class SqlLexer(private val ion: IonSystem) : Lexer { val tokenType: TokenType? get() = null val lexType: LexType - get() = NONE + get() = LexType.NONE val replacement: Int get() = REPLACE_SAME @@ -89,7 +87,7 @@ class SqlLexer(private val ion: IonSystem) : Lexer { /** State node and corresponding state table. */ internal class TableState(override val stateType: StateType, override val tokenType: TokenType? = null, - override val lexType: LexType = NONE, + override val lexType: LexType = LexType.NONE, override val replacement: Int = REPLACE_SAME, var delegate: State = ERROR_STATE, setup: TableState.() -> Unit = { }) : State { @@ -121,7 +119,7 @@ class SqlLexer(private val ion: IonSystem) : Lexer { fun selfRepeatingDelegate(stateType: StateType, tokenType: TokenType? = null, - lexType: LexType = NONE) { + lexType: LexType = LexType.NONE) { delegate = object : State { override val stateType = stateType override val tokenType = tokenType @@ -133,7 +131,7 @@ class SqlLexer(private val ion: IonSystem) : Lexer { fun delta(chars: String, stateType: StateType, tokenType: TokenType? = null, - lexType: LexType = NONE, + lexType: LexType = LexType.NONE, replacement: Int = REPLACE_SAME, delegate: State = this, setup: TableState.(String) -> Unit = { }): TableState { @@ -199,83 +197,83 @@ class SqlLexer(private val ion: IonSystem) : Lexer { private val REPLACE_NOTHING = -2 /** Synthetic state for EOF to trigger a flush of the last token. */ - private val EOF_STATE = RepeatingState(END) + private val EOF_STATE = RepeatingState(StateType.END) /** Error state. */ - private val ERROR_STATE = RepeatingState(ERROR) + private val ERROR_STATE = RepeatingState(StateType.ERROR) /** Initial state. */ - private val INITIAL_STATE = TableState(INITIAL) { + private val INITIAL_STATE = TableState(StateType.INITIAL) { val initialState = this - delta("(", START_AND_TERMINAL, LEFT_PAREN) - delta(")", START_AND_TERMINAL, RIGHT_PAREN) - delta("[", START_AND_TERMINAL, LEFT_BRACKET) - delta("]", START_AND_TERMINAL, RIGHT_BRACKET) - delta("{", START_AND_TERMINAL, LEFT_CURLY) - delta("}", START_AND_TERMINAL, RIGHT_CURLY) - delta(":", START_AND_TERMINAL, COLON) - delta(",", START_AND_TERMINAL, COMMA) - delta("*", START_AND_TERMINAL, STAR) - delta(";", START_AND_TERMINAL, SEMICOLON) - delta("?", START_AND_TERMINAL, QUESTION_MARK) - - delta(NON_OVERLOADED_OPERATOR_CHARS, START_AND_TERMINAL, OPERATOR) - - delta("|", START) { - delta("|", TERMINAL, OPERATOR, delegate = initialState) + delta("(", StateType.START_AND_TERMINAL, TokenType.LEFT_PAREN) + delta(")", StateType.START_AND_TERMINAL, TokenType.RIGHT_PAREN) + delta("[", StateType.START_AND_TERMINAL, TokenType.LEFT_BRACKET) + delta("]", StateType.START_AND_TERMINAL, TokenType.RIGHT_BRACKET) + delta("{", StateType.START_AND_TERMINAL, TokenType.LEFT_CURLY) + delta("}", StateType.START_AND_TERMINAL, TokenType.RIGHT_CURLY) + delta(":", StateType.START_AND_TERMINAL, TokenType.COLON) + delta(",", StateType.START_AND_TERMINAL, TokenType.COMMA) + delta("*", StateType.START_AND_TERMINAL, TokenType.STAR) + delta(";", StateType.START_AND_TERMINAL, TokenType.SEMICOLON) + delta("?", StateType.START_AND_TERMINAL, TokenType.QUESTION_MARK) + + delta(NON_OVERLOADED_OPERATOR_CHARS, StateType.START_AND_TERMINAL, TokenType.OPERATOR) + + delta("|", StateType.START) { + delta("|", StateType.TERMINAL, TokenType.OPERATOR, delegate = initialState) } - delta("!", START) { - delta("=", TERMINAL, OPERATOR, delegate = initialState) + delta("!", StateType.START) { + delta("=", StateType.TERMINAL, TokenType.OPERATOR, delegate = initialState) } - delta("<", START_AND_TERMINAL, OPERATOR) { - delta("=", TERMINAL, OPERATOR, delegate = initialState) - delta(">", TERMINAL, OPERATOR, delegate = initialState) - delta("<", TERMINAL, LEFT_DOUBLE_ANGLE_BRACKET, delegate = initialState) + delta("<", StateType.START_AND_TERMINAL, TokenType.OPERATOR) { + delta("=", StateType.TERMINAL, TokenType.OPERATOR, delegate = initialState) + delta(">", StateType.TERMINAL, TokenType.OPERATOR, delegate = initialState) + delta("<", StateType.TERMINAL, TokenType.LEFT_DOUBLE_ANGLE_BRACKET, delegate = initialState) } - delta(">", START_AND_TERMINAL, OPERATOR) { - delta("=", TERMINAL, OPERATOR, delegate = initialState) - delta(">", TERMINAL, RIGHT_DOUBLE_ANGLE_BRACKET, delegate = initialState) + delta(">", StateType.START_AND_TERMINAL, TokenType.OPERATOR) { + delta("=", StateType.TERMINAL, TokenType.OPERATOR, delegate = initialState) + delta(">", StateType.TERMINAL, TokenType.RIGHT_DOUBLE_ANGLE_BRACKET, delegate = initialState) } - delta(IDENT_START_CHARS, START_AND_TERMINAL, IDENTIFIER) { - delta(IDENT_CONTINUE_CHARS, TERMINAL, IDENTIFIER) + delta(IDENT_START_CHARS, StateType.START_AND_TERMINAL, TokenType.IDENTIFIER) { + delta(IDENT_CONTINUE_CHARS, StateType.TERMINAL, TokenType.IDENTIFIER) } fun TableState.deltaDecimalInteger(stateType: StateType, lexType: LexType, setup: TableState.(String) -> Unit = { }): Unit { - delta(DIGIT_CHARS, stateType, LITERAL, lexType, delegate = initialState) { - delta(DIGIT_CHARS, TERMINAL, LITERAL, lexType) + delta(DIGIT_CHARS, stateType, TokenType.LITERAL, lexType, delegate = initialState) { + delta(DIGIT_CHARS, StateType.TERMINAL, TokenType.LITERAL, lexType) setup(it) } } fun TableState.deltaDecimalFraction(setup: TableState.(String) -> Unit = { }): Unit { - delta(".", TERMINAL, LITERAL, DECIMAL) { - deltaDecimalInteger(TERMINAL, DECIMAL, setup) + delta(".", StateType.TERMINAL, TokenType.LITERAL, LexType.DECIMAL) { + deltaDecimalInteger(StateType.TERMINAL, LexType.DECIMAL, setup) } } fun TableState.deltaExponent(setup: TableState.(String) -> Unit = { }): Unit { - delta(E_NOTATION_CHARS, INCOMPLETE, delegate = ERROR_STATE) { - delta(SIGN_CHARS, INCOMPLETE, delegate = ERROR_STATE) { - deltaDecimalInteger(TERMINAL, DECIMAL, setup) + delta(E_NOTATION_CHARS, StateType.INCOMPLETE, delegate = ERROR_STATE) { + delta(SIGN_CHARS, StateType.INCOMPLETE, delegate = ERROR_STATE) { + deltaDecimalInteger(StateType.TERMINAL, LexType.DECIMAL, setup) } - deltaDecimalInteger(TERMINAL, DECIMAL, setup) + deltaDecimalInteger(StateType.TERMINAL, LexType.DECIMAL, setup) } } fun TableState.deltaNumber(stateType: StateType) { - deltaDecimalInteger(stateType, INTEGER) { + deltaDecimalInteger(stateType, LexType.INTEGER) { deltaDecimalFraction { deltaExponent { } } deltaExponent { } } when (stateType) { - START_AND_TERMINAL -> { + StateType.START_AND_TERMINAL -> { // at the top-level we need to support dot as a special - delta(".", START_AND_TERMINAL, DOT) { - deltaDecimalInteger(TERMINAL, DECIMAL) { + delta(".", StateType.START_AND_TERMINAL, TokenType.DOT) { + deltaDecimalInteger(StateType.TERMINAL, LexType.DECIMAL) { deltaExponent { } } } @@ -288,108 +286,108 @@ class SqlLexer(private val ion: IonSystem) : Lexer { } } - deltaNumber(START_AND_TERMINAL) + deltaNumber(StateType.START_AND_TERMINAL) fun TableState.deltaQuote(quoteChar: String, tokenType: TokenType, lexType: LexType): Unit { - delta(quoteChar, START, replacement = REPLACE_NOTHING) { - selfRepeatingDelegate(INCOMPLETE) + delta(quoteChar, StateType.START, replacement = REPLACE_NOTHING) { + selfRepeatingDelegate(StateType.INCOMPLETE) val quoteState = this - delta(quoteChar, TERMINAL, tokenType, lexType = lexType, replacement = REPLACE_NOTHING, delegate = initialState) { - delta(quoteChar, INCOMPLETE, delegate = quoteState) + delta(quoteChar, StateType.TERMINAL, tokenType, lexType = lexType, replacement = REPLACE_NOTHING, delegate = initialState) { + delta(quoteChar, StateType.INCOMPLETE, delegate = quoteState) } } } - deltaQuote(SINGLE_QUOTE_CHARS, LITERAL, SQ_STRING) - deltaQuote(DOUBLE_QUOTE_CHARS, QUOTED_IDENTIFIER, DQ_STRING) + deltaQuote(SINGLE_QUOTE_CHARS, TokenType.LITERAL, LexType.SQ_STRING) + deltaQuote(DOUBLE_QUOTE_CHARS, TokenType.QUOTED_IDENTIFIER, LexType.DQ_STRING) // Ion literals - very partial lexing of Ion to support nested back-tick // in Ion strings/symbols/comments - delta(BACKTICK_CHARS, START, replacement = REPLACE_NOTHING) { - selfRepeatingDelegate(INCOMPLETE) + delta(BACKTICK_CHARS, StateType.START, replacement = REPLACE_NOTHING) { + selfRepeatingDelegate(StateType.INCOMPLETE) val quoteState = this - delta("/", INCOMPLETE) { - delta("/", INCOMPLETE) { + delta("/", StateType.INCOMPLETE) { + delta("/", StateType.INCOMPLETE) { val ionCommentState = this - selfRepeatingDelegate(INCOMPLETE) - delta(BACKTICK_CHARS, INCOMPLETE, delegate = ionCommentState) - delta(NL_WHITESPACE_CHARS, INCOMPLETE, delegate = quoteState) + selfRepeatingDelegate(StateType.INCOMPLETE) + delta(BACKTICK_CHARS, StateType.INCOMPLETE, delegate = ionCommentState) + delta(NL_WHITESPACE_CHARS, StateType.INCOMPLETE, delegate = quoteState) } - delta("*", INCOMPLETE) { + delta("*", StateType.INCOMPLETE) { val ionCommentState = this - selfRepeatingDelegate(INCOMPLETE) - delta(BACKTICK_CHARS, INCOMPLETE, delegate = ionCommentState) - delta("*", INCOMPLETE) { - delta("/", INCOMPLETE, delegate = quoteState) + selfRepeatingDelegate(StateType.INCOMPLETE) + delta(BACKTICK_CHARS, StateType.INCOMPLETE, delegate = ionCommentState) + delta("*", StateType.INCOMPLETE) { + delta("/", StateType.INCOMPLETE, delegate = quoteState) } } } - delta(DOUBLE_QUOTE_CHARS, INCOMPLETE) { + delta(DOUBLE_QUOTE_CHARS, StateType.INCOMPLETE) { val ionStringState = this - selfRepeatingDelegate(INCOMPLETE) + selfRepeatingDelegate(StateType.INCOMPLETE) - delta("\\", INCOMPLETE) { - delta(DOUBLE_QUOTE_CHARS, INCOMPLETE, delegate = ionStringState) + delta("\\", StateType.INCOMPLETE) { + delta(DOUBLE_QUOTE_CHARS, StateType.INCOMPLETE, delegate = ionStringState) } - delta(BACKTICK_CHARS, INCOMPLETE, delegate = ionStringState) - delta(DOUBLE_QUOTE_CHARS, INCOMPLETE, delegate = quoteState) + delta(BACKTICK_CHARS, StateType.INCOMPLETE, delegate = ionStringState) + delta(DOUBLE_QUOTE_CHARS, StateType.INCOMPLETE, delegate = quoteState) } - delta(SINGLE_QUOTE_CHARS, INCOMPLETE) { + delta(SINGLE_QUOTE_CHARS, StateType.INCOMPLETE) { val ionStringState = this - selfRepeatingDelegate(INCOMPLETE) + selfRepeatingDelegate(StateType.INCOMPLETE) - delta("\\", INCOMPLETE) { - delta(SINGLE_QUOTE_CHARS, INCOMPLETE, delegate = ionStringState) + delta("\\", StateType.INCOMPLETE) { + delta(SINGLE_QUOTE_CHARS, StateType.INCOMPLETE, delegate = ionStringState) } - delta(BACKTICK_CHARS, INCOMPLETE, delegate = ionStringState) - delta(SINGLE_QUOTE_CHARS, INCOMPLETE, delegate = quoteState) { - delta(SINGLE_QUOTE_CHARS, INCOMPLETE, delegate = ionStringState) { + delta(BACKTICK_CHARS, StateType.INCOMPLETE, delegate = ionStringState) + delta(SINGLE_QUOTE_CHARS, StateType.INCOMPLETE, delegate = quoteState) { + delta(SINGLE_QUOTE_CHARS, StateType.INCOMPLETE, delegate = ionStringState) { val ionLongStringState = this - selfRepeatingDelegate(INCOMPLETE) + selfRepeatingDelegate(StateType.INCOMPLETE) - delta("\\", INCOMPLETE) { - delta(SINGLE_QUOTE_CHARS, INCOMPLETE, delegate = ionLongStringState) + delta("\\", StateType.INCOMPLETE) { + delta(SINGLE_QUOTE_CHARS, StateType.INCOMPLETE, delegate = ionLongStringState) } - delta(BACKTICK_CHARS, INCOMPLETE, delegate = ionLongStringState) - delta(SINGLE_QUOTE_CHARS, INCOMPLETE, delegate = ionLongStringState) { - delta(SINGLE_QUOTE_CHARS, INCOMPLETE, delegate = ionLongStringState) { - delta(SINGLE_QUOTE_CHARS, INCOMPLETE, delegate = quoteState) + delta(BACKTICK_CHARS, StateType.INCOMPLETE, delegate = ionLongStringState) + delta(SINGLE_QUOTE_CHARS, StateType.INCOMPLETE, delegate = ionLongStringState) { + delta(SINGLE_QUOTE_CHARS, StateType.INCOMPLETE, delegate = ionLongStringState) { + delta(SINGLE_QUOTE_CHARS, StateType.INCOMPLETE, delegate = quoteState) } } } } } - delta("{", INCOMPLETE) { - delta("{", INCOMPLETE) { - selfRepeatingDelegate(INCOMPLETE) - delta("}", INCOMPLETE) { - delta("}", INCOMPLETE, delegate = quoteState) + delta("{", StateType.INCOMPLETE) { + delta("{", StateType.INCOMPLETE) { + selfRepeatingDelegate(StateType.INCOMPLETE) + delta("}", StateType.INCOMPLETE) { + delta("}", StateType.INCOMPLETE, delegate = quoteState) } } } - delta(BACKTICK_CHARS, TERMINAL, TokenType.ION_LITERAL, LexType.ION_LITERAL, replacement = REPLACE_NOTHING, delegate = initialState) + delta(BACKTICK_CHARS, StateType.TERMINAL, TokenType.ION_LITERAL, LexType.ION_LITERAL, replacement = REPLACE_NOTHING, delegate = initialState) } - delta(ALL_WHITESPACE_CHARS, START_AND_TERMINAL, null, WHITESPACE) + delta(ALL_WHITESPACE_CHARS, StateType.START_AND_TERMINAL, null, LexType.WHITESPACE) // block comment and divide operator - delta("/", START_AND_TERMINAL, OPERATOR) { - delta("*", INCOMPLETE) { - selfRepeatingDelegate(INCOMPLETE) - delta("*", INCOMPLETE) { - delta("/", TERMINAL, null, WHITESPACE, delegate = initialState) + delta("/", StateType.START_AND_TERMINAL, TokenType.OPERATOR) { + delta("*", StateType.INCOMPLETE) { + selfRepeatingDelegate(StateType.INCOMPLETE) + delta("*", StateType.INCOMPLETE) { + delta("/", StateType.TERMINAL, null, LexType.WHITESPACE, delegate = initialState) } } } // line comment, subtraction operator, and signed positive integer - delta("-", START_AND_TERMINAL, OPERATOR) { + delta("-", StateType.START_AND_TERMINAL, TokenType.OPERATOR) { // inline comments don't need a special terminator before EOF - delta("-", TERMINAL, null, WHITESPACE) { - selfRepeatingDelegate(TERMINAL, null, WHITESPACE) - delta(NL_WHITESPACE_CHARS, TERMINAL, null, WHITESPACE, delegate = initialState) + delta("-", StateType.TERMINAL, null, LexType.WHITESPACE) { + selfRepeatingDelegate(StateType.TERMINAL, null, LexType.WHITESPACE) + delta(NL_WHITESPACE_CHARS, StateType.TERMINAL, null, LexType.WHITESPACE, delegate = initialState) } } @@ -409,9 +407,9 @@ class SqlLexer(private val ion: IonSystem) : Lexer { */ private fun makePropertyBag(tokenString: String, tracker: PositionTracker): PropertyValueMap { val pvmap = PropertyValueMap() - pvmap[LINE_NUMBER] = tracker.line - pvmap[COLUMN_NUMBER] = tracker.col - pvmap[TOKEN_STRING] = tokenString + pvmap[Property.LINE_NUMBER] = tracker.line + pvmap[Property.COLUMN_NUMBER] = tracker.col + pvmap[Property.TOKEN_STRING] = tokenString return pvmap } @@ -434,16 +432,16 @@ class SqlLexer(private val ion: IonSystem) : Lexer { tokenCodePointCount++; fun errInvalidChar(): Nothing = - throw LexerException(errorCode = LEXER_INVALID_CHAR, errorContext = makePropertyBag(repr(cp), tracker)) + throw LexerException(errorCode = ErrorCode.LEXER_INVALID_CHAR, errorContext = makePropertyBag(repr(cp), tracker)) fun errInvalidOperator(operator: String): Nothing = - throw LexerException(errorCode = LEXER_INVALID_OPERATOR, errorContext = makePropertyBag(operator, tracker)) + throw LexerException(errorCode = ErrorCode.LEXER_INVALID_OPERATOR, errorContext = makePropertyBag(operator, tracker)) fun errInvalidLiteral(literal: String): Nothing = - throw LexerException(errorCode = LEXER_INVALID_LITERAL, errorContext = makePropertyBag(literal, tracker)) + throw LexerException(errorCode = ErrorCode.LEXER_INVALID_LITERAL, errorContext = makePropertyBag(literal, tracker)) fun errInvalidIonLiteral(literal: String, cause: IonException): Nothing = - throw LexerException(errorCode = LEXER_INVALID_ION_LITERAL, + throw LexerException(errorCode = ErrorCode.LEXER_INVALID_ION_LITERAL, errorContext = makePropertyBag(literal, tracker), cause = cause) @@ -459,89 +457,89 @@ class SqlLexer(private val ion: IonSystem) : Lexer { val nextType = next.stateType when { - nextType == ERROR -> errInvalidChar() + nextType == StateType.ERROR -> errInvalidChar() nextType.beginsToken -> { // we can only start a token if we've properly ended another one. - if (currType != INITIAL && !currType.endsToken) { + if (currType != StateType.INITIAL && !currType.endsToken) { errInvalidChar() } - if (currType.endsToken && curr.lexType != WHITESPACE) { + if (currType.endsToken && curr.lexType != LexType.WHITESPACE) { // flush out the previous token val text = buffer.toString() var tokenType = curr.tokenType!! val ionValue = when (tokenType) { - OPERATOR -> { + TokenType.OPERATOR -> { val unaliased = OPERATOR_ALIASES[text] ?: text when (unaliased) { in ALL_OPERATORS -> ion.newSymbol(unaliased) else -> errInvalidOperator(unaliased) } } - IDENTIFIER -> { + TokenType.IDENTIFIER -> { val lower = text.toLowerCase() when { - curr.lexType == DQ_STRING -> ion.newSymbol(text) + curr.lexType == LexType.DQ_STRING -> ion.newSymbol(text) lower in ALL_SINGLE_LEXEME_OPERATORS -> { // an operator that looks like a keyword - tokenType = OPERATOR + tokenType = TokenType.OPERATOR ion.newSymbol(lower) } lower == "as" -> { // AS token - tokenType = AS + tokenType = TokenType.AS ion.newSymbol(lower) } lower == "at" -> { // AS token - tokenType = AT + tokenType = TokenType.AT ion.newSymbol(lower) } lower == "by" -> { // BY token - tokenType = BY + tokenType = TokenType.BY ion.newSymbol(lower) } lower == "null" -> { // literal null - tokenType = NULL + tokenType = TokenType.NULL ion.newNull() } lower == "missing" -> { // special literal for MISSING - tokenType = MISSING + tokenType = TokenType.MISSING ion.newNull() } lower == "for" -> { // used as an argument delimiter for substring - tokenType = FOR + tokenType = TokenType.FOR ion.newSymbol(lower) } lower == "asc" -> { - tokenType = ASC + tokenType = TokenType.ASC ion.newSymbol(lower) } lower == "desc" -> { - tokenType = DESC + tokenType = TokenType.DESC ion.newSymbol(lower) } lower in BOOLEAN_KEYWORDS -> { // literal boolean - tokenType = LITERAL + tokenType = TokenType.LITERAL ion.newBool(lower == "true") } lower in KEYWORDS -> { // unquoted identifier that is a keyword - tokenType = KEYWORD + tokenType = TokenType.KEYWORD ion.newSymbol(TYPE_ALIASES[lower] ?: lower) } else -> ion.newSymbol(text) } } - LITERAL -> when (curr.lexType) { - SQ_STRING -> ion.newString(text) - INTEGER -> ion.newInt(BigInteger(text, 10)) - DECIMAL -> try { + TokenType.LITERAL -> when (curr.lexType) { + LexType.SQ_STRING -> ion.newString(text) + LexType.INTEGER -> ion.newInt(BigInteger(text, 10)) + LexType.DECIMAL -> try { ion.newDecimal(bigDecimalOf(text)) } catch (e: NumberFormatException) { @@ -560,7 +558,7 @@ class SqlLexer(private val ion: IonSystem) : Lexer { errInvalidIonLiteral(text, e) } } - QUESTION_MARK -> { + TokenType.QUESTION_MARK -> { ion.newInt(++parameterCt) } else -> ion.newSymbol(text) @@ -588,7 +586,7 @@ class SqlLexer(private val ion: IonSystem) : Lexer { } // if next state is the EOF marker add it to `tokens`. - if (next.stateType == END) tokens.add( + if (next.stateType == StateType.END) tokens.add( Token( type = TokenType.EOF, value = ion.newSymbol("EOF"), diff --git a/lang/src/org/partiql/lang/syntax/SqlParser.kt b/lang/src/org/partiql/lang/syntax/SqlParser.kt index 5b73a9257d..3b23784f18 100644 --- a/lang/src/org/partiql/lang/syntax/SqlParser.kt +++ b/lang/src/org/partiql/lang/syntax/SqlParser.kt @@ -14,28 +14,62 @@ package org.partiql.lang.syntax -import com.amazon.ion.* -import com.amazon.ionelement.api.* -import org.partiql.lang.ast.* +import com.amazon.ion.IntegerSize +import com.amazon.ion.IonInt +import com.amazon.ion.IonSexp +import com.amazon.ion.IonSystem +import com.amazon.ionelement.api.emptyMetaContainer +import com.amazon.ionelement.api.ionInt +import com.amazon.ionelement.api.ionString +import com.amazon.ionelement.api.metaContainerOf +import com.amazon.ionelement.api.toIonElement +import org.partiql.lang.ast.AstSerializer +import org.partiql.lang.ast.AstVersion +import org.partiql.lang.ast.ExprNode +import org.partiql.lang.ast.IonElementMetaContainer +import org.partiql.lang.ast.IsCountStarMeta +import org.partiql.lang.ast.IsImplictJoinMeta +import org.partiql.lang.ast.IsIonLiteralMeta +import org.partiql.lang.ast.LegacyLogicalNotMeta +import org.partiql.lang.ast.Meta +import org.partiql.lang.ast.NAryOp +import org.partiql.lang.ast.SourceLocationMeta +import org.partiql.lang.ast.SqlDataType +import org.partiql.lang.ast.toExprNode import org.partiql.lang.domains.PartiqlAst import org.partiql.lang.errors.ErrorCode -import org.partiql.lang.errors.ErrorCode.* import org.partiql.lang.errors.Property -import org.partiql.lang.errors.Property.* -import org.partiql.lang.errors.* -import org.partiql.lang.eval.time.* -import org.partiql.lang.syntax.SqlParser.AliasSupportType.* -import org.partiql.lang.syntax.SqlParser.ArgListMode.* -import org.partiql.lang.syntax.SqlParser.ParseType.* -import org.partiql.lang.syntax.TokenType.* -import org.partiql.lang.syntax.TokenType.KEYWORD +import org.partiql.lang.errors.PropertyValueMap +import org.partiql.lang.eval.time.MAX_PRECISION_FOR_TIME import org.partiql.lang.types.CustomType -import org.partiql.lang.util.* +import org.partiql.lang.util.DATE_PATTERN_REGEX +import org.partiql.lang.util.atomFromHead +import org.partiql.lang.util.checkThreadInterrupted +import org.partiql.lang.util.err +import org.partiql.lang.util.errExpectedTokenType +import org.partiql.lang.util.genericTimeRegex +import org.partiql.lang.util.getPrecisionFromTimeString +import org.partiql.lang.util.head +import org.partiql.lang.util.ionValue +import org.partiql.lang.util.isNumeric +import org.partiql.lang.util.isText +import org.partiql.lang.util.isUnsignedInteger +import org.partiql.lang.util.longValue +import org.partiql.lang.util.numberValue +import org.partiql.lang.util.onlyEndOfStatement +import org.partiql.lang.util.stringValue +import org.partiql.lang.util.tail +import org.partiql.lang.util.tailExpectedKeyword +import org.partiql.lang.util.tailExpectedToken +import org.partiql.lang.util.timeWithoutTimeZoneRegex +import org.partiql.lang.util.unaryMinus import org.partiql.pig.runtime.SymbolPrimitive import java.time.LocalDate -import java.time.format.DateTimeFormatter.* -import java.time.* +import java.time.LocalTime +import java.time.OffsetTime import java.time.format.DateTimeFormatter +import java.time.format.DateTimeFormatter.ISO_LOCAL_DATE +import java.time.format.DateTimeFormatter.ISO_TIME import java.time.format.DateTimeParseException import java.time.temporal.Temporal @@ -181,22 +215,22 @@ class SqlParser( fun deriveExpected(expectedType1: TokenType, expectedType2: TokenType): Pair = if (expectedType1 != this.remaining.head?.type && expectedType2 != this.remaining.head?.type) { val pvmap = PropertyValueMap() - pvmap[EXPECTED_TOKEN_TYPE_1_OF_2] = expectedType1 - pvmap[EXPECTED_TOKEN_TYPE_2_OF_2] = expectedType2 - this.remaining.err("Expected $type", PARSE_EXPECTED_2_TOKEN_TYPES, pvmap) + pvmap[Property.EXPECTED_TOKEN_TYPE_1_OF_2] = expectedType1 + pvmap[Property.EXPECTED_TOKEN_TYPE_2_OF_2] = expectedType2 + this.remaining.err("Expected $type", ErrorCode.PARSE_EXPECTED_2_TOKEN_TYPES, pvmap) } else { Pair(copy(remaining = this.remaining.tail), this.remaining.head!!) } fun deriveExpectedKeyword(keyword: String): ParseNode = derive { tailExpectedKeyword(keyword) } - val isNumericLiteral = type == ATOM && when (token?.type) { - LITERAL, ION_LITERAL -> token.value?.isNumeric ?: false + val isNumericLiteral = type == ParseType.ATOM && when (token?.type) { + TokenType.LITERAL, TokenType.ION_LITERAL -> token.value?.isNumeric ?: false else -> false } fun numberValue(): Number = token?.value?.numberValue() - ?: unsupported("Could not interpret token as number", PARSE_EXPECTED_NUMBER) + ?: unsupported("Could not interpret token as number", ErrorCode.PARSE_EXPECTED_NUMBER) fun unsupported(message: String, errorCode: ErrorCode, errorContext: PropertyValueMap = PropertyValueMap()): Nothing = remaining.err(message, errorCode, errorContext) @@ -232,17 +266,20 @@ class SqlParser( //*************************************** private fun ParseNode.toAstStatement(): PartiqlAst.Statement { return when (type) { - ATOM, LIST, BAG, STRUCT, UNARY, BINARY, TERNARY, TYPE_FUNCTION, CALL, CALL_AGG, NULLIF, COALESCE, - CALL_DISTINCT_AGG, CALL_AGG_WILDCARD, PATH, PARAMETER, CASE, SELECT_LIST, - SELECT_VALUE, PIVOT, DATE, TIME, TIME_WITH_TIME_ZONE -> PartiqlAst.build { query(toAstExpr(), getMetas()) } + ParseType.ATOM, ParseType.LIST, ParseType.BAG, ParseType.STRUCT, ParseType.UNARY, ParseType.BINARY, + ParseType.TERNARY, ParseType.TYPE_FUNCTION, ParseType.CALL, ParseType.CALL_AGG, ParseType.NULLIF, + ParseType.COALESCE, ParseType.CALL_DISTINCT_AGG, ParseType.CALL_AGG_WILDCARD, ParseType.PATH, + ParseType.PARAMETER, ParseType.CASE, ParseType.SELECT_LIST, ParseType.SELECT_VALUE, ParseType.PIVOT, + ParseType.DATE, ParseType.TIME, ParseType.TIME_WITH_TIME_ZONE -> PartiqlAst.build { query(toAstExpr(), getMetas()) } - FROM, INSERT, INSERT_VALUE, SET, UPDATE, REMOVE, DELETE, DML_LIST -> toAstDml() + ParseType.FROM, ParseType.INSERT, ParseType.INSERT_VALUE, ParseType.SET, ParseType.UPDATE, ParseType.REMOVE, + ParseType.DELETE, ParseType.DML_LIST -> toAstDml() - CREATE_TABLE, DROP_TABLE, CREATE_INDEX, DROP_INDEX -> toAstDdl() - - EXEC -> toAstExec() + ParseType.CREATE_TABLE, ParseType.DROP_TABLE, ParseType.CREATE_INDEX, ParseType.DROP_INDEX -> toAstDdl() - else -> unsupported("Unsupported syntax for $type", PARSE_UNSUPPORTED_SYNTAX) + ParseType.EXEC -> toAstExec() + + else -> unsupported("Unsupported syntax for $type", ErrorCode.PARSE_UNSUPPORTED_SYNTAX) } } @@ -252,19 +289,19 @@ class SqlParser( return PartiqlAst.build { when (type) { - ATOM -> when (token?.type){ - LITERAL, NULL, TRIM_SPECIFICATION, DATETIME_PART -> lit(token.value!!.toIonElement(), metas) - ION_LITERAL -> lit(token.value!!.toIonElement(), metas + metaToIonMetaContainer(IsIonLiteralMeta.instance)) - MISSING -> missing(metas) - QUOTED_IDENTIFIER -> id(token.text!!, caseSensitive(), unqualified(), metas) - IDENTIFIER -> id(token.text!!, caseInsensitive(), unqualified(), metas) + ParseType.ATOM -> when (token?.type){ + TokenType.LITERAL, TokenType.NULL, TokenType.TRIM_SPECIFICATION, TokenType.DATETIME_PART -> lit(token.value!!.toIonElement(), metas) + TokenType.ION_LITERAL -> lit(token.value!!.toIonElement(), metas + metaToIonMetaContainer(IsIonLiteralMeta.instance)) + TokenType.MISSING -> missing(metas) + TokenType.QUOTED_IDENTIFIER -> id(token.text!!, caseSensitive(), unqualified(), metas) + TokenType.IDENTIFIER -> id(token.text!!, caseInsensitive(), unqualified(), metas) else -> errMalformedParseTree("Unsupported atom token type ${token?.type}") } - LIST -> list(children.map { it.toAstExpr() }, metas) - BAG -> bag(children.map { it.toAstExpr() }, metas) - STRUCT -> { + ParseType.LIST -> list(children.map { it.toAstExpr() }, metas) + ParseType.BAG -> bag(children.map { it.toAstExpr() }, metas) + ParseType.STRUCT -> { val fields = children.map { - if (it.type != MEMBER) { + if (it.type != ParseType.MEMBER) { errMalformedParseTree("Expected MEMBER node as direct descendant of a STRUCT node but instead found ${it.type}") } if (it.children.size != 2) { @@ -276,7 +313,7 @@ class SqlParser( } struct(fields, metas) } - UNARY, BINARY, TERNARY -> { + ParseType.UNARY, ParseType.BINARY, ParseType.TERNARY -> { when (token!!.text) { "is" -> isType(children[0].toAstExpr(), children[1].toAstType(), metas) "is_not" -> not( @@ -297,8 +334,8 @@ class SqlParser( val childToken = childNode.token ?: errMalformedParseTree("@ node does not have a token") when (childToken.type) { - QUOTED_IDENTIFIER -> id(childToken.text!!, caseSensitive(), localsFirst(), childNode.getMetas()) - IDENTIFIER -> id(childToken.text!!, caseInsensitive(), localsFirst(), childNode.getMetas()) + TokenType.QUOTED_IDENTIFIER -> id(childToken.text!!, caseSensitive(), localsFirst(), childNode.getMetas()) + TokenType.IDENTIFIER -> id(childToken.text!!, caseInsensitive(), localsFirst(), childNode.getMetas()) else -> errMalformedParseTree("Unexpected child node token type of @ operator node $childToken") } } @@ -318,18 +355,18 @@ class SqlParser( } } } - NULLIF -> { + ParseType.NULLIF -> { nullIf( children[0].toAstExpr(), children[1].toAstExpr(), metas) } - COALESCE -> { + ParseType.COALESCE -> { coalesce( children.map { it.toAstExpr() }, metas) } - TYPE_FUNCTION -> { + ParseType.TYPE_FUNCTION -> { val funcExpr = children[0].toAstExpr() val dataType = children[1].toAstType() when(token?.keywordText) { @@ -339,7 +376,7 @@ class SqlParser( else -> errMalformedParseTree("Unexpected type function token: $token") } } - CALL -> { + ParseType.CALL -> { when (val funcName = token?.text!!.toLowerCase()) { // special case--list/sexp/bag "functions" are intrinsic to the literal form "sexp" -> sexp(children.map { it.toAstExpr()}, metas) @@ -354,16 +391,16 @@ class SqlParser( } } } - CALL_AGG -> { + ParseType.CALL_AGG -> { val funcName = SymbolPrimitive(token?.text!!.toLowerCase(), emptyMetaContainer()) callAgg_(all(), funcName, children[0].toAstExpr(), metas) } - CALL_DISTINCT_AGG -> { + ParseType.CALL_DISTINCT_AGG -> { val funcName = SymbolPrimitive(token?.text!!.toLowerCase(), emptyMetaContainer()) callAgg_(distinct(), funcName, children[0].toAstExpr(), metas) } - CALL_AGG_WILDCARD -> { - if(token!!.type != KEYWORD || token.keywordText != "count") { + ParseType.CALL_AGG_WILDCARD -> { + if(token!!.type != TokenType.KEYWORD || token.keywordText != "count") { errMalformedParseTree("only COUNT can be used with a wildcard") } // Should only get the [SourceLocationMeta] if present, not any other metas. @@ -373,49 +410,50 @@ class SqlParser( val symbolicPrimitive = SymbolPrimitive("count", srcLocationMetaOnly) callAgg_(all(), symbolicPrimitive, lit, metas + metaToIonMetaContainer(IsCountStarMeta.instance)) } - PATH -> { + ParseType.PATH -> { val rootExpr = children[0].toAstExpr() val pathComponents = children.drop(1).map { when(it.type) { - PATH_DOT -> { + ParseType.PATH_DOT -> { if(it.children.size != 1) { errMalformedParseTree("Unexpected number of child elements in PATH_DOT ParseNode") } val atomParseNode = it.children[0] val atomMetas = atomParseNode.getMetas() when (atomParseNode.type) { - CASE_SENSITIVE_ATOM, CASE_INSENSITIVE_ATOM -> { + ParseType.CASE_SENSITIVE_ATOM, ParseType.CASE_INSENSITIVE_ATOM -> { val lit = lit(ionString(atomParseNode.token?.text!!), atomMetas) - val caseSensitivity = if (atomParseNode.type == CASE_SENSITIVE_ATOM) caseSensitive() else caseInsensitive() + val caseSensitivity = if (atomParseNode.type == ParseType.CASE_SENSITIVE_ATOM) caseSensitive() else caseInsensitive() pathExpr(lit, caseSensitivity, atomMetas) } - PATH_UNPIVOT -> pathUnpivot(atomMetas) + ParseType.PATH_UNPIVOT -> pathUnpivot(atomMetas) else -> errMalformedParseTree("Unsupported child path node of PATH_DOT") } } - PATH_SQB -> { + ParseType.PATH_SQB -> { if(it.children.size != 1) { errMalformedParseTree("Unexpected number of child elements in PATH_SQB ParseNode") } val child = it.children[0] val childMetas = child.getMetas() - if (child.type == PATH_WILDCARD) pathWildcard(childMetas) else pathExpr(child.toAstExpr(), caseSensitive(), childMetas) + if (child.type == ParseType.PATH_WILDCARD) pathWildcard(childMetas) else pathExpr(child.toAstExpr(), caseSensitive(), childMetas) } else -> errMalformedParseTree("Unsupported path component: ${it.type}") } } path(rootExpr, pathComponents, metas) } - PARAMETER -> parameter(token!!.value!!.longValue(), metas) - CASE -> { + ParseType.PARAMETER -> parameter(token!!.value!!.longValue(), metas) + ParseType.CASE -> { val branches = ArrayList() val cases = exprPairList(branches) var elseExpr: PartiqlAst.Expr? = null fun ParseNode.addCases() = children.forEach { when(it.type) { - WHEN -> branches.add(exprPair(it.children[0].toAstExpr(), it.children[1].toAstExpr())) - ELSE -> elseExpr = it.children[0].toAstExpr() + ParseType.WHEN -> + branches.add(exprPair(it.children[0].toAstExpr(), it.children[1].toAstExpr())) + ParseType.ELSE -> elseExpr = it.children[0].toAstExpr() else -> errMalformedParseTree("CASE clause must be WHEN or ELSE") } } @@ -435,7 +473,7 @@ class SqlParser( else -> errMalformedParseTree("CASE must be searched or simple") } } - SELECT_LIST, SELECT_VALUE, PIVOT -> { + ParseType.SELECT_LIST, ParseType.SELECT_VALUE, ParseType.PIVOT -> { // The first child of a SELECT_LIST parse node can be either DISTINCT or ARG_LIST. // If it is ARG_LIST, the children of that node are the select items and the SetQuantifier is ALL // If it is DISTINCT, the SetQuantifier is DISTINCT and there should be one child node, an ARG_LIST @@ -448,11 +486,11 @@ class SqlParser( // If the query parsed was a `SELECT DISTINCT ...`, children[0] is of type DISTINCT and its // children are the actual select list. - val setQuantifier = if (children[0].type == DISTINCT) distinct() else null - val selectList = if (children[0].type == DISTINCT) children[0].children[0] else children[0] + val setQuantifier = if (children[0].type == ParseType.DISTINCT) distinct() else null + val selectList = if (children[0].type == ParseType.DISTINCT) children[0].children[0] else children[0] val fromList = children[1] - if (fromList.type != FROM_CLAUSE) { + if (fromList.type != ParseType.FROM_CLAUSE) { errMalformedParseTree("Invalid second child of SELECT_LIST") } @@ -465,16 +503,16 @@ class SqlParser( val unconsumedChildren = children.drop(2).toMutableList() val projection = when (type) { - SELECT_LIST -> { + ParseType.SELECT_LIST -> { // We deal with ProjectStar first val childNodes = selectList.children - if (childNodes.any { it.type == PROJECT_ALL && it.children.isEmpty() }) { + if (childNodes.any { it.type == ParseType.PROJECT_ALL && it.children.isEmpty() }) { if (childNodes.size > 1) error("More than one select item when SELECT * was present.") projectStar(childNodes[0].getMetas()) } else { val selectListItems = childNodes.map { when (it.type) { - PROJECT_ALL -> projectAll(it.children[0].toAstExpr()) + ParseType.PROJECT_ALL -> projectAll(it.children[0].toAstExpr()) else -> { val (asAliasSymbol, parseNode) = it.unwrapAsAlias() projectExpr_(parseNode.toAstExpr(), asAliasSymbol) @@ -484,8 +522,8 @@ class SqlParser( projectList(selectListItems, metas) } } - SELECT_VALUE -> projectValue(selectList.toAstExpr()) - PIVOT -> { + ParseType.SELECT_VALUE -> projectValue(selectList.toAstExpr()) + ParseType.PIVOT -> { val member = children[0] val asExpr = member.children[0].toAstExpr() val atExpr = member.children[1].toAstExpr() @@ -496,20 +534,21 @@ class SqlParser( val fromSource = fromList.children[0].toFromSource() - val fromLet = unconsumedChildren.firstOrNull { it.type == LET }?.let { + val fromLet = unconsumedChildren.firstOrNull { it.type == ParseType.LET }?.let { unconsumedChildren.remove(it) it.toLetSource() } - val whereExpr = unconsumedChildren.firstOrNull { it.type == WHERE }?.let { + val whereExpr = unconsumedChildren.firstOrNull { it.type == ParseType.WHERE }?.let { unconsumedChildren.remove(it) it.children[0].toAstExpr() } - val groupBy = unconsumedChildren.firstOrNull { it.type == GROUP || it.type == GROUP_PARTIAL }?.let { + val groupBy = unconsumedChildren.firstOrNull { it.type == ParseType.GROUP || + it.type == ParseType.GROUP_PARTIAL }?.let { unconsumedChildren.remove(it) val groupingStrategy = when (it.type) { - GROUP -> groupFull() + ParseType.GROUP -> groupFull() else -> groupPartial() } val groupAsName = if (it.children.size > 1) it.children[1].toSymbolicName() else null @@ -525,12 +564,12 @@ class SqlParser( ) } - val havingExpr = unconsumedChildren.firstOrNull { it.type == HAVING }?.let { + val havingExpr = unconsumedChildren.firstOrNull { it.type == ParseType.HAVING }?.let { unconsumedChildren.remove(it) it.children[0].toAstExpr() } - val orderBy = unconsumedChildren.firstOrNull { it.type == ORDER_BY }?.let { + val orderBy = unconsumedChildren.firstOrNull { it.type == ParseType.ORDER_BY }?.let { unconsumedChildren.remove(it) orderBy( it.children[0].children.map { @@ -543,12 +582,12 @@ class SqlParser( ) } - val limitExpr = unconsumedChildren.firstOrNull { it.type == LIMIT }?.let { + val limitExpr = unconsumedChildren.firstOrNull { it.type == ParseType.LIMIT }?.let { unconsumedChildren.remove(it) it.children[0].toAstExpr() } - val offsetExpr = unconsumedChildren.firstOrNull { it.type == OFFSET }?.let { + val offsetExpr = unconsumedChildren.firstOrNull { it.type == ParseType.OFFSET }?.let { unconsumedChildren.remove(it) it.children[0].toAstExpr() } @@ -569,34 +608,37 @@ class SqlParser( metas = metas ) } - DATE -> { + ParseType.DATE -> { val dateString = token!!.text!! val (year, month, day) = dateString.split("-") date(year.toLong(), month.toLong(), day.toLong(), metas) } - TIME -> { + ParseType.TIME -> { val timeString = token!!.text!! val precision = children[0].token!!.value!!.numberValue().toLong() val time = LocalTime.parse(timeString, ISO_TIME) litTime( - timeValue(time.hour.toLong(), time.minute.toLong(), time.second.toLong(), time.nano.toLong(), precision, false, null), + timeValue(time.hour.toLong(), time.minute.toLong(), time.second.toLong(), time.nano.toLong(), + precision, false, null), metas ) } - TIME_WITH_TIME_ZONE -> { + ParseType.TIME_WITH_TIME_ZONE -> { val timeString = token!!.text!! val precision = children[0].token!!.value!!.longValue() try { val time = OffsetTime.parse(timeString) litTime( - timeValue(time.hour.toLong(), time.minute.toLong(), time.second.toLong(), time.nano.toLong(), precision, true, (time.offset.totalSeconds/60).toLong()), + timeValue(time.hour.toLong(), time.minute.toLong(), time.second.toLong(), + time.nano.toLong(), precision, true, (time.offset.totalSeconds/60).toLong()), metas ) } catch (e: DateTimeParseException) { // In case time zone not explicitly specified val time = LocalTime.parse(timeString) litTime( - timeValue(time.hour.toLong(), time.minute.toLong(), time.second.toLong(), time.nano.toLong(), precision, true, null), + timeValue(time.hour.toLong(), time.minute.toLong(), time.second.toLong(), + time.nano.toLong(), precision, true, null), metas ) } @@ -611,12 +653,12 @@ class SqlParser( return PartiqlAst.build { when (type) { - FROM -> { + ParseType.FROM -> { // The first child is the operation, the second child is the from list, // each child following is an optional clause (e.g. ORDER BY) val operation = children[0].toAstDml() val fromSource = children[1].also { - if (it.type != FROM_CLAUSE) { + if (it.type != ParseType.FROM_CLAUSE) { errMalformedParseTree("Invalid second child of FROM") } @@ -629,11 +671,11 @@ class SqlParser( // If any unconsumed children remain, we've missed something and should throw an exception. val unconsumedChildren = children.drop(2).toMutableList() - val where = unconsumedChildren.firstOrNull { it.type == WHERE }?.let { + val where = unconsumedChildren.firstOrNull { it.type == ParseType.WHERE }?.let { unconsumedChildren.remove(it) it.children[0].toAstExpr() } - val returning = unconsumedChildren.firstOrNull { it.type == RETURNING }?.let { + val returning = unconsumedChildren.firstOrNull { it.type == ParseType.RETURNING }?.let { unconsumedChildren.remove(it) it.toReturningExpr() } @@ -643,7 +685,7 @@ class SqlParser( operation.copy(from = fromSource, where = where, returning = returning, metas = metas) } - INSERT, INSERT_VALUE -> { + ParseType.INSERT, ParseType.INSERT_VALUE -> { val insertReturning = toInsertReturning() dml( dmlOpList(insertReturning.ops), @@ -651,11 +693,11 @@ class SqlParser( metas = metas ) } - SET, UPDATE, REMOVE, DELETE -> dml( + ParseType.SET, ParseType.UPDATE, ParseType.REMOVE, ParseType.DELETE -> dml( dmlOpList(toDmlOperation()), metas = metas ) - DML_LIST -> { + ParseType.DML_LIST -> { val dmlOps = children.flatMap { it.toDmlOperation() } dml( dmlOpList(dmlOps), @@ -672,22 +714,22 @@ class SqlParser( return PartiqlAst.build { when (type) { - CREATE_TABLE -> ddl( + ParseType.CREATE_TABLE -> ddl( createTable(children[0].token!!.text!!), metas ) - DROP_TABLE -> ddl( + ParseType.DROP_TABLE -> ddl( dropTable(children[0].toIdentifier()), metas ) - CREATE_INDEX -> ddl( + ParseType.CREATE_INDEX -> ddl( createIndex( children[0].toIdentifier(), children[1].children.map { it.toAstExpr() } ), metas ) - DROP_INDEX -> ddl( + ParseType.DROP_INDEX -> ddl( dropIndex(children[1].toIdentifier(), children[0].toIdentifier()), metas ) @@ -701,7 +743,7 @@ class SqlParser( return PartiqlAst.build { when (type) { - EXEC -> exec_( + ParseType.EXEC -> exec_( SymbolPrimitive(token?.text!!.toLowerCase(), emptyMetaContainer()), children.map { it.toAstExpr() }, metas @@ -712,7 +754,7 @@ class SqlParser( } private fun ParseNode.toAstType(): PartiqlAst.Type { - if (type != TYPE) { + if (type != ParseType.TYPE) { errMalformedParseTree("Expected ParseType.TYPE instead of $type") } @@ -821,7 +863,7 @@ class SqlParser( return PartiqlAst.build { when (type) { - FROM_SOURCE_JOIN -> { + ParseType.FROM_SOURCE_JOIN -> { val isCrossJoin = token?.keywordText?.contains("cross") ?: false if (!isCrossJoin && children.size != 3) { errMalformedParseTree("Incorrect number of clauses provided to JOIN") @@ -851,7 +893,7 @@ class SqlParser( return PartiqlAst.build { when (unwrappedParseNode.type) { - UNPIVOT -> unpivot_( + ParseType.UNPIVOT -> unpivot_( unwrappedParseNode.children[0].toAstExpr(), aliases.asName, aliases.atName, @@ -872,15 +914,15 @@ class SqlParser( val metas = getMetas() return when (type) { - AS_ALIAS -> { + ParseType.AS_ALIAS -> { if(variables.asName != null) error("Invalid parse tree: AS_ALIAS encountered more than once in FROM source") children[0].unwrapAliases(variables.copy(asName = SymbolPrimitive(token!!.text!!, metas))) } - AT_ALIAS -> { + ParseType.AT_ALIAS -> { if(variables.atName != null) error("Invalid parse tree: AT_ALIAS encountered more than once in FROM source") children[0].unwrapAliases(variables.copy(atName = SymbolPrimitive(token!!.text!!, metas))) } - BY_ALIAS -> { + ParseType.BY_ALIAS -> { if(variables.byName != null) error("Invalid parse tree: BY_ALIAS encountered more than once in FROM source") children[0].unwrapAliases(variables.copy(byName = SymbolPrimitive(token!!.text!!, metas))) } @@ -901,7 +943,7 @@ class SqlParser( } private fun ParseNode.toReturningMapping(): PartiqlAst.ReturningMapping { - if(type != RETURNING_MAPPING) { + if(type != ParseType.RETURNING_MAPPING) { errMalformedParseTree("Expected ParseType.RETURNING_MAPPING instead of $type") } return PartiqlAst.build { @@ -917,12 +959,12 @@ class SqlParser( private fun ParseNode.toInsertReturning(): InsertReturning = when (type) { - INSERT -> { + ParseType.INSERT -> { val ops = listOf(PartiqlAst.DmlOp.Insert(children[0].toAstExpr(), children[1].toAstExpr())) // We will remove items from this collection as we consume them. // If any unconsumed children remain, we've missed something and should throw an exception. val unconsumedChildren = children.drop(2).toMutableList() - val returning = unconsumedChildren.firstOrNull { it.type == RETURNING }?.let { + val returning = unconsumedChildren.firstOrNull { it.type == ParseType.RETURNING }?.let { unconsumedChildren.remove(it) it.toReturningExpr() } @@ -932,12 +974,12 @@ class SqlParser( InsertReturning(ops, returning) } - INSERT_VALUE -> { + ParseType.INSERT_VALUE -> { fun getOnConflict(onConflictChildren: List): PartiqlAst.OnConflict { onConflictChildren.getOrNull(0)?.let { firstNode -> val condition = firstNode.toAstExpr() onConflictChildren.getOrNull(1)?.let { secondNode -> - if (CONFLICT_ACTION == secondNode.type && "do_nothing" == secondNode.token?.keywordText) { + if (ParseType.CONFLICT_ACTION == secondNode.type && "do_nothing" == secondNode.token?.keywordText) { return PartiqlAst.build { onConflict(condition, doNothing()) } } } @@ -953,18 +995,19 @@ class SqlParser( val unconsumedChildren = children.drop(2).toMutableList() // Handle AT clause - val position = unconsumedChildren.firstOrNull { it.type != ON_CONFLICT && it.type != RETURNING }?.let { + val position = unconsumedChildren.firstOrNull { it.type != ParseType.ON_CONFLICT && + it.type != ParseType.RETURNING }?.let { unconsumedChildren.remove(it) it.toAstExpr() } - val onConflict = unconsumedChildren.firstOrNull { it.type == ON_CONFLICT }?.let { + val onConflict = unconsumedChildren.firstOrNull { it.type == ParseType.ON_CONFLICT }?.let { unconsumedChildren.remove(it) getOnConflict(it.children) } val ops = listOf(PartiqlAst.build { insertValue(lvalue, value, position, onConflict) }) - val returning = unconsumedChildren.firstOrNull { it.type == RETURNING }?.let { + val returning = unconsumedChildren.firstOrNull { it.type == ParseType.RETURNING }?.let { unconsumedChildren.remove(it) it.toReturningExpr() } @@ -974,23 +1017,23 @@ class SqlParser( InsertReturning(ops, returning) } - else -> unsupported("Unsupported syntax for $type", PARSE_UNSUPPORTED_SYNTAX) + else -> unsupported("Unsupported syntax for $type", ErrorCode.PARSE_UNSUPPORTED_SYNTAX) } private fun ParseNode.toColumnComponent(metas: IonElementMetaContainer): PartiqlAst.ColumnComponent = PartiqlAst.build { when (type) { - RETURNING_WILDCARD -> returningWildcard(metas) + ParseType.RETURNING_WILDCARD -> returningWildcard(metas) else -> returningColumn(this@toColumnComponent.toAstExpr()) } } private fun ParseNode.toDmlOperation(): List = when (type) { - INSERT -> { + ParseType.INSERT -> { listOf(PartiqlAst.build { insert(children[0].toAstExpr(), children[1].toAstExpr()) }) } - INSERT_VALUE -> { + ParseType.INSERT_VALUE -> { val lvalue = children[0].toAstExpr() val value = children[1].toAstExpr() @@ -999,18 +1042,19 @@ class SqlParser( val unconsumedChildren = children.drop(2).toMutableList() // Handle AT clause - val position = unconsumedChildren.firstOrNull { it.type != ON_CONFLICT && it.type != RETURNING }?.let { + val position = unconsumedChildren.firstOrNull { it.type != ParseType.ON_CONFLICT && + it.type != ParseType.RETURNING }?.let { unconsumedChildren.remove(it) it.toAstExpr() } - val onConflict = unconsumedChildren.firstOrNull { it.type == ON_CONFLICT }?.let { + val onConflict = unconsumedChildren.firstOrNull { it.type == ParseType.ON_CONFLICT }?.let { unconsumedChildren.remove(it) val onConflictChildren = it.children onConflictChildren.getOrNull(0)?.let { val condition = it.toAstExpr() onConflictChildren.getOrNull(1)?.let { - if (CONFLICT_ACTION == it.type && "do_nothing" == it.token?.keywordText) { + if (ParseType.CONFLICT_ACTION == it.type && "do_nothing" == it.token?.keywordText) { PartiqlAst.build { onConflict(condition, doNothing()) } } } @@ -1023,7 +1067,7 @@ class SqlParser( listOf(PartiqlAst.build { insertValue(lvalue, value, position, onConflict) }) } - SET, UPDATE -> children.map { + ParseType.SET, ParseType.UPDATE -> children.map { PartiqlAst.build { set( assignment( @@ -1033,20 +1077,20 @@ class SqlParser( ) } } - REMOVE -> listOf(PartiqlAst.build { remove(children[0].toAstExpr()) }) - DELETE -> listOf(PartiqlAst.build { delete() }) - else -> unsupported("Unsupported syntax for $type", PARSE_UNSUPPORTED_SYNTAX) + ParseType.REMOVE -> listOf(PartiqlAst.build { remove(children[0].toAstExpr()) }) + ParseType.DELETE -> listOf(PartiqlAst.build { delete() }) + else -> unsupported("Unsupported syntax for $type", ErrorCode.PARSE_UNSUPPORTED_SYNTAX) } private fun ParseNode.unwrapAsAlias(): AsAlias = - if (type == AS_ALIAS) { + if (type == ParseType.AS_ALIAS) { AsAlias(SymbolPrimitive(token!!.text!!, getMetas()), children[0]) } else { AsAlias(null, this) } private fun ParseNode.toIdentifier(): PartiqlAst.Identifier { - if (type != ATOM){ + if (type != ParseType.ATOM){ errMalformedParseTree("Cannot transform ParseNode type: $type to identifier") } @@ -1054,21 +1098,21 @@ class SqlParser( return PartiqlAst.build { when (token?.type){ - QUOTED_IDENTIFIER -> identifier(token.text!!, caseSensitive(), metas) - IDENTIFIER -> identifier(token.text!!, caseInsensitive(), metas) + TokenType.QUOTED_IDENTIFIER -> identifier(token.text!!, caseSensitive(), metas) + TokenType.IDENTIFIER -> identifier(token.text!!, caseInsensitive(), metas) else -> errMalformedParseTree("Cannot transform atom token type ${token?.type} to identifier") } } } private fun ParseNode.toOrderingSpec(): PartiqlAst.OrderingSpec { - if (type != ORDERING_SPEC) { + if (type != ParseType.ORDERING_SPEC) { errMalformedParseTree("Expected ParseType.ORDERING_SPEC instead of $type") } return PartiqlAst.build { when (token?.type) { - ASC -> asc() - DESC -> desc() + TokenType.ASC -> asc() + TokenType.DESC -> desc() else -> errMalformedParseTree("Invalid ordering spec parsing") } } @@ -1079,7 +1123,7 @@ class SqlParser( errMalformedParseTree("Expected ParseNode to have a token") } when (token.type) { - LITERAL, ION_LITERAL, IDENTIFIER, QUOTED_IDENTIFIER -> { + TokenType.LITERAL, TokenType.ION_LITERAL, TokenType.IDENTIFIER, TokenType.QUOTED_IDENTIFIER -> { val tokenText = token.text ?: errMalformedParseTree("Expected ParseNode.token to have text") return SymbolPrimitive(tokenText, getMetas()) } @@ -1105,7 +1149,7 @@ class SqlParser( private val Token.customKeywordText: String? get() = when (type) { - IDENTIFIER -> when (text?.toLowerCase()) { + TokenType.IDENTIFIER -> when (text?.toLowerCase()) { in CUSTOM_KEYWORDS -> text?.toLowerCase() in CUSTOM_TYPE_ALIASES.keys -> CUSTOM_TYPE_ALIASES[text?.toLowerCase()] else -> null @@ -1115,7 +1159,7 @@ class SqlParser( private val Token.customType: SqlDataType? get() = when (type) { - IDENTIFIER -> when (text?.toLowerCase()) { + TokenType.IDENTIFIER -> when (text?.toLowerCase()) { in CUSTOM_KEYWORDS -> SqlDataType.CustomDataType(text!!.toLowerCase()) in CUSTOM_TYPE_ALIASES.keys -> CUSTOM_TYPE_ALIASES[text?.toLowerCase()]?.let { SqlDataType.CustomDataType(it.toLowerCase()) @@ -1185,7 +1229,7 @@ class SqlParser( fun parseRightExpr() = if (rem.size < 3) { rem.err( "Missing right-hand side expression of infix operator", - PARSE_EXPECTED_EXPRESSION + ErrorCode.PARSE_EXPECTED_EXPRESSION ) } else { rem.tail.parseExpression( @@ -1198,12 +1242,12 @@ class SqlParser( "is", "is_not" -> rem.tail.parseType(op.keywordText!!) // IN has context sensitive parsing rules around parenthesis "in", "not_in" -> when { - rem.tail.head?.type == LEFT_PAREN + rem.tail.head?.type == TokenType.LEFT_PAREN && rem.tail.tail.head?.keywordText !in IN_OP_NORMAL_EVAL_KEYWORDS -> rem.tail.tail.parseArgList( - aliasSupportType = NONE, - mode = NORMAL_ARG_LIST - ).deriveExpected(RIGHT_PAREN).copy(LIST) + aliasSupportType = AliasSupportType.NONE, + mode = ArgListMode.NORMAL_ARG_LIST + ).deriveExpected(TokenType.RIGHT_PAREN).copy(ParseType.LIST) else -> parseRightExpr() } else -> parseRightExpr() @@ -1211,19 +1255,19 @@ class SqlParser( rem = right.remaining expr = when { - op.isBinaryOperator -> ParseNode(BINARY, op, listOf(expr, right), rem) + op.isBinaryOperator -> ParseNode(ParseType.BINARY, op, listOf(expr, right), rem) else -> when (op.keywordText) { "between", "not_between" -> { val rest = rem.tailExpectedKeyword("and") if (rest.onlyEndOfStatement()) { - rem.head.err("Expected expression after AND", PARSE_EXPECTED_EXPRESSION) + rem.head.err("Expected expression after AND", ErrorCode.PARSE_EXPECTED_EXPRESSION) } else { rem = rest val third = rem.parseExpression( precedence = op.infixPrecedence ) rem = third.remaining - ParseNode(TERNARY, op, listOf(expr, right, third), rem) + ParseNode(ParseType.TERNARY, op, listOf(expr, right, third), rem) } } "like", "not_like" -> { @@ -1231,18 +1275,18 @@ class SqlParser( rem.head?.keywordText == "escape" -> { val rest = rem.tailExpectedKeyword("escape") if (rest.onlyEndOfStatement()) { - rem.head.err("Expected expression after ESCAPE", PARSE_EXPECTED_EXPRESSION) + rem.head.err("Expected expression after ESCAPE", ErrorCode.PARSE_EXPECTED_EXPRESSION) } else { rem = rest val third = rem.parseExpression(precedence = op.infixPrecedence) rem = third.remaining - ParseNode(TERNARY, op, listOf(expr, right, third), rem) + ParseNode(ParseType.TERNARY, op, listOf(expr, right, third), rem) } } - else -> ParseNode(BINARY, op, listOf(expr, right), rem) + else -> ParseNode(ParseType.BINARY, op, listOf(expr, right), rem) } } - else -> rem.err("Unknown infix operator", PARSE_UNKNOWN_OPERATOR) + else -> rem.err("Unknown infix operator", ErrorCode.PARSE_UNKNOWN_OPERATOR) } } } @@ -1254,7 +1298,7 @@ class SqlParser( true -> { val op = head!! fun makeUnaryParseNode(term: ParseNode) = - ParseNode(UNARY, op, listOf(term), term.remaining) + ParseNode(ParseType.UNARY, op, listOf(term), term.remaining) // constant fold unary plus/minus into constant literals when (op.keywordText) { @@ -1287,8 +1331,8 @@ class SqlParser( val term = when (pathMode) { PathMode.FULL_PATH -> parseTerm() PathMode.SIMPLE_PATH -> when (head?.type) { - QUOTED_IDENTIFIER, IDENTIFIER -> atomFromHead() - else -> err("Expected identifier for simple path", PARSE_INVALID_PATH_COMPONENT) + TokenType.QUOTED_IDENTIFIER, TokenType.IDENTIFIER -> atomFromHead() + else -> err("Expected identifier for simple path", ErrorCode.PARSE_INVALID_PATH_COMPONENT) } } val path = ArrayList(listOf(term)) @@ -1297,44 +1341,44 @@ class SqlParser( var hasPath = true while (hasPath) { when (rem.head?.type) { - DOT -> { + TokenType.DOT -> { val dotToken = rem.head!! // consume first dot rem = rem.tail val pathPart = when (rem.head?.type) { - IDENTIFIER -> { - val litToken = Token(LITERAL, ion.newString(rem.head?.text!!), rem.head!!.span) - ParseNode(CASE_INSENSITIVE_ATOM, litToken, emptyList(), rem.tail) + TokenType.IDENTIFIER -> { + val litToken = Token(TokenType.LITERAL, ion.newString(rem.head?.text!!), rem.head!!.span) + ParseNode(ParseType.CASE_INSENSITIVE_ATOM, litToken, emptyList(), rem.tail) } - QUOTED_IDENTIFIER -> { - val litToken = Token(LITERAL, ion.newString(rem.head?.text!!), rem.head!!.span) - ParseNode(CASE_SENSITIVE_ATOM, litToken, emptyList(), rem.tail) + TokenType.QUOTED_IDENTIFIER -> { + val litToken = Token(TokenType.LITERAL, ion.newString(rem.head?.text!!), rem.head!!.span) + ParseNode(ParseType.CASE_SENSITIVE_ATOM, litToken, emptyList(), rem.tail) } - STAR -> { + TokenType.STAR -> { if (pathMode != PathMode.FULL_PATH) { - rem.err("Invalid path dot component for simple path", PARSE_INVALID_PATH_COMPONENT) + rem.err("Invalid path dot component for simple path", ErrorCode.PARSE_INVALID_PATH_COMPONENT) } - ParseNode(PATH_UNPIVOT, rem.head, emptyList(), rem.tail) + ParseNode(ParseType.PATH_UNPIVOT, rem.head, emptyList(), rem.tail) } else -> { - rem.err("Invalid path dot component", PARSE_INVALID_PATH_COMPONENT) + rem.err("Invalid path dot component", ErrorCode.PARSE_INVALID_PATH_COMPONENT) } } - path.add(ParseNode(PATH_DOT, dotToken, listOf(pathPart), rem)) + path.add(ParseNode(ParseType.PATH_DOT, dotToken, listOf(pathPart), rem)) rem = rem.tail } - LEFT_BRACKET -> { + TokenType.LEFT_BRACKET -> { val leftBracketToken = rem.head!! rem = rem.tail val expr = when (rem.head?.type) { - STAR -> ParseNode(PATH_WILDCARD, rem.head, emptyList(), rem.tail) + TokenType.STAR -> ParseNode(ParseType.PATH_WILDCARD, rem.head, emptyList(), rem.tail) else -> rem.parseExpression() - }.deriveExpected(RIGHT_BRACKET) - if (pathMode == PathMode.SIMPLE_PATH && expr.type != ATOM && expr.token?.type != LITERAL) { - rem.err("Invalid path component for simple path", PARSE_INVALID_PATH_COMPONENT) + }.deriveExpected(TokenType.RIGHT_BRACKET) + if (pathMode == PathMode.SIMPLE_PATH && expr.type != ParseType.ATOM && expr.token?.type != TokenType.LITERAL) { + rem.err("Invalid path component for simple path", ErrorCode.PARSE_INVALID_PATH_COMPONENT) } - path.add(ParseNode(PATH_SQB, leftBracketToken, listOf(expr), rem.tail)) + path.add(ParseNode(ParseType.PATH_SQB, leftBracketToken, listOf(expr), rem.tail)) rem = expr.remaining } else -> hasPath = false @@ -1343,26 +1387,26 @@ class SqlParser( return when (path.size) { 1 -> term - else -> ParseNode(PATH, null, path, rem) + else -> ParseNode(ParseType.PATH, null, path, rem) } } private fun List.parseTerm(): ParseNode = when (head?.type) { - OPERATOR -> when (head?.keywordText) { + TokenType.OPERATOR -> when (head?.keywordText) { // the lexical scope operator is **only** allowed with identifiers "@" -> when (tail.head?.type) { - IDENTIFIER, QUOTED_IDENTIFIER -> ParseNode( - UNARY, + TokenType.IDENTIFIER, TokenType.QUOTED_IDENTIFIER -> ParseNode( + ParseType.UNARY, head, listOf(tail.atomFromHead()), tail.tail ) - else -> err("Identifier must follow @-operator", PARSE_MISSING_IDENT_AFTER_AT) + else -> err("Identifier must follow @-operator", ErrorCode.PARSE_MISSING_IDENT_AFTER_AT) } - else -> err("Unexpected operator", PARSE_UNEXPECTED_OPERATOR) + else -> err("Unexpected operator", ErrorCode.PARSE_UNEXPECTED_OPERATOR) } - KEYWORD -> when (head?.keywordText) { + TokenType.KEYWORD -> when (head?.keywordText) { in BASE_DML_KEYWORDS -> parseBaseDml() "update" -> tail.parseUpdate() "delete" -> tail.parseDelete(head!!) @@ -1378,7 +1422,7 @@ class SqlParser( "from" -> tail.parseFrom() // table value constructor--which aliases to bag constructor in PartiQL with very // specific syntax - "values" -> tail.parseTableValues().copy(type = BAG) + "values" -> tail.parseTableValues().copy(type = ParseType.BAG) "substring" -> tail.parseSubstring(head!!) "trim" -> tail.parseTrim(head!!) "extract" -> tail.parseExtract(head!!) @@ -1388,45 +1432,46 @@ class SqlParser( "nullif" -> tail.parseNullIf(head!!) "coalesce" -> tail.parseCoalesce() in FUNCTION_NAME_KEYWORDS -> when (tail.head?.type) { - LEFT_PAREN -> + TokenType.LEFT_PAREN -> tail.tail.parseFunctionCall(head!!) - else -> err("Unexpected keyword", PARSE_UNEXPECTED_KEYWORD) + else -> err("Unexpected keyword", ErrorCode.PARSE_UNEXPECTED_KEYWORD) } "exec" -> tail.parseExec() - else -> err("Unexpected keyword", PARSE_UNEXPECTED_KEYWORD) + else -> err("Unexpected keyword", ErrorCode.PARSE_UNEXPECTED_KEYWORD) } - LEFT_PAREN -> { + TokenType.LEFT_PAREN -> { val group = tail.parseArgList( - aliasSupportType = NONE, - mode = NORMAL_ARG_LIST - ).deriveExpected(RIGHT_PAREN) + aliasSupportType = AliasSupportType.NONE, + mode = ArgListMode.NORMAL_ARG_LIST + ).deriveExpected(TokenType.RIGHT_PAREN) when (group.children.size) { - 0 -> tail.err("Expression group cannot be empty", PARSE_EXPECTED_EXPRESSION) + 0 -> tail.err("Expression group cannot be empty", ErrorCode.PARSE_EXPECTED_EXPRESSION) // expression grouping 1 -> group.children[0].copy(remaining = group.remaining) // row value constructor--which aliases to list constructor in PartiQL - else -> group.copy(type = LIST) + else -> group.copy(type = ParseType.LIST) } } - LEFT_BRACKET -> when (tail.head?.type) { - RIGHT_BRACKET -> ParseNode(LIST, null, emptyList(), tail.tail) + TokenType.LEFT_BRACKET -> when (tail.head?.type) { + TokenType.RIGHT_BRACKET -> ParseNode(ParseType.LIST, null, emptyList(), tail.tail) else -> tail.parseListLiteral() } - LEFT_DOUBLE_ANGLE_BRACKET -> when (tail.head?.type) { - RIGHT_DOUBLE_ANGLE_BRACKET -> ParseNode(BAG, null, emptyList(), tail.tail) + TokenType.LEFT_DOUBLE_ANGLE_BRACKET -> when (tail.head?.type) { + TokenType.RIGHT_DOUBLE_ANGLE_BRACKET -> ParseNode(ParseType.BAG, null, emptyList(), tail.tail) else -> tail.parseBagLiteral() } - LEFT_CURLY -> when (tail.head?.type) { - RIGHT_CURLY -> ParseNode(STRUCT, null, emptyList(), tail.tail) + TokenType.LEFT_CURLY -> when (tail.head?.type) { + TokenType.RIGHT_CURLY -> ParseNode(ParseType.STRUCT, null, emptyList(), tail.tail) else -> tail.parseStructLiteral() } - IDENTIFIER, QUOTED_IDENTIFIER -> when (tail.head?.type) { - LEFT_PAREN -> tail.tail.parseFunctionCall(head!!) + TokenType.IDENTIFIER, TokenType.QUOTED_IDENTIFIER -> when (tail.head?.type) { + TokenType.LEFT_PAREN -> tail.tail.parseFunctionCall(head!!) else -> atomFromHead() } - QUESTION_MARK -> ParseNode(PARAMETER, head!!, listOf(), tail) - ION_LITERAL, LITERAL, NULL, MISSING, TRIM_SPECIFICATION -> atomFromHead() - else -> err("Unexpected term", PARSE_UNEXPECTED_TERM) + TokenType.QUESTION_MARK -> ParseNode(ParseType.PARAMETER, head!!, listOf(), tail) + TokenType.ION_LITERAL, TokenType.LITERAL, TokenType.NULL, TokenType.MISSING, + TokenType.TRIM_SPECIFICATION -> atomFromHead() + else -> err("Unexpected term", ErrorCode.PARSE_UNEXPECTED_TERM) }.let { parseNode -> // for many of the terms here we parse the tail, assuming the head as // context, but that loses the metas and other info from that token. @@ -1453,7 +1498,7 @@ class SqlParser( children.add(caseBody) rem = caseBody.remaining - return ParseNode(CASE, null, children, rem) + return ParseNode(ParseType.CASE, null, children, rem) } private fun List.parseCaseBody(): ParseNode { @@ -1466,75 +1511,75 @@ class SqlParser( val result = rem.parseExpression() rem = result.remaining - children.add(ParseNode(WHEN, null, listOf(conditionExpr, result), rem)) + children.add(ParseNode(ParseType.WHEN, null, listOf(conditionExpr, result), rem)) } if (children.isEmpty()) { - err("Expected a WHEN clause in CASE", PARSE_EXPECTED_WHEN_CLAUSE) + err("Expected a WHEN clause in CASE", ErrorCode.PARSE_EXPECTED_WHEN_CLAUSE) } if (rem.head?.keywordText == "else") { val elseExpr = rem.tail.parseExpression() rem = elseExpr.remaining - children.add(ParseNode(ELSE, null, listOf(elseExpr), rem)) + children.add(ParseNode(ParseType.ELSE, null, listOf(elseExpr), rem)) } - return ParseNode(ARG_LIST, null, children, rem) + return ParseNode(ParseType.ARG_LIST, null, children, rem) .deriveExpectedKeyword("end") } private fun List.parseTypeFunction(): ParseNode { val functionName = head?.keywordText!! var rem = tail - if (rem.head?.type != LEFT_PAREN) { - rem.err("Missing left parenthesis after $functionName", PARSE_EXPECTED_LEFT_PAREN_AFTER_CAST) + if (rem.head?.type != TokenType.LEFT_PAREN) { + rem.err("Missing left parenthesis after $functionName", ErrorCode.PARSE_EXPECTED_LEFT_PAREN_AFTER_CAST) } - val valueExpr = rem.tail.parseExpression().deriveExpected(AS) + val valueExpr = rem.tail.parseExpression().deriveExpected(TokenType.AS) rem = valueExpr.remaining - val typeNode = rem.parseType(functionName).deriveExpected(RIGHT_PAREN) + val typeNode = rem.parseType(functionName).deriveExpected(TokenType.RIGHT_PAREN) rem = typeNode.remaining - return ParseNode(TYPE_FUNCTION, head, listOf(valueExpr, typeNode), rem) + return ParseNode(ParseType.TYPE_FUNCTION, head, listOf(valueExpr, typeNode), rem) } private fun List.parseNullIf(nullIfToken: Token) : ParseNode { - if (head?.type != LEFT_PAREN) { - err("Missing left parenthesis after nullif", PARSE_EXPECTED_LEFT_PAREN_VALUE_CONSTRUCTOR) + if (head?.type != TokenType.LEFT_PAREN) { + err("Missing left parenthesis after nullif", ErrorCode.PARSE_EXPECTED_LEFT_PAREN_VALUE_CONSTRUCTOR) } - val expr1 = tail.parseExpression().deriveExpected(COMMA) + val expr1 = tail.parseExpression().deriveExpected(TokenType.COMMA) var rem = expr1.remaining - val expr2 = rem.parseExpression().deriveExpected(RIGHT_PAREN) + val expr2 = rem.parseExpression().deriveExpected(TokenType.RIGHT_PAREN) rem = expr2.remaining - return ParseNode(NULLIF, nullIfToken, listOf(expr1, expr2), rem) + return ParseNode(ParseType.NULLIF, nullIfToken, listOf(expr1, expr2), rem) } private fun List.parseCoalesce() : ParseNode { - if (head?.type != LEFT_PAREN) { - err("Missing left parenthesis after coalesce", PARSE_EXPECTED_LEFT_PAREN_VALUE_CONSTRUCTOR) + if (head?.type != TokenType.LEFT_PAREN) { + err("Missing left parenthesis after coalesce", ErrorCode.PARSE_EXPECTED_LEFT_PAREN_VALUE_CONSTRUCTOR) } - return tail.parseArgList(aliasSupportType = NONE, mode = NORMAL_ARG_LIST) - .copy(type = COALESCE, token = head) - .deriveExpected(RIGHT_PAREN) + return tail.parseArgList(aliasSupportType = AliasSupportType.NONE, mode = ArgListMode.NORMAL_ARG_LIST) + .copy(type = ParseType.COALESCE, token = head) + .deriveExpected(TokenType.RIGHT_PAREN) } private fun List.parseType(opName: String): ParseNode { val typeName = head?.keywordText val typeArity = ALL_TYPE_NAME_ARITY_MAP[typeName] ?: (head?.customType?.arityRange ?: - err("Expected type name", PARSE_EXPECTED_TYPE_NAME)) + err("Expected type name", ErrorCode.PARSE_EXPECTED_TYPE_NAME)) val typeNode = when (tail.head?.type) { - LEFT_PAREN -> tail.tail.parseArgList( - aliasSupportType = NONE, - mode = NORMAL_ARG_LIST + TokenType.LEFT_PAREN -> tail.tail.parseArgList( + aliasSupportType = AliasSupportType.NONE, + mode = ArgListMode.NORMAL_ARG_LIST ).copy( - type = TYPE, + type = ParseType.TYPE, token = head - ).deriveExpected(RIGHT_PAREN) + ).deriveExpected(TokenType.RIGHT_PAREN) - else -> ParseNode(TYPE, head, emptyList(), tail) + else -> ParseNode(ParseType.TYPE, head, emptyList(), tail) } // Check for the optional "WITH TIME ZONE" specifier for TIME and validate the value of precision. // Note that this needs to be checked explicitly as the keywordtext for "TIME WITH TIME ZONE" consists of multiple words. @@ -1547,7 +1592,7 @@ class SqlParser( ) { precision.token.err( "Expected integer value between 0 and 9 for precision", - PARSE_INVALID_PRECISION_FOR_TIME + ErrorCode.PARSE_INVALID_PRECISION_FOR_TIME ) } } @@ -1566,16 +1611,16 @@ class SqlParser( if (typeNode.children.size !in typeArity) { val pvmap = PropertyValueMap() - pvmap[CAST_TO] = typeName?: "" - pvmap[EXPECTED_ARITY_MIN] = typeArity.first - pvmap[EXPECTED_ARITY_MAX] = typeArity.last - tail.err("$opName type argument $typeName must have arity of $typeArity", PARSE_CAST_ARITY, pvmap) + pvmap[Property.CAST_TO] = typeName?: "" + pvmap[Property.EXPECTED_ARITY_MIN] = typeArity.first + pvmap[Property.EXPECTED_ARITY_MAX] = typeArity.last + tail.err("$opName type argument $typeName must have arity of $typeArity", ErrorCode.PARSE_CAST_ARITY, pvmap) } for (child in typeNode.children) { - if (child.type != ATOM - || child.token?.type != LITERAL + if (child.type != ParseType.ATOM + || child.token?.type != TokenType.LITERAL || child.token.value?.isUnsignedInteger != true) { - err("Type parameter must be an unsigned integer literal", PARSE_INVALID_TYPE_PARAM) + err("Type parameter must be an unsigned integer literal", ErrorCode.PARSE_INVALID_TYPE_PARAM) } } @@ -1606,7 +1651,7 @@ class SqlParser( rem = it.remaining } - return ParseNode(FROM, null, listOf(operation, fromList) + children, rem) + return ParseNode(ParseType.FROM, null, listOf(operation, fromList) + children, rem) } private fun List.parseBaseDmls() : ParseNode { @@ -1619,14 +1664,14 @@ class SqlParser( } if (nodes.size == 0) { - err("Expected data manipulation", PARSE_MISSING_OPERATION) + err("Expected data manipulation", ErrorCode.PARSE_MISSING_OPERATION) } if (nodes.size == 1) { return nodes[0] } - return ParseNode(DML_LIST, null, nodes, rem) + return ParseNode(ParseType.DML_LIST, null, nodes, rem) } private fun List.parseBaseDml(): ParseNode { @@ -1648,25 +1693,25 @@ class SqlParser( val returning = rem.parseOptionalReturning()?.also { rem = it.remaining } - ParseNode(INSERT_VALUE, null, listOfNotNull(lvalue, value, position, onConflict, returning), rem) + ParseNode(ParseType.INSERT_VALUE, null, listOfNotNull(lvalue, value, position, onConflict, returning), rem) } else { val values = rem.parseExpression() - ParseNode(INSERT, null, listOf(lvalue, values), values.remaining) + ParseNode(ParseType.INSERT, null, listOf(lvalue, values), values.remaining) } } - "set" -> rem.tail.parseSetAssignments(UPDATE) + "set" -> rem.tail.parseSetAssignments(ParseType.UPDATE) "remove" -> { val lvalue = rem.tail.parsePathTerm(PathMode.SIMPLE_PATH) rem = lvalue.remaining - ParseNode(REMOVE, null, listOf(lvalue), rem) + ParseNode(ParseType.REMOVE, null, listOf(lvalue), rem) } - else -> err("Expected data manipulation", PARSE_MISSING_OPERATION) + else -> err("Expected data manipulation", ErrorCode.PARSE_MISSING_OPERATION) } } private fun List.parseConflictAction(token: Token): ParseNode { val rem = this - return ParseNode(CONFLICT_ACTION, token, emptyList(), rem.tail) + return ParseNode(ParseType.CONFLICT_ACTION, token, emptyList(), rem.tail) } // Parse the optional ON CONFLICT clause in 'INSERT VALUE AT ON CONFLICT WHERE ' @@ -1683,32 +1728,32 @@ class SqlParser( "do_nothing" -> { val conflictAction = onConflictRem.parseConflictAction(onConflictRem.head!!) var nodes = listOfNotNull(onConflictExpression, conflictAction) - ParseNode(ON_CONFLICT, null, nodes, conflictAction.remaining) + ParseNode(ParseType.ON_CONFLICT, null, nodes, conflictAction.remaining) } - else -> rem.head.err("invalid ON CONFLICT syntax", PARSE_EXPECTED_CONFLICT_ACTION) + else -> rem.head.err("invalid ON CONFLICT syntax", ErrorCode.PARSE_EXPECTED_CONFLICT_ACTION) } } - else -> rem.head.err("invalid ON CONFLICT syntax", PARSE_EXPECTED_WHERE_CLAUSE) + else -> rem.head.err("invalid ON CONFLICT syntax", ErrorCode.PARSE_EXPECTED_WHERE_CLAUSE) } } else null } private fun List.parseSetAssignments(type: ParseType): ParseNode = parseArgList( - aliasSupportType = NONE, - mode = SET_CLAUSE_ARG_LIST + aliasSupportType = AliasSupportType.NONE, + mode = ArgListMode.SET_CLAUSE_ARG_LIST ).run { if (children.isEmpty()) { - remaining.err("Expected assignment for SET", PARSE_MISSING_SET_ASSIGNMENT) + remaining.err("Expected assignment for SET", ErrorCode.PARSE_MISSING_SET_ASSIGNMENT) } copy(type = type) } private fun List.parseDelete(name: Token): ParseNode { if (head?.keywordText != "from") { - err("Expected FROM after DELETE", PARSE_UNEXPECTED_TOKEN) + err("Expected FROM after DELETE", ErrorCode.PARSE_UNEXPECTED_TOKEN) } - return tail.parseLegacyDml { ParseNode(DELETE, name, emptyList(), this) } + return tail.parseLegacyDml { ParseNode(ParseType.DELETE, name, emptyList(), this) } } private fun List.parseUpdate(): ParseNode = parseLegacyDml { @@ -1719,7 +1764,7 @@ class SqlParser( var rem = this val returningElems = listOf(rem.parseReturningElems()) rem = returningElems.first().remaining - return ParseNode(type = RETURNING, token = null, children = returningElems, remaining = rem) + return ParseNode(type = ParseType.RETURNING, token = null, children = returningElems, remaining = rem) } private inline fun List.parseLegacyDml(parseDmlOp: List.() -> ParseNode): ParseNode { @@ -1740,7 +1785,7 @@ class SqlParser( } } - children.add(ParseNode(FROM_CLAUSE, null, listOf(source), rem)) + children.add(ParseNode(ParseType.FROM_CLAUSE, null, listOf(source), rem)) val operation = rem.parseDmlOp().also { rem = it.remaining @@ -1757,7 +1802,7 @@ class SqlParser( } // generate a FROM-node to normalize the parse tree - return ParseNode(FROM, null, listOf(operation) + children, rem) + return ParseNode(ParseType.FROM, null, listOf(operation) + children, rem) } private fun List.parseOptionalWhere(): ParseNode? { @@ -1767,7 +1812,7 @@ class SqlParser( if (rem.head?.keywordText == "where") { val expr = rem.tail.parseExpression() rem = expr.remaining - return ParseNode(WHERE, null, listOf(expr), rem) + return ParseNode(ParseType.WHERE, null, listOf(expr), rem) } return null @@ -1788,7 +1833,7 @@ class SqlParser( var rem = this var returningMapping = rem.parseReturningMapping().also { rem = it.remaining } var column = rem.parseColumn().also { rem = it.remaining } - ParseNode(type = RETURNING_ELEM, token = null, children = listOf(returningMapping, column), remaining = rem) + ParseNode(type = ParseType.RETURNING_ELEM, token = null, children = listOf(returningMapping, column), remaining = rem) } } @@ -1796,21 +1841,24 @@ class SqlParser( var rem = this when (rem.head?.keywordText) { "modified_old", "modified_new", "all_old", "all_new" -> { - return ParseNode(type = RETURNING_MAPPING, token = rem.head, children = listOf(), remaining = rem.tail) + return ParseNode(type = ParseType.RETURNING_MAPPING, token = rem.head, children = listOf(), + remaining = rem.tail) } - else -> rem.err("Expected ( MODIFIED | ALL ) ( NEW | OLD ) in each returning element.", PARSE_EXPECTED_RETURNING_CLAUSE) + else -> rem.err("Expected ( MODIFIED | ALL ) ( NEW | OLD ) in each returning element.", + ErrorCode.PARSE_EXPECTED_RETURNING_CLAUSE) } } private fun List.parseColumn(): ParseNode { return when (this.head?.type) { - STAR -> ParseNode(RETURNING_WILDCARD, this.head, listOf(), this.tail) + TokenType.STAR -> ParseNode(ParseType.RETURNING_WILDCARD, this.head, listOf(), this.tail) else -> { var expr = parseExpression().let { when (it.type) { - PATH -> inspectColumnPathExpression(it) - ATOM -> it - else -> this.err("Unsupported syntax in RETURNING columns.", PARSE_UNSUPPORTED_RETURNING_CLAUSE_SYNTAX) + ParseType.PATH -> inspectColumnPathExpression(it) + ParseType.ATOM -> it + else -> this.err("Unsupported syntax in RETURNING columns.", + ErrorCode.PARSE_UNSUPPORTED_RETURNING_CLAUSE_SYNTAX) } } expr @@ -1820,7 +1868,8 @@ class SqlParser( private fun inspectColumnPathExpression(pathNode: ParseNode): ParseNode { if (pathNode.children.size > 2) { - pathNode.children[2].token?.err("More than two paths in RETURNING columns.", PARSE_UNSUPPORTED_RETURNING_CLAUSE_SYNTAX) + pathNode.children[2].token?.err("More than two paths in RETURNING columns.", + ErrorCode.PARSE_UNSUPPORTED_RETURNING_CLAUSE_SYNTAX) } return pathNode } @@ -1831,7 +1880,8 @@ class SqlParser( rem = value.remaining val name = rem.parseExpression() rem = name.remaining - val selectAfterProjection = parseSelectAfterProjection(PIVOT,ParseNode(MEMBER, null, listOf(name, value), rem)) + val selectAfterProjection = parseSelectAfterProjection(ParseType.PIVOT, + ParseNode(ParseType.MEMBER, null, listOf(name, value), rem)) return selectAfterProjection } @@ -1850,16 +1900,16 @@ class SqlParser( else -> false } - var type = SELECT_LIST + var type = ParseType.SELECT_LIST var projection = when { rem.head?.keywordText == "value" -> { - type = SELECT_VALUE + type = ParseType.SELECT_VALUE rem.tail.parseExpression() } else -> { val list = rem.parseSelectList() if (list.children.isEmpty()) { - rem.err("Cannot have empty SELECT list", PARSE_EMPTY_SELECT) + rem.err("Cannot have empty SELECT list", ErrorCode.PARSE_EMPTY_SELECT) } val asterisk = list.children.firstOrNull { it.type == ParseType.PROJECT_ALL && it.children.isEmpty() } @@ -1874,7 +1924,7 @@ class SqlParser( } } if (distinct) { - projection = ParseNode(DISTINCT, null, listOf(projection), projection.remaining) + projection = ParseNode(ParseType.DISTINCT, null, listOf(projection), projection.remaining) } val parseSelectAfterProjection = parseSelectAfterProjection(type, projection) @@ -1910,45 +1960,45 @@ class SqlParser( */ private fun List.parseCreateTable(): ParseNode { val identifier = when (head?.type) { - QUOTED_IDENTIFIER, IDENTIFIER -> { + TokenType.QUOTED_IDENTIFIER, TokenType.IDENTIFIER -> { atomFromHead() } else -> { err("Expected identifier!", ErrorCode.PARSE_UNEXPECTED_TOKEN) } } - return ParseNode(CREATE_TABLE, null, listOf(identifier), identifier.remaining) + return ParseNode(ParseType.CREATE_TABLE, null, listOf(identifier), identifier.remaining) } private fun List.parseDropIndex(): ParseNode { var rem = this val identifier = when (rem.head?.type) { - IDENTIFIER, QUOTED_IDENTIFIER -> { + TokenType.IDENTIFIER, TokenType.QUOTED_IDENTIFIER -> { atomFromHead() } else -> { - rem.err("Expected identifier!", PARSE_UNEXPECTED_TOKEN) + rem.err("Expected identifier!", ErrorCode.PARSE_UNEXPECTED_TOKEN) } } rem = rem.tail if (rem.head?.keywordText != "on") { - rem.err("Expected ON", PARSE_UNEXPECTED_TOKEN) + rem.err("Expected ON", ErrorCode.PARSE_UNEXPECTED_TOKEN) } rem = rem.tail val target = when (rem.head?.type) { - QUOTED_IDENTIFIER, IDENTIFIER -> { + TokenType.QUOTED_IDENTIFIER, TokenType.IDENTIFIER -> { rem.atomFromHead() } else -> { - rem.err("Table target must be an identifier", PARSE_UNEXPECTED_TOKEN) + rem.err("Table target must be an identifier", ErrorCode.PARSE_UNEXPECTED_TOKEN) } } rem = rem.tail - return ParseNode(DROP_INDEX, null, listOf(identifier, target), rem) + return ParseNode(ParseType.DROP_INDEX, null, listOf(identifier, target), rem) } /** @@ -1956,7 +2006,7 @@ class SqlParser( */ private fun List.parseDropTable(): ParseNode { val identifier = when (head?.type) { - QUOTED_IDENTIFIER, IDENTIFIER -> { + TokenType.QUOTED_IDENTIFIER, TokenType.IDENTIFIER -> { atomFromHead() } else -> { @@ -1964,7 +2014,7 @@ class SqlParser( } } - return ParseNode(DROP_TABLE, null, listOf(identifier), identifier.remaining) + return ParseNode(ParseType.DROP_TABLE, null, listOf(identifier), identifier.remaining) } /** @@ -1982,7 +2032,7 @@ class SqlParser( rem = rem.tail val target = when (rem.head?.type) { - QUOTED_IDENTIFIER, IDENTIFIER -> { + TokenType.QUOTED_IDENTIFIER, TokenType.IDENTIFIER -> { rem.atomFromHead() } else -> { @@ -1991,15 +2041,16 @@ class SqlParser( } rem = target.remaining - if (rem.head?.type != LEFT_PAREN) { + if (rem.head?.type != TokenType.LEFT_PAREN) { rem.err("Expected parenthesis for keys", ErrorCode.PARSE_UNEXPECTED_TOKEN) } // TODO support full expressions here... only simple paths for now - val keys = rem.tail.parseArgList(NONE, SIMPLE_PATH_ARG_LIST).deriveExpected(RIGHT_PAREN) + val keys = rem.tail.parseArgList(AliasSupportType.NONE, ArgListMode.SIMPLE_PATH_ARG_LIST) + .deriveExpected(TokenType.RIGHT_PAREN) rem = keys.remaining // TODO support other syntax options - return ParseNode(CREATE_INDEX, null, listOf(target, keys), rem) + return ParseNode(ParseType.CREATE_INDEX, null, listOf(target, keys), rem) } /** @@ -2043,13 +2094,13 @@ class SqlParser( val flattened = flattenParseNode(pathNode).drop(2) //Is invalid if contains PATH_WILDCARD (i.e. to `[*]`} - flattened.firstOrNull { it.type == PATH_WILDCARD } + flattened.firstOrNull { it.type == ParseType.PATH_WILDCARD } ?.token ?.err("Invalid use of * in select list", ErrorCode.PARSE_INVALID_CONTEXT_FOR_WILDCARD_IN_SELECT_LIST) //Is invalid if contains PATH_WILDCARD_UNPIVOT (i.e. * as part of a dotted expression) anywhere except at the end. //i.e. f.*.b is invalid but f.b.* is not. - flattened.dropLast(1).firstOrNull { it.type == PATH_UNPIVOT } + flattened.dropLast(1).firstOrNull { it.type == ParseType.PATH_UNPIVOT } ?.token ?.err("Invalid use of * in select list", ErrorCode.PARSE_INVALID_CONTEXT_FOR_WILDCARD_IN_SELECT_LIST) @@ -2059,14 +2110,14 @@ class SqlParser( //Is invalid if contains a square bracket anywhere and a wildcard at the end. //i.e f[1].* is invalid - flattened.firstOrNull { it.type == PATH_SQB } + flattened.firstOrNull { it.type == ParseType.PATH_SQB } ?.token ?.err("Cannot use [] and * together in SELECT list expression", ErrorCode.PARSE_CANNOT_MIX_SQB_AND_WILDCARD_IN_SELECT_LIST) val pathPart = pathNode.copy(children = pathNode.children.dropLast(1)) return ParseNode( - type = PROJECT_ALL, + type = ParseType.PROJECT_ALL, token = null, children = listOf(if (pathPart.children.size == 1) pathPart.children[0] else pathPart), remaining = pathNode.remaining) @@ -2076,19 +2127,19 @@ class SqlParser( private fun List.parseSelectList(): ParseNode { return parseCommaList { - if (this.head?.type == STAR) { - ParseNode(PROJECT_ALL, this.head, listOf(), this.tail) + if (this.head?.type == TokenType.STAR) { + ParseNode(ParseType.PROJECT_ALL, this.head, listOf(), this.tail) } else if (this.head != null && this.head?.keywordText in RESERVED_KEYWORDS) { this.head.err( "Expected identifier or an expression but found unexpected keyword '${this.head?.keywordText?: ""}' in a select list.", - PARSE_UNEXPECTED_KEYWORD + ErrorCode.PARSE_UNEXPECTED_KEYWORD ) } else { val expr = parseExpression().let { when (it.type) { - PATH -> inspectPathExpression(it) + ParseType.PATH -> inspectPathExpression(it) else -> it } } @@ -2105,7 +2156,7 @@ class SqlParser( // TODO support SELECT with no FROM if (rem.head?.keywordText != "from") { - rem.err("Expected FROM after SELECT list", PARSE_SELECT_MISSING_FROM) + rem.err("Expected FROM after SELECT list", ErrorCode.PARSE_SELECT_MISSING_FROM) } val fromList = rem.tail.parseFromSourceList(OperatorPrecedenceGroups.SELECT.precedence) @@ -2127,16 +2178,16 @@ class SqlParser( children.add(letParseNode) } - parseOptionalSingleExpressionClause(WHERE) + parseOptionalSingleExpressionClause(ParseType.WHERE) if (rem.head?.keywordText == "order") { - rem = rem.tail.tailExpectedToken(BY) + rem = rem.tail.tailExpectedToken(TokenType.BY) val orderByChildren = listOf(rem.parseOrderByArgList()) rem = orderByChildren.first().remaining children.add( - ParseNode(type = ORDER_BY, token = null, children = orderByChildren, remaining = rem) + ParseNode(type = ParseType.ORDER_BY, token = null, children = orderByChildren, remaining = rem) ) } @@ -2145,24 +2196,25 @@ class SqlParser( val type = when (rem.head?.keywordText) { "partial" -> { rem = rem.tail - GROUP_PARTIAL + ParseType.GROUP_PARTIAL } - else -> GROUP + else -> ParseType.GROUP } val groupChildren = ArrayList() - rem = rem.tailExpectedToken(BY) + rem = rem.tailExpectedToken(TokenType.BY) val groupKey = rem.parseArgList( - aliasSupportType = AS_ONLY, - mode = NORMAL_ARG_LIST, + aliasSupportType = AliasSupportType.AS_ONLY, + mode = ArgListMode.NORMAL_ARG_LIST, precedence = OperatorPrecedenceGroups.SELECT.precedence ) groupKey.children.forEach { // TODO support ordinal case - if (it.token?.type == LITERAL) { - it.token.err("Literals (including ordinals) not supported in GROUP BY", PARSE_UNSUPPORTED_LITERALS_GROUPBY) + if (it.token?.type == TokenType.LITERAL) { + it.token.err("Literals (including ordinals) not supported in GROUP BY", + ErrorCode.PARSE_UNSUPPORTED_LITERALS_GROUPBY) } } groupChildren.add(groupKey) @@ -2172,7 +2224,8 @@ class SqlParser( rem = rem.tail.tailExpectedKeyword("as") if (rem.head?.type?.isIdentifier() != true) { - rem.err("Expected identifier for GROUP name", PARSE_EXPECTED_IDENT_FOR_GROUP_NAME) + rem.err("Expected identifier for GROUP name", + ErrorCode.PARSE_EXPECTED_IDENT_FOR_GROUP_NAME) } groupChildren.add(rem.atomFromHead()) rem = rem.tail @@ -2187,23 +2240,23 @@ class SqlParser( ) } - parseOptionalSingleExpressionClause(HAVING) + parseOptionalSingleExpressionClause(ParseType.HAVING) - parseOptionalSingleExpressionClause(LIMIT) + parseOptionalSingleExpressionClause(ParseType.LIMIT) - parseOptionalSingleExpressionClause(OFFSET) + parseOptionalSingleExpressionClause(ParseType.OFFSET) return ParseNode(selectType, null, children, rem) } private fun List.parseFunctionCall(name: Token): ParseNode { fun parseCallArguments(callName: String, args: List, callType: ParseType): ParseNode = when(args.head?.type) { - STAR -> err("$callName(*) is not allowed", PARSE_UNSUPPORTED_CALL_WITH_STAR) - RIGHT_PAREN -> ParseNode(callType, name, emptyList(), tail) + TokenType.STAR -> err("$callName(*) is not allowed", ErrorCode.PARSE_UNSUPPORTED_CALL_WITH_STAR) + TokenType.RIGHT_PAREN -> ParseNode(callType, name, emptyList(), tail) else -> { - args.parseArgList(aliasSupportType = NONE, mode = NORMAL_ARG_LIST) + args.parseArgList(aliasSupportType = AliasSupportType.NONE, mode = ArgListMode.NORMAL_ARG_LIST) .copy(type = callType, token = name) - .deriveExpected(RIGHT_PAREN) + .deriveExpected(TokenType.RIGHT_PAREN) } } @@ -2214,84 +2267,85 @@ class SqlParser( return when (callName) { "count" -> { when { - head?.type == RIGHT_PAREN -> { - err("Aggregate functions are always unary", PARSE_NON_UNARY_AGREGATE_FUNCTION_CALL) + head?.type == TokenType.RIGHT_PAREN -> { + err("Aggregate functions are always unary", ErrorCode.PARSE_NON_UNARY_AGREGATE_FUNCTION_CALL) } // COUNT(*) - head?.type == STAR -> { - ParseNode(CALL_AGG_WILDCARD, name, emptyList(), tail).deriveExpected(RIGHT_PAREN) + head?.type == TokenType.STAR -> { + ParseNode(ParseType.CALL_AGG_WILDCARD, name, emptyList(), tail).deriveExpected(TokenType.RIGHT_PAREN) } - head?.type == KEYWORD && keywordText == "distinct" -> { + head?.type == TokenType.KEYWORD && keywordText == "distinct" -> { when(memoizedTail.head?.type) { // COUNT(DISTINCT *) - STAR -> { - err("COUNT(DISTINCT *) is not supported", PARSE_UNSUPPORTED_CALL_WITH_STAR) + TokenType.STAR -> { + err("COUNT(DISTINCT *) is not supported", ErrorCode.PARSE_UNSUPPORTED_CALL_WITH_STAR) } // COUNT(DISTINCT expression) else -> { - memoizedTail.parseArgList(aliasSupportType = NONE, mode = NORMAL_ARG_LIST) - .copy(type = CALL_DISTINCT_AGG, token = name) - .deriveExpected(RIGHT_PAREN) + memoizedTail.parseArgList(aliasSupportType = AliasSupportType.NONE, mode = ArgListMode.NORMAL_ARG_LIST) + .copy(type = ParseType.CALL_DISTINCT_AGG, token = name) + .deriveExpected(TokenType.RIGHT_PAREN) } } } - head?.type == KEYWORD && keywordText == "all" -> { + head?.type == TokenType.KEYWORD && keywordText == "all" -> { when(memoizedTail.head?.type) { - STAR -> err("COUNT(ALL *) is not supported", PARSE_UNSUPPORTED_CALL_WITH_STAR) + TokenType.STAR -> err("COUNT(ALL *) is not supported", ErrorCode.PARSE_UNSUPPORTED_CALL_WITH_STAR) // COUNT(ALL expression) else -> { - memoizedTail.parseArgList(aliasSupportType = NONE, mode = NORMAL_ARG_LIST) - .copy(type = CALL_AGG, token = name) - .deriveExpected(RIGHT_PAREN) + memoizedTail.parseArgList(aliasSupportType = AliasSupportType.NONE, mode = ArgListMode.NORMAL_ARG_LIST) + .copy(type = ParseType.CALL_AGG, token = name) + .deriveExpected(TokenType.RIGHT_PAREN) } } } - else -> parseArgList(aliasSupportType = NONE, mode = NORMAL_ARG_LIST) - .copy(type = CALL_AGG, token = name) - .deriveExpected(RIGHT_PAREN) + else -> parseArgList(aliasSupportType = AliasSupportType.NONE, mode = ArgListMode.NORMAL_ARG_LIST) + .copy(type = ParseType.CALL_AGG, token = name) + .deriveExpected(TokenType.RIGHT_PAREN) } } in STANDARD_AGGREGATE_FUNCTIONS -> { val call = when { - head?.type == KEYWORD && head?.keywordText == "distinct" -> { - parseCallArguments(callName, tail, CALL_DISTINCT_AGG) + head?.type == TokenType.KEYWORD && head?.keywordText == "distinct" -> { + parseCallArguments(callName, tail, ParseType.CALL_DISTINCT_AGG) } - head?.type == KEYWORD && head?.keywordText == "all" -> { - parseCallArguments(callName, tail, CALL_AGG) + head?.type == TokenType.KEYWORD && head?.keywordText == "all" -> { + parseCallArguments(callName, tail, ParseType.CALL_AGG) } else -> { - parseCallArguments(callName, this, CALL_AGG) + parseCallArguments(callName, this, ParseType.CALL_AGG) } } if (call.children.size != 1) { - err("Aggregate functions are always unary", PARSE_NON_UNARY_AGREGATE_FUNCTION_CALL) + err("Aggregate functions are always unary", + ErrorCode.PARSE_NON_UNARY_AGREGATE_FUNCTION_CALL) } call } // normal function - else -> parseCallArguments(callName, this, CALL) + else -> parseCallArguments(callName, this, ParseType.CALL) } } private fun List.parseExec(): ParseNode { var rem = this - if (rem.head?.type == EOF) { - rem.err("No stored procedure provided", PARSE_NO_STORED_PROCEDURE_PROVIDED) + if (rem.head?.type == TokenType.EOF) { + rem.err("No stored procedure provided", ErrorCode.PARSE_NO_STORED_PROCEDURE_PROVIDED) } rem.forEach { if (it.keywordText?.toLowerCase() == "exec") { - it.err("EXEC call found at unexpected location", PARSE_UNEXPECTED_TERM) + it.err("EXEC call found at unexpected location", ErrorCode.PARSE_UNEXPECTED_TERM) } } @@ -2299,16 +2353,16 @@ class SqlParser( rem = rem.tail // Stored procedure call has no args - if (rem.head?.type == EOF) { - return ParseNode(EXEC, procedureName, emptyList(), rem) + if (rem.head?.type == TokenType.EOF) { + return ParseNode(ParseType.EXEC, procedureName, emptyList(), rem) } - else if (rem.head?.type == LEFT_PAREN) { - rem.err("Unexpected $LEFT_PAREN found following stored procedure call", PARSE_UNEXPECTED_TOKEN) + else if (rem.head?.type == TokenType.LEFT_PAREN) { + rem.err("Unexpected ${TokenType.LEFT_PAREN} found following stored procedure call", ErrorCode.PARSE_UNEXPECTED_TOKEN) } - return rem.parseArgList(aliasSupportType = NONE, mode = NORMAL_ARG_LIST) - .copy(type = EXEC, token = procedureName) + return rem.parseArgList(aliasSupportType = AliasSupportType.NONE, mode = ArgListMode.NORMAL_ARG_LIST) + .copy(type = ParseType.EXEC, token = procedureName) } /** @@ -2320,10 +2374,11 @@ class SqlParser( private fun List.parseSubstring(name: Token): ParseNode { var rem = this - if (rem.head?.type != LEFT_PAREN) { + if (rem.head?.type != TokenType.LEFT_PAREN) { val pvmap = PropertyValueMap() - pvmap[EXPECTED_TOKEN_TYPE] = LEFT_PAREN - rem.err("Expected $LEFT_PAREN", PARSE_EXPECTED_LEFT_PAREN_BUILTIN_FUNCTION_CALL, pvmap) + pvmap[Property.EXPECTED_TOKEN_TYPE] = TokenType.LEFT_PAREN + rem.err("Expected ${TokenType.LEFT_PAREN}", + ErrorCode.PARSE_EXPECTED_LEFT_PAREN_BUILTIN_FUNCTION_CALL, pvmap) } var stringExpr = tail.parseExpression() @@ -2335,14 +2390,15 @@ class SqlParser( parseSql92Syntax = true stringExpr.deriveExpectedKeyword("from") } - rem.head!!.type == COMMA -> stringExpr.deriveExpected(COMMA) - else -> rem.err("Expected $KEYWORD 'from' OR $COMMA", PARSE_EXPECTED_ARGUMENT_DELIMITER) + rem.head!!.type == TokenType.COMMA -> stringExpr.deriveExpected(TokenType.COMMA) + else -> rem.err("Expected ${TokenType.KEYWORD} 'from' OR ${TokenType.COMMA}", + ErrorCode.PARSE_EXPECTED_ARGUMENT_DELIMITER) } val (positionExpr: ParseNode, expectedToken: Token) = stringExpr.remaining.parseExpression() - .deriveExpected(if(parseSql92Syntax) FOR else COMMA, RIGHT_PAREN) + .deriveExpected(if(parseSql92Syntax) TokenType.FOR else TokenType.COMMA, TokenType.RIGHT_PAREN) - if (expectedToken.type == RIGHT_PAREN) { + if (expectedToken.type == TokenType.RIGHT_PAREN) { return ParseNode( ParseType.CALL, name, @@ -2352,7 +2408,7 @@ class SqlParser( } rem = positionExpr.remaining - val lengthExpr = rem.parseExpression().deriveExpected(RIGHT_PAREN) + val lengthExpr = rem.parseExpression().deriveExpected(TokenType.RIGHT_PAREN) return ParseNode(ParseType.CALL, name, listOf(stringExpr, positionExpr, lengthExpr), @@ -2366,7 +2422,8 @@ class SqlParser( * Syntax is TRIM([[ specification ] [to trim characters] FROM] ). */ private fun List.parseTrim(name: Token): ParseNode { - if (head?.type != LEFT_PAREN) err("Expected $LEFT_PAREN", PARSE_EXPECTED_LEFT_PAREN_BUILTIN_FUNCTION_CALL) + if (head?.type != TokenType.LEFT_PAREN) err("Expected ${TokenType.LEFT_PAREN}", + ErrorCode.PARSE_EXPECTED_LEFT_PAREN_BUILTIN_FUNCTION_CALL) var rem = tail val arguments = mutableListOf() @@ -2380,8 +2437,10 @@ class SqlParser( val maybeTrimSpec = rem.head val hasSpecification = when { - maybeTrimSpec?.type == IDENTIFIER && TRIM_SPECIFICATION_KEYWORDS.contains(maybeTrimSpec.text?.toLowerCase()) -> { - arguments.add(ParseNode(ATOM, maybeTrimSpec.copy(type = TRIM_SPECIFICATION), listOf(), rem.tail)) + maybeTrimSpec?.type == TokenType.IDENTIFIER && + TRIM_SPECIFICATION_KEYWORDS.contains(maybeTrimSpec.text?.toLowerCase()) -> { + arguments.add(ParseNode(ParseType.ATOM, maybeTrimSpec.copy(type = TokenType.TRIM_SPECIFICATION), + listOf(), rem.tail)) rem = rem.tail true @@ -2414,8 +2473,8 @@ class SqlParser( } } - if(rem.head?.type != RIGHT_PAREN) { - rem.err("Expected $RIGHT_PAREN", PARSE_EXPECTED_RIGHT_PAREN_BUILTIN_FUNCTION_CALL) + if(rem.head?.type != TokenType.RIGHT_PAREN) { + rem.err("Expected ${TokenType.RIGHT_PAREN}", ErrorCode.PARSE_EXPECTED_RIGHT_PAREN_BUILTIN_FUNCTION_CALL) } return ParseNode(ParseType.CALL, name, arguments, rem.tail) @@ -2424,10 +2483,10 @@ class SqlParser( private fun List.parseDateTimePart(): ParseNode { val maybeDateTimePart = this.head return when { - maybeDateTimePart?.type == IDENTIFIER && DATE_TIME_PART_KEYWORDS.contains(maybeDateTimePart.text?.toLowerCase()) -> { - ParseNode(ATOM, maybeDateTimePart.copy(type = DATETIME_PART), listOf(), this.tail) + maybeDateTimePart?.type == TokenType.IDENTIFIER && DATE_TIME_PART_KEYWORDS.contains(maybeDateTimePart.text?.toLowerCase()) -> { + ParseNode(ParseType.ATOM, maybeDateTimePart.copy(type = TokenType.DATETIME_PART), listOf(), this.tail) } - else -> maybeDateTimePart.err("Expected one of: $DATE_TIME_PART_KEYWORDS", PARSE_EXPECTED_DATE_TIME_PART) + else -> maybeDateTimePart.err("Expected one of: $DATE_TIME_PART_KEYWORDS", ErrorCode.PARSE_EXPECTED_DATE_TIME_PART) } } @@ -2437,14 +2496,13 @@ class SqlParser( * Syntax is EXTRACT( FROM ). */ private fun List.parseExtract(name: Token): ParseNode { - if (head?.type != LEFT_PAREN) err("Expected $LEFT_PAREN", - PARSE_EXPECTED_LEFT_PAREN_BUILTIN_FUNCTION_CALL) - + if (head?.type != TokenType.LEFT_PAREN) err("Expected ${TokenType.LEFT_PAREN}", + ErrorCode.PARSE_EXPECTED_LEFT_PAREN_BUILTIN_FUNCTION_CALL) val dateTimePart = this.tail.parseDateTimePart().deriveExpectedKeyword("from") val rem = dateTimePart.remaining - val dateTimeType = rem.parseExpression().deriveExpected(RIGHT_PAREN) + val dateTimeType = rem.parseExpression().deriveExpected(TokenType.RIGHT_PAREN) - return ParseNode(CALL, name, listOf(dateTimePart, dateTimeType), dateTimeType.remaining) + return ParseNode(ParseType.CALL, name, listOf(dateTimePart, dateTimeType), dateTimeType.remaining) } /** @@ -2452,8 +2510,9 @@ class SqlParser( */ private fun List.parseDate(): ParseNode { val dateStringToken = head - if (dateStringToken?.value == null || dateStringToken.type != LITERAL || !dateStringToken.value.isText) { - err("Expected date string followed by the keyword DATE, found ${head?.value?.type}", PARSE_UNEXPECTED_TOKEN) + if (dateStringToken?.value == null || dateStringToken.type != TokenType.LITERAL || !dateStringToken.value.isText) { + err("Expected date string followed by the keyword DATE, found ${head?.value?.type}", + ErrorCode.PARSE_UNEXPECTED_TOKEN) } val dateString = dateStringToken.value.stringValue() @@ -2462,15 +2521,15 @@ class SqlParser( // Filter out the extended dates which can be specified with the '+' or '-' symbol. // '+99999-03-10' for example is allowed by LocalDate.parse and should be filtered out. if (!DATE_PATTERN_REGEX.matches(dateString!!)) { - err("Expected DATE string to be of the format yyyy-MM-dd", PARSE_INVALID_DATE_STRING) + err("Expected DATE string to be of the format yyyy-MM-dd", ErrorCode.PARSE_INVALID_DATE_STRING) } try { LocalDate.parse(dateString, ISO_LOCAL_DATE) } catch (e: DateTimeParseException) { - err(e.localizedMessage, PARSE_INVALID_DATE_STRING) + err(e.localizedMessage, ErrorCode.PARSE_INVALID_DATE_STRING) } - return ParseNode(DATE, head, listOf(), tail) + return ParseNode(ParseType.DATE, head, listOf(), tail) } /** @@ -2482,22 +2541,22 @@ class SqlParser( */ private fun List.parseOptionalPrecision(): ParseNode = // If the optional precision is present - if (head?.type == LEFT_PAREN) { + if (head?.type == TokenType.LEFT_PAREN) { var rem = tail // Expected precision token to be unsigned integer between 0 and 9 inclusive - if (rem.head == null || rem.head!!.type != LITERAL || !rem.head!!.value!!.isUnsignedInteger || + if (rem.head == null || rem.head!!.type != TokenType.LITERAL || !rem.head!!.value!!.isUnsignedInteger || rem.head!!.value!!.longValue() < 0 || rem.head!!.value!!.longValue() > MAX_PRECISION_FOR_TIME) { - rem.head.err("Expected integer value between 0 and 9 for precision", PARSE_INVALID_PRECISION_FOR_TIME) + rem.head.err("Expected integer value between 0 and 9 for precision", ErrorCode.PARSE_INVALID_PRECISION_FOR_TIME) } val precision = rem.head rem = rem.tail - if (rem.head?.type != RIGHT_PAREN) { - rem.head.errExpectedTokenType(RIGHT_PAREN) + if (rem.head?.type != TokenType.RIGHT_PAREN) { + rem.head.errExpectedTokenType(TokenType.RIGHT_PAREN) } - ParseNode(PRECISION, precision, listOf(), rem.tail) + ParseNode(ParseType.PRECISION, precision, listOf(), rem.tail) } else { - ParseNode(PRECISION, null, listOf(), this) + ParseNode(ParseType.PRECISION, null, listOf(), this) } /** @@ -2505,7 +2564,7 @@ class SqlParser( */ private fun List.checkForOptionalTimeZone(): Pair, Boolean> { // If the keyword is specified for time zone, it must be a series of keywords - "with time zone" - if (head?.type == KEYWORD) { + if (head?.type == TokenType.KEYWORD) { val rem = tailExpectedKeyword("with"). tailExpectedKeyword("time"). @@ -2546,7 +2605,7 @@ class SqlParser( parse(time, formatter) } catch (e: DateTimeParseException) { - rem.head.err(e.localizedMessage, PARSE_INVALID_TIME_STRING) + rem.head.err(e.localizedMessage, ErrorCode.PARSE_INVALID_TIME_STRING) } } @@ -2559,10 +2618,10 @@ class SqlParser( rem = remainingAfterOptionalTimeZone val timeStringToken = rem.head - if (timeStringToken?.value == null || timeStringToken.type != LITERAL || !timeStringToken.value.isText) { + if (timeStringToken?.value == null || timeStringToken.type != TokenType.LITERAL || !timeStringToken.value.isText) { rem.head.err( "Expected time string followed by the keyword TIME OR TIME WITH TIME ZONE, found ${rem.head?.value?.type}", - PARSE_UNEXPECTED_TOKEN + ErrorCode.PARSE_UNEXPECTED_TOKEN ) } @@ -2571,7 +2630,7 @@ class SqlParser( val timeString = timeStringToken.value.stringValue()?.replace(" ", "") if (!genericTimeRegex.matches(timeString!!)) { rem.head.err("Invalid format for time string. Expected format is \"TIME [(p)] [WITH TIME ZONE] HH:MM:SS[.ddddd...][+|-HH:MM]\"", - PARSE_INVALID_TIME_STRING) + ErrorCode. PARSE_INVALID_TIME_STRING) } // For "TIME WITH TIME ZONE", if the time zone is not explicitly specified, we still consider it as valid. // We will add the default time zone to it later in the evaluation phase. @@ -2587,10 +2646,10 @@ class SqlParser( // The source span here is just the filler value and does not reflect the actual source location of the precision // as it does not exists in case the precision is unspecified. val precisionOfValue = precision.token ?: - Token(LITERAL, ion.newInt(getPrecisionFromTimeString(timeString)), timeStringToken.span) + Token(TokenType.LITERAL, ion.newInt(getPrecisionFromTimeString(timeString)), timeStringToken.span) return ParseNode( - if (withTimeZone) TIME_WITH_TIME_ZONE else TIME, + if (withTimeZone) ParseType.TIME_WITH_TIME_ZONE else ParseType.TIME, rem.head!!.copy(value = ion.newString(timeString)), listOf(precision.copy(token = precisionOfValue)), rem.tail) @@ -2603,15 +2662,14 @@ class SqlParser( * is the value of [name]. */ private fun List.parseDateAddOrDateDiff(name: Token): ParseNode { - if (head?.type != LEFT_PAREN) err("Expected $LEFT_PAREN", - PARSE_EXPECTED_LEFT_PAREN_BUILTIN_FUNCTION_CALL) - - val dateTimePart = this.tail.parseDateTimePart().deriveExpected(COMMA) + if (head?.type != TokenType.LEFT_PAREN) err("Expected ${TokenType.LEFT_PAREN}", + ErrorCode.PARSE_EXPECTED_LEFT_PAREN_BUILTIN_FUNCTION_CALL) + val dateTimePart = this.tail.parseDateTimePart().deriveExpected(TokenType.COMMA) - val timestamp1 = dateTimePart.remaining.parseExpression().deriveExpected(COMMA) - val timestamp2 = timestamp1.remaining.parseExpression().deriveExpected(RIGHT_PAREN) + val timestamp1 = dateTimePart.remaining.parseExpression().deriveExpected(TokenType.COMMA) + val timestamp2 = timestamp1.remaining.parseExpression().deriveExpected(TokenType.RIGHT_PAREN) - return ParseNode(CALL, name, listOf(dateTimePart, timestamp1, timestamp2), timestamp2.remaining) + return ParseNode(ParseType.CALL, name, listOf(dateTimePart, timestamp1, timestamp2), timestamp2.remaining) } private fun List.parseLet(): ParseNode { @@ -2620,96 +2678,99 @@ class SqlParser( var child = rem.parseExpression() rem = child.remaining - if (rem.head?.type != AS) { - rem.head.err("Expected $AS following $LET expr", PARSE_EXPECTED_AS_FOR_LET) + if (rem.head?.type != TokenType.AS) { + rem.head.err("Expected ${TokenType.AS} following ${ParseType.LET} expr", + ErrorCode.PARSE_EXPECTED_AS_FOR_LET) } rem = rem.tail if (rem.head?.type?.isIdentifier() != true) { - rem.head.err("Expected identifier for $AS-alias", PARSE_EXPECTED_IDENT_FOR_ALIAS) + rem.head.err("Expected identifier for ${TokenType.AS}-alias", + ErrorCode.PARSE_EXPECTED_IDENT_FOR_ALIAS) } var name = rem.head rem = rem.tail - letClauses.add(ParseNode(AS_ALIAS, name, listOf(child), rem)) + letClauses.add(ParseNode(ParseType.AS_ALIAS, name, listOf(child), rem)) - while (rem.head?.type == COMMA) { + while (rem.head?.type == TokenType.COMMA) { rem = rem.tail child = rem.parseExpression() rem = child.remaining - if (rem.head?.type != AS) { - rem.head.err("Expected $AS following $LET expr", PARSE_EXPECTED_AS_FOR_LET) + if (rem.head?.type != TokenType.AS) { + rem.head.err("Expected ${TokenType.AS} following ${ParseType.LET} expr", ErrorCode.PARSE_EXPECTED_AS_FOR_LET) } rem = rem.tail if (rem.head?.type?.isIdentifier() != true) { - rem.head.err("Expected identifier for $AS-alias", PARSE_EXPECTED_IDENT_FOR_ALIAS) + rem.head.err("Expected identifier for ${TokenType.AS}-alias", ErrorCode.PARSE_EXPECTED_IDENT_FOR_ALIAS) } name = rem.head rem = rem.tail - letClauses.add(ParseNode(AS_ALIAS, name, listOf(child), rem)) + letClauses.add(ParseNode(ParseType.AS_ALIAS, name, listOf(child), rem)) } - return ParseNode(LET, null, letClauses, rem) + return ParseNode(ParseType.LET, null, letClauses, rem) } private fun List.parseListLiteral(): ParseNode = parseArgList( - aliasSupportType = NONE, - mode = NORMAL_ARG_LIST + aliasSupportType = AliasSupportType.NONE, + mode = ArgListMode.NORMAL_ARG_LIST ).copy( - type = LIST - ).deriveExpected(RIGHT_BRACKET) + type = ParseType.LIST + ).deriveExpected(TokenType.RIGHT_BRACKET) private fun List.parseBagLiteral(): ParseNode = parseArgList( - aliasSupportType = NONE, - mode = NORMAL_ARG_LIST + aliasSupportType = AliasSupportType.NONE, + mode = ArgListMode.NORMAL_ARG_LIST ).copy( - type = BAG - ).deriveExpected(RIGHT_DOUBLE_ANGLE_BRACKET) + type = ParseType.BAG + ).deriveExpected(TokenType.RIGHT_DOUBLE_ANGLE_BRACKET) private fun List.parseStructLiteral(): ParseNode = parseArgList( - aliasSupportType = NONE, - mode = STRUCT_LITERAL_ARG_LIST + aliasSupportType = AliasSupportType.NONE, + mode = ArgListMode.STRUCT_LITERAL_ARG_LIST ).copy( - type = STRUCT - ).deriveExpected(RIGHT_CURLY) + type = ParseType.STRUCT + ).deriveExpected(TokenType.RIGHT_CURLY) private fun List.parseTableValues(): ParseNode = parseCommaList { var rem = this - if (rem.head?.type != LEFT_PAREN) { - err("Expected $LEFT_PAREN for row value constructor", PARSE_EXPECTED_LEFT_PAREN_VALUE_CONSTRUCTOR) + if (rem.head?.type != TokenType.LEFT_PAREN) { + err("Expected ${TokenType.LEFT_PAREN} for row value constructor", + ErrorCode.PARSE_EXPECTED_LEFT_PAREN_VALUE_CONSTRUCTOR) } rem = rem.tail rem.parseArgList( - aliasSupportType = NONE, - mode = NORMAL_ARG_LIST + aliasSupportType = AliasSupportType.NONE, + mode = ArgListMode.NORMAL_ARG_LIST ).copy( - type = LIST - ).deriveExpected(RIGHT_PAREN) + type = ParseType.LIST + ).deriveExpected(TokenType.RIGHT_PAREN) } private val parseCommaDelim: List.() -> ParseNode? = { when (head?.type) { - COMMA -> atomFromHead() + TokenType.COMMA -> atomFromHead() else -> null } } private val parseJoinDelim: List.() -> ParseNode? = { when (head?.type) { - COMMA -> atomFromHead(INNER_JOIN) - KEYWORD -> when (head?.keywordText) { - "join", "cross_join", "inner_join" -> atomFromHead(INNER_JOIN) - "left_join", "left_cross_join" -> atomFromHead(LEFT_JOIN) - "right_join", "right_cross_join" -> atomFromHead(RIGHT_JOIN) - "outer_join", "outer_cross_join" -> atomFromHead(OUTER_JOIN) + TokenType.COMMA -> atomFromHead(ParseType.INNER_JOIN) + TokenType.KEYWORD -> when (head?.keywordText) { + "join", "cross_join", "inner_join" -> atomFromHead(ParseType.INNER_JOIN) + "left_join", "left_cross_join" -> atomFromHead(ParseType.LEFT_JOIN) + "right_join", "right_cross_join" -> atomFromHead(ParseType.RIGHT_JOIN) + "outer_join", "outer_cross_join" -> atomFromHead(ParseType.OUTER_JOIN) else -> null } else -> null @@ -2725,16 +2786,16 @@ class SqlParser( rem = child.remaining when (rem.head?.type) { - ASC, DESC -> { + TokenType.ASC, TokenType.DESC -> { sortSpecKey = listOf(child, ParseNode( - type = ORDERING_SPEC, + type = ParseType.ORDERING_SPEC, token = rem.head, children = listOf(), remaining = rem.tail)) rem = rem.tail } } - ParseNode(type = SORT_SPEC, token = null, children = sortSpecKey, remaining = rem) + ParseNode(type = ParseType.SORT_SPEC, token = null, children = sortSpecKey, remaining = rem) } } @@ -2744,20 +2805,19 @@ class SqlParser( "unpivot" -> { val actualChild = rem.tail.parseExpression(precedence) ParseNode( - UNPIVOT, + ParseType.UNPIVOT, rem.head, listOf(actualChild), actualChild.remaining ) } else -> { - val isSubqueryOrLiteral = rem.tail.head?.type == LITERAL || rem.tail.head?.keywordText == "select" - if (rem.head?.type == LEFT_PAREN && !isSubqueryOrLiteral) { + val isSubqueryOrLiteral = rem.tail.head?.type == TokenType.LITERAL || rem.tail.head?.keywordText == "select" + if (rem.head?.type == TokenType.LEFT_PAREN && !isSubqueryOrLiteral) { // Starts with a left paren and is not a subquery or literal, so parse as a from source rem = rem.tail - rem.parseFromSource(precedence).deriveExpected(RIGHT_PAREN) - } - else { + rem.parseFromSource(precedence).deriveExpected(TokenType.RIGHT_PAREN) + } else { rem.parseExpression(precedence) } } @@ -2782,7 +2842,7 @@ class SqlParser( if (parseRemaining) { while (delim?.type?.isJoin == true) { val isCrossJoin = delim.token?.keywordText?.contains("cross") ?: false - val hasOnClause = delim.token?.type == KEYWORD && !isCrossJoin + val hasOnClause = delim.token?.type == TokenType.KEYWORD && !isCrossJoin var children : List var joinToken : Token? = delim.token @@ -2790,15 +2850,15 @@ class SqlParser( if (hasOnClause) { // Explicit join - if (rem.head?.type == LEFT_PAREN) { + if (rem.head?.type == TokenType.LEFT_PAREN) { // Starts with a left paren. Could indicate subquery/literal or indicate higher precedence - val isSubqueryOrLiteral = rem.tail.head?.type == LITERAL || rem.tail.head?.keywordText == "select" + val isSubqueryOrLiteral = rem.tail.head?.type == TokenType.LITERAL || rem.tail.head?.keywordText == "select" val parenClause = rem.parseFromSource(precedence, parseRemaining = true) rem = parenClause.remaining // check for an ON-clause if (rem.head?.keywordText != "on") { - rem.err("Expected 'ON'", PARSE_MALFORMED_JOIN) + rem.err("Expected 'ON'", ErrorCode.PARSE_MALFORMED_JOIN) } val onClause = rem.tail.parseExpression(precedence) @@ -2820,7 +2880,7 @@ class SqlParser( // check for an ON-clause if (rem.head?.keywordText != "on") { - rem.err("Expected 'ON'", PARSE_MALFORMED_JOIN) + rem.err("Expected 'ON'", ErrorCode.PARSE_MALFORMED_JOIN) } val onClause = rem.tail.parseExpression(precedence) @@ -2836,14 +2896,14 @@ class SqlParser( val rightRef = rem.parseFromSource(precedence, parseRemaining = false) rem = rightRef.remaining children = listOf(left, rightRef) - if (delim.token?.type == COMMA) { + if (delim.token?.type == TokenType.COMMA) { joinToken = delim.token?.copy( - type = KEYWORD, + type = TokenType.KEYWORD, value = ion.newSymbol("cross_join") ) } } - left = ParseNode(FROM_SOURCE_JOIN, joinToken, children, rem) + left = ParseNode(ParseType.FROM_SOURCE_JOIN, joinToken, children, rem) delim = rem.parseJoinDelim() } return left @@ -2854,7 +2914,7 @@ class SqlParser( private fun List.parseFromSourceList(precedence: Int = -1): ParseNode { val child = this.parseFromSource(precedence) - return ParseNode(FROM_CLAUSE, null, listOf(child), child.remaining) + return ParseNode(ParseType.FROM_CLAUSE, null, listOf(child), child.remaining) } private fun List.parseArgList( @@ -2867,24 +2927,24 @@ class SqlParser( return parseDelimitedList(parseDelim) { delim -> var rem = this var child = when (mode) { - STRUCT_LITERAL_ARG_LIST -> { - val field = rem.parseExpression(precedence).deriveExpected(COLON) + ArgListMode.STRUCT_LITERAL_ARG_LIST -> { + val field = rem.parseExpression(precedence).deriveExpected(TokenType.COLON) rem = field.remaining val value = rem.parseExpression(precedence) - ParseNode(MEMBER, null, listOf(field, value), value.remaining) + ParseNode(ParseType.MEMBER, null, listOf(field, value), value.remaining) } - SIMPLE_PATH_ARG_LIST -> rem.parsePathTerm(PathMode.SIMPLE_PATH) - SET_CLAUSE_ARG_LIST -> { + ArgListMode.SIMPLE_PATH_ARG_LIST -> rem.parsePathTerm(PathMode.SIMPLE_PATH) + ArgListMode.SET_CLAUSE_ARG_LIST -> { val lvalue = rem.parsePathTerm(PathMode.SIMPLE_PATH) rem = lvalue.remaining if (rem.head?.keywordText != "=") { - rem.err("Expected '='", PARSE_MISSING_SET_ASSIGNMENT) + rem.err("Expected '='", ErrorCode.PARSE_MISSING_SET_ASSIGNMENT) } rem = rem.tail val rvalue = rem.parseExpression(precedence) - ParseNode(ASSIGNMENT, null, listOf(lvalue, rvalue), rvalue.remaining) + ParseNode(ParseType.ASSIGNMENT, null, listOf(lvalue, rvalue), rvalue.remaining) } - NORMAL_ARG_LIST -> rem.parseExpression(precedence) + ArgListMode.NORMAL_ARG_LIST -> rem.parseExpression(precedence) } rem = child.remaining @@ -2928,7 +2988,8 @@ class SqlParser( rem = rem.tail val name = rem.head if (rem.head?.type?.isIdentifier() != true) { - rem.head.err("Expected identifier for $keywordTokenType-alias", PARSE_EXPECTED_IDENT_FOR_ALIAS) + rem.head.err("Expected identifier for $keywordTokenType-alias", + ErrorCode.PARSE_EXPECTED_IDENT_FOR_ALIAS) } rem = rem.tail ParseNode(parseNodeType, name, listOf(child), rem) @@ -2942,13 +3003,13 @@ class SqlParser( } private fun List.parseOptionalAsAlias(child: ParseNode) = - parseOptionalAlias(child = child, keywordTokenType = AS, keywordIsOptional = true, parseNodeType = AS_ALIAS) + parseOptionalAlias(child = child, keywordTokenType = TokenType.AS, keywordIsOptional = true, parseNodeType = ParseType.AS_ALIAS) private fun List.parseOptionalAtAlias(child: ParseNode) = - parseOptionalAlias(child = child, keywordTokenType = AT, keywordIsOptional = false, parseNodeType = AT_ALIAS) + parseOptionalAlias(child = child, keywordTokenType = TokenType.AT, keywordIsOptional = false, parseNodeType = ParseType.AT_ALIAS) private fun List.parseOptionalByAlias(child: ParseNode) = - parseOptionalAlias(child = child, keywordTokenType = BY, keywordIsOptional = false, parseNodeType = BY_ALIAS) + parseOptionalAlias(child = child, keywordTokenType = TokenType.BY, keywordIsOptional = false, parseNodeType = ParseType.BY_ALIAS) private inline fun List.parseCommaList(parseItem: List.() -> ParseNode) = parseDelimitedList(parseCommaDelim) { parseItem() } @@ -2982,12 +3043,13 @@ class SqlParser( rem = delim.remaining } - return ParseNode(ARG_LIST, null, items, rem) + return ParseNode(ParseType.ARG_LIST, null, items, rem) } private fun ParseNode.throwTopLevelParserError(): Nothing = - token?.err("Keyword ${token.text} only expected at the top level in the query", PARSE_UNEXPECTED_TERM) - ?: throw ParserException("Keyword ${token?.text} only expected at the top level in the query", PARSE_UNEXPECTED_TERM, PropertyValueMap()) + token?.err("Keyword ${token.text} only expected at the top level in the query", ErrorCode.PARSE_UNEXPECTED_TERM) + ?: throw ParserException("Keyword ${token?.text} only expected at the top level in the query", + ErrorCode.PARSE_UNEXPECTED_TERM, PropertyValueMap()) /** * Validates tree to make sure that the top level tokens are not found below the top level. @@ -3026,7 +3088,7 @@ class SqlParser( node = it, level = level + 1, topLevelTokenSeen = topLevelTokenSeen || isTopLevelType, - dmlListTokenSeen = dmlListTokenSeen || node.type == DML_LIST + dmlListTokenSeen = dmlListTokenSeen || node.type == ParseType.DML_LIST ) } } @@ -3046,9 +3108,9 @@ class SqlParser( val rem = node.remaining if (!rem.onlyEndOfStatement()) { when (rem.head?.type) { - SEMICOLON -> rem.tail.err("Unexpected token after semicolon. (Only one query is allowed.)", - PARSE_UNEXPECTED_TOKEN) - else -> rem.err("Unexpected token after expression", PARSE_UNEXPECTED_TOKEN) + TokenType.SEMICOLON -> rem.tail.err("Unexpected token after semicolon. (Only one query is allowed.)", + ErrorCode.PARSE_UNEXPECTED_TOKEN) + else -> rem.err("Unexpected token after expression", ErrorCode.PARSE_UNEXPECTED_TOKEN) } } diff --git a/lang/src/org/partiql/lang/syntax/Token.kt b/lang/src/org/partiql/lang/syntax/Token.kt index e0d094ed4d..3f88e80bb0 100644 --- a/lang/src/org/partiql/lang/syntax/Token.kt +++ b/lang/src/org/partiql/lang/syntax/Token.kt @@ -15,8 +15,7 @@ package org.partiql.lang.syntax import com.amazon.ion.IonValue -import org.partiql.lang.util.* -import org.partiql.lang.syntax.TokenType.* +import org.partiql.lang.util.stringValue /** * Simple [IonValue] based token for lexing PartiQL. @@ -29,28 +28,28 @@ data class Token(val type: TokenType, val keywordText: String? get() = when (type) { - OPERATOR, KEYWORD, AS, AT -> text - MISSING -> "missing" - NULL -> "null" + TokenType.OPERATOR, TokenType.KEYWORD, TokenType.AS, TokenType.AT -> text + TokenType.MISSING -> "missing" + TokenType.NULL -> "null" else -> null } val isSpecialOperator: Boolean get() = when (type) { - OPERATOR -> text in SPECIAL_OPERATORS + TokenType.OPERATOR -> text in SPECIAL_OPERATORS else -> false } val isBinaryOperator: Boolean get() = when (type) { - OPERATOR, KEYWORD -> text in BINARY_OPERATORS - STAR -> true + TokenType.OPERATOR, TokenType.KEYWORD -> text in BINARY_OPERATORS + TokenType.STAR -> true else -> false } val isUnaryOperator: Boolean get() = when (type){ - OPERATOR, KEYWORD -> text in UNARY_OPERATORS + TokenType.OPERATOR, TokenType.KEYWORD -> text in UNARY_OPERATORS else -> false } diff --git a/lang/src/org/partiql/lang/util/BindingHelpers.kt b/lang/src/org/partiql/lang/util/BindingHelpers.kt index e94f3a607b..1809088941 100644 --- a/lang/src/org/partiql/lang/util/BindingHelpers.kt +++ b/lang/src/org/partiql/lang/util/BindingHelpers.kt @@ -14,9 +14,10 @@ package org.partiql.lang.util -import com.amazon.ion.* -import org.partiql.lang.errors.* -import org.partiql.lang.eval.* +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.eval.BindingCase +import org.partiql.lang.eval.err internal fun errAmbiguousBinding(bindingName: String, matchingNames: List): Nothing { err("Multiple matches were found for the specified identifier", diff --git a/lang/src/org/partiql/lang/util/CollectionExtensions.kt b/lang/src/org/partiql/lang/util/CollectionExtensions.kt index 305a1bb597..51c5b7aa65 100644 --- a/lang/src/org/partiql/lang/util/CollectionExtensions.kt +++ b/lang/src/org/partiql/lang/util/CollectionExtensions.kt @@ -14,10 +14,9 @@ package org.partiql.lang.util -import com.amazon.ion.* -import org.partiql.lang.eval.* -import java.util.* -import java.util.Collections.* +import org.partiql.lang.eval.ExprValue +import org.partiql.lang.eval.ExprValueType +import org.partiql.lang.eval.isUnknown /** Returns the first element of the list or `null` if it doesn't exist. */ inline val List.head: T? diff --git a/lang/src/org/partiql/lang/util/ExprValueFormatter.kt b/lang/src/org/partiql/lang/util/ExprValueFormatter.kt index 4a3c76f99a..32e42d15bb 100644 --- a/lang/src/org/partiql/lang/util/ExprValueFormatter.kt +++ b/lang/src/org/partiql/lang/util/ExprValueFormatter.kt @@ -1,12 +1,9 @@ package org.partiql.lang.util -import com.amazon.ion.system.* -import org.partiql.lang.eval.* -import org.partiql.lang.eval.ExprValueType.* -import java.lang.StringBuilder -import java.time.LocalTime -import java.time.OffsetTime -import java.time.format.DateTimeFormatter +import com.amazon.ion.system.IonTextWriterBuilder +import org.partiql.lang.eval.ExprValue +import org.partiql.lang.eval.ExprValueType +import org.partiql.lang.eval.name private const val MISSING_STRING = "MISSING" private const val NULL_STRING = "NULL" @@ -41,34 +38,28 @@ class ConfigurableExprValueFormatter(private val config: Configuration) : ExprVa fun recursivePrettyPrint(value: ExprValue) { when (value.type) { - MISSING -> out.append(MISSING_STRING) - NULL -> out.append(NULL_STRING) - - BOOL -> out.append(value.scalar.booleanValue().toString()) - - INT, DECIMAL -> out.append(value.scalar.numberValue().toString()) - - STRING -> out.append("'${value.scalar.stringValue()}'") - - DATE -> out.append(value.scalar.dateValue().toString()) - - TIME -> out.append(value.scalar.timeValue().toString()) + ExprValueType.MISSING -> out.append(MISSING_STRING) + ExprValueType.NULL -> out.append(NULL_STRING) + ExprValueType.BOOL -> out.append(value.scalar.booleanValue().toString()) + ExprValueType.INT, ExprValueType.DECIMAL -> out.append(value.scalar.numberValue().toString()) + ExprValueType.STRING -> out.append("'${value.scalar.stringValue()}'") + ExprValueType.DATE -> out.append(value.scalar.dateValue().toString()) + ExprValueType.TIME -> out.append(value.scalar.timeValue().toString()) // fallback to an Ion literal for all types that don't have a native PartiQL representation - FLOAT, TIMESTAMP, SYMBOL, CLOB, BLOB, SEXP -> prettyPrintIonLiteral(value) + ExprValueType.FLOAT, ExprValueType.TIMESTAMP, ExprValueType.SYMBOL, + ExprValueType.CLOB,ExprValueType. BLOB, ExprValueType.SEXP -> prettyPrintIonLiteral(value) - LIST -> prettyPrintContainer(value, "[", "]") - BAG -> prettyPrintContainer(value, "<<", ">>") - STRUCT -> prettyPrintContainer(value, "{", "}") { v -> + ExprValueType.LIST -> prettyPrintContainer(value, "[", "]") + ExprValueType.BAG -> prettyPrintContainer(value, "<<", ">>") + ExprValueType.STRUCT -> prettyPrintContainer(value, "{", "}") { v -> val fieldName = v.name!!.scalar.stringValue() out.append("'$fieldName': ") - recursivePrettyPrint(v) } } } - private fun prettyPrintContainer(value: ExprValue, openingMarker: String, closingMarker: String, diff --git a/lang/src/org/partiql/lang/util/IonValueExtensions.kt b/lang/src/org/partiql/lang/util/IonValueExtensions.kt index d5cb6f1152..ed6e0a7076 100644 --- a/lang/src/org/partiql/lang/util/IonValueExtensions.kt +++ b/lang/src/org/partiql/lang/util/IonValueExtensions.kt @@ -14,9 +14,27 @@ package org.partiql.lang.util -import com.amazon.ion.* -import org.partiql.lang.eval.* -import java.math.* +import com.amazon.ion.IntegerSize +import com.amazon.ion.IonBool +import com.amazon.ion.IonContainer +import com.amazon.ion.IonDecimal +import com.amazon.ion.IonFloat +import com.amazon.ion.IonInt +import com.amazon.ion.IonList +import com.amazon.ion.IonLob +import com.amazon.ion.IonNull +import com.amazon.ion.IonSequence +import com.amazon.ion.IonSexp +import com.amazon.ion.IonStruct +import com.amazon.ion.IonSymbol +import com.amazon.ion.IonText +import com.amazon.ion.IonTimestamp +import com.amazon.ion.IonValue +import com.amazon.ion.Timestamp +import org.partiql.lang.eval.BAG_ANNOTATION +import org.partiql.lang.eval.MISSING_ANNOTATION +import java.math.BigDecimal +import java.math.BigInteger @JvmName("IonValueUtils") @@ -65,7 +83,7 @@ fun IonValue.numberValue(): Number = when { isNullValue -> err("Expected non-null number: $this") else -> when (this) { is IonInt -> javaValue() - is IonFloat -> doubleValue() + is IonFloat -> doubleValue() is IonDecimal -> decimalValue() else -> err("Expected number: $this") } diff --git a/lang/src/org/partiql/lang/util/IonWriterContext.kt b/lang/src/org/partiql/lang/util/IonWriterContext.kt index f59aa664da..8ef8cc988b 100644 --- a/lang/src/org/partiql/lang/util/IonWriterContext.kt +++ b/lang/src/org/partiql/lang/util/IonWriterContext.kt @@ -14,7 +14,9 @@ package org.partiql.lang.util -import com.amazon.ion.* +import com.amazon.ion.IonType +import com.amazon.ion.IonValue +import com.amazon.ion.IonWriter /** * A simple wrapper for writing Ion from Kotlin. diff --git a/lang/src/org/partiql/lang/util/LongExtensions.kt b/lang/src/org/partiql/lang/util/LongExtensions.kt index f3424a695d..99aba18189 100644 --- a/lang/src/org/partiql/lang/util/LongExtensions.kt +++ b/lang/src/org/partiql/lang/util/LongExtensions.kt @@ -1,7 +1,5 @@ package org.partiql.lang.util -import java.lang.IllegalStateException - /** * Converts [this] [Long] to a [Int], throwing an exception in case the value is outside the range of an [Int]. * diff --git a/lang/src/org/partiql/lang/util/NumberExtensions.kt b/lang/src/org/partiql/lang/util/NumberExtensions.kt index a858f14a5e..3c1c8e8587 100644 --- a/lang/src/org/partiql/lang/util/NumberExtensions.kt +++ b/lang/src/org/partiql/lang/util/NumberExtensions.kt @@ -14,9 +14,14 @@ package org.partiql.lang.util -import com.amazon.ion.* -import org.partiql.lang.eval.* -import java.math.* +import com.amazon.ion.Decimal +import com.amazon.ion.IonSystem +import com.amazon.ion.IonValue +import org.partiql.lang.eval.errIntOverflow +import java.math.BigDecimal +import java.math.BigInteger +import java.math.MathContext +import java.math.RoundingMode private val MATH_CONTEXT = MathContext(38, RoundingMode.HALF_EVEN) // TODO should this be configurable? @@ -25,7 +30,7 @@ private val MATH_CONTEXT = MathContext(38, RoundingMode.HALF_EVEN) // TODO shoul * and factory methods */ internal fun bigDecimalOf(num: Number, mc: MathContext = MATH_CONTEXT): BigDecimal = when (num) { - is Decimal -> num + is Decimal -> num is Int -> BigDecimal(num, mc) is Long -> BigDecimal(num, mc) is Double -> BigDecimal(num, mc) diff --git a/lang/src/org/partiql/lang/util/PropertyMapHelpers.kt b/lang/src/org/partiql/lang/util/PropertyMapHelpers.kt index b0c999b856..79eb783633 100644 --- a/lang/src/org/partiql/lang/util/PropertyMapHelpers.kt +++ b/lang/src/org/partiql/lang/util/PropertyMapHelpers.kt @@ -14,9 +14,10 @@ package org.partiql.lang.util -import com.amazon.ion.* -import org.partiql.lang.errors.* -import org.partiql.lang.syntax.* +import com.amazon.ion.IonValue +import org.partiql.lang.errors.Property +import org.partiql.lang.errors.PropertyValueMap +import org.partiql.lang.syntax.TokenType /** * Helper function to reduce the syntactical overhead of creating a [PropertyValueMap]. @@ -30,7 +31,7 @@ fun propertyValueMapOf(vararg properties: Pair): PropertyValueMap is Long -> pvm[it.first] = it.second as Long is String -> pvm[it.first] = it.second as String is TokenType -> pvm[it.first] = it.second as TokenType - is IonValue -> pvm[it.first] = it.second as IonValue + is IonValue -> pvm[it.first] = it.second as IonValue is Enum<*> -> pvm[it.first] = it.second.toString() else -> throw IllegalArgumentException("Cannot convert ${it.second.javaClass.name} to PropertyValue") } diff --git a/lang/src/org/partiql/lang/util/TokenListExtensions.kt b/lang/src/org/partiql/lang/util/TokenListExtensions.kt index 56e2672298..b9ddd1664a 100644 --- a/lang/src/org/partiql/lang/util/TokenListExtensions.kt +++ b/lang/src/org/partiql/lang/util/TokenListExtensions.kt @@ -17,7 +17,11 @@ package org.partiql.lang.util import org.partiql.lang.errors.ErrorCode import org.partiql.lang.errors.Property import org.partiql.lang.errors.PropertyValueMap -import org.partiql.lang.syntax.* +import org.partiql.lang.syntax.ParserException +import org.partiql.lang.syntax.SourceSpan +import org.partiql.lang.syntax.SqlParser +import org.partiql.lang.syntax.Token +import org.partiql.lang.syntax.TokenType /** * Predicate to check if the list of [Token]'s only contains a end of statement with diff --git a/lang/test/org/partiql/lang/TestBase.kt b/lang/test/org/partiql/lang/TestBase.kt index b39adca5e0..c910604711 100644 --- a/lang/test/org/partiql/lang/TestBase.kt +++ b/lang/test/org/partiql/lang/TestBase.kt @@ -14,22 +14,35 @@ package org.partiql.lang -import com.amazon.ion.* +import com.amazon.ion.Decimal +import com.amazon.ion.IonSystem +import com.amazon.ion.IonValue +import com.amazon.ion.Timestamp import com.amazon.ion.system.IonSystemBuilder -import org.assertj.core.api.* -import org.partiql.lang.ast.* -import org.partiql.lang.eval.* -import org.partiql.lang.errors.* -import org.partiql.lang.util.* import org.junit.Assert import org.junit.runner.RunWith -import java.util.* import junitparams.JUnitParamsRunner +import org.assertj.core.api.SoftAssertions +import org.partiql.lang.ast.ExprNode import org.partiql.lang.ast.passes.AstRewriterBase +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.errors.PropertyType +import org.partiql.lang.errors.PropertyValue +import org.partiql.lang.errors.PropertyValueMap +import org.partiql.lang.eval.BindingCase +import org.partiql.lang.eval.BindingName +import org.partiql.lang.eval.Bindings +import org.partiql.lang.eval.EvaluationException +import org.partiql.lang.eval.ExprValue +import org.partiql.lang.eval.ExprValueFactory +import org.partiql.lang.eval.cloneAndRemoveAnnotations import org.partiql.lang.eval.time.Time +import org.partiql.lang.util.SexpAstPrettyPrinter +import org.partiql.lang.util.softAssert import java.math.BigDecimal import java.time.LocalDate -import kotlin.reflect.* +import kotlin.reflect.KClass /** * Validates [errorCode] and [expectedValues] for given exception [ex]. diff --git a/lang/test/org/partiql/lang/ast/AstNodeTest.kt b/lang/test/org/partiql/lang/ast/AstNodeTest.kt index b9149e72fa..42717286b1 100644 --- a/lang/test/org/partiql/lang/ast/AstNodeTest.kt +++ b/lang/test/org/partiql/lang/ast/AstNodeTest.kt @@ -1,12 +1,14 @@ package org.partiql.lang.ast -import com.amazon.ion.* -import com.amazon.ion.system.* -import junitparams.* -import org.junit.* -import org.junit.Assert.* -import org.junit.runner.* -import org.partiql.lang.syntax.* +import com.amazon.ion.IonSystem +import com.amazon.ion.system.IonSystemBuilder +import junitparams.JUnitParamsRunner +import junitparams.Parameters +import org.junit.Assert.assertTrue +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.partiql.lang.syntax.SqlParser // TODO: add tests for DDL & DML ExprNodes. diff --git a/lang/test/org/partiql/lang/ast/AstSerDeTests.kt b/lang/test/org/partiql/lang/ast/AstSerDeTests.kt index 192f05ec45..9c47b3fca1 100644 --- a/lang/test/org/partiql/lang/ast/AstSerDeTests.kt +++ b/lang/test/org/partiql/lang/ast/AstSerDeTests.kt @@ -14,9 +14,9 @@ package org.partiql.lang.ast -import org.partiql.lang.* -import junitparams.* -import org.junit.* +import junitparams.Parameters +import org.junit.Test +import org.partiql.lang.TestBase /** * This class contains tests for (de)serialization of metas. diff --git a/lang/test/org/partiql/lang/ast/IsIonLiteralMetaTest.kt b/lang/test/org/partiql/lang/ast/IsIonLiteralMetaTest.kt index a6cf04235c..5277a7ced7 100644 --- a/lang/test/org/partiql/lang/ast/IsIonLiteralMetaTest.kt +++ b/lang/test/org/partiql/lang/ast/IsIonLiteralMetaTest.kt @@ -14,8 +14,9 @@ package org.partiql.lang.ast * language governing permissions and limitations under the License. */ -import com.amazon.ion.system.* -import org.junit.* +import com.amazon.ion.system.IonSystemBuilder +import org.junit.Assert +import org.junit.Test import org.partiql.lang.syntax.SqlParser class IsIonLiteralMetaTest { diff --git a/lang/test/org/partiql/lang/ast/PathComponentExprTest.kt b/lang/test/org/partiql/lang/ast/PathComponentExprTest.kt index 7eaab78211..05a5f4ae1f 100644 --- a/lang/test/org/partiql/lang/ast/PathComponentExprTest.kt +++ b/lang/test/org/partiql/lang/ast/PathComponentExprTest.kt @@ -14,12 +14,16 @@ package org.partiql.lang.ast -import com.amazon.ion.* -import com.amazon.ion.system.* -import junitparams.* +import com.amazon.ion.IonSystem +import com.amazon.ion.system.IonSystemBuilder +import junitparams.JUnitParamsRunner +import junitparams.Parameters import org.junit.Test -import org.junit.runner.* -import kotlin.test.* +import org.junit.runner.RunWith +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNotEquals +import kotlin.test.assertTrue @RunWith(JUnitParamsRunner::class) class PathComponentExprTest { diff --git a/lang/test/org/partiql/lang/ast/SourceLocationMetaTest.kt b/lang/test/org/partiql/lang/ast/SourceLocationMetaTest.kt index f82c63bff7..16cb03dc1b 100644 --- a/lang/test/org/partiql/lang/ast/SourceLocationMetaTest.kt +++ b/lang/test/org/partiql/lang/ast/SourceLocationMetaTest.kt @@ -14,10 +14,9 @@ package org.partiql.lang.ast -import com.amazon.ion.system.* -import org.junit.* +import com.amazon.ion.system.IonSystemBuilder import org.junit.Test -import kotlin.test.* +import kotlin.test.assertEquals class SourceLocationMetaTest { @Test diff --git a/lang/test/org/partiql/lang/ast/VariableReferenceTest.kt b/lang/test/org/partiql/lang/ast/VariableReferenceTest.kt index 2b9722c9e6..379608a502 100644 --- a/lang/test/org/partiql/lang/ast/VariableReferenceTest.kt +++ b/lang/test/org/partiql/lang/ast/VariableReferenceTest.kt @@ -14,9 +14,9 @@ package org.partiql.lang.ast -import org.junit.* +import org.junit.Assert import org.junit.Test -import kotlin.test.* +import kotlin.test.assertEquals class VariableReferenceTest { diff --git a/lang/test/org/partiql/lang/ast/passes/AstWalkerTests.kt b/lang/test/org/partiql/lang/ast/passes/AstWalkerTests.kt index 3fd10efe9b..3fb11fffed 100644 --- a/lang/test/org/partiql/lang/ast/passes/AstWalkerTests.kt +++ b/lang/test/org/partiql/lang/ast/passes/AstWalkerTests.kt @@ -14,14 +14,21 @@ package org.partiql.lang.ast.passes -import com.amazon.ion.system.* -import org.partiql.lang.ast.* -import org.partiql.lang.syntax.* -import junitparams.* -import org.junit.* +import com.amazon.ion.system.IonSystemBuilder + +import junitparams.JUnitParamsRunner +import junitparams.Parameters import org.junit.Test -import org.junit.runner.* -import kotlin.test.* +import org.junit.runner.RunWith +import org.partiql.lang.ast.DataManipulationOperation +import org.partiql.lang.ast.DataType +import org.partiql.lang.ast.ExprNode +import org.partiql.lang.ast.FromSource +import org.partiql.lang.ast.PathComponent +import org.partiql.lang.ast.SelectListItem +import org.partiql.lang.ast.SelectProjection +import org.partiql.lang.syntax.SqlParser +import kotlin.test.assertEquals /** * [AstWalker] simply traverses each node in the [ExprNode] instance but performs no transformations. diff --git a/lang/test/org/partiql/lang/ast/passes/RewriterTestBase.kt b/lang/test/org/partiql/lang/ast/passes/RewriterTestBase.kt index 851f591426..313d251204 100644 --- a/lang/test/org/partiql/lang/ast/passes/RewriterTestBase.kt +++ b/lang/test/org/partiql/lang/ast/passes/RewriterTestBase.kt @@ -14,8 +14,7 @@ package org.partiql.lang.ast.passes -import org.partiql.lang.syntax.* - +import org.partiql.lang.syntax.SqlParserTestBase @Deprecated("New rewriters should implement PIG's PartiqlAst.VisitorTransform and use VisitorTransformTestBase to test") abstract class RewriterTestBase : SqlParserTestBase() { diff --git a/lang/test/org/partiql/lang/errors/LexerErrorsTest.kt b/lang/test/org/partiql/lang/errors/LexerErrorsTest.kt index 577af1f9df..310884570f 100644 --- a/lang/test/org/partiql/lang/errors/LexerErrorsTest.kt +++ b/lang/test/org/partiql/lang/errors/LexerErrorsTest.kt @@ -14,10 +14,12 @@ package org.partiql.lang.errors -import org.partiql.lang.* -import org.partiql.lang.syntax.* -import org.partiql.lang.util.* import org.junit.Test +import org.partiql.lang.TestBase +import org.partiql.lang.checkErrorAndErrorContext +import org.partiql.lang.syntax.LexerException +import org.partiql.lang.syntax.SqlLexer +import org.partiql.lang.util.softAssert class LexerErrorsTest : TestBase() { diff --git a/lang/test/org/partiql/lang/errors/ParserErrorsTest.kt b/lang/test/org/partiql/lang/errors/ParserErrorsTest.kt index ad94e7b880..97849acf33 100644 --- a/lang/test/org/partiql/lang/errors/ParserErrorsTest.kt +++ b/lang/test/org/partiql/lang/errors/ParserErrorsTest.kt @@ -14,10 +14,11 @@ package org.partiql.lang.errors import com.amazon.ion.Timestamp +import org.junit.Ignore import org.partiql.lang.syntax.TokenType -import org.partiql.lang.util.* -import org.junit.* +import org.junit.Test import org.partiql.lang.syntax.SqlParserTestBase +import org.partiql.lang.util.sourceLocationProperties class ParserErrorsTest : SqlParserTestBase() { diff --git a/lang/test/org/partiql/lang/errors/PropertyValueMapTest.kt b/lang/test/org/partiql/lang/errors/PropertyValueMapTest.kt index 073a8fbf8d..274a1d475a 100644 --- a/lang/test/org/partiql/lang/errors/PropertyValueMapTest.kt +++ b/lang/test/org/partiql/lang/errors/PropertyValueMapTest.kt @@ -14,11 +14,10 @@ package org.partiql.lang.errors -import org.partiql.lang.* -import org.partiql.lang.errors.Property.* import org.partiql.lang.syntax.TokenType import org.junit.Before import org.junit.Test +import org.partiql.lang.TestBase class PropertyValueMapTest : TestBase() { @@ -29,29 +28,29 @@ class PropertyValueMapTest : TestBase() { @Before fun setUp() { - onlyColumnValueMap[COLUMN_NUMBER] = 11L - oneOfEachType[EXPECTED_TOKEN_TYPE] = TokenType.COMMA - oneOfEachType[KEYWORD] = "test" - oneOfEachType[EXPECTED_ARITY_MAX] = 1 - oneOfEachType[TOKEN_VALUE] = ion.newEmptyList() - oneOfEachType[COLUMN_NUMBER] = 11L + onlyColumnValueMap[Property.COLUMN_NUMBER] = 11L + oneOfEachType[Property.EXPECTED_TOKEN_TYPE] = TokenType.COMMA + oneOfEachType[Property.KEYWORD] = "test" + oneOfEachType[Property.EXPECTED_ARITY_MAX] = 1 + oneOfEachType[Property.TOKEN_VALUE] = ion.newEmptyList() + oneOfEachType[Property.COLUMN_NUMBER] = 11L } @Test fun getPropFromEmptyBag() { - assertNull(emptyValueMap[LINE_NUMBER]) + assertNull(emptyValueMap[Property.LINE_NUMBER]) } @Test fun getAbsentPropFromNonEmptyBag() { - assertNull(onlyColumnValueMap[LINE_NUMBER]) + assertNull(onlyColumnValueMap[Property.LINE_NUMBER]) } @Test fun getValues() { - assertEquals(11L, oneOfEachType[COLUMN_NUMBER]?.longValue()) - assertEquals(TokenType.COMMA, oneOfEachType[EXPECTED_TOKEN_TYPE]?.tokenTypeValue()) - assertEquals("test", oneOfEachType[KEYWORD]?.stringValue()) - assertEquals(1, oneOfEachType[EXPECTED_ARITY_MAX]?.integerValue()) - assertEquals(11L, oneOfEachType[COLUMN_NUMBER]?.longValue()) + assertEquals(11L, oneOfEachType[Property.COLUMN_NUMBER]?.longValue()) + assertEquals(TokenType.COMMA, oneOfEachType[Property.EXPECTED_TOKEN_TYPE]?.tokenTypeValue()) + assertEquals("test", oneOfEachType[Property.KEYWORD]?.stringValue()) + assertEquals(1, oneOfEachType[Property.EXPECTED_ARITY_MAX]?.integerValue()) + assertEquals(11L, oneOfEachType[Property.COLUMN_NUMBER]?.longValue()) } } \ No newline at end of file diff --git a/lang/test/org/partiql/lang/errors/SqlExceptionTest.kt b/lang/test/org/partiql/lang/errors/SqlExceptionTest.kt index 729c227d4a..bb449303a3 100644 --- a/lang/test/org/partiql/lang/errors/SqlExceptionTest.kt +++ b/lang/test/org/partiql/lang/errors/SqlExceptionTest.kt @@ -14,10 +14,9 @@ package org.partiql.lang.errors -import org.partiql.lang.* -import org.partiql.lang.errors.Property.* import org.junit.Test - +import org.partiql.lang.SqlException +import org.partiql.lang.TestBase class SqlExceptionTest : TestBase() { @@ -33,9 +32,9 @@ class SqlExceptionTest : TestBase() { @Test fun noErrorMessageErrorCodeContext() { val errorContext = PropertyValueMap() - errorContext[COLUMN_NUMBER] = 10L - errorContext[LINE_NUMBER] = 20L - errorContext[TOKEN_STRING] = "c" + errorContext[Property.COLUMN_NUMBER] = 10L + errorContext[Property.LINE_NUMBER] = 20L + errorContext[Property.TOKEN_STRING] = "c" val ex = SqlException(ErrorCode.LEXER_INVALID_CHAR, errorContext) @@ -45,9 +44,9 @@ class SqlExceptionTest : TestBase() { @Test fun customErrorMessageErrorCodeContext() { val errorContext = PropertyValueMap() - errorContext[COLUMN_NUMBER] = 10L - errorContext[LINE_NUMBER] = 20L - errorContext[TOKEN_STRING] = "c" + errorContext[Property.COLUMN_NUMBER] = 10L + errorContext[Property.LINE_NUMBER] = 20L + errorContext[Property.TOKEN_STRING] = "c" val ex = SqlException("Unexpected token", ErrorCode.LEXER_INVALID_CHAR, errorContext) @@ -57,9 +56,9 @@ class SqlExceptionTest : TestBase() { @Test fun toStringDoesNotAccumulateMessageText() { val errorContext = PropertyValueMap() - errorContext[COLUMN_NUMBER] = 10L - errorContext[LINE_NUMBER] = 20L - errorContext[TOKEN_STRING] = "c" + errorContext[Property.COLUMN_NUMBER] = 10L + errorContext[Property.LINE_NUMBER] = 20L + errorContext[Property.TOKEN_STRING] = "c" val ex = SqlException("Unexpected token", ErrorCode.LEXER_INVALID_CHAR, errorContext) diff --git a/lang/test/org/partiql/lang/eval/BindingsTest.kt b/lang/test/org/partiql/lang/eval/BindingsTest.kt index d1455b61b6..9fbd84bdea 100644 --- a/lang/test/org/partiql/lang/eval/BindingsTest.kt +++ b/lang/test/org/partiql/lang/eval/BindingsTest.kt @@ -14,10 +14,10 @@ package org.partiql.lang.eval -import org.junit.* -import org.partiql.lang.* -import org.partiql.lang.errors.* -import org.partiql.lang.util.* +import org.junit.Test +import org.partiql.lang.TestBase +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.util.newFromIonText class BindingsTest : TestBase() { diff --git a/lang/test/org/partiql/lang/eval/CompileOptionsTest.kt b/lang/test/org/partiql/lang/eval/CompileOptionsTest.kt index 3fc7776491..70c5f5a93c 100644 --- a/lang/test/org/partiql/lang/eval/CompileOptionsTest.kt +++ b/lang/test/org/partiql/lang/eval/CompileOptionsTest.kt @@ -14,8 +14,8 @@ package org.partiql.lang.eval -import org.junit.* -import org.junit.Assert.* +import org.junit.Assert.assertEquals +import org.junit.Test import java.time.ZoneOffset class CompileOptionsTest { diff --git a/lang/test/org/partiql/lang/eval/EvaluatingCompilerDateTimeTests.kt b/lang/test/org/partiql/lang/eval/EvaluatingCompilerDateTimeTests.kt index a90d41caeb..a700fd1aee 100644 --- a/lang/test/org/partiql/lang/eval/EvaluatingCompilerDateTimeTests.kt +++ b/lang/test/org/partiql/lang/eval/EvaluatingCompilerDateTimeTests.kt @@ -5,7 +5,10 @@ import com.amazon.ion.IonTimestamp import org.junit.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ArgumentsSource -import org.partiql.lang.eval.time.* +import org.partiql.lang.eval.time.MINUTES_PER_HOUR +import org.partiql.lang.eval.time.NANOS_PER_SECOND +import org.partiql.lang.eval.time.SECONDS_PER_MINUTE +import org.partiql.lang.eval.time.Time import org.partiql.lang.util.ArgumentsProviderBase import org.partiql.lang.util.getOffsetHHmm import java.math.RoundingMode diff --git a/lang/test/org/partiql/lang/eval/EvaluatingCompilerGroupByTest.kt b/lang/test/org/partiql/lang/eval/EvaluatingCompilerGroupByTest.kt index b5a26ce05b..0aa16257ad 100644 --- a/lang/test/org/partiql/lang/eval/EvaluatingCompilerGroupByTest.kt +++ b/lang/test/org/partiql/lang/eval/EvaluatingCompilerGroupByTest.kt @@ -14,10 +14,10 @@ package org.partiql.lang.eval -import org.partiql.lang.errors.* -import org.partiql.lang.util.* -import junitparams.* -import org.junit.* +import junitparams.Parameters +import org.junit.Test +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property class EvaluatingCompilerGroupByTest : EvaluatorTestBase() { diff --git a/lang/test/org/partiql/lang/eval/EvaluatingCompilerHavingTest.kt b/lang/test/org/partiql/lang/eval/EvaluatingCompilerHavingTest.kt index 4c0fe84424..61b34d98f3 100644 --- a/lang/test/org/partiql/lang/eval/EvaluatingCompilerHavingTest.kt +++ b/lang/test/org/partiql/lang/eval/EvaluatingCompilerHavingTest.kt @@ -14,9 +14,9 @@ package org.partiql.lang.eval -import org.partiql.lang.errors.* -import junitparams.* -import org.junit.* +import junitparams.Parameters +import org.junit.Test +import org.partiql.lang.errors.ErrorCode class EvaluatingCompilerHavingTest : EvaluatorTestBase() { val session = mapOf( diff --git a/lang/test/org/partiql/lang/eval/EvaluatingCompilerIntTest.kt b/lang/test/org/partiql/lang/eval/EvaluatingCompilerIntTest.kt index 5f900df272..e25c8a0eb9 100644 --- a/lang/test/org/partiql/lang/eval/EvaluatingCompilerIntTest.kt +++ b/lang/test/org/partiql/lang/eval/EvaluatingCompilerIntTest.kt @@ -14,10 +14,11 @@ package org.partiql.lang.eval -import junitparams.* -import org.junit.* -import java.math.* -import java.util.* +import junitparams.Parameters +import org.junit.BeforeClass +import org.junit.Test +import java.math.BigInteger +import java.util.Random /** diff --git a/lang/test/org/partiql/lang/eval/EvaluatingCompilerNAryTests.kt b/lang/test/org/partiql/lang/eval/EvaluatingCompilerNAryTests.kt index 883b5e5a6b..f7e123fa24 100644 --- a/lang/test/org/partiql/lang/eval/EvaluatingCompilerNAryTests.kt +++ b/lang/test/org/partiql/lang/eval/EvaluatingCompilerNAryTests.kt @@ -14,13 +14,16 @@ package org.partiql.lang.eval -import com.amazon.ion.* -import org.partiql.lang.ast.* -import junitparams.* -import org.junit.* -import org.junit.runner.* -import org.partiql.lang.* - +import com.amazon.ion.IonValue +import junitparams.JUnitParamsRunner +import junitparams.Parameters +import org.junit.Test +import org.junit.runner.RunWith +import org.partiql.lang.CompilerPipeline +import org.partiql.lang.ast.Literal +import org.partiql.lang.ast.NAry +import org.partiql.lang.ast.NAryOp +import org.partiql.lang.ast.metaContainerOf /** * This test class is needed to test certain types of [NAryOp] with an arity > 2. diff --git a/lang/test/org/partiql/lang/eval/EvaluationSessionTest.kt b/lang/test/org/partiql/lang/eval/EvaluationSessionTest.kt index 45aef5d888..5ea65e51ca 100644 --- a/lang/test/org/partiql/lang/eval/EvaluationSessionTest.kt +++ b/lang/test/org/partiql/lang/eval/EvaluationSessionTest.kt @@ -14,10 +14,10 @@ package org.partiql.lang.eval -import com.amazon.ion.* -import org.partiql.lang.util.* +import com.amazon.ion.Timestamp import org.junit.Test -import kotlin.test.* +import org.partiql.lang.util.softAssert +import kotlin.test.assertEquals class EvaluationSessionTest { private fun assertDefault(block: () -> EvaluationSession) { diff --git a/lang/test/org/partiql/lang/eval/EvaluatorTestBase.kt b/lang/test/org/partiql/lang/eval/EvaluatorTestBase.kt index d88be00a2d..fe2c1d60f2 100644 --- a/lang/test/org/partiql/lang/eval/EvaluatorTestBase.kt +++ b/lang/test/org/partiql/lang/eval/EvaluatorTestBase.kt @@ -14,16 +14,31 @@ package org.partiql.lang.eval +import org.partiql.lang.CompilerPipeline +import org.partiql.lang.TestBase +import org.partiql.lang.ast.AstDeserializerBuilder +import org.partiql.lang.ast.AstSerializer +import org.partiql.lang.ast.AstVersion +import org.partiql.lang.ast.ExprNode import com.amazon.ion.IonType import com.amazon.ion.IonValue -import org.partiql.lang.* -import org.partiql.lang.ast.* -import org.partiql.lang.errors.* -import org.partiql.lang.syntax.* -import org.partiql.lang.util.* +import org.partiql.lang.CUSTOM_TEST_TYPES +import org.partiql.lang.SqlException import org.partiql.lang.ast.passes.MetaStrippingRewriter -import kotlin.reflect.* -import kotlin.test.* +import org.partiql.lang.ast.toAstStatement +import org.partiql.lang.ast.toExprNode +import org.partiql.lang.checkErrorAndErrorContext +import org.partiql.lang.errors.ErrorBehaviorInPermissiveMode +import org.partiql.lang.errors.ErrorCategory +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.syntax.SqlParser +import org.partiql.lang.util.ConfigurableExprValueFormatter +import org.partiql.lang.util.asSequence +import org.partiql.lang.util.newFromIonText +import org.partiql.lang.util.softAssert +import kotlin.reflect.KClass +import kotlin.test.assertEquals /** * This class is being deprecated because it is becoming unmaintainable but can't be removed yet. diff --git a/lang/test/org/partiql/lang/eval/ExprValueAdaptersTest.kt b/lang/test/org/partiql/lang/eval/ExprValueAdaptersTest.kt index ee0f8f842d..117017ceb1 100644 --- a/lang/test/org/partiql/lang/eval/ExprValueAdaptersTest.kt +++ b/lang/test/org/partiql/lang/eval/ExprValueAdaptersTest.kt @@ -14,9 +14,9 @@ package org.partiql.lang.eval -import org.partiql.lang.* import org.junit.Test -import org.partiql.lang.util.* +import org.partiql.lang.TestBase +import org.partiql.lang.util.newFromIonText class ExprValueAdaptersTest : TestBase() { @Test diff --git a/lang/test/org/partiql/lang/eval/ExprValueFactoryTest.kt b/lang/test/org/partiql/lang/eval/ExprValueFactoryTest.kt index 5c54cfffbf..599f5d88fe 100644 --- a/lang/test/org/partiql/lang/eval/ExprValueFactoryTest.kt +++ b/lang/test/org/partiql/lang/eval/ExprValueFactoryTest.kt @@ -14,25 +14,29 @@ package org.partiql.lang.eval -import junitparams.* -import org.junit.* -import org.junit.runner.* -import com.amazon.ion.* -import com.amazon.ion.system.* +import com.amazon.ion.IonTimestamp +import com.amazon.ion.IonValue +import com.amazon.ion.Timestamp +import com.amazon.ion.system.IonSystemBuilder +import junitparams.JUnitParamsRunner +import junitparams.Parameters +import org.junit.Assert import org.junit.Test +import org.junit.runner.RunWith import org.partiql.lang.errors.ErrorCode import org.partiql.lang.eval.time.Time import org.partiql.lang.util.seal +import java.math.BigDecimal import org.partiql.lang.util.isBag import org.partiql.lang.util.isMissing -import java.math.* import java.time.LocalDate import java.time.LocalTime import java.time.OffsetTime import java.time.ZoneOffset -import kotlin.math.pow -import kotlin.test.* - +import kotlin.test.assertEquals +import kotlin.test.assertNull +import kotlin.test.assertTrue +import kotlin.test.fail @RunWith(JUnitParamsRunner::class) class ExprValueFactoryTest { diff --git a/lang/test/org/partiql/lang/eval/LikePredicateTest.kt b/lang/test/org/partiql/lang/eval/LikePredicateTest.kt index 98dedec30a..0161aaa159 100644 --- a/lang/test/org/partiql/lang/eval/LikePredicateTest.kt +++ b/lang/test/org/partiql/lang/eval/LikePredicateTest.kt @@ -14,13 +14,12 @@ package org.partiql.lang.eval -import org.partiql.lang.* -import org.partiql.lang.errors.* -import org.partiql.lang.util.* -import org.assertj.core.api.* -import org.junit.* +import org.assertj.core.api.SoftAssertions import org.junit.Test -import kotlin.test.* +import org.partiql.lang.SqlException +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.util.softAssert +import kotlin.test.assertFailsWith class LikePredicateTest : EvaluatorTestBase() { diff --git a/lang/test/org/partiql/lang/eval/NaturalExprValueComparatorsTest.kt b/lang/test/org/partiql/lang/eval/NaturalExprValueComparatorsTest.kt index 8bc60c0f37..e938dccc6e 100644 --- a/lang/test/org/partiql/lang/eval/NaturalExprValueComparatorsTest.kt +++ b/lang/test/org/partiql/lang/eval/NaturalExprValueComparatorsTest.kt @@ -17,9 +17,9 @@ package org.partiql.lang.eval import org.partiql.lang.SqlException import junitparams.Parameters import org.junit.Test +import java.util.Collections +import java.util.Random import org.partiql.lang.errors.ErrorCode -import java.util.* -import org.partiql.lang.eval.NaturalExprValueComparators.* class NaturalExprValueComparatorsTest : EvaluatorTestBase() { // the lists below represent the expected ordering of values @@ -343,8 +343,8 @@ class NaturalExprValueComparatorsTest : EvaluatorTestBase() { return (1..iterations).flatMap { listOf( - shuffleCase("BASIC VALUES (NULLS FIRST)", NULLS_FIRST, basicExprs), - shuffleCase("BASIC VALUES (NULLS LAST)", NULLS_LAST, basicExprs.moveHeadToTail()) + shuffleCase("BASIC VALUES (NULLS FIRST)", NaturalExprValueComparators.NULLS_FIRST, basicExprs), + shuffleCase("BASIC VALUES (NULLS LAST)", NaturalExprValueComparators.NULLS_LAST, basicExprs.moveHeadToTail()) ) } } diff --git a/lang/test/org/partiql/lang/eval/NodeMetadataTest.kt b/lang/test/org/partiql/lang/eval/NodeMetadataTest.kt index 1062ee83a4..bf7d45564b 100644 --- a/lang/test/org/partiql/lang/eval/NodeMetadataTest.kt +++ b/lang/test/org/partiql/lang/eval/NodeMetadataTest.kt @@ -14,14 +14,17 @@ package org.partiql.lang.eval -import org.partiql.lang.errors.* -import org.partiql.lang.util.* -import junitparams.* -import org.assertj.core.api.Assertions.* -import org.junit.* +import junitparams.JUnitParamsRunner +import junitparams.Parameters +import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import org.junit.runner.* -import kotlin.test.* +import org.junit.runner.RunWith +import org.partiql.lang.errors.Property +import org.partiql.lang.errors.PropertyType +import org.partiql.lang.errors.PropertyValue +import org.partiql.lang.errors.PropertyValueMap +import org.partiql.lang.util.softAssert +import kotlin.test.assertTrue @RunWith(JUnitParamsRunner::class) class NodeMetadataTest { diff --git a/lang/test/org/partiql/lang/eval/QuotedIdentifierTests.kt b/lang/test/org/partiql/lang/eval/QuotedIdentifierTests.kt index af7c2d7d4d..4a6fc4f06a 100644 --- a/lang/test/org/partiql/lang/eval/QuotedIdentifierTests.kt +++ b/lang/test/org/partiql/lang/eval/QuotedIdentifierTests.kt @@ -14,9 +14,10 @@ package org.partiql.lang.eval -import org.partiql.lang.errors.* -import org.partiql.lang.util.* -import org.junit.* +import org.junit.Test +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.util.sourceLocationProperties class QuotedIdentifierTests : EvaluatorTestBase() { diff --git a/lang/test/org/partiql/lang/eval/SimpleEvaluatingCompilerTests.kt b/lang/test/org/partiql/lang/eval/SimpleEvaluatingCompilerTests.kt index 82eb82f1b6..8c284f84e1 100644 --- a/lang/test/org/partiql/lang/eval/SimpleEvaluatingCompilerTests.kt +++ b/lang/test/org/partiql/lang/eval/SimpleEvaluatingCompilerTests.kt @@ -14,9 +14,10 @@ package org.partiql.lang.eval -import org.partiql.lang.errors.* -import org.partiql.lang.util.* -import org.junit.* +import org.junit.Test +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.errors.Property +import org.partiql.lang.util.sourceLocationProperties class SimpleEvaluatingCompilerTests : EvaluatorTestBase() { val session = mapOf( diff --git a/lang/test/org/partiql/lang/eval/builtins/ConcatEvaluationTest.kt b/lang/test/org/partiql/lang/eval/builtins/ConcatEvaluationTest.kt index 38152bd5a3..8478242588 100644 --- a/lang/test/org/partiql/lang/eval/builtins/ConcatEvaluationTest.kt +++ b/lang/test/org/partiql/lang/eval/builtins/ConcatEvaluationTest.kt @@ -4,16 +4,13 @@ import org.junit.Test import org.partiql.lang.errors.ErrorCode.EVALUATOR_CONCAT_FAILED_DUE_TO_INCOMPATIBLE_TYPE import org.partiql.lang.errors.Property.ACTUAL_ARGUMENT_TYPES import org.partiql.lang.eval.EvaluatorTestBase -import org.partiql.lang.eval.ExprValueType.INT import org.partiql.lang.eval.ExprValueType.STRING +import org.partiql.lang.eval.ExprValueType.INT import org.partiql.lang.eval.ExprValueType.STRUCT -import org.partiql.lang.eval.ExprValueType.SYMBOL import org.partiql.lang.eval.ExprValueType.TIMESTAMP import org.partiql.lang.util.sourceLocationProperties class ConcatEvaluationTest : EvaluatorTestBase() { - private val argumentTypeMap = mapOf(ACTUAL_ARGUMENT_TYPES to listOf(STRING, SYMBOL).toString()) - @Test fun concatWrongLeftType() = checkInputThrowingEvaluationException("1 || 'a'", diff --git a/lang/test/org/partiql/lang/eval/builtins/DateDiffExprFunctionTest.kt b/lang/test/org/partiql/lang/eval/builtins/DateDiffExprFunctionTest.kt index 7ee917640b..7473914a1e 100644 --- a/lang/test/org/partiql/lang/eval/builtins/DateDiffExprFunctionTest.kt +++ b/lang/test/org/partiql/lang/eval/builtins/DateDiffExprFunctionTest.kt @@ -1,12 +1,15 @@ package org.partiql.lang.eval.builtins -import com.amazon.ion.* -import org.partiql.lang.* -import org.partiql.lang.eval.* -import org.partiql.lang.util.* -import junitparams.* -import org.assertj.core.api.Assertions.* -import org.junit.* +import com.amazon.ion.Timestamp +import junitparams.Parameters +import org.assertj.core.api.Assertions.assertThatThrownBy +import org.junit.Test +import org.partiql.lang.TestBase +import org.partiql.lang.eval.Environment +import org.partiql.lang.eval.EvaluationException +import org.partiql.lang.eval.RequiredArgs +import org.partiql.lang.eval.call +import org.partiql.lang.eval.numberValue class DateDiffExprFunctionTest : TestBase() { private val env = Environment.standard() diff --git a/lang/test/org/partiql/lang/eval/builtins/TimestampParserTest.kt b/lang/test/org/partiql/lang/eval/builtins/TimestampParserTest.kt index aa9f34ba70..21777aa9aa 100644 --- a/lang/test/org/partiql/lang/eval/builtins/TimestampParserTest.kt +++ b/lang/test/org/partiql/lang/eval/builtins/TimestampParserTest.kt @@ -1,17 +1,19 @@ package org.partiql.lang.eval.builtins -import com.amazon.ion.* -import org.partiql.lang.errors.* -import org.partiql.lang.eval.* -import junitparams.* -import junitparams.naming.* -import org.junit.* +import com.amazon.ion.Timestamp +import junitparams.JUnitParamsRunner +import junitparams.Parameters +import junitparams.naming.TestCaseName import org.junit.Test -import org.junit.runner.* -import java.lang.reflect.* -import java.time.format.* -import java.time.temporal.* -import kotlin.test.* +import org.junit.runner.RunWith +import org.partiql.lang.errors.ErrorCode +import org.partiql.lang.eval.EvaluationException +import java.lang.reflect.Type +import java.time.format.DateTimeParseException +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.fail @RunWith(JUnitParamsRunner::class) class TimestampParserTest { diff --git a/lang/test/org/partiql/lang/eval/builtins/TimestampTemporalAccessorTests.kt b/lang/test/org/partiql/lang/eval/builtins/TimestampTemporalAccessorTests.kt index 35dab018af..806af3c624 100644 --- a/lang/test/org/partiql/lang/eval/builtins/TimestampTemporalAccessorTests.kt +++ b/lang/test/org/partiql/lang/eval/builtins/TimestampTemporalAccessorTests.kt @@ -1,6 +1,5 @@ package org.partiql.lang.eval.builtins - import com.amazon.ion.Timestamp import junitparams.JUnitParamsRunner import junitparams.Parameters @@ -11,7 +10,7 @@ import org.junit.runner.RunWith import java.time.DateTimeException import java.time.format.DateTimeFormatter import java.time.temporal.UnsupportedTemporalTypeException -import java.util.* +import java.util.Random import kotlin.test.assertEquals import kotlin.test.assertNull diff --git a/lang/test/org/partiql/lang/eval/builtins/TrimEvaluationTest.kt b/lang/test/org/partiql/lang/eval/builtins/TrimEvaluationTest.kt index 8391951fc0..56d1e8bf69 100644 --- a/lang/test/org/partiql/lang/eval/builtins/TrimEvaluationTest.kt +++ b/lang/test/org/partiql/lang/eval/builtins/TrimEvaluationTest.kt @@ -5,7 +5,6 @@ import org.partiql.lang.errors.ErrorCode import org.partiql.lang.errors.Property import org.partiql.lang.eval.EvaluatorTestBase - class TrimEvaluationTest : EvaluatorTestBase() { @Test diff --git a/lang/test/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternLexerTest.kt b/lang/test/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternLexerTest.kt index 71cdc1e668..d1881f1484 100644 --- a/lang/test/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternLexerTest.kt +++ b/lang/test/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternLexerTest.kt @@ -10,7 +10,7 @@ class TimestampFormatPatternLexerTest { private fun pattern(s: String) = Token(TokenType.PATTERN, s) private fun assertTokens(s: String, vararg tokens: Token) = assertEquals(tokens.toList(), - TimestampFormatPatternLexer().tokenize(s)) + TimestampFormatPatternLexer().tokenize(s)) @Test fun singlePatternToken() = assertTokens("y", pattern("y")) diff --git a/lang/test/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternParserTest.kt b/lang/test/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternParserTest.kt index b6673afff9..c98d0e6f25 100644 --- a/lang/test/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternParserTest.kt +++ b/lang/test/org/partiql/lang/eval/builtins/timestamp/TimestampFormatPatternParserTest.kt @@ -1,11 +1,11 @@ package org.partiql.lang.eval.builtins.timestamp -import org.partiql.lang.util.* -import junitparams.* -import org.junit.* +import junitparams.JUnitParamsRunner +import junitparams.Parameters import org.junit.Test -import org.junit.runner.* -import kotlin.test.* +import org.junit.runner.RunWith +import org.partiql.lang.util.softAssert +import kotlin.test.assertEquals @RunWith(JUnitParamsRunner::class) internal class TimestampFormatPatternParserTest { @@ -106,7 +106,6 @@ internal class TimestampFormatPatternParserTest { assertEquals(pair.second, formatPattern.formatItems) } - @Test fun mostPreciseField() { //NOTE: we can't parameterize this unless we want to expose TimestampParser.FormatPatternPrecision as public. @@ -123,7 +122,6 @@ internal class TimestampFormatPatternParserTest { } } - private data class MostPreciseFieldTestCase( val pattern: String, val expectedResult: TimestampField, @@ -182,6 +180,4 @@ internal class TimestampFormatPatternParserTest { //Valid symbols within quotes should not influence the result MostPreciseFieldTestCase("y'M d s'", TimestampField.YEAR), MostPreciseFieldTestCase("y'y'", TimestampField.YEAR)) - - } \ No newline at end of file diff --git a/lang/test/org/partiql/lang/eval/builtins/timestamp/ToTimestampFormatPatternValidationTest.kt b/lang/test/org/partiql/lang/eval/builtins/timestamp/ToTimestampFormatPatternValidationTest.kt index b8767e40f8..d6107082b0 100644 --- a/lang/test/org/partiql/lang/eval/builtins/timestamp/ToTimestampFormatPatternValidationTest.kt +++ b/lang/test/org/partiql/lang/eval/builtins/timestamp/ToTimestampFormatPatternValidationTest.kt @@ -7,10 +7,10 @@ import org.junit.runner.RunWith import org.partiql.lang.errors.ErrorCode import org.partiql.lang.errors.Property import org.partiql.lang.eval.EvaluatorTestBase + import org.partiql.lang.util.sourceLocationProperties import org.partiql.lang.util.to - @RunWith(JUnitParamsRunner::class) class ToTimestampFormatPatternValidationTest : EvaluatorTestBase() { diff --git a/lang/test/org/partiql/lang/eval/io/CustomExceptionHandlerTest.kt b/lang/test/org/partiql/lang/eval/io/CustomExceptionHandlerTest.kt index a59c662d02..049b431317 100644 --- a/lang/test/org/partiql/lang/eval/io/CustomExceptionHandlerTest.kt +++ b/lang/test/org/partiql/lang/eval/io/CustomExceptionHandlerTest.kt @@ -3,7 +3,12 @@ package org.partiql.lang.eval.io import com.amazon.ion.system.IonSystemBuilder import org.junit.Test import org.partiql.lang.CompilerPipeline -import org.partiql.lang.eval.* +import org.partiql.lang.eval.CompileOptions +import org.partiql.lang.eval.Environment +import org.partiql.lang.eval.EvaluationSession +import org.partiql.lang.eval.ExprFunction +import org.partiql.lang.eval.ExprValue +import org.partiql.lang.eval.ThunkOptions import org.partiql.lang.types.FunctionSignature import org.partiql.lang.types.StaticType import java.lang.IllegalStateException diff --git a/lang/test/org/partiql/lang/eval/io/DelimitedValuesTest.kt b/lang/test/org/partiql/lang/eval/io/DelimitedValuesTest.kt index 279d9f9ffd..74e8be871b 100644 --- a/lang/test/org/partiql/lang/eval/io/DelimitedValuesTest.kt +++ b/lang/test/org/partiql/lang/eval/io/DelimitedValuesTest.kt @@ -14,13 +14,16 @@ package org.partiql.lang.eval.io +import org.partiql.lang.eval.io.DelimitedValues.ConversionMode.AUTO +import org.partiql.lang.eval.io.DelimitedValues.ConversionMode.NONE import org.apache.commons.csv.CSVFormat -import org.partiql.lang.* -import org.partiql.lang.eval.io.DelimitedValues.ConversionMode -import org.partiql.lang.eval.io.DelimitedValues.ConversionMode.* import org.junit.Test -import org.partiql.lang.eval.* -import org.partiql.lang.util.* +import org.partiql.lang.TestBase +import org.partiql.lang.eval.ExprValue +import org.partiql.lang.eval.ExprValueType +import org.partiql.lang.eval.cloneAndRemoveAnnotations +import org.partiql.lang.eval.orderedNamesValue +import org.partiql.lang.util.newFromIonText import java.io.StringReader import java.io.StringWriter @@ -34,7 +37,7 @@ class DelimitedValuesTest : TestBase() { private fun read(text: String, csvFormat: CSVFormat, - conversionMode: ConversionMode): ExprValue = + conversionMode: DelimitedValues.ConversionMode): ExprValue = DelimitedValues.exprValue(valueFactory, StringReader(text), csvFormat, conversionMode) private fun assertWrite(expectedText: String, diff --git a/lang/test/org/partiql/lang/eval/time/TimeTest.kt b/lang/test/org/partiql/lang/eval/time/TimeTest.kt index d5ceeb39c3..9a205cb901 100644 --- a/lang/test/org/partiql/lang/eval/time/TimeTest.kt +++ b/lang/test/org/partiql/lang/eval/time/TimeTest.kt @@ -4,7 +4,7 @@ import junitparams.JUnitParamsRunner import junitparams.Parameters import org.junit.Assert import org.junit.Test -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.runner.RunWith import org.partiql.lang.errors.ErrorCode import org.partiql.lang.eval.EvaluationException diff --git a/lang/test/org/partiql/lang/schemadiscovery/SchemaInferencerFromExampleTests.kt b/lang/test/org/partiql/lang/schemadiscovery/SchemaInferencerFromExampleTests.kt index ed54997f5f..75f304001b 100644 --- a/lang/test/org/partiql/lang/schemadiscovery/SchemaInferencerFromExampleTests.kt +++ b/lang/test/org/partiql/lang/schemadiscovery/SchemaInferencerFromExampleTests.kt @@ -14,7 +14,6 @@ import org.partiql.lang.util.ArgumentsProviderBase import java.lang.AssertionError import java.math.BigInteger - private const val typeName = "SchemaInferencerFromExample" private const val schemaId = "partiql.isl" private val islHeader = """ diff --git a/lang/test/org/partiql/lang/syntax/SqlLexerTest.kt b/lang/test/org/partiql/lang/syntax/SqlLexerTest.kt index 0450f7b709..c57a36a119 100644 --- a/lang/test/org/partiql/lang/syntax/SqlLexerTest.kt +++ b/lang/test/org/partiql/lang/syntax/SqlLexerTest.kt @@ -14,10 +14,8 @@ package org.partiql.lang.syntax -import org.partiql.lang.* -import org.partiql.lang.syntax.TokenType.* import org.junit.Test -import java.util.* +import org.partiql.lang.TestBase class SqlLexerTest : TestBase() { val lexer = SqlLexer(ion) @@ -50,147 +48,147 @@ class SqlLexerTest : TestBase() { @Test fun punctuation() = assertTokens( "()[]{}:,.*<<>>;", - token(LEFT_PAREN, "'('", 1, 1, 1), - token(RIGHT_PAREN, "')'", 1, 2, 1), - token(LEFT_BRACKET, "'['", 1, 3, 1), - token(RIGHT_BRACKET, "']'", 1, 4, 1), - token(LEFT_CURLY, "'{'", 1, 5, 1), - token(RIGHT_CURLY, "'}'", 1, 6, 1), - token(COLON, "':'", 1, 7, 1), - token(COMMA, "','", 1, 8, 1), - token(DOT, "'.'", 1, 9, 1), - token(STAR, "'*'", 1, 10, 1), - token(LEFT_DOUBLE_ANGLE_BRACKET, "'<<'", 1, 11, 2), - token(RIGHT_DOUBLE_ANGLE_BRACKET, "'>>'", 1, 13, 2), - token(SEMICOLON, "';'", 1, 15, 1) + token(TokenType.LEFT_PAREN, "'('", 1, 1, 1), + token(TokenType.RIGHT_PAREN, "')'", 1, 2, 1), + token(TokenType.LEFT_BRACKET, "'['", 1, 3, 1), + token(TokenType.RIGHT_BRACKET, "']'", 1, 4, 1), + token(TokenType.LEFT_CURLY, "'{'", 1, 5, 1), + token(TokenType.RIGHT_CURLY, "'}'", 1, 6, 1), + token(TokenType.COLON, "':'", 1, 7, 1), + token(TokenType.COMMA, "','", 1, 8, 1), + token(TokenType.DOT, "'.'", 1, 9, 1), + token(TokenType.STAR, "'*'", 1, 10, 1), + token(TokenType.LEFT_DOUBLE_ANGLE_BRACKET, "'<<'", 1, 11, 2), + token(TokenType.RIGHT_DOUBLE_ANGLE_BRACKET, "'>>'", 1, 13, 2), + token(TokenType.SEMICOLON, "';'", 1, 15, 1) ) @Test fun keywordsThatHaveTheirOwnTokenTypes() = assertTokens( "AS AT FOR", - token(AS, "as", 1, 1, 2), - token(AT, "at", 1, 4, 2), - token(FOR, "for", 1, 7, 3) + token(TokenType.AS, "as", 1, 1, 2), + token(TokenType.AT, "at", 1, 4, 2), + token(TokenType.FOR, "for", 1, 7, 3) ) @Test fun whitespaceAndIdentifiers() = assertTokens( "ab\r\n_bc_ \r\r \$cd\$\n\r\tde1", - token(IDENTIFIER, "ab", 1, 1, 2), - token(IDENTIFIER, "_bc_", 2, 1, 4), - token(IDENTIFIER, "\$cd\$", 4, 2, 4), - token(IDENTIFIER, "de1", 6, 2, 3) + token(TokenType.IDENTIFIER, "ab", 1, 1, 2), + token(TokenType.IDENTIFIER, "_bc_", 2, 1, 4), + token(TokenType.IDENTIFIER, "\$cd\$", 4, 2, 4), + token(TokenType.IDENTIFIER, "de1", 6, 2, 3) ) @Test fun whitespaceAndQuotedIdentifiers() = assertTokens( "\"ab\"\r\n\"_bc_\" \r\r \"\$cd\$\"\n\r\t\"de1\"", - token(QUOTED_IDENTIFIER, "ab", 1, 1, 4), - token(QUOTED_IDENTIFIER, "_bc_", 2, 1, 6), - token(QUOTED_IDENTIFIER, "\$cd\$", 4, 2, 6), - token(QUOTED_IDENTIFIER, "de1", 6, 2, 5) + token(TokenType.QUOTED_IDENTIFIER, "ab", 1, 1, 4), + token(TokenType.QUOTED_IDENTIFIER, "_bc_", 2, 1, 6), + token(TokenType.QUOTED_IDENTIFIER, "\$cd\$", 4, 2, 6), + token(TokenType.QUOTED_IDENTIFIER, "de1", 6, 2, 5) ) @Test fun inlineCommentAtEnd() = assertTokens( "ab\n--Ignore Me", - token(IDENTIFIER, "ab", 1, 1, 2) + token(TokenType.IDENTIFIER, "ab", 1, 1, 2) ) @Test fun inlineCommentAtEndNoContent() = assertTokens( "ab--", - token(IDENTIFIER, "ab", 1, 1, 2) + token(TokenType.IDENTIFIER, "ab", 1, 1, 2) ) @Test fun blockCommentAtStart() = assertTokens( "/*Ignore Me*/ab", - token(IDENTIFIER, "ab", 1, 14, 2) + token(TokenType.IDENTIFIER, "ab", 1, 14, 2) ) @Test fun blockCommentAtEnd() = assertTokens( "ab\n/*Ignore Me*/", - token(IDENTIFIER, "ab", 1, 1, 2) + token(TokenType.IDENTIFIER, "ab", 1, 1, 2) ) @Test fun booleans() = assertTokens( "true false truefalse", - token(LITERAL, "true", 1, 1, 4), - token(LITERAL, "false", 1, 6, 5), - token(IDENTIFIER, "truefalse", 1, 12, 9) + token(TokenType.LITERAL, "true", 1, 1, 4), + token(TokenType.LITERAL, "false", 1, 6, 5), + token(TokenType.IDENTIFIER, "truefalse", 1, 12, 9) ) @Test fun nullAndMissing() = assertTokens( "null Null MISSING `null`", - token(NULL, "null", 1, 1, 4), - token(NULL, "null", 1, 6, 4), - token(MISSING, "null", 1, 11, 7), - token(ION_LITERAL, "null", 1, 19, 6) + token(TokenType.NULL, "null", 1, 1, 4), + token(TokenType.NULL, "null", 1, 6, 4), + token(TokenType.MISSING, "null", 1, 11, 7), + token(TokenType.ION_LITERAL, "null", 1, 19, 6) ) @Test fun numbers() = assertTokens( "500 600. 0.1 . .1 0000 0.00e0 1e+1", - token(LITERAL, "500", 1, 1, 3), - token(LITERAL, "600d0", 1, 5, 4), - token(LITERAL, "1d-1", 1, 10, 3), - token(DOT, "'.'", 1, 14, 1), - token(LITERAL, "1d-1", 1, 16, 2), - token(LITERAL, "0", 1, 19, 4), - token(LITERAL, "0d-2", 1, 24, 6), - token(LITERAL, "1d1", 1, 31, 4) + token(TokenType.LITERAL, "500", 1, 1, 3), + token(TokenType.LITERAL, "600d0", 1, 5, 4), + token(TokenType.LITERAL, "1d-1", 1, 10, 3), + token(TokenType.DOT, "'.'", 1, 14, 1), + token(TokenType.LITERAL, "1d-1", 1, 16, 2), + token(TokenType.LITERAL, "0", 1, 19, 4), + token(TokenType.LITERAL, "0d-2", 1, 24, 6), + token(TokenType.LITERAL, "1d1", 1, 31, 4) ) @Test fun signedNumbers() = assertTokens( "+500 -600. -0.1 . +.1 -0000 +0.00e0 -+-1e+1", - token(OPERATOR, "'+'", 1, 1, 1), - token(LITERAL, "500", 1, 2, 3), - token(OPERATOR, "'-'", 1, 6, 1), - token(LITERAL, "600d0", 1, 7, 4), - token(OPERATOR, "'-'", 1, 12, 1), - token(LITERAL, "1d-1", 1, 13, 3), - token(DOT, "'.'", 1, 17, 1), - token(OPERATOR, "'+'", 1, 19, 1), - token(LITERAL, "1d-1", 1, 20, 2), - token(OPERATOR, "'-'", 1, 23, 1), - token(LITERAL, "0", 1, 24, 4), - token(OPERATOR, "'+'", 1, 29, 1), - token(LITERAL, "0d-2", 1, 30, 6), - token(OPERATOR, "'-'", 1, 37, 1), - token(OPERATOR, "'+'", 1, 38, 1), - token(OPERATOR, "'-'", 1, 39, 1), - token(LITERAL, "1d1", 1, 40, 4) + token(TokenType.OPERATOR, "'+'", 1, 1, 1), + token(TokenType.LITERAL, "500", 1, 2, 3), + token(TokenType.OPERATOR, "'-'", 1, 6, 1), + token(TokenType.LITERAL, "600d0", 1, 7, 4), + token(TokenType.OPERATOR, "'-'", 1, 12, 1), + token(TokenType.LITERAL, "1d-1", 1, 13, 3), + token(TokenType.DOT, "'.'", 1, 17, 1), + token(TokenType.OPERATOR, "'+'", 1, 19, 1), + token(TokenType.LITERAL, "1d-1", 1, 20, 2), + token(TokenType.OPERATOR, "'-'", 1, 23, 1), + token(TokenType.LITERAL, "0", 1, 24, 4), + token(TokenType.OPERATOR, "'+'", 1, 29, 1), + token(TokenType.LITERAL, "0d-2", 1, 30, 6), + token(TokenType.OPERATOR, "'-'", 1, 37, 1), + token(TokenType.OPERATOR, "'+'", 1, 38, 1), + token(TokenType.OPERATOR, "'-'", 1, 39, 1), + token(TokenType.LITERAL, "1d1", 1, 40, 4) ) @Test fun quotedIon() = assertTokens( "`1e0` `{a:5}` `/*`*/\"`\"` `//`\n'''`'''` `{{ +AB//A== }}` `{{ \"not a comment //\" }}`", - token(ION_LITERAL, "1e0", 1, 1, 5), - token(ION_LITERAL, "{a:5}", 1, 7, 7), - token(ION_LITERAL, "\"`\"", 1, 15, 10), - token(ION_LITERAL, "\"`\"", 1, 26, 13), - token(ION_LITERAL, "{{ +AB//A== }}", 2, 10, 16), - token(ION_LITERAL, "{{ \"not a comment //\" }}", 2, 27, 26) + token(TokenType.ION_LITERAL, "1e0", 1, 1, 5), + token(TokenType.ION_LITERAL, "{a:5}", 1, 7, 7), + token(TokenType.ION_LITERAL, "\"`\"", 1, 15, 10), + token(TokenType.ION_LITERAL, "\"`\"", 1, 26, 13), + token(TokenType.ION_LITERAL, "{{ +AB//A== }}", 2, 10, 16), + token(TokenType.ION_LITERAL, "{{ \"not a comment //\" }}", 2, 27, 26) ) @Test fun quotedStrings() = assertTokens( "'1e0' '{''a'':5}'", - token(LITERAL, "\"1e0\"", 1, 1, 5), - token(LITERAL, "\"{'a':5}\"", 1, 7, 11) + token(TokenType.LITERAL, "\"1e0\"", 1, 1, 5), + token(TokenType.LITERAL, "\"{'a':5}\"", 1, 7, 11) ) @Test fun quotedIdentifiers() = assertTokens( "\"1e0\" \"{\"\"a\"\":5}\"", - token(QUOTED_IDENTIFIER, "'1e0'", 1, 1, 5), - token(QUOTED_IDENTIFIER, "'{\"a\":5}'", 1, 7, 11) + token(TokenType.QUOTED_IDENTIFIER, "'1e0'", 1, 1, 5), + token(TokenType.QUOTED_IDENTIFIER, "'{\"a\":5}'", 1, 7, 11) ) @Test @@ -199,16 +197,16 @@ class SqlLexerTest : TestBase() { val expected = ArrayList() for (op in ALL_SINGLE_LEXEME_OPERATORS) { val type = when (op) { - "*" -> STAR - in ALL_OPERATORS -> OPERATOR - in KEYWORDS -> KEYWORD - else -> OPERATOR + "*" -> TokenType.STAR + in ALL_OPERATORS -> TokenType.OPERATOR + in KEYWORDS -> TokenType.KEYWORD + else -> TokenType.OPERATOR } expected.add(token(type, "'$op'", 1, buf.length + 1L, op.length.toLong())) buf.append(op) // make sure we have a token between things to avoid hitting multi-lexeme // tokens by mistake - expected.add(token(LITERAL, "1", 1, buf.length + 2L, 1)) + expected.add(token(TokenType.LITERAL, "1", 1, buf.length + 2L, 1)) buf.append(" 1 ") } assertTokens(buf.toString(), *expected.toTypedArray()) @@ -217,206 +215,208 @@ class SqlLexerTest : TestBase() { @Test fun multiLexemeOperators() = assertTokens( "UNION ALL IS NOT union_all is_not", - token(OPERATOR, "union_all", 1, 1, 5), - token(OPERATOR, "is_not", 1, 11, 2), - token(IDENTIFIER, "union_all", 1, 18, 9), - token(IDENTIFIER, "is_not", 1, 28, 6) + token(TokenType.OPERATOR, "union_all", 1, 1, 5), + token(TokenType.OPERATOR, "is_not", 1, 11, 2), + token(TokenType.IDENTIFIER, "union_all", 1, 18, 9), + token(TokenType.IDENTIFIER, "is_not", 1, 28, 6) ) @Test fun multiLexemeKeywords() = assertTokens( "CHARACTER VARYING DoUblE PrEcision double_precision character_varying", - token(KEYWORD, "character_varying", 1, 1, 9), - token(KEYWORD, "double_precision", 1, 19, 6), - token(IDENTIFIER, "double_precision", 1, 36, 16), - token(IDENTIFIER, "character_varying", 1, 53, 17) + token(TokenType.KEYWORD, "character_varying", 1, 1, 9), + token(TokenType.KEYWORD, "double_precision", 1, 19, 6), + token(TokenType.IDENTIFIER, "double_precision", 1, 36, 16), + token(TokenType.IDENTIFIER, "character_varying", 1, 53, 17) ) @Test fun joinKeywords() = assertTokens( "cRoSs Join left join left left Inner joiN RIGHT JOIN RIGHT OUTER JOIN LEFT OUTER JOIN" + - "\nFULL join OUTER JOIN FULL OUTER JOIN" + - "\nCROSS CROSS JOIN JOIN", - token(KEYWORD, "cross_join", 1, 1, 5), - token(KEYWORD, "left_join", 1, 12, 4), - token(KEYWORD, "left", 1, 22, 4), - token(KEYWORD, "left", 1, 27, 4), - token(KEYWORD, "inner_join", 1, 32, 5), - token(KEYWORD, "right_join", 1, 43, 5), - token(KEYWORD, "right_join", 1, 54, 5), - token(KEYWORD, "left_join", 1, 71, 4), - token(KEYWORD, "outer_join", 2, 1, 4), - token(KEYWORD, "outer_join", 2, 11, 5), - token(KEYWORD, "outer_join", 2, 22, 4), - token(KEYWORD, "cross", 3, 1, 5), - token(KEYWORD, "cross_join", 3, 7, 5), - token(KEYWORD, "join", 3, 18, 4) + "\nFULL join OUTER JOIN FULL OUTER JOIN" + + "\nCROSS CROSS JOIN JOIN", + token(TokenType.KEYWORD, "cross_join", 1, 1, 5), + token(TokenType.KEYWORD, "left_join", 1, 12, 4), + token(TokenType.KEYWORD, "left", 1, 22, 4), + token(TokenType.KEYWORD, "left", 1, 27, 4), + token(TokenType.KEYWORD, "inner_join", 1, 32, 5), + token(TokenType.KEYWORD, "right_join", 1, 43, 5), + token(TokenType.KEYWORD, "right_join", 1, 54, 5), + token(TokenType.KEYWORD, "left_join", 1, 71, 4), + token(TokenType.KEYWORD, "outer_join", 2, 1, 4), + token(TokenType.KEYWORD, "outer_join", 2, 11, 5), + token(TokenType.KEYWORD, "outer_join", 2, 22, 4), + token(TokenType.KEYWORD, "cross", 3, 1, 5), + token(TokenType.KEYWORD, "cross_join", 3, 7, 5), + token(TokenType.KEYWORD, "join", 3, 18, 4) ) @Test fun functionKeywordNames() = assertTokens( - "SUBSTRING", - token(KEYWORD, "substring", 1, 1, 9) + "SUBSTRING", + token(TokenType.KEYWORD, "substring", 1, 1, 9) ) @Test fun boolType() = assertTokens( "BOOL", - token(KEYWORD, "boolean", 1, 1, 4) + token(TokenType.KEYWORD, "boolean", 1, 1, 4) ) + @Test fun smallintType() = assertTokens( "SMALLINT", - token(KEYWORD, "smallint", 1, 1, 8) + token(TokenType.KEYWORD, "smallint", 1, 1, 8) ) @Test fun integer4Type() = assertTokens( "INTEGER4", - token(KEYWORD, "integer4", 1, 1, 8) + token(TokenType.KEYWORD, "integer4", 1, 1, 8) ) + @Test fun int4Type() = assertTokens( "INT4", - token(KEYWORD, "integer4", 1, 1, 4) + token(TokenType.KEYWORD, "integer4", 1, 1, 4) ) @Test fun intType() = assertTokens( "INT", - token(KEYWORD, "integer", 1, 1, 3) + token(TokenType.KEYWORD, "integer", 1, 1, 3) ) @Test fun integerType() = assertTokens( "INTEGER", - token(KEYWORD, "integer", 1, 1, 7) + token(TokenType.KEYWORD, "integer", 1, 1, 7) ) @Test fun floatType() = assertTokens( "FLOAT", - token(KEYWORD, "float", 1, 1, 5) + token(TokenType.KEYWORD, "float", 1, 1, 5) ) @Test fun realType() = assertTokens( "REAL", - token(KEYWORD, "real", 1, 1, 4) + token(TokenType.KEYWORD, "real", 1, 1, 4) ) @Test fun doublePrecisionType() = assertTokens( "DOUBLE PRECISION", - token(KEYWORD, "double_precision", 1, 1, 6) + token(TokenType.KEYWORD, "double_precision", 1, 1, 6) ) @Test fun decimalType() = assertTokens( "DECIMAL", - token(KEYWORD, "decimal", 1, 1, 7) + token(TokenType.KEYWORD, "decimal", 1, 1, 7) ) @Test fun numericType() = assertTokens( "NUMERIC", - token(KEYWORD, "numeric", 1, 1, 7) + token(TokenType.KEYWORD, "numeric", 1, 1, 7) ) @Test fun timestampType() = assertTokens( "TIMESTAMP", - token(KEYWORD, "timestamp", 1, 1, 9) + token(TokenType.KEYWORD, "timestamp", 1, 1, 9) ) @Test fun characterType() = assertTokens( "CHARACTER", - token(KEYWORD, "character", 1, 1, 9) + token(TokenType.KEYWORD, "character", 1, 1, 9) ) @Test fun charType() = assertTokens( "CHAR", - token(KEYWORD, "character", 1, 1, 4) + token(TokenType.KEYWORD, "character", 1, 1, 4) ) @Test fun varcharType() = assertTokens( "VARCHAR", - token(KEYWORD, "character_varying", 1, 1, 7) + token(TokenType.KEYWORD, "character_varying", 1, 1, 7) ) @Test fun characterVaryingType() = assertTokens( "CHARACTER VARYING", - token(KEYWORD, "character_varying", 1, 1, 9) + token(TokenType.KEYWORD, "character_varying", 1, 1, 9) ) @Test fun stringType() = assertTokens( "STRING", - token(KEYWORD, "string", 1, 1, 6) + token(TokenType.KEYWORD, "string", 1, 1, 6) ) @Test fun symbolType() = assertTokens( "SYMBOL", - token(KEYWORD, "symbol", 1, 1, 6) + token(TokenType.KEYWORD, "symbol", 1, 1, 6) ) @Test fun clobType() = assertTokens( "CLOB", - token(KEYWORD, "clob", 1, 1, 4) + token(TokenType.KEYWORD, "clob", 1, 1, 4) ) @Test fun blobType() = assertTokens( "BLOB", - token(KEYWORD, "blob", 1, 1, 4) + token(TokenType.KEYWORD, "blob", 1, 1, 4) ) @Test fun structType() = assertTokens( "STRUCT", - token(KEYWORD, "struct", 1, 1, 6) + token(TokenType.KEYWORD, "struct", 1, 1, 6) ) @Test fun listType() = assertTokens( "LIST", - token(KEYWORD, "list", 1, 1, 4) + token(TokenType.KEYWORD, "list", 1, 1, 4) ) @Test fun sexpType() = assertTokens( "SEXP", - token(KEYWORD, "sexp", 1, 1, 4) + token(TokenType.KEYWORD, "sexp", 1, 1, 4) ) @Test fun esBooleanType() = assertTokens( "ES_boolean", - token(IDENTIFIER, "ES_boolean", 1, 1, 10) + token(TokenType.IDENTIFIER, "ES_boolean", 1, 1, 10) ) @Test fun esIntegerType() = assertTokens( "ES_integer", - token(IDENTIFIER, "ES_integer", 1, 1, 10) + token(TokenType.IDENTIFIER, "ES_integer", 1, 1, 10) ) @Test fun esFloatType() = assertTokens( "ES_float", - token(IDENTIFIER, "ES_float", 1, 1, 8) + token(TokenType.IDENTIFIER, "ES_float", 1, 1, 8) ) @Test fun esTextType() = assertTokens( "ES_text", - token(IDENTIFIER, "ES_text", 1, 1, 7) + token(TokenType.IDENTIFIER, "ES_text", 1, 1, 7) ) @Test(expected = LexerException::class) @@ -432,88 +432,90 @@ class SqlLexerTest : TestBase() { @Test fun rsVarcharMax() = assertTokens( "RS_varchar_max", - token(IDENTIFIER, "RS_varchar_max", 1, 1, 14) + token(TokenType.IDENTIFIER, "RS_varchar_max", 1, 1, 14) ) @Test fun rsReal() = assertTokens( "RS_real", - token(IDENTIFIER, "RS_real", 1, 1, 7) + token(TokenType.IDENTIFIER, "RS_real", 1, 1, 7) ) @Test fun rsFloat4() = assertTokens( "RS_float4", - token(IDENTIFIER, "RS_float4", 1, 1, 9) + token(TokenType.IDENTIFIER, "RS_float4", 1, 1, 9) ) @Test fun rsDoublePrecision() = assertTokens( "RS_double_precision", - token(IDENTIFIER, "RS_double_precision", 1, 1, 19) + token(TokenType.IDENTIFIER, "RS_double_precision", 1, 1, 19) ) + @Test fun rsFloat() = assertTokens( "RS_float", - token(IDENTIFIER,"RS_float", 1, 1, 8) + token(TokenType.IDENTIFIER, "RS_float", 1, 1, 8) ) + @Test fun rsFloat8() = assertTokens( "RS_float8", - token(IDENTIFIER, "RS_float8", 1, 1, 9) + token(TokenType.IDENTIFIER, "RS_float8", 1, 1, 9) ) @Test fun sparkFloat() = assertTokens( "SPARK_float", - token(IDENTIFIER, "SPARK_float", 1, 1, 11) + token(TokenType.IDENTIFIER, "SPARK_float", 1, 1, 11) ) @Test fun sparkShort() = assertTokens( "SPARK_short", - token(IDENTIFIER, "SPARK_short", 1, 1, 11) + token(TokenType.IDENTIFIER, "SPARK_short", 1, 1, 11) ) @Test fun sparkInteger() = assertTokens( "SPARK_integer", - token(IDENTIFIER, "SPARK_integer", 1, 1, 13) + token(TokenType.IDENTIFIER, "SPARK_integer", 1, 1, 13) ) @Test fun sparkLong() = assertTokens( "SPARK_long", - token(IDENTIFIER, "SPARK_long", 1, 1, 10) + token(TokenType.IDENTIFIER, "SPARK_long", 1, 1, 10) ) @Test fun sparkDouble() = assertTokens( "SPARK_double", - token(IDENTIFIER, "SPARK_double", 1, 1, 12) + token(TokenType.IDENTIFIER, "SPARK_double", 1, 1, 12) ) @Test fun sparkBoolean() = assertTokens( "SPARK_boolean", - token(IDENTIFIER, "SPARK_boolean", 1, 1, 13) + token(TokenType.IDENTIFIER, "SPARK_boolean", 1, 1, 13) ) @Test fun rsInteger() = assertTokens( "RS_integer", - token(IDENTIFIER, "RS_integer", 1, 1, 10) + token(TokenType.IDENTIFIER, "RS_integer", 1, 1, 10) ) @Test fun rsBigint() = assertTokens( "RS_bigint", - token(IDENTIFIER, "RS_bigint", 1, 1, 9) + token(TokenType.IDENTIFIER, "RS_bigint", 1, 1, 9) ) @Test fun rsBoolean() = assertTokens( "RS_boolean", - token(IDENTIFIER, "RS_boolean", 1, 1, 10) + token(TokenType.IDENTIFIER, "RS_boolean", 1, 1, 10) ) -} +} \ No newline at end of file diff --git a/lang/test/org/partiql/lang/syntax/SqlParserDateTimeTests.kt b/lang/test/org/partiql/lang/syntax/SqlParserDateTimeTests.kt index 5e08621897..ac709a8470 100644 --- a/lang/test/org/partiql/lang/syntax/SqlParserDateTimeTests.kt +++ b/lang/test/org/partiql/lang/syntax/SqlParserDateTimeTests.kt @@ -5,10 +5,10 @@ import junitparams.Parameters import org.junit.Test import org.partiql.lang.domains.PartiqlAst import org.partiql.lang.domains.id -import java.util.* import org.partiql.lang.errors.ErrorCode import org.partiql.lang.errors.Property import org.partiql.lang.util.to +import java.util.Random class SqlParserDateTimeTests : SqlParserTestBase() { diff --git a/lang/test/org/partiql/lang/syntax/SqlParserPrecedenceTest.kt b/lang/test/org/partiql/lang/syntax/SqlParserPrecedenceTest.kt index ffb578a817..065dc3c7ec 100644 --- a/lang/test/org/partiql/lang/syntax/SqlParserPrecedenceTest.kt +++ b/lang/test/org/partiql/lang/syntax/SqlParserPrecedenceTest.kt @@ -14,13 +14,12 @@ package org.partiql.lang.syntax -import junitparams.* -import junitparams.naming.* -import org.junit.* import com.amazon.ionelement.api.toIonElement +import junitparams.Parameters +import junitparams.naming.TestCaseName +import org.junit.Test import org.partiql.lang.domains.PartiqlAst - class SqlParserPrecedenceTest : SqlParserTestBase() { @Test diff --git a/lang/test/org/partiql/lang/util/AssertJExtensions.kt b/lang/test/org/partiql/lang/util/AssertJExtensions.kt index d70c4b6df6..faa7773f50 100644 --- a/lang/test/org/partiql/lang/util/AssertJExtensions.kt +++ b/lang/test/org/partiql/lang/util/AssertJExtensions.kt @@ -14,6 +14,6 @@ package org.partiql.lang.util -import org.assertj.core.api.* +import org.assertj.core.api.SoftAssertions internal fun softAssert(assertions: SoftAssertions.() -> Unit) = SoftAssertions().apply(assertions).assertAll() \ No newline at end of file diff --git a/lang/test/org/partiql/lang/util/AstExtensions.kt b/lang/test/org/partiql/lang/util/AstExtensions.kt index ac37bdba9f..d3460bb8b0 100644 --- a/lang/test/org/partiql/lang/util/AstExtensions.kt +++ b/lang/test/org/partiql/lang/util/AstExtensions.kt @@ -15,11 +15,11 @@ package org.partiql.lang.util -import com.amazon.ion.* -import com.amazon.ion.system.* -import org.junit.* +import com.amazon.ion.IonSexp +import com.amazon.ion.IonSymbol +import com.amazon.ion.system.IonSystemBuilder import org.junit.Test -import kotlin.test.* +import kotlin.test.assertEquals /** * rewrites the ast mixing the identifiers case, for example `(id identifier)` is rewritten to `(id IdEnTiFiEr)`. diff --git a/lang/test/org/partiql/lang/util/CollectionsFoldLeftProductTest.kt b/lang/test/org/partiql/lang/util/CollectionsFoldLeftProductTest.kt index 5392123d6c..9401dec609 100644 --- a/lang/test/org/partiql/lang/util/CollectionsFoldLeftProductTest.kt +++ b/lang/test/org/partiql/lang/util/CollectionsFoldLeftProductTest.kt @@ -14,8 +14,6 @@ package org.partiql.lang.util -import java.util.* - class CollectionsFoldLeftProductTest : CollectionsProductTest() { var expectedCount: Int = 0 var actualCount: Int = 0 diff --git a/lang/test/org/partiql/lang/util/CollectionsListTests.kt b/lang/test/org/partiql/lang/util/CollectionsListTests.kt index ea721daf9e..78e0f3d65e 100644 --- a/lang/test/org/partiql/lang/util/CollectionsListTests.kt +++ b/lang/test/org/partiql/lang/util/CollectionsListTests.kt @@ -14,8 +14,8 @@ package org.partiql.lang.util -import org.partiql.lang.* import org.junit.Test +import org.partiql.lang.TestBase /* * Copyright 2017 Amazon.com, Inc. or its affiliates. All rights reserved. diff --git a/lang/test/org/partiql/lang/util/CollectionsProductTest.kt b/lang/test/org/partiql/lang/util/CollectionsProductTest.kt index e892911610..fae2194979 100644 --- a/lang/test/org/partiql/lang/util/CollectionsProductTest.kt +++ b/lang/test/org/partiql/lang/util/CollectionsProductTest.kt @@ -14,8 +14,8 @@ package org.partiql.lang.util -import org.partiql.lang.* import org.junit.Test +import org.partiql.lang.TestBase open class CollectionsProductTest() : TestBase() { fun assertCartesianProduct(collections: List>, expected: List>) { diff --git a/lang/test/org/partiql/lang/util/ConfigurableExprValueFormatterTest.kt b/lang/test/org/partiql/lang/util/ConfigurableExprValueFormatterTest.kt index 4d496778dd..0bd1f9ff1e 100644 --- a/lang/test/org/partiql/lang/util/ConfigurableExprValueFormatterTest.kt +++ b/lang/test/org/partiql/lang/util/ConfigurableExprValueFormatterTest.kt @@ -1,14 +1,17 @@ package org.partiql.lang.util -import com.amazon.ion.system.* -import junitparams.* -import org.junit.* +import com.amazon.ion.system.IonSystemBuilder +import junitparams.JUnitParamsRunner +import junitparams.Parameters import org.junit.Test -import org.junit.runner.* -import org.partiql.lang.* -import org.partiql.lang.eval.* -import org.partiql.lang.syntax.* -import kotlin.test.* +import org.junit.runner.RunWith +import org.partiql.lang.CompilerPipeline +import org.partiql.lang.eval.EvaluationSession +import org.partiql.lang.eval.ExprValue +import org.partiql.lang.syntax.SqlLexer +import org.partiql.lang.syntax.SqlParser +import kotlin.test.assertEquals +import kotlin.test.assertTrue @RunWith(JUnitParamsRunner::class) diff --git a/lang/test/org/partiql/lang/util/ExprValueFactoryExtensions.kt b/lang/test/org/partiql/lang/util/ExprValueFactoryExtensions.kt index 8a7ed8ce18..6264e6ca6e 100644 --- a/lang/test/org/partiql/lang/util/ExprValueFactoryExtensions.kt +++ b/lang/test/org/partiql/lang/util/ExprValueFactoryExtensions.kt @@ -14,7 +14,8 @@ package org.partiql.lang.util -import org.partiql.lang.eval.* +import org.partiql.lang.eval.ExprValue +import org.partiql.lang.eval.ExprValueFactory internal fun ExprValueFactory.newFromIonText(ionText: String): ExprValue = this.newFromIonValue(this.ion.singleValue(ionText)) \ No newline at end of file diff --git a/lang/test/org/partiql/lang/util/NumbersTest.kt b/lang/test/org/partiql/lang/util/NumbersTest.kt index af9ea7891e..f1f0cbab6d 100644 --- a/lang/test/org/partiql/lang/util/NumbersTest.kt +++ b/lang/test/org/partiql/lang/util/NumbersTest.kt @@ -15,8 +15,8 @@ package org.partiql.lang.util import com.amazon.ion.Decimal -import org.partiql.lang.* import org.junit.Test +import org.partiql.lang.TestBase import java.math.BigDecimal class NumbersTest : TestBase() { diff --git a/lang/test/org/partiql/lang/util/SexpAstPrettyPrinter.kt b/lang/test/org/partiql/lang/util/SexpAstPrettyPrinter.kt index 9b67961e53..94fe3c5829 100644 --- a/lang/test/org/partiql/lang/util/SexpAstPrettyPrinter.kt +++ b/lang/test/org/partiql/lang/util/SexpAstPrettyPrinter.kt @@ -14,7 +14,9 @@ package org.partiql.lang.util -import com.amazon.ion.* +import com.amazon.ion.IonSexp +import com.amazon.ion.IonSymbol +import com.amazon.ion.IonValue /** * Formats "tagged s-expressions" in a pretty, readable fashion, i.e.