Skip to content

Commit

Permalink
Replaces ConnectorMetadata with Catalog interfaces (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell authored Aug 21, 2024
1 parent eda118f commit 7aeb1be
Show file tree
Hide file tree
Showing 63 changed files with 1,085 additions and 2,210 deletions.
18 changes: 11 additions & 7 deletions partiql-cli/src/main/kotlin/org/partiql/cli/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import org.partiql.cli.pipeline.Pipeline
import org.partiql.cli.shell.Shell
import org.partiql.eval.PartiQLEngine
import org.partiql.eval.PartiQLResult
import org.partiql.plugins.memory.MemoryCatalog
import org.partiql.planner.catalog.Name
import org.partiql.plugins.memory.MemoryConnector
import org.partiql.plugins.memory.MemoryTable
import org.partiql.spi.connector.Connector
import org.partiql.types.StaticType
import org.partiql.types.PType
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.io.PartiQLValueTextWriter
import org.partiql.value.ion.IonDatum
import picocli.CommandLine
import java.io.File
import java.io.InputStream
Expand Down Expand Up @@ -223,16 +225,18 @@ internal class MainCommand : Runnable {
} else {
ionNull()
}
val catalog = MemoryCatalog.builder()
val connector = MemoryConnector.builder()
.name("default")
.define(
name = "stdin",
type = StaticType.ANY,
value = value,
MemoryTable.of(
name = Name.of("stdin"),
schema = PType.dynamic(),
datum = IonDatum.of(value.asAnyElement())
)
)
.build()
return mapOf(
"default" to MemoryConnector(catalog)
"default" to connector
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.partiql.parser.PartiQLParser
import org.partiql.plan.PartiQLPlan
import org.partiql.planner.PartiQLPlanner
import org.partiql.spi.connector.Connector
import org.partiql.spi.connector.ConnectorSession
import java.time.Instant
import org.partiql.planner.catalog.Session as PlannerSession

Expand All @@ -34,15 +33,13 @@ internal class Pipeline private constructor(
@JvmField val mode: PartiQLEngine.Mode,
) {

val connector = object : ConnectorSession {
override fun getQueryId(): String = queryId
override fun getUserId(): String = userId
}
private val catalogs = connectors.values.map { it.getCatalog() }

fun planner() = PlannerSession.builder()
.identity(userId)
.namespace(currentDirectory)
.catalog(currentCatalog)
.catalogs(*connectors.map { it.key to it.value.getMetadata(connector) }.toTypedArray())
.catalogs(*catalogs.toTypedArray())
.build()

fun engine() = PartiQLEngine.Session(
Expand Down
13 changes: 1 addition & 12 deletions partiql-cli/src/main/kotlin/org/partiql/cli/shell/Shell.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import org.jline.utils.InfoCmp
import org.joda.time.Duration
import org.partiql.cli.pipeline.Pipeline
import org.partiql.eval.PartiQLResult
import org.partiql.spi.BindingCase
import org.partiql.spi.BindingName
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.io.PartiQLValueTextWriter
import java.io.Closeable
Expand Down Expand Up @@ -250,16 +248,7 @@ internal class Shell(
out.error("No connector for catalog ${session.currentCatalog}.")
continue
}
// Create a path from the arg
val arg1 = args.getOrNull(1)
val path = if (arg1 == null) {
emptyList<BindingName>()
} else {
arg1.split(".").map { BindingName(it, BindingCase.INSENSITIVE) }
}
// Query connector metadata
TODO("Connectors do not support listing metadata")
out.println()
out.error("Connectors do not support listing metadata")
}
"session" -> {
// Print session information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import org.partiql.eval.internal.operator.rex.ExprVarGlobal
import org.partiql.plan.Catalog
import org.partiql.plan.PartiQLPlan
import org.partiql.plan.Ref
import org.partiql.planner.catalog.Name
import org.partiql.spi.connector.ConnectorBindings
import org.partiql.spi.connector.ConnectorPath
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.Fn
import org.partiql.spi.fn.SqlFnProvider
Expand All @@ -27,8 +27,8 @@ internal class Symbols private constructor(private val catalogs: Array<C>) {
) {

// TEMPORARY FOR DEPENDENCY REASONS
fun getFn(path: ConnectorPath, specific: String): Fn? = SqlFnProvider.getFn(specific)
fun getAgg(path: ConnectorPath, specific: String): Agg? = SqlFnProvider.getAgg(specific)
fun getFn(name: Name, specific: String): Fn? = SqlFnProvider.getFn(specific)
fun getAgg(name: Name, specific: String): Agg? = SqlFnProvider.getAgg(specific)

override fun toString(): String = name
}
Expand All @@ -39,8 +39,8 @@ internal class Symbols private constructor(private val catalogs: Array<C>) {
if (item == null || item !is Catalog.Item.Value) {
error("Invalid reference $ref; missing value entry for catalog `$catalog`.")
}
val path = ConnectorPath(item.path)
return ExprVarGlobal(path, catalog.bindings)
val name = Name.of(item.path)
return ExprVarGlobal(name, catalog.bindings)
}

fun getFn(ref: Ref): Fn {
Expand All @@ -50,8 +50,8 @@ internal class Symbols private constructor(private val catalogs: Array<C>) {
error("Invalid reference $ref; missing function entry for catalog `$catalog`.")
}
// Lookup in connector
val path = ConnectorPath(item.path)
return catalog.getFn(path, item.specific)
val name = Name.of(item.path)
return catalog.getFn(name, item.specific)
?: error("Catalog `$catalog` has no entry for function $item")
}

Expand All @@ -62,8 +62,8 @@ internal class Symbols private constructor(private val catalogs: Array<C>) {
error("Invalid reference $ref; missing aggregation entry for catalog `$catalog`.")
}
// Lookup in connector
val path = ConnectorPath(item.path)
return catalog.getAgg(path, item.specific)
val name = Name.of(item.path)
return catalog.getAgg(name, item.specific)
?: error("Catalog `$catalog` has no entry for aggregation function $item")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package org.partiql.eval.internal.operator.rex
import org.partiql.eval.internal.Environment
import org.partiql.eval.internal.operator.Operator
import org.partiql.eval.value.Datum
import org.partiql.planner.catalog.Name
import org.partiql.spi.connector.ConnectorBindings
import org.partiql.spi.connector.ConnectorPath
import org.partiql.value.PartiQLValueExperimental

@OptIn(PartiQLValueExperimental::class)
internal class ExprVarGlobal(
private val path: ConnectorPath,
private val name: Name,
private val bindings: ConnectorBindings,
) : Operator.Expr {

// TODO: Potentially make ConnectorBindings return PQLValue
override fun eval(env: Environment): Datum = Datum.of(bindings.getValue(path))
override fun eval(env: Environment): Datum {
return bindings.getBinding(name)!!.getDatum()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.partiql.eval.internal

import com.amazon.ionelement.api.createIonElementLoader
import com.amazon.ionelement.api.loadSingleElement
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.parallel.Execution
Expand All @@ -13,10 +14,11 @@ import org.partiql.parser.PartiQLParser
import org.partiql.plan.PartiQLPlan
import org.partiql.plan.debug.PlanPrinter
import org.partiql.planner.builder.PartiQLPlannerBuilder
import org.partiql.planner.catalog.Name
import org.partiql.planner.catalog.Session
import org.partiql.plugins.memory.MemoryCatalog
import org.partiql.plugins.memory.MemoryConnector
import org.partiql.spi.connector.ConnectorSession
import org.partiql.plugins.memory.MemoryTable
import org.partiql.types.PType
import org.partiql.types.StaticType
import org.partiql.value.CollectionValue
import org.partiql.value.PartiQLValue
Expand All @@ -28,6 +30,7 @@ import org.partiql.value.int32Value
import org.partiql.value.int64Value
import org.partiql.value.intValue
import org.partiql.value.io.PartiQLValueIonWriterBuilder
import org.partiql.value.ion.IonDatum
import org.partiql.value.listValue
import org.partiql.value.missingValue
import org.partiql.value.nullValue
Expand Down Expand Up @@ -1258,19 +1261,22 @@ class PartiQLEngineDefaultTest {

internal fun assert() {
val statement = parser.parse(input).root
val catalogBuilder = MemoryCatalog.builder().name("memory")
globals.forEach { global ->
catalogBuilder.define(global.name, global.type, loader.loadSingleElement(global.value))
}
val catalog = catalogBuilder.build()
val connector = MemoryConnector(catalog)
val connectorSession = object : ConnectorSession {
override fun getQueryId(): String = "q"
override fun getUserId(): String = "u"
}
val connector = MemoryConnector.builder()
.name("memory")
.apply {
globals.forEach {
val table = MemoryTable.of(
name = Name.of(it.name),
schema = PType.fromStaticType(it.type),
datum = IonDatum.of(loadSingleElement(it.value))
)
define(table)
}
}
.build()
val session = Session.builder()
.catalog("memory")
.catalogs("memory" to connector.getMetadata(connectorSession))
.catalogs(connector.getCatalog())
.build()
val plan = planner.plan(statement, session)
val prepared = engine.prepare(plan.plan, PartiQLEngine.Session(mapOf("memory" to connector), mode = mode))
Expand Down Expand Up @@ -1344,15 +1350,10 @@ class PartiQLEngineDefaultTest {

private fun run(mode: PartiQLEngine.Mode): Pair<PartiQLValue, PartiQLPlan> {
val statement = parser.parse(input).root
val catalog = MemoryCatalog.builder().name("memory").build()
val connector = MemoryConnector(catalog)
val connectorSession = object : ConnectorSession {
override fun getQueryId(): String = "q"
override fun getUserId(): String = "u"
}
val connector = MemoryConnector.builder().name("memory").build()
val session = Session.builder()
.catalog("memory")
.catalogs("memory" to connector.getMetadata(connectorSession))
.catalogs(connector.getCatalog())
.build()
val plan = planner.plan(statement, session)
val prepared = engine.prepare(plan.plan, PartiQLEngine.Session(mapOf("memory" to connector), mode = mode))
Expand Down
11 changes: 0 additions & 11 deletions partiql-lang/api/partiql-lang.api
Original file line number Diff line number Diff line change
Expand Up @@ -2253,17 +2253,6 @@ public final class org/partiql/lang/planner/transforms/AstNormalizeKt {
public static final fun normalize (Lorg/partiql/lang/domains/PartiqlAst$Statement;)Lorg/partiql/lang/domains/PartiqlAst$Statement;
}

public final class org/partiql/lang/planner/transforms/PlannerSession {
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/Map;Ljava/time/Instant;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/Map;Ljava/time/Instant;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getCatalogConfig ()Ljava/util/Map;
public final fun getCurrentCatalog ()Ljava/lang/String;
public final fun getCurrentDirectory ()Ljava/util/List;
public final fun getInstant ()Ljava/time/Instant;
public final fun getQueryId ()Ljava/lang/String;
public final fun getUserId ()Ljava/lang/String;
}

public final class org/partiql/lang/planner/transforms/UtilKt {
public static final field PLAN_VERSION_NUMBER Ljava/lang/String;
public static final fun isLitTrue (Lorg/partiql/lang/domains/PartiqlPhysical$Expr;)Z
Expand Down

This file was deleted.

Loading

0 comments on commit 7aeb1be

Please sign in to comment.