-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
558 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLEngineBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.partiql.eval | ||
|
||
import org.partiql.spi.connector.ConnectorBindings | ||
|
||
class PartiQLEngineBuilder { | ||
|
||
private var catalogs: MutableMap<String, ConnectorBindings> = mutableMapOf() | ||
|
||
/** | ||
* Build the builder, return an implementation of a [PartiQLEngine] | ||
* | ||
* @return | ||
*/ | ||
public fun build(): PartiQLEngine = PartiQLEngineDefault(catalogs) | ||
|
||
/** | ||
* Java style method for assigning a Catalog name to [ConnectorBindings]. | ||
* | ||
* @param catalog | ||
* @param metadata | ||
* @return | ||
*/ | ||
public fun addCatalog(catalog: String, bindings: ConnectorBindings): PartiQLEngineBuilder = this.apply { | ||
this.catalogs[catalog] = bindings | ||
} | ||
|
||
/** | ||
* Kotlin style method for assigning Catalog names to [ConnectorBindings]. | ||
* | ||
* @param catalogs | ||
* @return | ||
*/ | ||
public fun catalogs(vararg catalogs: Pair<String, ConnectorBindings>): PartiQLEngineBuilder = this.apply { | ||
this.catalogs = mutableMapOf(*catalogs) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLEngineDefault.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.partiql.eval | ||
|
||
import org.partiql.eval.internal.Compiler | ||
import org.partiql.eval.internal.Record | ||
import org.partiql.plan.PartiQLPlan | ||
import org.partiql.spi.connector.ConnectorBindings | ||
import org.partiql.value.PartiQLValue | ||
import org.partiql.value.PartiQLValueExperimental | ||
|
||
internal class PartiQLEngineDefault( | ||
private val catalogs: Map<String, ConnectorBindings>, | ||
) : PartiQLEngine { | ||
|
||
@OptIn(PartiQLValueExperimental::class) | ||
override fun prepare(plan: PartiQLPlan): PartiQLStatement<*> { | ||
try { | ||
val compiler = Compiler(plan, catalogs) | ||
val expression = compiler.compile() | ||
return object : PartiQLStatement.Query { | ||
override fun execute(): PartiQLValue { | ||
return expression.eval(Record.empty) | ||
} | ||
} | ||
} catch (ex: Exception) { | ||
// TODO wrap in some PartiQL Exception | ||
throw ex | ||
} | ||
} | ||
|
||
@OptIn(PartiQLValueExperimental::class) | ||
override fun execute(statement: PartiQLStatement<*>): PartiQLResult { | ||
return when (statement) { | ||
is PartiQLStatement.Query -> try { | ||
val value = statement.execute() | ||
PartiQLResult.Value(value) | ||
} catch (ex: Exception) { | ||
PartiQLResult.Error(ex) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.