Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Removes PartiQLValue from the planner #1594

Draft
wants to merge 3 commits into
base: v1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions partiql-plan/api/partiql-plan.api
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public final class org/partiql/plan/Plan {
public static final fun rexOpCollection (Ljava/util/List;)Lorg/partiql/plan/Rex$Op$Collection;
public static final fun rexOpErr (Ljava/lang/String;Ljava/util/List;)Lorg/partiql/plan/Rex$Op$Err;
public static final fun rexOpGlobal (Lorg/partiql/plan/Ref;)Lorg/partiql/plan/Rex$Op$Global;
public static final fun rexOpLit (Lorg/partiql/value/PartiQLValue;)Lorg/partiql/plan/Rex$Op$Lit;
public static final fun rexOpLit (Lorg/partiql/spi/value/Datum;)Lorg/partiql/plan/Rex$Op$Lit;
public static final fun rexOpMissing (Ljava/lang/String;Ljava/util/List;)Lorg/partiql/plan/Rex$Op$Missing;
public static final fun rexOpNullif (Lorg/partiql/plan/Rex;Lorg/partiql/plan/Rex;)Lorg/partiql/plan/Rex$Op$Nullif;
public static final fun rexOpPathIndex (Lorg/partiql/plan/Rex;Lorg/partiql/plan/Rex;)Lorg/partiql/plan/Rex$Op$Path$Index;
Expand Down Expand Up @@ -1143,13 +1143,13 @@ public final class org/partiql/plan/Rex$Op$Global$Companion {

public final class org/partiql/plan/Rex$Op$Lit : org/partiql/plan/Rex$Op {
public static final field Companion Lorg/partiql/plan/Rex$Op$Lit$Companion;
public final field value Lorg/partiql/value/PartiQLValue;
public fun <init> (Lorg/partiql/value/PartiQLValue;)V
public final field value Lorg/partiql/spi/value/Datum;
public fun <init> (Lorg/partiql/spi/value/Datum;)V
public fun accept (Lorg/partiql/plan/visitor/PlanVisitor;Ljava/lang/Object;)Ljava/lang/Object;
public static final fun builder ()Lorg/partiql/plan/builder/RexOpLitBuilder;
public final fun component1 ()Lorg/partiql/value/PartiQLValue;
public final fun copy (Lorg/partiql/value/PartiQLValue;)Lorg/partiql/plan/Rex$Op$Lit;
public static synthetic fun copy$default (Lorg/partiql/plan/Rex$Op$Lit;Lorg/partiql/value/PartiQLValue;ILjava/lang/Object;)Lorg/partiql/plan/Rex$Op$Lit;
public final fun component1 ()Lorg/partiql/spi/value/Datum;
public final fun copy (Lorg/partiql/spi/value/Datum;)Lorg/partiql/plan/Rex$Op$Lit;
public static synthetic fun copy$default (Lorg/partiql/plan/Rex$Op$Lit;Lorg/partiql/spi/value/Datum;ILjava/lang/Object;)Lorg/partiql/plan/Rex$Op$Lit;
public fun equals (Ljava/lang/Object;)Z
public fun getChildren ()Ljava/util/List;
public fun hashCode ()I
Expand Down Expand Up @@ -1644,8 +1644,8 @@ public final class org/partiql/plan/builder/PlanBuilder {
public static synthetic fun rexOpErr$default (Lorg/partiql/plan/builder/PlanBuilder;Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/partiql/plan/Rex$Op$Err;
public final fun rexOpGlobal (Lorg/partiql/plan/Ref;Lkotlin/jvm/functions/Function1;)Lorg/partiql/plan/Rex$Op$Global;
public static synthetic fun rexOpGlobal$default (Lorg/partiql/plan/builder/PlanBuilder;Lorg/partiql/plan/Ref;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/partiql/plan/Rex$Op$Global;
public final fun rexOpLit (Lorg/partiql/value/PartiQLValue;Lkotlin/jvm/functions/Function1;)Lorg/partiql/plan/Rex$Op$Lit;
public static synthetic fun rexOpLit$default (Lorg/partiql/plan/builder/PlanBuilder;Lorg/partiql/value/PartiQLValue;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/partiql/plan/Rex$Op$Lit;
public final fun rexOpLit (Lorg/partiql/spi/value/Datum;Lkotlin/jvm/functions/Function1;)Lorg/partiql/plan/Rex$Op$Lit;
public static synthetic fun rexOpLit$default (Lorg/partiql/plan/builder/PlanBuilder;Lorg/partiql/spi/value/Datum;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/partiql/plan/Rex$Op$Lit;
public final fun rexOpMissing (Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function1;)Lorg/partiql/plan/Rex$Op$Missing;
public static synthetic fun rexOpMissing$default (Lorg/partiql/plan/builder/PlanBuilder;Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/partiql/plan/Rex$Op$Missing;
public final fun rexOpNullif (Lorg/partiql/plan/Rex;Lorg/partiql/plan/Rex;Lkotlin/jvm/functions/Function1;)Lorg/partiql/plan/Rex$Op$Nullif;
Expand Down Expand Up @@ -2191,12 +2191,12 @@ public final class org/partiql/plan/builder/RexOpGlobalBuilder {

public final class org/partiql/plan/builder/RexOpLitBuilder {
public fun <init> ()V
public fun <init> (Lorg/partiql/value/PartiQLValue;)V
public synthetic fun <init> (Lorg/partiql/value/PartiQLValue;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lorg/partiql/spi/value/Datum;)V
public synthetic fun <init> (Lorg/partiql/spi/value/Datum;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun build ()Lorg/partiql/plan/Rex$Op$Lit;
public final fun getValue ()Lorg/partiql/value/PartiQLValue;
public final fun setValue (Lorg/partiql/value/PartiQLValue;)V
public final fun value (Lorg/partiql/value/PartiQLValue;)Lorg/partiql/plan/builder/RexOpLitBuilder;
public final fun getValue ()Lorg/partiql/spi/value/Datum;
public final fun setValue (Lorg/partiql/spi/value/Datum;)V
public final fun value (Lorg/partiql/spi/value/Datum;)Lorg/partiql/plan/builder/RexOpLitBuilder;
}

public final class org/partiql/plan/builder/RexOpMissingBuilder {
Expand Down
1 change: 0 additions & 1 deletion partiql-plan/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ val generate = tasks.register<Exec>("generate") {
"--poems", "visitor",
"--poems", "builder",
"--poems", "util",
"--opt-in", "org.partiql.value.PartiQLValueExperimental",
"./src/main/resources/partiql_plan.ion"
)
}
Expand Down
2 changes: 1 addition & 1 deletion partiql-plan/src/main/resources/partiql_plan.ion
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
imports::{
kotlin: [
partiql_value::'org.partiql.value.PartiQLValue',
partiql_value::'org.partiql.spi.value.Datum',
partiql_value_type::'org.partiql.types.PType',
static_type::'org.partiql.types.PType',
function::'org.partiql.spi.fn.Function',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import org.partiql.spi.catalog.Name
import org.partiql.spi.catalog.Table
import org.partiql.spi.fn.Aggregation
import org.partiql.spi.fn.Function
import org.partiql.value.PartiQLValue
import org.partiql.spi.value.Datum
import org.partiql.value.PartiQLValueExperimental
import kotlin.random.Random

Expand Down Expand Up @@ -234,7 +234,7 @@ internal data class Rex(
}

internal data class Lit(
@JvmField internal val `value`: PartiQLValue,
@JvmField internal val `value`: Datum,
) : Op() {
public override val children: List<PlanNode> = emptyList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ internal class PlanTransform(

override fun visitRexOp(node: Rex.Op, ctx: Unit) = super.visitRexOp(node, ctx) as org.partiql.plan.Rex.Op

@OptIn(PartiQLValueExperimental::class)
override fun visitRexOpLit(node: Rex.Op.Lit, ctx: Unit) = org.partiql.plan.rexOpLit(node.value)

override fun visitRexOpVar(node: Rex.Op.Var, ctx: Unit) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import org.partiql.planner.internal.PlannerFlag
import org.partiql.planner.internal.ProblemGenerator
import org.partiql.planner.internal.ir.SetQuantifier
import org.partiql.planner.internal.ir.visitor.PlanBaseVisitor
import org.partiql.spi.value.Datum
import org.partiql.types.Field
import org.partiql.types.PType
import org.partiql.value.PartiQLValueExperimental
import org.partiql.planner.internal.ir.PartiQLPlan as IPlan
import org.partiql.planner.internal.ir.PlanNode as INode
import org.partiql.planner.internal.ir.Rel as IRel
Expand Down Expand Up @@ -244,9 +242,8 @@ internal class PlanTransformV1(private val flags: Set<PlannerFlag>) {
return factory.rexVar(depth = node.depth, offset = node.ref)
}

@OptIn(PartiQLValueExperimental::class)
override fun visitRexOpLit(node: IRex.Op.Lit, ctx: PType): Any {
return factory.rexLit(Datum.of(node.value))
return factory.rexLit(node.value)
}

// RELATION OPERATORS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ import org.partiql.planner.internal.ir.rexOpStruct
import org.partiql.planner.internal.ir.rexOpStructField
import org.partiql.planner.internal.ir.rexOpVarLocal
import org.partiql.planner.internal.typer.CompilerType
import org.partiql.spi.value.Datum
import org.partiql.types.PType
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.boolValue
import org.partiql.value.int32Value
import org.partiql.value.stringValue

/**
* Lexically scoped state for use in translating an individual SELECT statement.
Expand Down Expand Up @@ -276,13 +275,12 @@ internal object RelConverter {
*
* TODO compute basic schema
*/
@OptIn(PartiQLValueExperimental::class)
override fun visitFromJoin(node: From.Join, nil: Rel): Rel {
val lhs = visitFrom(node.lhs, nil)
val rhs = visitFrom(node.rhs, nil)
val schema = lhs.type.schema + rhs.type.schema // Note: This gets more specific in PlanTyper. It is only used to find binding names here.
val props = emptySet<Rel.Prop>()
val condition = node.condition?.let { RexConverter.apply(it, env) } ?: rex(BOOL, rexOpLit(boolValue(true)))
val condition = node.condition?.let { RexConverter.apply(it, env) } ?: rex(BOOL, rexOpLit(Datum.bool(true)))
val joinType = when (node.type) {
From.Join.Type.LEFT_OUTER, From.Join.Type.LEFT -> Rel.Op.Join.Type.LEFT
From.Join.Type.RIGHT_OUTER, From.Join.Type.RIGHT -> Rel.Op.Join.Type.RIGHT
Expand Down Expand Up @@ -423,7 +421,7 @@ internal object RelConverter {
schema.add(binding)
val fields = input.type.schema.mapIndexed { bindingIndex, currBinding ->
rexOpStructField(
k = rex(STRING, rexOpLit(stringValue(currBinding.name))),
k = rex(STRING, rexOpLit(Datum.string(currBinding.name))),
v = rex(ANY, rexOpVarLocal(0, bindingIndex))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.partiql.planner.internal.transforms

import com.amazon.ionelement.api.loadSingleElement
import org.partiql.ast.AstNode
import org.partiql.ast.DatetimeField
import org.partiql.ast.Expr
Expand Down Expand Up @@ -55,16 +54,12 @@ import org.partiql.planner.internal.ir.rexOpVarUnresolved
import org.partiql.planner.internal.typer.CompilerType
import org.partiql.planner.internal.typer.PlanTyper.Companion.toCType
import org.partiql.spi.catalog.Identifier
import org.partiql.spi.value.Datum
import org.partiql.spi.value.ion.IonDatum
import org.partiql.types.PType
import org.partiql.value.MissingValue
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.StringValue
import org.partiql.value.boolValue
import org.partiql.value.int32Value
import org.partiql.value.int64Value
import org.partiql.value.io.PartiQLValueIonReaderBuilder
import org.partiql.value.nullValue
import org.partiql.value.stringValue
import org.partiql.ast.Identifier as AstIdentifier

/**
Expand All @@ -76,7 +71,6 @@ internal object RexConverter {

internal fun applyRel(expr: Expr, context: Env): Rex = expr.accept(ToRex, context)

@OptIn(PartiQLValueExperimental::class)
@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")
private object ToRex : AstBaseVisitor<Rex, Env>() {

Expand All @@ -94,26 +88,29 @@ internal object RexConverter {
override fun defaultReturn(node: AstNode, context: Env): Rex =
throw IllegalArgumentException("unsupported rex $node")

/**
* TODO REMOVE PartiQLValue from AST – https://github.com/partiql/partiql-lang-kotlin/issues/1589
*/
@OptIn(PartiQLValueExperimental::class)
override fun visitExprLit(node: Expr.Lit, context: Env): Rex {
val type = CompilerType(
_delegate = node.value.type.toPType(),
isNullValue = node.value.isNull,
isMissingValue = node.value is MissingValue
)
val op = rexOpLit(node.value)
val op = rexOpLit(Datum.of(node.value))
return rex(type, op)
}

/**
* TODO PartiQLValue will be replaced by Datum (i.e. IonDatum) is a subsequent PR.
* TODO add registration of variant types to catalog functionality.
*/
override fun visitExprVariant(node: Expr.Variant, ctx: Env): Rex {
if (node.encoding != "ion") {
throw IllegalArgumentException("unsupported encoding ${node.encoding}")
val value = when (node.encoding.lowercase()) {
"ion" -> IonDatum.of(node.value)
else -> throw IllegalArgumentException("unsupported variant encoding ${node.encoding}")
}
val ion = loadSingleElement(node.value)
val value = PartiQLValueIonReaderBuilder.standard().build(ion).read()
val type = CompilerType(value.type.toPType())
val type = CompilerType(value.type)
return rex(type, rexOpLit(value))
}

Expand Down Expand Up @@ -299,6 +296,7 @@ internal object RexConverter {
}
}

@OptIn(PartiQLValueExperimental::class)
override fun visitExprPath(node: Expr.Path, context: Env): Rex {
// Args
val root = visitExprCoerce(node.root, context)
Expand Down Expand Up @@ -416,7 +414,7 @@ internal object RexConverter {
val schema = acc.type.schema + scan.type.schema
val props = emptySet<Rel.Prop>()
val type = relType(schema, props)
rel(type, relOpJoin(acc, scan, rex(BOOL, rexOpLit(boolValue(true))), Rel.Op.Join.Type.INNER))
rel(type, relOpJoin(acc, scan, rex(BOOL, rexOpLit(Datum.bool(true))), Rel.Op.Join.Type.INNER))
}

// compute the ref used by select construct
Expand Down Expand Up @@ -472,7 +470,7 @@ internal object RexConverter {
return rel(relType, relOpUnpivot(path))
}

private fun rexString(str: String) = rex(STRING, rexOpLit(stringValue(str)))
private fun rexString(str: String) = rex(STRING, rexOpLit(Datum.string(str)))

override fun visitExprCall(node: Expr.Call, context: Env): Rex {
val type = (ANY)
Expand Down Expand Up @@ -580,7 +578,7 @@ internal object RexConverter {
}.toMutableList()

val defaultRex = when (val default = node.default) {
null -> rex(type = ANY, op = rexOpLit(value = nullValue()))
null -> rex(type = ANY, op = rexOpLit(value = Datum.nullValue()))
else -> visitExprCoerce(default, context)
}
val op = rexOpCase(branches = branches, default = defaultRex)
Expand Down Expand Up @@ -758,7 +756,7 @@ internal object RexConverter {
val type = ANY
// Args
val arg0 = visitExprCoerce(node.value, ctx)
val arg1 = node.start?.let { visitExprCoerce(it, ctx) } ?: rex(INT, rexOpLit(int64Value(1)))
val arg1 = node.start?.let { visitExprCoerce(it, ctx) } ?: rex(INT, rexOpLit(Datum.bigint(1)))
val arg2 = node.length?.let { visitExprCoerce(it, ctx) }
// Call Variants
val call = when (arg2) {
Expand Down Expand Up @@ -836,8 +834,8 @@ internal object RexConverter {
call(
"substring",
cv,
rex(INT4, rexOpLit(int32Value(1))),
rex(ANY, call("minus", sp, rex(INT4, rexOpLit(int32Value(1)))))
rex(INT4, rexOpLit(Datum.integer(1))),
rex(ANY, call("minus", sp, rex(INT4, rexOpLit(Datum.integer(1)))))
)
)
val p2 = rex(ANY, call("concat", p1, rs))
Expand Down Expand Up @@ -968,7 +966,14 @@ internal object RexConverter {
return rexOpCallUnresolved(id, args.toList())
}

private fun Int?.toRex() = rex(INT4, rexOpLit(int32Value(this)))
private fun Int?.toRex(): Rex {
val datum = if (this == null) {
Datum.nullValue(PType.integer())
} else {
Datum.integer(this)
}
return rex(INT4, rexOpLit(datum))
}

private val ANY: CompilerType = CompilerType(PType.dynamic())
private val BOOL: CompilerType = CompilerType(PType.bool())
Expand Down
Loading
Loading