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

Ports evaluation changes to v1 plans #1573

Merged
merged 3 commits into from
Sep 6, 2024
Merged
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
121 changes: 95 additions & 26 deletions partiql-plan/api/partiql-plan.api

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions partiql-plan/src/main/kotlin/org/partiql/plan/v1/Schema.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import org.partiql.types.Field
*/
public interface Schema {

public fun getSize(): Int = getFields().size

public fun getFields(): List<Field>

public fun getField(name: String): Field
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.partiql.plan.v1.builder

import org.partiql.eval.value.Datum
import org.partiql.plan.v1.Schema
import org.partiql.plan.v1.operator.rel.Rel
import org.partiql.plan.v1.operator.rel.RelAggregate
import org.partiql.plan.v1.operator.rel.RelAggregateCall
import org.partiql.plan.v1.operator.rel.RelAggregateCallImpl
import org.partiql.plan.v1.operator.rel.RelAggregateImpl
import org.partiql.plan.v1.operator.rel.RelCollation
import org.partiql.plan.v1.operator.rel.RelCorrelate
Expand Down Expand Up @@ -43,8 +45,10 @@ import org.partiql.plan.v1.operator.rex.RexArray
import org.partiql.plan.v1.operator.rex.RexArrayImpl
import org.partiql.plan.v1.operator.rex.RexBag
import org.partiql.plan.v1.operator.rex.RexBagImpl
import org.partiql.plan.v1.operator.rex.RexCall
import org.partiql.plan.v1.operator.rex.RexCallImpl
import org.partiql.plan.v1.operator.rex.RexCallDynamic
import org.partiql.plan.v1.operator.rex.RexCallDynamicImpl
import org.partiql.plan.v1.operator.rex.RexCallStatic
import org.partiql.plan.v1.operator.rex.RexCallStaticImpl
import org.partiql.plan.v1.operator.rex.RexCase
import org.partiql.plan.v1.operator.rex.RexCaseImpl
import org.partiql.plan.v1.operator.rex.RexCast
Expand All @@ -57,6 +61,8 @@ import org.partiql.plan.v1.operator.rex.RexLit
import org.partiql.plan.v1.operator.rex.RexLitImpl
import org.partiql.plan.v1.operator.rex.RexMissing
import org.partiql.plan.v1.operator.rex.RexMissingImpl
import org.partiql.plan.v1.operator.rex.RexNullIf
import org.partiql.plan.v1.operator.rex.RexNullIfImpl
import org.partiql.plan.v1.operator.rex.RexPathIndex
import org.partiql.plan.v1.operator.rex.RexPathIndexImpl
import org.partiql.plan.v1.operator.rex.RexPathKey
Expand Down Expand Up @@ -84,6 +90,7 @@ import org.partiql.plan.v1.operator.rex.RexTableImpl
import org.partiql.plan.v1.operator.rex.RexVar
import org.partiql.plan.v1.operator.rex.RexVarImpl
import org.partiql.planner.catalog.Table
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.Fn
import org.partiql.types.PType

Expand Down Expand Up @@ -119,6 +126,17 @@ public interface PlanFactory {
public fun relAggregate(input: Rel, calls: List<RelAggregateCall>, groups: List<Rex>): RelAggregate =
RelAggregateImpl(input, calls, groups)

/**
* Create a [RelAggregateCall] instance.
*
* @param aggregation
* @param args
* @param isDistinct
* @return
*/
public fun relAggregateCall(aggregation: Agg, args: List<Rex>, isDistinct: Boolean = false): RelAggregateCall =
RelAggregateCallImpl(aggregation, args, isDistinct)

/**
* Create a [RelCorrelate] instance for a lateral cross join.
*
Expand All @@ -136,7 +154,8 @@ public interface PlanFactory {
* @param joinType
* @return
*/
public fun relCorrelate(lhs: Rel, rhs: Rel, joinType: RelJoinType): RelCorrelate = RelCorrelateImpl(lhs, rhs, joinType)
public fun relCorrelate(lhs: Rel, rhs: Rel, joinType: RelJoinType): RelCorrelate =
RelCorrelateImpl(lhs, rhs, joinType)

/**
* Create a [RelDistinct] instance.
Expand Down Expand Up @@ -230,8 +249,8 @@ public interface PlanFactory {
* @param type
* @return
*/
public fun relJoin(lhs: Rel, rhs: Rel, condition: Rex?, type: RelJoinType): RelJoin =
RelJoinImpl(lhs, rhs, condition, type)
public fun relJoin(lhs: Rel, rhs: Rel, condition: Rex?, type: RelJoinType, lhsSchema: Schema? = null, rhsSchema: Schema? = null): RelJoin =
RelJoinImpl(lhs, rhs, condition, type, lhsSchema, rhsSchema)

/**
* Create a [RelLimit] instance.
Expand Down Expand Up @@ -322,13 +341,22 @@ public interface PlanFactory {
public fun rexBag(values: Collection<Rex>): RexBag = RexBagImpl(values)

/**
* Create a [RexCall] instance.
* Create a [RexCallStatic] instance.
*
* @param function
* @param args
* @return
*/
public fun rexCall(function: Fn, args: List<Rex>): RexCall = RexCallImpl(function, args)
public fun rexCall(function: Fn, args: List<Rex>): RexCallStatic = RexCallStaticImpl(function, args)

/**
* Create a [RexCallDynamic] instance.
*
* @param functions
* @param args
* @return
*/
public fun rexCall(functions: List<Fn>, args: List<Rex>): RexCallDynamic = RexCallDynamicImpl(functions, args)

/**
* Create a [RexCase] instance for a searched case-when.
Expand Down Expand Up @@ -374,7 +402,7 @@ public interface PlanFactory {
* @param offset
* @return
*/
public fun rexCol(depth: Int, offset: Int): RexVar = RexVarImpl(depth, offset)
public fun rexVar(depth: Int, offset: Int): RexVar = RexVarImpl(depth, offset)

/**
* TODO AUDIT ME
Expand Down Expand Up @@ -404,6 +432,11 @@ public interface PlanFactory {
*/
public fun rexLit(value: Datum): RexLit = RexLitImpl(value)

/**
* Create a [RexNullIf] instance.
*/
public fun rexNullIf(value: Rex, nullifier: Rex): RexNullIf = RexNullIfImpl(value, nullifier)

/**
* Create a [RexPathIndex] instance.
*
Expand Down Expand Up @@ -474,7 +507,8 @@ public interface PlanFactory {
* @param rel
* @return
*/
public fun rexSubquery(rel: Rel, constructor: Rex, asScalar: Boolean): RexSubquery = RexSubqueryImpl(rel, constructor, asScalar)
public fun rexSubquery(rel: Rel, constructor: Rex, asScalar: Boolean): RexSubquery =
RexSubqueryImpl(rel, constructor, asScalar)

/**
* Create a [RexSubqueryComp] instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class RexBuilder private constructor(rex: Builder) {

@JvmStatic
public fun col(depth: Int, offset: Int): RexBuilder = RexBuilder {
it.rexCol(depth, offset)
it.rexVar(depth, offset)
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
package org.partiql.plan.v1.operator.rel

import org.partiql.plan.v1.operator.rex.Rex
import org.partiql.types.PType
import org.partiql.spi.fn.Agg

/**
* TODO DOCUMENTATION
*/
public interface RelAggregateCall {

public fun isDistinct(): Boolean
public fun getAgg(): Agg

public fun getName(): String
public fun getArgs(): List<Rex>

public fun getType(): PType
public fun isDistinct(): Boolean
}

public fun getArgs(): List<Rex>
/**
* Internal standard implementation of [RelAggregateCall].
*
* DO NOT USE FINAL.
*
* @property agg
* @property args
* @property isDistinct
*/
internal class RelAggregateCallImpl(
private var agg: Agg,
private var args: List<Rex>,
private var isDistinct: Boolean,
) : RelAggregateCall {
override fun getAgg(): Agg = agg
override fun getArgs(): List<Rex> = args
override fun isDistinct(): Boolean = isDistinct
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,31 @@ package org.partiql.plan.v1.operator.rel
import org.partiql.plan.v1.operator.rex.RexVar

/**
* TODO DOCUMENTATION
* Logical representation of an EXCLUDE path.
*/
public interface RelExcludePath {

public fun getRoot(): RexVar

public fun getSteps(): RelExcludeStep
public fun getSteps(): Collection<RelExcludeStep>

public companion object {

@JvmStatic
public fun of(root: RexVar, steps: Collection<RelExcludeStep>): RelExcludePath = RelExcludePathImpl(root, steps)
}
}

/**
* Internal standard implementation of [RelExcludePath].
*
* @property root
* @property steps
*/
internal class RelExcludePathImpl(
private var root: RexVar,
private var steps: Collection<RelExcludeStep>,
) : RelExcludePath {
override fun getRoot(): RexVar = root
override fun getSteps(): Collection<RelExcludeStep> = steps
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,103 @@
package org.partiql.plan.v1.operator.rel

/**
* TODO DOCUMENTATION
* Logical EXCLUDE step, one of: index, key, symbol, struct wildcard, or collection wildcard.
*/
public interface RelExcludeStep {

public fun getSubsteps(): List<RelExcludeStep>
public fun getSubsteps(): Collection<RelExcludeStep>

/**
* TODO DOCUMENTATION
*/
public interface Index : RelExcludeStep {
public fun getIndex(): Int
}
companion object {

/**
* TODO DOCUMENTATION
*/
public interface Key : RelExcludeStep {
public fun getKey(): String
}
@JvmStatic
public fun index(index: Int, substeps: List<RelExcludeStep> = emptyList()): RelExcludeIndex =
RelExcludeIndexImpl(index, substeps)

@JvmStatic
public fun key(key: String, substeps: List<RelExcludeStep> = emptyList()): RelExcludeKey =
RelExcludeKeyImpl(key, substeps)

@JvmStatic
public fun symbol(symbol: String, substeps: List<RelExcludeStep> = emptyList()): RelExcludeSymbol =
RelExcludeSymbolImpl(symbol, substeps)

/**
* TODO DOCUMENTATION
*/
public interface Symbol : RelExcludeStep {
public fun getSymbol(): String
@JvmStatic
public fun struct(substeps: List<RelExcludeStep> = emptyList()): RelExcludeStructWildcard =
RelExcludeStructWildcardImpl(substeps)

@JvmStatic
public fun collection(substeps: List<RelExcludeStep> = emptyList()): RelExcludeCollectionWildcard =
RelExcludeCollectionWildcardImpl(substeps)
}
}

/**
* Logical representation of an EXCLUDE path index step.
*/
public interface RelExcludeIndex : RelExcludeStep {
public fun getIndex(): Int
}

private data class RelExcludeIndexImpl(
private val index: Int,
private val substeps: List<RelExcludeStep> = emptyList(),
) : RelExcludeIndex {
override fun getSubsteps(): Collection<RelExcludeStep> = substeps
override fun getIndex(): Int = index
}

/**
* Logical representation of an EXCLUDE path key step.
*/
public interface RelExcludeKey : RelExcludeStep {
public fun getKey(): String
}

/**
* TODO DOCUMENTATION
*/
public interface StructWildcard : RelExcludeStep
// TODO hashcode/equals without data class
private data class RelExcludeKeyImpl(
private val key: String,
private val substeps: List<RelExcludeStep> = emptyList(),
) : RelExcludeKey {
override fun getSubsteps(): Collection<RelExcludeStep> = substeps
override fun getKey(): String = key
}

/**
* Logical representation of an EXCLUDE path symbol step.
*/
public interface RelExcludeSymbol : RelExcludeStep {
public fun getSymbol(): String
}

// TODO hashcode/equals without data class
private data class RelExcludeSymbolImpl(
private val symbol: String,
private val substeps: List<RelExcludeStep> = emptyList(),
) : RelExcludeSymbol {
override fun getSubsteps(): Collection<RelExcludeStep> = substeps
override fun getSymbol(): String = symbol
}

/**
* Logical representation of an EXCLUDE struct wildcard step.
*/
public interface RelExcludeStructWildcard : RelExcludeStep

// TODO hashcode/equals without data class
private data class RelExcludeStructWildcardImpl(
private val substeps: List<RelExcludeStep> = emptyList(),
) : RelExcludeStructWildcard {
override fun getSubsteps(): Collection<RelExcludeStep> = substeps
}

/**
* Logical representation of an EXCLUDE collection wildcard step.
*/
public interface RelExcludeCollectionWildcard : RelExcludeStep

/**
* TODO DOCUMENTATION
*/
public interface CollectionWildcard : RelExcludeStep
// TODO hashcode/equals without data class
private data class RelExcludeCollectionWildcardImpl(
private val substeps: List<RelExcludeStep> = emptyList(),
) : RelExcludeCollectionWildcard {
override fun getSubsteps(): Collection<RelExcludeStep> = substeps
}
Loading
Loading