Skip to content

Commit

Permalink
Merge pull request #1272 from partiql/simplify-dynamic-fns
Browse files Browse the repository at this point in the history
Removes the dynamic function definition
  • Loading branch information
johnedquinn authored Nov 29, 2023
2 parents c23ca8c + 17ed56e commit 8662f3b
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 61 deletions.
11 changes: 3 additions & 8 deletions partiql-plan/src/main/resources/partiql_plan.ion
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ global::{

// Functions

fn::[
static::{
signature: scalar_signature,
},
dynamic::{
signatures: list::[scalar_signature],
}
]
fn::{
signature: scalar_signature,
}

agg::{
signature: aggregation_signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package org.partiql.planner.internal.ir

import org.partiql.planner.internal.ir.builder.AggResolvedBuilder
import org.partiql.planner.internal.ir.builder.AggUnresolvedBuilder
import org.partiql.planner.internal.ir.builder.FnDynamicBuilder
import org.partiql.planner.internal.ir.builder.FnResolvedBuilder
import org.partiql.planner.internal.ir.builder.FnUnresolvedBuilder
import org.partiql.planner.internal.ir.builder.GlobalBuilder
Expand Down Expand Up @@ -126,7 +125,6 @@ internal sealed class Fn : PlanNode() {
internal override fun <R, C> accept(visitor: PlanVisitor<R, C>, ctx: C): R = when (this) {
is Resolved -> visitor.visitFnResolved(this, ctx)
is Unresolved -> visitor.visitFnUnresolved(this, ctx)
is Dynamic -> visitor.visitFnDynamic(this, ctx)
}

internal data class Resolved(
Expand Down Expand Up @@ -164,21 +162,6 @@ internal sealed class Fn : PlanNode() {
internal fun builder(): FnUnresolvedBuilder = FnUnresolvedBuilder()
}
}

internal data class Dynamic(
@JvmField
internal val signatures: List<FunctionSignature.Scalar>,
) : Fn() {
internal override val children: List<PlanNode> = emptyList()

internal override fun <R, C> accept(visitor: PlanVisitor<R, C>, ctx: C): R =
visitor.visitFnDynamic(this, ctx)

internal companion object {
@JvmStatic
internal fun builder(): FnDynamicBuilder = FnDynamicBuilder()
}
}
}

internal sealed class Agg : PlanNode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ internal fun fnResolved(signature: FunctionSignature.Scalar): Fn.Resolved = Fn.R
internal fun fnUnresolved(identifier: Identifier, isHidden: Boolean): Fn.Unresolved =
Fn.Unresolved(identifier, isHidden)

internal fun fnDynamic(signatures: List<FunctionSignature.Scalar>): Fn.Dynamic =
Fn.Dynamic(signatures)

internal fun aggResolved(signature: FunctionSignature.Aggregation): Agg.Resolved =
Agg.Resolved(signature)

Expand All @@ -39,6 +36,7 @@ internal fun identifierQualified(root: Identifier.Symbol, steps: List<Identifier

internal fun rex(type: StaticType, op: Rex.Op): Rex = Rex(type, op)

@OptIn(PartiQLValueExperimental::class)
internal fun rexOpLit(`value`: PartiQLValue): Rex.Op.Lit = Rex.Op.Lit(value)

internal fun rexOpVarResolved(ref: Int): Rex.Op.Var.Resolved = Rex.Op.Var.Resolved(ref)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ internal class PlanBuilder {
return builder.build()
}

internal fun fnDynamic(
signatures: MutableList<FunctionSignature.Scalar> = mutableListOf(),
block: FnDynamicBuilder.() -> Unit = {},
): Fn.Dynamic {
val builder = FnDynamicBuilder(signatures)
builder.block()
return builder.build()
}

internal fun aggResolved(
signature: FunctionSignature.Aggregation? = null,
block: AggResolvedBuilder.() -> Unit = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,6 @@ internal class FnUnresolvedBuilder(
)
}

internal class FnDynamicBuilder(
internal var signatures: MutableList<FunctionSignature.Scalar> = mutableListOf(),
) {
internal fun signatures(signatures: MutableList<FunctionSignature.Scalar>): FnDynamicBuilder =
this.apply {
this.signatures = signatures
}

internal fun build(): Fn.Dynamic = Fn.Dynamic(signatures = signatures)
}

internal class AggResolvedBuilder(
internal var signature: FunctionSignature.Aggregation? = null,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ internal abstract class PlanRewriter<C> : PlanBaseVisitor<PlanNode, C>() {
}
}

override fun visitFnDynamic(node: Fn.Dynamic, ctx: C): PlanNode {
val signatures = node.signatures
return node
}

override fun visitAggResolved(node: Agg.Resolved, ctx: C): PlanNode {
val signature = node.signature
return node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ internal abstract class PlanBaseVisitor<R, C> : PlanVisitor<R, C> {
override fun visitFn(node: Fn, ctx: C): R = when (node) {
is Fn.Resolved -> visitFnResolved(node, ctx)
is Fn.Unresolved -> visitFnUnresolved(node, ctx)
is Fn.Dynamic -> visitFnDynamic(node, ctx)
}

override fun visitFnResolved(node: Fn.Resolved, ctx: C): R = defaultVisit(node, ctx)

override fun visitFnUnresolved(node: Fn.Unresolved, ctx: C): R = defaultVisit(node, ctx)

override fun visitFnDynamic(node: Fn.Dynamic, ctx: C): R = defaultVisit(node, ctx)

override fun visitAgg(node: Agg, ctx: C): R = when (node) {
is Agg.Resolved -> visitAggResolved(node, ctx)
is Agg.Unresolved -> visitAggUnresolved(node, ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ internal interface PlanVisitor<R, C> {

fun visitFnUnresolved(node: Fn.Unresolved, ctx: C): R

fun visitFnDynamic(node: Fn.Dynamic, ctx: C): R

fun visitAgg(node: Agg, ctx: C): R

fun visitAggResolved(node: Agg.Resolved, ctx: C): R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ internal object PlanTransform : PlanBaseVisitor<PlanNode, ProblemCallback>() {
return org.partiql.plan.global(path, type)
}

override fun visitFnResolved(node: Fn.Resolved, ctx: ProblemCallback) = org.partiql.plan.fnStatic(node.signature)
override fun visitFnResolved(node: Fn.Resolved, ctx: ProblemCallback) = org.partiql.plan.fn(node.signature)

override fun visitFnUnresolved(node: Fn.Unresolved, ctx: ProblemCallback): org.partiql.plan.Rex.Op {
return org.partiql.plan.Rex.Op.Err("Unresolved function")
}

override fun visitFnDynamic(node: Fn.Dynamic, ctx: ProblemCallback) = org.partiql.plan.fnDynamic(node.signatures)

override fun visitAgg(node: Agg, ctx: ProblemCallback) = super.visitAgg(node, ctx) as org.partiql.plan.Agg

override fun visitAggResolved(node: Agg.Resolved, ctx: ProblemCallback) = org.partiql.plan.Agg(node.signature)
Expand Down

0 comments on commit 8662f3b

Please sign in to comment.