Skip to content

Commit

Permalink
Intermediate internalization of functions to planner
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Jul 26, 2024
1 parent 16a400a commit b4eed3f
Show file tree
Hide file tree
Showing 136 changed files with 1,152 additions and 1,629 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ internal class Compiler(
return RelAggregate(input, groups, calls)
}

@OptIn(FnExperimental::class)

override fun visitRelOpAggregateCall(node: Rel.Op.Aggregate.Call, ctx: PType?): Operator.Aggregation {
val args = node.args.map { visitRex(it, it.type).modeHandled() }
val setQuantifier: Operator.Aggregation.SetQuantifier = when (node.setQuantifier) {
Expand Down Expand Up @@ -212,7 +212,7 @@ internal class Compiler(
return ExprPathIndex(root, index)
}

@OptIn(FnExperimental::class)

override fun visitRexOpCallStatic(node: Rex.Op.Call.Static, ctx: PType?): Operator {
val fn = symbols.getFn(node.fn)
val args = node.args.map { visitRex(it, ctx) }.toTypedArray()
Expand All @@ -225,7 +225,7 @@ internal class Compiler(
}
}

@OptIn(FnExperimental::class)

override fun visitRexOpCallDynamic(node: Rex.Op.Call.Dynamic, ctx: PType?): Operator {
val args = node.args.map { visitRex(it, ctx).modeHandled() }.toTypedArray()
// Check candidate list size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.partiql.spi.fn.FnExperimental
*
* @property catalogs
*/
@OptIn(FnExperimental::class)

internal class Symbols private constructor(private val catalogs: Array<C>) {

private class C(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal sealed interface Operator {

interface Aggregation : Operator {

@OptIn(FnExperimental::class)

val delegate: Agg

val args: List<Expr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.partiql.planner.catalog.Name
import org.partiql.planner.catalog.Session
import org.partiql.planner.internal.casts.CastTable
import org.partiql.planner.internal.casts.Coercions
import org.partiql.planner.internal.fn.AggSignature
import org.partiql.planner.internal.ir.Ref
import org.partiql.planner.internal.ir.Rel
import org.partiql.planner.internal.ir.Rex
Expand All @@ -22,8 +23,8 @@ import org.partiql.spi.BindingCase
import org.partiql.spi.BindingName
import org.partiql.spi.BindingPath
import org.partiql.spi.connector.ConnectorMetadata
import org.partiql.spi.fn.AggSignature
import org.partiql.spi.fn.FnExperimental
import org.partiql.planner.internal.fn.AggSignature
import org.partiql.planner.internal.fn.FnExperimental
import org.partiql.types.PType
import org.partiql.types.PType.Kind

Expand Down Expand Up @@ -52,16 +53,6 @@ internal class Env(private val session: Session) {
*/
private val objects: PathResolverObj = PathResolverObj(catalog, catalogs, session)

/**
* A [PathResolver] for looking up functions given both unqualified and qualified names.
*/
private val fns: PathResolverFn = PathResolverFn(catalog, catalogs, session)

/**
* A [PathResolver] for aggregation function lookup.
*/
private val aggs: PathResolverAgg = PathResolverAgg(catalog, catalogs, session)

/**
* This function looks up a global [BindingPath], returning a global reference expression.
*
Expand All @@ -84,8 +75,7 @@ internal class Env(private val session: Session) {
val tail = path.steps.drop(depth)
return if (tail.isEmpty()) root else root.toPath(tail)
}

@OptIn(FnExperimental::class)

fun resolveFn(path: BindingPath, args: List<Rex>): Rex? {
val item = fns.lookup(path) ?: return null
// Invoke FnResolver to determine if we made a match
Expand Down Expand Up @@ -144,7 +134,6 @@ internal class Env(private val session: Session) {
}
}

@OptIn(FnExperimental::class)
fun resolveAgg(name: String, setQuantifier: Rel.Op.Aggregate.SetQuantifier, args: List<Rex>): Rel.Op.Aggregate.Call.Resolved? {
// TODO: Eventually, do we want to support sensitive lookup? With a path?
val path = BindingPath(listOf(BindingName(name, BindingCase.INSENSITIVE)))
Expand Down Expand Up @@ -217,7 +206,7 @@ internal class Env(private val session: Session) {
return userInputPath.steps.size + actualAbsolutePath.size - pathSentToConnector.steps.size
}

@OptIn(FnExperimental::class)

private fun match(candidates: List<AggSignature>, args: List<PType>): Pair<AggSignature, Array<Ref.Cast?>>? {
// 1. Check for an exact match
for (candidate in candidates) {
Expand All @@ -243,7 +232,7 @@ internal class Env(private val session: Session) {
/**
* Check if this function accepts the exact input argument types. Assume same arity.
*/
@OptIn(FnExperimental::class)

private fun AggSignature.matches(args: List<PType>): Boolean {
for (i in args.indices) {
val a = args[i]
Expand All @@ -259,7 +248,6 @@ internal class Env(private val session: Session) {
* @param args
* @return
*/
@OptIn(FnExperimental::class)
private fun AggSignature.match(args: List<PType>): Pair<AggSignature, Array<Ref.Cast?>>? {
val mapping = arrayOfNulls<Ref.Cast?>(args.size)
for (i in args.indices) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package org.partiql.planner.internal

import org.partiql.spi.fn.FnExperimental
import org.partiql.spi.fn.FnParameter
import org.partiql.spi.fn.FnSignature
import org.partiql.planner.internal.fn.FnParameter
import org.partiql.planner.internal.fn.FnSignature
import org.partiql.types.PType
import org.partiql.types.PType.Kind
import org.partiql.value.PartiQLValueExperimental

/**
* Function precedence comparator; this is not formally specified.
*
* 1. Fewest args first
* 2. Parameters are compared left-to-right
*/
@OptIn(PartiQLValueExperimental::class, FnExperimental::class)
internal object FnComparator : Comparator<FnSignature> {

override fun compare(fn1: FnSignature, fn2: FnSignature): Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.partiql.planner.internal

import org.partiql.planner.internal.fn.FnSignature
import org.partiql.planner.internal.ir.Ref
import org.partiql.spi.fn.FnExperimental
import org.partiql.spi.fn.FnSignature

/**
* Result of matching an unresolved function.
*/
@OptIn(FnExperimental::class)

internal sealed class FnMatch {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import org.partiql.planner.internal.casts.Coercions
import org.partiql.planner.internal.ir.Ref
import org.partiql.planner.internal.typer.CompilerType
import org.partiql.planner.internal.typer.PlanTyper.Companion.toCType
import org.partiql.spi.fn.FnExperimental
import org.partiql.spi.fn.FnSignature
import org.partiql.planner.internal.fn.FnSignature
import org.partiql.types.PType.Kind

/**
Expand All @@ -23,7 +22,7 @@ import org.partiql.types.PType.Kind
*
* Reference https://www.postgresql.org/docs/current/typeconv-func.html
*/
@OptIn(FnExperimental::class)

internal object FnResolver {

/**
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.partiql.value.PartiQLValueExperimental
/**
* Represents an SQL table-value expression call.
*/
@FnExperimental
public interface Agg {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.partiql.value.PartiQLValueType
* @property isDecomposable Flag indicating this aggregation can be decomposed
* @constructor
*/
@FnExperimental
@OptIn(PartiQLValueExperimental::class)
public class AggSignature(
@JvmField public val name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.partiql.value.PartiQLValueExperimental
/**
* Represents a scalar function (SQL row-value call expression).
*/
@FnExperimental
public interface Fn {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.partiql.value.PartiQLValueType
* @property name A human-readable name to help clarify its use.
* @property type The parameter's PartiQL type.
*/
@FnExperimental
@OptIn(PartiQLValueExperimental::class)
public data class FnParameter(
public val name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.partiql.value.PartiQLValueType
* @property isMissable Flag indicating this function's operator may return a MISSING value.
* @property isMissingCall Flag indicating if any of the call arguments is MISSING, the return MISSING.
*/
@FnExperimental
@OptIn(PartiQLValueExperimental::class)
public data class FnSignature(
@JvmField public val name: String,
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit b4eed3f

Please sign in to comment.