Skip to content

Commit

Permalink
Reset function things closer to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Jul 18, 2024
1 parent 5879f3a commit 103fe1e
Show file tree
Hide file tree
Showing 15 changed files with 440 additions and 350 deletions.
137 changes: 66 additions & 71 deletions partiql-planner/api/partiql-planner.api
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public final class org/partiql/planner/PartiQLPlanner$Result {
}

public abstract interface class org/partiql/planner/catalog/Catalog {
public abstract fun getFunctions (Lorg/partiql/planner/catalog/Session;Lorg/partiql/planner/catalog/Name;)Ljava/util/Collection;
public abstract fun getName ()Ljava/lang/String;
public abstract fun getRoutines (Lorg/partiql/planner/catalog/Session;Lorg/partiql/planner/catalog/Name;)Ljava/util/Collection;
public abstract fun getTable (Lorg/partiql/planner/catalog/Session;Lorg/partiql/planner/catalog/Name;)Lorg/partiql/planner/catalog/Table;
public abstract fun getTableHandle (Lorg/partiql/planner/catalog/Session;Lorg/partiql/planner/catalog/Identifier;)Lorg/partiql/planner/catalog/Table$Handle;
public abstract fun listNamespaces (Lorg/partiql/planner/catalog/Session;)Ljava/util/Collection;
Expand All @@ -38,7 +38,7 @@ public abstract interface class org/partiql/planner/catalog/Catalog {
}

public final class org/partiql/planner/catalog/Catalog$DefaultImpls {
public static fun getRoutines (Lorg/partiql/planner/catalog/Catalog;Lorg/partiql/planner/catalog/Session;Lorg/partiql/planner/catalog/Name;)Ljava/util/Collection;
public static fun getFunctions (Lorg/partiql/planner/catalog/Catalog;Lorg/partiql/planner/catalog/Session;Lorg/partiql/planner/catalog/Name;)Ljava/util/Collection;
public static fun getTable (Lorg/partiql/planner/catalog/Catalog;Lorg/partiql/planner/catalog/Session;Lorg/partiql/planner/catalog/Name;)Lorg/partiql/planner/catalog/Table;
public static fun getTableHandle (Lorg/partiql/planner/catalog/Catalog;Lorg/partiql/planner/catalog/Session;Lorg/partiql/planner/catalog/Identifier;)Lorg/partiql/planner/catalog/Table$Handle;
public static fun listNamespaces (Lorg/partiql/planner/catalog/Catalog;Lorg/partiql/planner/catalog/Session;)Ljava/util/Collection;
Expand Down Expand Up @@ -76,6 +76,70 @@ public final class org/partiql/planner/catalog/Catalogs$DefaultImpls {
public static fun list (Lorg/partiql/planner/catalog/Catalogs;)Ljava/util/Collection;
}

public abstract interface class org/partiql/planner/catalog/Function {
public static final field Companion Lorg/partiql/planner/catalog/Function$Companion;
public abstract fun getName ()Ljava/lang/String;
public abstract fun getParameters ()[Lorg/partiql/planner/catalog/Function$Parameter;
public abstract fun getReturnType ()Lorg/partiql/types/PType;
public abstract fun getSpecific ()Ljava/lang/String;
}

public abstract interface class org/partiql/planner/catalog/Function$Aggregation : org/partiql/planner/catalog/Function {
public abstract fun getSpecific ()Ljava/lang/String;
}

public final class org/partiql/planner/catalog/Function$Aggregation$DefaultImpls {
public static fun getParameters (Lorg/partiql/planner/catalog/Function$Aggregation;)[Lorg/partiql/planner/catalog/Function$Parameter;
public static fun getSpecific (Lorg/partiql/planner/catalog/Function$Aggregation;)Ljava/lang/String;
}

public final class org/partiql/planner/catalog/Function$Companion {
public final fun scalar (Ljava/lang/String;Ljava/util/Collection;Lorg/partiql/types/PType;)Lorg/partiql/planner/catalog/Function$Scalar;
public final fun scalar (Ljava/lang/String;Ljava/util/Collection;Lorg/partiql/types/PType;Lorg/partiql/planner/catalog/Function$Properties;)Lorg/partiql/planner/catalog/Function$Scalar;
public static synthetic fun scalar$default (Lorg/partiql/planner/catalog/Function$Companion;Ljava/lang/String;Ljava/util/Collection;Lorg/partiql/types/PType;Lorg/partiql/planner/catalog/Function$Properties;ILjava/lang/Object;)Lorg/partiql/planner/catalog/Function$Scalar;
}

public final class org/partiql/planner/catalog/Function$DefaultImpls {
public static fun getParameters (Lorg/partiql/planner/catalog/Function;)[Lorg/partiql/planner/catalog/Function$Parameter;
}

public final class org/partiql/planner/catalog/Function$Parameter {
public final field name Ljava/lang/String;
public final field type Lorg/partiql/types/PType$Kind;
public fun <init> (Ljava/lang/String;Lorg/partiql/types/PType$Kind;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Lorg/partiql/types/PType$Kind;
public final fun copy (Ljava/lang/String;Lorg/partiql/types/PType$Kind;)Lorg/partiql/planner/catalog/Function$Parameter;
public static synthetic fun copy$default (Lorg/partiql/planner/catalog/Function$Parameter;Ljava/lang/String;Lorg/partiql/types/PType$Kind;ILjava/lang/Object;)Lorg/partiql/planner/catalog/Function$Parameter;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class org/partiql/planner/catalog/Function$Properties {
public final field isNullCall Z
public fun <init> ()V
public fun <init> (Z)V
public synthetic fun <init> (ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Z
public final fun copy (Z)Lorg/partiql/planner/catalog/Function$Properties;
public static synthetic fun copy$default (Lorg/partiql/planner/catalog/Function$Properties;ZILjava/lang/Object;)Lorg/partiql/planner/catalog/Function$Properties;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public abstract interface class org/partiql/planner/catalog/Function$Scalar : org/partiql/planner/catalog/Function {
public abstract fun getProperties ()Lorg/partiql/planner/catalog/Function$Properties;
public abstract fun getSpecific ()Ljava/lang/String;
}

public final class org/partiql/planner/catalog/Function$Scalar$DefaultImpls {
public static fun getParameters (Lorg/partiql/planner/catalog/Function$Scalar;)[Lorg/partiql/planner/catalog/Function$Parameter;
public static fun getProperties (Lorg/partiql/planner/catalog/Function$Scalar;)Lorg/partiql/planner/catalog/Function$Properties;
public static fun getSpecific (Lorg/partiql/planner/catalog/Function$Scalar;)Ljava/lang/String;
}

public final class org/partiql/planner/catalog/Identifier : java/lang/Iterable, kotlin/jvm/internal/markers/KMappedMarker {
public static final field Companion Lorg/partiql/planner/catalog/Identifier$Companion;
public synthetic fun <init> ([Lorg/partiql/planner/catalog/Identifier$Part;Lorg/partiql/planner/catalog/Identifier$Part;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand Down Expand Up @@ -191,75 +255,6 @@ public final class org/partiql/planner/catalog/Path$Companion {
public final fun of ([Lorg/partiql/planner/catalog/Namespace;)Lorg/partiql/planner/catalog/Path;
}

public abstract interface class org/partiql/planner/catalog/Routine {
public static final field Companion Lorg/partiql/planner/catalog/Routine$Companion;
public abstract fun getName ()Ljava/lang/String;
public abstract fun getParameters ()[Lorg/partiql/planner/catalog/Routine$Parameter;
public abstract fun getReturnType ()Lorg/partiql/types/PType;
}

public abstract interface class org/partiql/planner/catalog/Routine$Aggregation : org/partiql/planner/catalog/Routine {
}

public final class org/partiql/planner/catalog/Routine$Aggregation$DefaultImpls {
public static fun getParameters (Lorg/partiql/planner/catalog/Routine$Aggregation;)[Lorg/partiql/planner/catalog/Routine$Parameter;
}

public final class org/partiql/planner/catalog/Routine$Companion {
public final fun scalar (Ljava/lang/String;Ljava/util/Collection;Lorg/partiql/types/PType;)Lorg/partiql/planner/catalog/Routine$Scalar;
public final fun scalar (Ljava/lang/String;Ljava/util/Collection;Lorg/partiql/types/PType;Lorg/partiql/planner/catalog/Routine$Properties;)Lorg/partiql/planner/catalog/Routine$Scalar;
public static synthetic fun scalar$default (Lorg/partiql/planner/catalog/Routine$Companion;Ljava/lang/String;Ljava/util/Collection;Lorg/partiql/types/PType;Lorg/partiql/planner/catalog/Routine$Properties;ILjava/lang/Object;)Lorg/partiql/planner/catalog/Routine$Scalar;
}

public final class org/partiql/planner/catalog/Routine$DefaultImpls {
public static fun getParameters (Lorg/partiql/planner/catalog/Routine;)[Lorg/partiql/planner/catalog/Routine$Parameter;
}

public abstract interface class org/partiql/planner/catalog/Routine$Operator : org/partiql/planner/catalog/Routine {
public abstract fun getLHS ()Lorg/partiql/types/PType$Kind;
public abstract fun getRHS ()Lorg/partiql/types/PType$Kind;
public abstract fun getSymbol ()Ljava/lang/String;
}

public final class org/partiql/planner/catalog/Routine$Operator$DefaultImpls {
public static fun getParameters (Lorg/partiql/planner/catalog/Routine$Operator;)[Lorg/partiql/planner/catalog/Routine$Parameter;
}

public final class org/partiql/planner/catalog/Routine$Parameter {
public final field name Ljava/lang/String;
public final field type Lorg/partiql/types/PType$Kind;
public fun <init> (Ljava/lang/String;Lorg/partiql/types/PType$Kind;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Lorg/partiql/types/PType$Kind;
public final fun copy (Ljava/lang/String;Lorg/partiql/types/PType$Kind;)Lorg/partiql/planner/catalog/Routine$Parameter;
public static synthetic fun copy$default (Lorg/partiql/planner/catalog/Routine$Parameter;Ljava/lang/String;Lorg/partiql/types/PType$Kind;ILjava/lang/Object;)Lorg/partiql/planner/catalog/Routine$Parameter;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class org/partiql/planner/catalog/Routine$Properties {
public final field isNullCall Z
public fun <init> ()V
public fun <init> (Z)V
public synthetic fun <init> (ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Z
public final fun copy (Z)Lorg/partiql/planner/catalog/Routine$Properties;
public static synthetic fun copy$default (Lorg/partiql/planner/catalog/Routine$Properties;ZILjava/lang/Object;)Lorg/partiql/planner/catalog/Routine$Properties;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public abstract interface class org/partiql/planner/catalog/Routine$Scalar : org/partiql/planner/catalog/Routine {
public abstract fun getProperties ()Lorg/partiql/planner/catalog/Routine$Properties;
}

public final class org/partiql/planner/catalog/Routine$Scalar$DefaultImpls {
public static fun getParameters (Lorg/partiql/planner/catalog/Routine$Scalar;)[Lorg/partiql/planner/catalog/Routine$Parameter;
public static fun getProperties (Lorg/partiql/planner/catalog/Routine$Scalar;)Lorg/partiql/planner/catalog/Routine$Properties;
}

public abstract interface class org/partiql/planner/catalog/Session {
public static final field Companion Lorg/partiql/planner/catalog/Session$Companion;
public static fun builder ()Lorg/partiql/planner/catalog/Session$Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public interface Catalog {
/**
* Get a routine's variants by name.
*
* @param name The case-sensitive [Routine] name.
* @return A collection of all [Routine]s in the current namespace with this name.
* @param name The case-sensitive [Function] name.
* @return A collection of all [Function]s in the current namespace with this name.
*/
public fun getRoutines(session: Session, name: Name): Collection<Routine> = emptyList()
public fun getFunctions(session: Session, name: Name): Collection<Function> = emptyList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package org.partiql.planner.catalog
import org.partiql.types.PType

/**
* A [Routine] is a PartiQL-routine callable from an expression context.
* A [Function] is a PartiQL-routine callable from an expression context.
*/
public sealed interface Routine {
public sealed interface Function {

/**
* The routine name. Required.
Expand All @@ -23,29 +23,46 @@ public sealed interface Routine {
public fun getReturnType(): PType

/**
* Represents an SQL row-value expression call.
* !! DO NOT OVERRIDE !!
*/
public interface Operator : Routine {
public fun getSymbol(): String
public fun getLHS(): PType.Kind?
public fun getRHS(): PType.Kind
}
public fun getSpecific(): String

/**
* Represents an SQL row-value expression call.
*/
public interface Scalar : Routine {
public interface Scalar : Function {

/**
* Additional function properties useful for planning. Optional.
*/
public fun getProperties(): Properties = DEFAULT_PROPERTIES

/**
* !! DO NOT OVERRIDE !!
*/
public override fun getSpecific(): String {
val name = getName()
val parameters = getParameters().joinToString("__") { it.type.name }
val returnType = getReturnType().kind.name
return "FN_${name}___${parameters}___${returnType}"
}
}

/**
* Represents an SQL table-value expression call.
*/
public interface Aggregation : Routine
public interface Aggregation : Function {

/**
* !! DO NOT OVERRIDE !!
*/
public override fun getSpecific(): String {
val name = getName()
val parameters = getParameters().joinToString("__") { it.type.name }
val returnType = getReturnType().kind.name
return "AGG_${name}___${parameters}___${returnType}"
}
}

/**
* [Parameter] is a formal argument's definition.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.partiql.planner.internal

import org.partiql.planner.catalog.Routine
import org.partiql.planner.catalog.Function
import org.partiql.types.PType
import org.partiql.types.PType.Kind

Expand All @@ -10,9 +10,9 @@ import org.partiql.types.PType.Kind
* 1. Fewest args first
* 2. Parameters are compared left-to-right
*/
internal object FnComparator : Comparator<Routine> {
internal object FnComparator : Comparator<Function> {

override fun compare(fn1: Routine, fn2: Routine): Int {
override fun compare(fn1: Function, fn2: Function): Int {
// Compare number of arguments
val p1 = fn1.getParameters()
val p2 = fn2.getParameters()
Expand All @@ -30,7 +30,7 @@ internal object FnComparator : Comparator<Routine> {
return 0
}

private fun Routine.Parameter.compareTo(other: Routine.Parameter): Int =
private fun Function.Parameter.compareTo(other: Function.Parameter): Int =
comparePrecedence(this.type, other.type)

private fun comparePrecedence(t1: PType.Kind, t2: PType.Kind): Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.partiql.planner.internal

import org.partiql.planner.catalog.Routine
import org.partiql.planner.catalog.Function
import org.partiql.planner.internal.ir.Ref

/**
Expand All @@ -15,7 +15,7 @@ internal sealed class FnMatch {
* @property mapping
*/
data class Static(
val signature: Routine,
val signature: Function,
val mapping: Array<Ref.Cast?>,
) : FnMatch() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.partiql.planner.internal

import org.partiql.planner.catalog.Routine
import org.partiql.planner.catalog.Function
import org.partiql.planner.internal.casts.Coercions
import org.partiql.planner.internal.ir.Ref
import org.partiql.planner.internal.typer.CompilerType
Expand Down Expand Up @@ -32,7 +32,7 @@ internal object FnResolver {
* @param args
* @return
*/
fun resolve(variants: List<Routine>, args: List<CompilerType>): FnMatch? {
fun resolve(variants: List<Function>, args: List<CompilerType>): FnMatch? {
val candidates = variants
.filter { it.getParameters().size == args.size }
.ifEmpty { return null }
Expand Down Expand Up @@ -85,7 +85,7 @@ internal object FnResolver {
* @param args
* @return
*/
private fun match(candidates: List<Routine>, args: List<CompilerType>): List<MatchResult> {
private fun match(candidates: List<Function>, args: List<CompilerType>): List<MatchResult> {
val matches = mutableSetOf<MatchResult>()
for (candidate in candidates) {
val m = candidate.match(args) ?: continue
Expand Down Expand Up @@ -115,7 +115,7 @@ internal object FnResolver {
/**
* Check if this function accepts the exact input argument types. Assume same arity.
*/
private fun Routine.matchesExactly(args: List<CompilerType>): Boolean {
private fun Function.matchesExactly(args: List<CompilerType>): Boolean {
val parameters = getParameters()
for (i in args.indices) {
val a = args[i].kind
Expand All @@ -131,7 +131,7 @@ internal object FnResolver {
* @param args
* @return
*/
private fun Routine.match(args: List<CompilerType>): MatchResult? {
private fun Function.match(args: List<CompilerType>): MatchResult? {
val mapping = arrayOfNulls<Ref.Cast?>(args.size)
val parameters = getParameters()
var exactInputTypes: Int = 0
Expand Down
Loading

0 comments on commit 103fe1e

Please sign in to comment.