Skip to content

Commit

Permalink
Merge pull request #1648 from johnedquinn/v1-static-type-removal
Browse files Browse the repository at this point in the history
Removes StaticType's public API
  • Loading branch information
johnedquinn authored Nov 18, 2024
2 parents 894e443 + 95b9d1b commit bfce6b2
Show file tree
Hide file tree
Showing 33 changed files with 199 additions and 1,144 deletions.
12 changes: 0 additions & 12 deletions partiql-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies {
implementation(project(":partiql-planner"))
implementation(project(":partiql-types"))
implementation(project(":partiql-spi"))
implementation(project(":plugins:partiql-local"))
implementation(Deps.csv)
implementation(Deps.awsSdkBom)
implementation(Deps.awsSdkDynamodb)
Expand Down Expand Up @@ -69,17 +68,6 @@ tasks.register<GradleBuild>("install") {
val testingPluginDirectory = "$buildDir/tmp/plugins"
val mockDBPluginDirectory = "$testingPluginDirectory/local"

tasks.register<Copy>("generateLocalPluginJar") {
dependsOn(":plugins:partiql-local:assemble")
from("${rootProject.projectDir}/plugins/partiql-local/build/libs")
into(mockDBPluginDirectory)
include("partiql-local-*.jar")
}

tasks.test.configure {
dependsOn(tasks.findByName("generateLocalPluginJar"))
}

tasks.withType<Test>().configureEach {
systemProperty("testingPluginDirectory", testingPluginDirectory)
}
Expand Down
2 changes: 1 addition & 1 deletion partiql-eval/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
annotationProcessor(Deps.lombok)
// Test
testImplementation(project(":partiql-parser"))
testImplementation(project(":plugins:partiql-local"))
testImplementation(testFixtures(project(":partiql-types"))) // TODO: Remove use of StaticType
testImplementation(Deps.junit4)
testImplementation(Deps.junit4Params)
testImplementation(Deps.junitVintage) // Enables JUnit4
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.partiql.spi.value.Datum
import org.partiql.spi.value.DatumReader
import org.partiql.types.PType
import org.partiql.types.StaticType
import org.partiql.types.fromStaticType
import org.partiql.value.PartiQLValue
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.bagValue
Expand Down Expand Up @@ -1327,7 +1328,7 @@ class PartiQLEvaluatorTest {
globals.forEach {
val table = Table.standard(
name = Name.of(it.name),
schema = PType.fromStaticType(it.type),
schema = fromStaticType(it.type),
datum = DatumReader.ion(it.value.byteInputStream()).next()!!
)
define(table)
Expand Down
5 changes: 3 additions & 2 deletions partiql-planner/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.dokka.gradle.DokkaTask
import kotlin.io.path.relativeTo
import kotlin.io.path.toPath

Expand Down Expand Up @@ -36,7 +37,7 @@ dependencies {
annotationProcessor(Deps.lombok)
// Test
testImplementation(project(":partiql-parser"))
testImplementation(project(":plugins:partiql-local"))
testImplementation(testFixtures(project(":partiql-types"))) // TODO: Remove use of StaticType
testImplementation(Deps.kotlinReflect)
// Test Fixtures
testFixturesImplementation(project(":partiql-spi"))
Expand Down Expand Up @@ -167,7 +168,7 @@ tasks.detekt {
dependsOn(tasks.withType<Copy>())
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
tasks.withType<DokkaTask>().configureEach {
dependsOn(tasks.withType<Copy>())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.partiql.planner.internal.typer.PlanTyper.Companion.toCType
import org.partiql.spi.catalog.Identifier
import org.partiql.types.PType
import org.partiql.types.PType.Kind
import org.partiql.types.StaticType
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.stringValue

Expand Down Expand Up @@ -132,7 +131,7 @@ internal data class Scope(
}

/**
* Searches for the [Identifier.Part] within the given [StaticType].
* Searches for the [Identifier.Part] within the given [CompilerType].
*
* Returns
* - true iff known to contain key
Expand Down
Original file line number Diff line number Diff line change
@@ -1,162 +1,12 @@
package org.partiql.planner.internal.typer

import org.partiql.planner.internal.ir.Rel
import org.partiql.planner.internal.ir.Rex
import org.partiql.planner.internal.typer.PlanTyper.Companion.toCType
import org.partiql.types.AnyOfType
import org.partiql.types.AnyType
import org.partiql.types.BagType
import org.partiql.types.BlobType
import org.partiql.types.BoolType
import org.partiql.types.ClobType
import org.partiql.types.DateType
import org.partiql.types.DecimalType
import org.partiql.types.FloatType
import org.partiql.types.GraphType
import org.partiql.types.IntType
import org.partiql.types.ListType
import org.partiql.types.MissingType
import org.partiql.types.NullType
import org.partiql.types.PType
import org.partiql.types.PType.Kind
import org.partiql.types.SexpType
import org.partiql.types.StaticType
import org.partiql.types.StringType
import org.partiql.types.StructType
import org.partiql.types.SymbolType
import org.partiql.types.TimeType
import org.partiql.types.TimestampType
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.PartiQLValueType

internal fun StaticType.isNumeric(): Boolean = (this is IntType || this is FloatType || this is DecimalType)

internal fun StaticType.isText(): Boolean = (this is SymbolType || this is StringType)

/**
* Returns whether [this] *may* be of a specific type. AKA: is it the type? Is it a union that holds the type?
*/
internal inline fun <reified T> StaticType.mayBeType(): Boolean {
return this.allTypes.any { it is T }
}

/**
* For each type in [this] type's [StaticType.allTypes], the [block] will be invoked. Non-null outputs of the [block]'s
* invocation will be returned.
*/
internal fun StaticType.inferListNotNull(block: (StaticType) -> StaticType?): List<StaticType> {
return this.flatten().allTypes.mapNotNull { type -> block(type) }
}

/**
* For each type in [this] type's [StaticType.allTypes], the [block] will be invoked. Non-null outputs of the [block]'s
* invocation will be returned.
*/
internal fun StaticType.inferRexListNotNull(block: (StaticType) -> Rex?): List<Rex> {
return this.flatten().allTypes.mapNotNull { type -> block(type) }
}

/**
* Per SQL, runtime types are always nullable
*/
@OptIn(PartiQLValueExperimental::class)
@Suppress("DEPRECATION")
internal fun PartiQLValueType.toStaticType(): StaticType = when (this) {
PartiQLValueType.ANY -> StaticType.ANY
PartiQLValueType.BOOL -> StaticType.BOOL
PartiQLValueType.INT8 -> StaticType.INT2
PartiQLValueType.INT16 -> StaticType.INT2
PartiQLValueType.INT32 -> StaticType.INT4
PartiQLValueType.INT64 -> StaticType.INT8
PartiQLValueType.INT -> StaticType.INT
PartiQLValueType.DECIMAL_ARBITRARY -> StaticType.DECIMAL
PartiQLValueType.DECIMAL -> StaticType.DECIMAL
PartiQLValueType.FLOAT32 -> StaticType.FLOAT
PartiQLValueType.FLOAT64 -> StaticType.FLOAT
PartiQLValueType.CHAR -> StaticType.CHAR
PartiQLValueType.STRING -> StaticType.STRING
PartiQLValueType.SYMBOL -> StaticType.SYMBOL
PartiQLValueType.BINARY -> TODO()
PartiQLValueType.BYTE -> TODO()
PartiQLValueType.BLOB -> StaticType.BLOB
PartiQLValueType.CLOB -> StaticType.CLOB
PartiQLValueType.DATE -> StaticType.DATE
PartiQLValueType.TIME -> StaticType.TIME
PartiQLValueType.TIMESTAMP -> StaticType.TIMESTAMP
PartiQLValueType.INTERVAL -> TODO()
PartiQLValueType.BAG -> StaticType.BAG
PartiQLValueType.LIST -> StaticType.LIST
PartiQLValueType.SEXP -> StaticType.SEXP
PartiQLValueType.STRUCT -> StaticType.STRUCT
PartiQLValueType.NULL -> StaticType.ANY
PartiQLValueType.MISSING -> StaticType.ANY
}

@OptIn(PartiQLValueExperimental::class)
@Suppress("DEPRECATION")
internal fun StaticType.toRuntimeType(): PartiQLValueType {
if (this is AnyOfType) {
// handle anyOf(null, T) cases
val t = types.filter { it !is NullType && it !is MissingType }
return if (t.size != 1) {
PartiQLValueType.ANY
} else {
t.first().asRuntimeType()
}
}
return this.asRuntimeType()
}

@OptIn(PartiQLValueExperimental::class)
internal fun StaticType.toRuntimeTypeOrNull(): PartiQLValueType? {
return try {
this.toRuntimeType()
} catch (_: Throwable) {
null
}
}

@Suppress("DEPRECATION")
@OptIn(PartiQLValueExperimental::class)
private fun StaticType.asRuntimeType(): PartiQLValueType = when (this) {
is AnyOfType -> PartiQLValueType.ANY
is AnyType -> PartiQLValueType.ANY
is BlobType -> PartiQLValueType.BLOB
is BoolType -> PartiQLValueType.BOOL
is ClobType -> PartiQLValueType.CLOB
is BagType -> PartiQLValueType.BAG
is ListType -> PartiQLValueType.LIST
is SexpType -> PartiQLValueType.SEXP
is DateType -> PartiQLValueType.DATE
// TODO: Run time decimal type does not model precision scale constraint yet
// despite that we match to Decimal vs Decimal_ARBITRARY (PVT) here
// but when mapping it back to Static Type, (i.e, mapping function return type to Value Type)
// we can only map to Unconstrained decimal (Static Type)
is DecimalType -> {
when (this.precisionScaleConstraint) {
is DecimalType.PrecisionScaleConstraint.Constrained -> PartiQLValueType.DECIMAL
DecimalType.PrecisionScaleConstraint.Unconstrained -> PartiQLValueType.DECIMAL_ARBITRARY
}
}
is FloatType -> PartiQLValueType.FLOAT64
is GraphType -> error("Graph type missing from runtime types")
is IntType -> when (this.rangeConstraint) {
IntType.IntRangeConstraint.SHORT -> PartiQLValueType.INT16
IntType.IntRangeConstraint.INT4 -> PartiQLValueType.INT32
IntType.IntRangeConstraint.LONG -> PartiQLValueType.INT64
IntType.IntRangeConstraint.UNCONSTRAINED -> PartiQLValueType.INT
}
MissingType -> PartiQLValueType.ANY
is NullType -> PartiQLValueType.ANY
is StringType -> PartiQLValueType.STRING
is StructType -> PartiQLValueType.STRUCT
is SymbolType -> PartiQLValueType.SYMBOL
is TimeType -> PartiQLValueType.TIME
is TimestampType -> PartiQLValueType.TIMESTAMP
}

/**
* Applies the given exclusion path to produce the reduced [StaticType]. [lastStepOptional] indicates if a previous
* Applies the given exclusion path to produce the reduced [CompilerType]. [lastStepOptional] indicates if a previous
* step in the exclude path includes a collection index exclude step. Currently, for paths with the last step as
* a struct symbol/key, the type inference will define that struct value as optional if [lastStepOptional] is true.
* Note, this specific behavior could change depending on `EXCLUDE`'s static typing behavior in a future RFC.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import org.partiql.planner.test.PartiQLTestProvider
import org.partiql.spi.catalog.Name
import org.partiql.spi.catalog.Session
import org.partiql.types.BagType
import org.partiql.types.PType
import org.partiql.types.StaticType
import org.partiql.types.StructType
import org.partiql.types.TupleConstraint
import org.partiql.types.fromStaticType
import java.io.File
import java.nio.file.Path
import java.util.stream.Stream
Expand All @@ -36,7 +36,7 @@ class PlanTest {
/**
* Table schema
*/
private val schema = PType.fromStaticType(
private val schema = fromStaticType(
BagType(
StructType(
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.partiql.types.PType
import org.partiql.types.StaticType
import org.partiql.types.StructType
import org.partiql.types.TupleConstraint
import org.partiql.types.fromStaticType
import kotlin.test.assertEquals

internal class PlannerPErrorReportingTests {
Expand Down Expand Up @@ -84,7 +85,7 @@ internal class PlannerPErrorReportingTests {
isSignal: Boolean,
assertion: (PErrorCollector) -> Unit,
expectedType: StaticType = StaticType.ANY
) : this(query, isSignal, assertion, PType.fromStaticType(expectedType).toCType())
) : this(query, isSignal, assertion, fromStaticType(expectedType).toCType())
}

companion object {
Expand Down
Loading

0 comments on commit bfce6b2

Please sign in to comment.