Skip to content

Commit

Permalink
Merge branch 'main' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Jun 3, 2024
2 parents 22bb461 + a2d5398 commit 9ee2e59
Show file tree
Hide file tree
Showing 71 changed files with 1,109 additions and 2,681 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,30 @@ Thank you to all who have contributed!
### Added

### Changed
- **Behavioral change**: The planner now does NOT support the NullType and MissingType variants of StaticType. The logic
is that the null and missing values are part of *all* data types. Therefore, one must assume that the types returned by
the planner allow for NULL and MISSING values. Similarly, the testFixtures Ion-encoded test resources
representing the catalog do not use "null" or "missing".
- **Behavioral change**: The `INTEGER/INT` type is now an alias to the `INT4` type. Previously the INTEGER type was
unconstrained which is not SQL-conformant and is causing issues in integrating with other systems. This release makes
INTEGER an alias for INT4 which is the internal type name. In a later release, we will make INTEGER the default 32-bit
integer with INT/INT4/INTEGER4 being aliases per other systems. This change only applies to
org.partiql.parser.PartiQLParser, not the org.partiql.lang.syntax.PartiQLParser.

### Deprecated
- We have deprecated `org.partiql.type.NullType` and `org.partiql.type.MissingType`. Please see the corresponding
information in the "Changed" section. In relation to the deprecation of the above, the following APIs have also
been deprecated:
- `org.partiql.type.StaticType.MISSING`
- `org.partiql.type.StaticType.NULL`
- `org.partiql.type.StaticType.NULL_OR_MISSING`
- `org.partiql.type.StaticType.asNullable()`
- `org.partiql.type.StaticType.isNullable()`
- `org.partiql.type.StaticType.isMissable()`
- `org.partiql.type.StaticType.asOptional()`
- `org.partiql.type.AnyOfType()`
- `org.partiql.value.PartiQLValueType.NULL`
- `org.partiql.value.PartiQLValueType.MISSING`

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ import org.partiql.lang.util.checkThreadInterrupted
import org.partiql.lang.util.error
import org.partiql.lang.util.getPrecisionFromTimeString
import org.partiql.lang.util.unaryMinus
import org.partiql.parser.internal.antlr.PartiQLBaseVisitor
import org.partiql.parser.antlr.PartiQLParser
import org.partiql.parser.antlr.PartiQLParserBaseVisitor
import org.partiql.parser.internal.antlr.PartiQLParser
import org.partiql.pig.runtime.SymbolPrimitive
import org.partiql.value.datetime.DateTimeException
Expand All @@ -73,12 +74,12 @@ import java.time.format.DateTimeFormatter
import java.time.format.DateTimeParseException

/**
* Extends ANTLR's generated [PartiQLBaseVisitor] to visit an ANTLR ParseTree and convert it into a PartiQL AST. This
* Extends ANTLR's generated [PartiQLParserBaseVisitor] to visit an ANTLR ParseTree and convert it into a PartiQL AST. This
* class uses the [PartiqlAst.PartiqlAstNode] to represent all nodes within the new AST.
*
* When the grammar in PartiQL.g4 is extended with a new rule, one needs to override corresponding visitor methods
* in this class, in order to extend the transformation from an ANTLR parse tree into a [PartqlAst] tree.
* (Trivial implementations of these methods are generated into [PartiQLBaseVisitor].)
* (Trivial implementations of these methods are generated into [PartiQLParserBaseVisitor].)
*
* For a rule of the form
* ```
Expand Down Expand Up @@ -119,7 +120,7 @@ internal class PartiQLPigVisitor(
val customTypes: List<CustomType> = listOf(),
private val parameterIndexes: Map<Int, Int> = mapOf(),
) :
PartiQLBaseVisitor<PartiqlAst.PartiqlAstNode>() {
PartiQLParserBaseVisitor<PartiqlAst.PartiqlAstNode>() {

companion object {
internal val TRIM_SPECIFICATION_KEYWORDS = setOf("both", "leading", "trailing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.partiql.lang.ast.passes.inference
import junitparams.JUnitParamsRunner
import junitparams.Parameters
import org.junit.Assert.assertEquals
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.partiql.types.DecimalType
Expand Down Expand Up @@ -85,6 +86,7 @@ class StaticTypeCastTests {

@Test
@Parameters
@Ignore("StaticType.ALL_TYPES no longer supports NULL/MISSING") // @Test comes from JUnit4, and therefore we must use @Ignore.
fun unionTypeCastTests(tc: TestCase) = runTest(tc)

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.partiql.lang.eval.visitors.inferencer

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.errors.Problem
Expand All @@ -20,6 +21,7 @@ import org.partiql.types.StructType

class InferencerMultipleProblemsTests {
@ParameterizedTest
@Disabled
@MethodSource("parametersForMultipleInferenceProblemsTests")
fun multipleInferenceProblemsTests(tc: TestCase) = runTest(tc)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.partiql.lang.eval.visitors.inferencer

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.errors.Problem
Expand Down Expand Up @@ -29,6 +30,7 @@ class InferencerNaryArithmeticTests {

@ParameterizedTest
@MethodSource("parametersForNAryArithmeticTests")
@Disabled
fun naryArithmeticInferenceTests(tc: InferencerTestUtil.TestCase) = runTest(tc)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.partiql.lang.eval.visitors.inferencer

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.errors.Problem
Expand All @@ -26,6 +27,7 @@ import org.partiql.types.StaticType
class InferencerNaryBetweenTests {
@ParameterizedTest
@MethodSource("parametersForNAryBetweenTests")
@Disabled("StaticType.ALL_TYPES no longer supports NULL/MISSING")
fun naryBetweenInferenceTests(tc: TestCase) = runTest(tc)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.partiql.lang.eval.visitors.inferencer

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.errors.Problem
Expand Down Expand Up @@ -33,6 +34,7 @@ import org.partiql.types.StructType
class InferencerNaryComparisonAndEqualityTests {
@ParameterizedTest
@MethodSource("parametersForNAryComparisonAndEqualityTests")
@Disabled("StaticType.ALL_TYPES no longer supports NULL/MISSING")
fun naryComparisonAndEqualityInferenceTests(tc: TestCase) = runTest(tc)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.partiql.lang.eval.visitors.inferencer

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.errors.Problem
Expand All @@ -25,6 +26,7 @@ import org.partiql.types.StringType
class InferencerNaryConcatTests {
@ParameterizedTest
@MethodSource("parametersForNAryConcatTests")
@Disabled("StaticType.ALL_TYPES no longer supports NULL/MISSING")
fun naryConcatInferenceTests(tc: TestCase) = runTest(tc)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.partiql.lang.eval.visitors.inferencer

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.errors.Problem
Expand All @@ -22,6 +23,7 @@ class InferencerNaryLikeTests {

@ParameterizedTest
@MethodSource("parametersForNAryLikeTests")
@Disabled("StaticType.ALL_TYPES no longer supports NULL/MISSING")
fun naryLikeInferenceTests(tc: TestCase) = runTest(tc)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.partiql.lang.eval.visitors.inferencer

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.errors.Problem
Expand All @@ -25,6 +26,7 @@ import org.partiql.types.StaticType
class InferencerNaryLogicalTests {
@ParameterizedTest
@MethodSource("parametersForNAryLogicalTests")
@Disabled("StaticType.ALL_TYPES no longer supports NULL/MISSING")
fun naryLogicalInferenceTests(tc: TestCase) = runTest(tc)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.partiql.lang.eval.visitors.inferencer

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.errors.Problem
Expand Down Expand Up @@ -31,6 +32,7 @@ import org.partiql.types.StaticType
class InferencerNaryOpInTests {
@ParameterizedTest
@MethodSource("parametersForNAryOpInTests")
@Disabled("StaticType.ALL_TYPES no longer supports NULL/MISSING")
fun nAryOpInTests(tc: TestCase) = runTest(tc)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.partiql.lang.eval.visitors.inferencer

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.lang.eval.visitors.inferencer.InferencerTestUtil.TestCase
Expand All @@ -10,6 +11,7 @@ import org.partiql.types.StaticType
class InferencerTrimFunctionTests {
@ParameterizedTest
@MethodSource("parametersForTrimFunctionTests")
@Disabled("StaticType.ALL_TYPES no longer supports NULL/MISSING")
fun trimFunctionTests(tc: TestCase) = runTest(tc)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.partiql.lang.eval.visitors.inferencer

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.errors.Problem
Expand All @@ -15,6 +16,7 @@ import org.partiql.types.StaticType
class InferencerUnaryArithmeticOpTests {
@ParameterizedTest
@MethodSource("parametersForUnaryArithmeticOpTests")
@Disabled("StaticType.ALL_TYPES no longer supports NULL/MISSING")
fun unaryArithmeticInferenceTests(tc: InferencerTestUtil.TestCase) = InferencerTestUtil.runTest(tc)

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3998,6 +3998,7 @@ class PartiQLParserTest : PartiQLParserTestBase() {
)

@Test
@Ignore("This test is disabled while the new parser uses INT as an INT4 alias whereas the older parser does not.")
fun createTableWithConstraints() = assertExpression(
"""
CREATE TABLE Customer (
Expand Down
2 changes: 2 additions & 0 deletions partiql-parser/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ tasks.processResources {
from("src/main/antlr") {
include("**/*.g4")
}
// TODO remove in next major version release.
rename("PartiQLParser.g4", "PartiQL.g4")
}

publish {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
grammar PartiQL;
parser grammar PartiQLParser;

options {
tokenVocab=PartiQLTokens;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ import org.partiql.ast.typeDate
import org.partiql.ast.typeDecimal
import org.partiql.ast.typeFloat32
import org.partiql.ast.typeFloat64
import org.partiql.ast.typeInt
import org.partiql.ast.typeInt2
import org.partiql.ast.typeInt4
import org.partiql.ast.typeInt8
Expand All @@ -214,7 +213,7 @@ import org.partiql.parser.PartiQLParserException
import org.partiql.parser.PartiQLSyntaxException
import org.partiql.parser.SourceLocation
import org.partiql.parser.SourceLocations
import org.partiql.parser.internal.antlr.PartiQLBaseVisitor
import org.partiql.parser.internal.antlr.PartiQLParserBaseVisitor
import org.partiql.parser.internal.util.DateTimeUtils
import org.partiql.value.NumericValue
import org.partiql.value.PartiQLValueExperimental
Expand Down Expand Up @@ -428,7 +427,7 @@ internal class PartiQLParserDefault : PartiQLParser {
private class Visitor(
private val locations: SourceLocations.Mutable,
private val parameters: Map<Int, Int> = mapOf(),
) : PartiQLBaseVisitor<AstNode>() {
) : PartiQLParserBaseVisitor<AstNode>() {

companion object {

Expand Down Expand Up @@ -2159,9 +2158,10 @@ internal class PartiQLParserDefault : PartiQLParser {
GeneratedParser.NULL -> typeNullType()
GeneratedParser.BOOL, GeneratedParser.BOOLEAN -> typeBool()
GeneratedParser.SMALLINT, GeneratedParser.INT2, GeneratedParser.INTEGER2 -> typeInt2()
// TODO, we have INT aliased to INT4 when it should be visa-versa.
GeneratedParser.INT4, GeneratedParser.INTEGER4 -> typeInt4()
GeneratedParser.INT, GeneratedParser.INTEGER -> typeInt4()
GeneratedParser.BIGINT, GeneratedParser.INT8, GeneratedParser.INTEGER8 -> typeInt8()
GeneratedParser.INT, GeneratedParser.INTEGER -> typeInt()
GeneratedParser.FLOAT -> typeFloat32()
GeneratedParser.DOUBLE -> typeFloat64()
GeneratedParser.REAL -> typeReal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ internal object ProblemGenerator {
}

fun missingRex(causes: List<Rex.Op>, problem: Problem): Rex =
rex(StaticType.MISSING, rexOpMissing(problem, causes))
rex(StaticType.ANY, rexOpMissing(problem, causes))

fun missingRex(causes: Rex.Op, problem: Problem): Rex =
rex(StaticType.MISSING, rexOpMissing(problem, listOf(causes)))
rex(StaticType.ANY, rexOpMissing(problem, listOf(causes)))

fun errorRex(causes: List<Rex.Op>, problem: Problem): Rex =
rex(StaticType.MISSING, rexOpErr(problem, causes))
rex(StaticType.ANY, rexOpErr(problem, causes))

fun errorRex(trace: Rex.Op, problem: Problem): Rex =
rex(StaticType.MISSING, rexOpErr(problem, listOf(trace)))
rex(StaticType.ANY, rexOpErr(problem, listOf(trace)))

private fun InternalIdentifier.debug(): String = when (this) {
is InternalIdentifier.Qualified -> (listOf(root.debug()) + steps.map { it.debug() }).joinToString(".")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import org.partiql.planner.internal.ir.rexOpSubquery
import org.partiql.planner.internal.ir.rexOpTupleUnion
import org.partiql.planner.internal.ir.rexOpVarLocal
import org.partiql.planner.internal.ir.rexOpVarUnresolved
import org.partiql.planner.internal.typer.toNonNullStaticType
import org.partiql.planner.internal.typer.toStaticType
import org.partiql.types.StaticType
import org.partiql.value.PartiQLValueExperimental
Expand Down Expand Up @@ -84,10 +83,7 @@ internal object RexConverter {
throw IllegalArgumentException("unsupported rex $node")

override fun visitExprLit(node: Expr.Lit, context: Env): Rex {
val type = when (node.value.isNull) {
true -> node.value.type.toStaticType()
else -> node.value.type.toNonNullStaticType()
}
val type = node.value.type.toStaticType()
val op = rexOpLit(node.value)
return rex(type, op)
}
Expand All @@ -96,10 +92,7 @@ internal object RexConverter {
val value =
PartiQLValueIonReaderBuilder
.standard().build(node.value).read()
val type = when (value.isNull) {
true -> value.type.toStaticType()
else -> value.type.toNonNullStaticType()
}
val type = value.type.toStaticType()
return rex(type, rexOpLit(value))
}

Expand Down Expand Up @@ -458,7 +451,7 @@ internal object RexConverter {
}.toMutableList()

val defaultRex = when (val default = node.default) {
null -> rex(type = StaticType.NULL, op = rexOpLit(value = nullValue()))
null -> rex(type = StaticType.ANY, op = rexOpLit(value = nullValue()))
else -> visitExprCoerce(default, context)
}
val op = rexOpCase(branches = branches, default = defaultRex)
Expand Down Expand Up @@ -741,8 +734,8 @@ internal object RexConverter {
val type = node.asType
val arg = visitExprCoerce(node.value, ctx)
val target = when (type) {
is Type.NullType -> PartiQLValueType.NULL
is Type.Missing -> PartiQLValueType.MISSING
is Type.NullType -> error("Cannot cast any value to NULL")
is Type.Missing -> error("Cannot cast any value to MISSING")
is Type.Bool -> PartiQLValueType.BOOL
is Type.Tinyint -> PartiQLValueType.INT8
is Type.Smallint, is Type.Int2 -> PartiQLValueType.INT16
Expand Down
Loading

0 comments on commit 9ee2e59

Please sign in to comment.