Skip to content

Commit

Permalink
Merge f27fe71 into 34d42ee
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 authored Dec 6, 2023
2 parents 34d42ee + f27fe71 commit e6ccf41
Show file tree
Hide file tree
Showing 10 changed files with 1,487 additions and 53 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Thank you to all who have contributed!
- Adds public `tag` field to IR nodes for associating metadata
- Adds AST Normalization Pass.
- Adds PartiQLPlanner Interface, which is responsible for translate an AST to a Plan.
- **EXPERIMENTAL** Evaluation of `EXCLUDE` in the `EvaluatingCompiler`
- This is currently marked as experimental until the RFC is approved https://github.com/partiql/partiql-lang/issues/27
- This will be added to the `PhysicalPlanCompiler` in an upcoming release

### Changed
- StaticTypeInferencer and PlanTyper will not raise an error when an expression is inferred to `NULL` or `unionOf(NULL, MISSING)`. In these cases the StaticTypeInferencer and PlanTyper will still raise the Problem Code `ExpressionAlwaysReturnsNullOrMissing` but the severity of the problem has been changed to warning. In the case an expression always returns `MISSING`, problem code `ExpressionAlwaysReturnsMissing` will be raised, which will have problem severity of error.
Expand Down
420 changes: 384 additions & 36 deletions partiql-lang/src/main/kotlin/org/partiql/lang/eval/EvaluatingCompiler.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ interface ExprValue : Iterable<ExprValue>, Faceted {
override fun bytesValue() = value
}

private class ListExprValue(val values: Sequence<ExprValue>) : BaseExprValue() {
internal class ListExprValue(val values: Sequence<ExprValue>) : BaseExprValue() {
override val type = ExprValueType.LIST
override val ordinalBindings by lazy { OrdinalBindings.ofList(toList()) }
override fun iterator() = values.mapIndexed { i, v -> v.namedValue(newInt(i)) }.iterator()
}

private class BagExprValue(val values: Sequence<ExprValue>) : BaseExprValue() {
internal class BagExprValue(val values: Sequence<ExprValue>) : BaseExprValue() {
override val type = ExprValueType.BAG
override val ordinalBindings = OrdinalBindings.EMPTY
override fun iterator() = values.iterator()
}

private class SexpExprValue(val values: Sequence<ExprValue>) : BaseExprValue() {
internal class SexpExprValue(val values: Sequence<ExprValue>) : BaseExprValue() {
override val type = ExprValueType.SEXP
override val ordinalBindings by lazy { OrdinalBindings.ofList(toList()) }
override fun iterator() = values.mapIndexed { i, v -> v.namedValue(newInt(i)) }.iterator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ fun ExprValue.asNamed(): Named = object : Named {
}

/** Binds the given name value as a [Named] facet delegate over this [ExprValue]. */
fun ExprValue.namedValue(nameValue: ExprValue): ExprValue = object : ExprValue by this, Named {
override val name = nameValue
override fun <T : Any?> asFacet(type: Class<T>?): T? =
downcast(type) ?: this@namedValue.asFacet(type)
override fun toString(): String = stringify()
}
fun ExprValue.namedValue(nameValue: ExprValue): ExprValue = NamedExprValue(nameValue, this)

/** Wraps this [ExprValue] in a delegate that always masks the [Named] facet. */
fun ExprValue.unnamedValue(): ExprValue = when (asFacet(Named::class.java)) {
Expand Down
11 changes: 11 additions & 0 deletions partiql-lang/src/main/kotlin/org/partiql/lang/eval/Named.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package org.partiql.lang.eval

import org.partiql.lang.util.downcast

/**
* Facet for a value to indicate that it either has a name within some context
* or an ordinal position.
Expand All @@ -27,3 +29,12 @@ interface Named {
*/
val name: ExprValue
}

/**
* An [ExprValue] that also implements [Named].
*/
internal class NamedExprValue(override val name: ExprValue, val value: ExprValue) : ExprValue by value, Named {
override fun <T : Any?> asFacet(type: Class<T>?): T? = downcast(type) ?: value.asFacet(type)

override fun toString(): String = stringify()
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum class StructOrdering {
* Provides a [ExprValueType.STRUCT] implementation lazily backed by a sequence.
*/
internal open class StructExprValue(
private val ordering: StructOrdering,
internal val ordering: StructOrdering,
private val sequence: Sequence<ExprValue>
) : BaseExprValue() {

Expand Down
Loading

0 comments on commit e6ccf41

Please sign in to comment.