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

Updates partiql-planner to latest partiql-spi interfaces #1358

Merged
merged 18 commits into from
Feb 1, 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
6 changes: 2 additions & 4 deletions partiql-cli/src/main/kotlin/org/partiql/cli/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.partiql.lang.eval.EvaluationSession
import org.partiql.parser.PartiQLParser
import org.partiql.plan.debug.PlanPrinter
import org.partiql.planner.PartiQLPlanner
import org.partiql.plugins.local.LocalConnector
import picocli.CommandLine
import java.io.PrintStream
import java.nio.file.Paths
Expand Down Expand Up @@ -72,9 +71,8 @@ object Debug {
val sess = PartiQLPlanner.Session(
queryId = UUID.randomUUID().toString(),
userId = "debug",
catalogs = mapOf(
"local" to LocalConnector.Metadata(root)
)
currentCatalog = "default",
catalogs = emptyMap(),
)
val result = planner.plan(statement, sess).plan
out.info("-- Plan ----------")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.partiql.cli.functions.ReadFile_1
import org.partiql.cli.functions.ReadFile_2
import org.partiql.cli.functions.WriteFile_1
import org.partiql.cli.functions.WriteFile_2
import org.partiql.cli.utils.ServiceLoaderUtil
import org.partiql.lang.CompilerPipeline
import org.partiql.lang.compiler.PartiQLCompilerBuilder
import org.partiql.lang.compiler.PartiQLCompilerPipeline
Expand Down Expand Up @@ -84,7 +83,7 @@ internal sealed class AbstractPipeline(open val options: PipelineOptions) {
WriteFile_1(ion),
WriteFile_2(ion),
QueryDDB(ion)
) + ServiceLoaderUtil.loadFunctions(pluginPath)
)
val parser = PartiQLParserBuilder().build()
return PipelineOptions(
pipeline,
Expand Down
537 changes: 0 additions & 537 deletions partiql-cli/src/main/kotlin/org/partiql/cli/utils/ServiceLoaderUtil.kt

This file was deleted.

26 changes: 18 additions & 8 deletions partiql-plan/src/main/resources/partiql_plan.ion
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
imports::{
kotlin: [
partiql_value::'org.partiql.value.PartiQLValue',
partiql_value_type::'org.partiql.value.PartiQLValueType',
static_type::'org.partiql.types.StaticType',
scalar_signature::'org.partiql.types.function.FunctionSignature$Scalar',
aggregation_signature::'org.partiql.types.function.FunctionSignature$Aggregation',
],
}

Expand Down Expand Up @@ -33,7 +32,13 @@ catalog::{

ref::{
catalog: int,
symbol: int
symbol: int,
_: [
cast::{
input: partiql_value_type,
target: partiql_value_type,
}
]
}

// Statements
Expand Down Expand Up @@ -91,10 +96,15 @@ rex::{
symbol::{ root: rex, key: string },
],

cast::{
cast: '.ref.cast',
arg: rex,
},

call::[
static::{
fn: ref,
args: list::[rex]
fn: ref,
args: list::[rex],
},

// Represents a dynamic function call. If all candidates are exhausted, dynamic calls will return MISSING.
Expand All @@ -108,10 +118,10 @@ rex::{
_: [
candidate::{
fn: ref,
coercions: list::[optional::ref]
coercions: list::[optional::'.ref.cast'],
}
]
}
},
],

case::{
Expand Down Expand Up @@ -270,7 +280,7 @@ rel::{
groups: list::[rex],
_: [
call::{
agg: ref,
agg: string,
args: list::[rex],
},
],
Expand Down
1 change: 1 addition & 0 deletions partiql-planner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ tasks.register<Exec>("codegen") {
"--poems", "builder",
"--poems", "util",
"--opt-in", "org.partiql.value.PartiQLValueExperimental",
"--opt-in", "org.partiql.spi.fn.FnExperimental",
"./src/main/resources/partiql_plan_internal.ion"
)
}
Expand Down
20 changes: 18 additions & 2 deletions partiql-planner/src/main/kotlin/org/partiql/planner/Errors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package org.partiql.planner

import org.partiql.errors.ProblemDetails
import org.partiql.errors.ProblemSeverity
import org.partiql.plan.Identifier
import org.partiql.spi.BindingCase
import org.partiql.spi.BindingPath
import org.partiql.types.StaticType

/**
Expand All @@ -24,11 +27,12 @@ public sealed class PlanningProblemDetails(
public data class CompileError(val errorMessage: String) :
PlanningProblemDetails(ProblemSeverity.ERROR, { errorMessage })

public data class UndefinedVariable(val variableName: String, val caseSensitive: Boolean) :
public data class UndefinedVariable(val id: BindingPath) :
PlanningProblemDetails(
ProblemSeverity.ERROR,
{
"Undefined variable '$variableName'." +
val caseSensitive = id.steps.any { it.case == BindingCase.SENSITIVE }
"Undefined variable '${id.key}'." +
quotationHint(caseSensitive)
}
)
Expand Down Expand Up @@ -134,3 +138,15 @@ private fun quotationHint(caseSensitive: Boolean) =
} else {
""
}

private fun Identifier.sql(): String = when (this) {
is Identifier.Qualified -> this.sql()
is Identifier.Symbol -> this.sql()
}

private fun Identifier.Qualified.sql(): String = root.sql() + "." + steps.joinToString(".") { it.sql() }

private fun Identifier.Symbol.sql(): String = when (caseSensitivity) {
Identifier.CaseSensitivity.SENSITIVE -> "\"$symbol\""
Identifier.CaseSensitivity.INSENSITIVE -> symbol
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ public interface PartiQLPlanner {
* @property userId
* @property currentCatalog
* @property currentDirectory
* @property catalogs
* @property instant
*/
public class Session(
public val queryId: String,
public val userId: String,
public val currentCatalog: String? = null,
public val currentCatalog: String,
public val currentDirectory: List<String> = emptyList(),
public val catalogs: Map<String, ConnectorMetadata> = emptyMap(),
public val instant: Instant = Instant.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ internal class PartiQLPlannerDefault(

// 3. Resolve variables
val typer = PlanTyper(env, onProblem)
val internal = org.partiql.planner.internal.ir.PartiQLPlan(
catalogs = env.catalogs,
statement = typer.resolve(root),
)
val typed = typer.resolve(root)
val internal = org.partiql.planner.internal.ir.PartiQLPlan(typed)

// 4. Assert plan has been resolved — translating to public API
var plan = PlanTransform.visitPartiQLPlan(internal, onProblem)
var plan = PlanTransform.transform(internal, onProblem)

// 5. Apply all passes
for (pass in passes) {
Expand Down
Loading
Loading