Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the unsafe DECIMAL to integer downcasts #1342

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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(),
)
Original file line number Diff line number Diff line change
@@ -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
@@ -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(
@@ -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 ------

//
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
type: "struct",
constraints: [closed],
fields: [
{
name: "nullable_int16s",
@@ -69,6 +70,10 @@
items: "int",
},
},
{
name: "d",
type: "decimal",
},
{
name: "decimals",
type: {
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);