Skip to content

Commit

Permalink
Merge 06e9da6 into 1e1a71f
Browse files Browse the repository at this point in the history
  • Loading branch information
rchowell authored Jan 19, 2024
2 parents 1e1a71f + 06e9da6 commit 3cd4498
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,41 +266,57 @@ internal class TypeLattice private constructor(
SYMBOL to explicit(),
)
graph[DECIMAL] = relationships(
BOOL to explicit(),
INT8 to explicit(),
INT16 to explicit(),
INT32 to explicit(),
INT64 to explicit(),
BOOL to explicit(),
DECIMAL to explicit(),
DECIMAL_ARBITRARY to explicit(),
INT to explicit(),
DECIMAL to coercion(),
DECIMAL_ARBITRARY to coercion(),
FLOAT32 to explicit(),
FLOAT64 to explicit(),
STRING to explicit(),
SYMBOL to explicit(),
)
graph[FLOAT32] = relationships(
graph[DECIMAL_ARBITRARY] = relationships(
BOOL to explicit(),
DECIMAL to explicit(),
INT8 to explicit(),
INT16 to explicit(),
INT32 to explicit(),
INT64 to explicit(),
INT to explicit(),
DECIMAL to coercion(),
DECIMAL_ARBITRARY to coercion(),
FLOAT32 to coercion(),
FLOAT64 to coercion(),
FLOAT32 to explicit(),
FLOAT64 to explicit(),
STRING to explicit(),
SYMBOL to explicit(),
)
graph[FLOAT64] = relationships(
graph[FLOAT32] = relationships(
BOOL to explicit(),
DECIMAL to explicit(),
INT8 to unsafe(),
INT16 to unsafe(),
INT32 to unsafe(),
INT64 to unsafe(),
INT to unsafe(),
DECIMAL to unsafe(),
DECIMAL_ARBITRARY to coercion(),
FLOAT32 to coercion(),
FLOAT64 to coercion(),
STRING to explicit(),
SYMBOL to explicit(),
)
graph[DECIMAL_ARBITRARY] = relationships(
graph[FLOAT64] = relationships(
BOOL to explicit(),
DECIMAL to explicit(),
INT8 to unsafe(),
INT16 to unsafe(),
INT32 to unsafe(),
INT64 to unsafe(),
INT to unsafe(),
DECIMAL to unsafe(),
DECIMAL_ARBITRARY to coercion(),
FLOAT32 to explicit(),
FLOAT64 to explicit(),
FLOAT64 to coercion(),
STRING to explicit(),
SYMBOL to explicit(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.partiql.types.BagType
import org.partiql.types.ListType
import org.partiql.types.SexpType
import org.partiql.types.StaticType
import org.partiql.types.StaticType.Companion.unionOf
import org.partiql.types.StructType
import org.partiql.types.TupleConstraint
import java.util.stream.Stream
Expand Down Expand Up @@ -448,6 +449,46 @@ class PlanTyperTestsPorted {
),
)

@JvmStatic
fun castCases() = listOf(
SuccessTestCase(
name = "DECIMAL AS INT2",
key = key("cast-00"),
catalog = "pql",
expected = StaticType.INT2,
),
SuccessTestCase(
name = "DECIMAL AS INT4",
key = key("cast-01"),
catalog = "pql",
expected = StaticType.INT4,
),
SuccessTestCase(
name = "DECIMAL AS INT8",
key = key("cast-02"),
catalog = "pql",
expected = StaticType.INT8,
),
SuccessTestCase(
name = "DECIMAL AS INT",
key = key("cast-03"),
catalog = "pql",
expected = StaticType.INT,
),
SuccessTestCase(
name = "DECIMAL AS BIGINT",
key = key("cast-04"),
catalog = "pql",
expected = StaticType.INT8,
),
SuccessTestCase(
name = "DECIMAL_ARBITRARY AS DECIMAL",
key = key("cast-05"),
catalog = "pql",
expected = StaticType.DECIMAL,
),
)

@JvmStatic
fun sessionVariables() = listOf(
SuccessTestCase(
Expand Down Expand Up @@ -3040,6 +3081,11 @@ class PlanTyperTestsPorted {
@Execution(ExecutionMode.CONCURRENT)
fun testIsType(tc: TestCase) = runTest(tc)

@ParameterizedTest
@MethodSource("castCases")
@Execution(ExecutionMode.CONCURRENT)
fun testCasts(tc: TestCase) = runTest(tc)

// --------- Finish Parameterized Tests ------

//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
type: "struct",
constraints: [closed],
fields: [
{
name: "nullable_int16s",
Expand Down Expand Up @@ -69,6 +70,10 @@
items: "int",
},
},
{
name: "d",
type: "decimal",
},
{
name: "decimals",
type: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--#[cast-00]
CAST(numbers.d AS INT2);

--#[cast-01]
CAST(numbers.d AS INT4);

--#[cast-02]
CAST(numbers.d AS INT8);

--#[cast-03]
CAST(numbers.d AS INT);

--#[cast-04]
CAST(numbers.d AS BIGINT);

--#[cast-05]
CAST(numbers.d AS DECIMAL);

0 comments on commit 3cd4498

Please sign in to comment.