diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt index 8f3f75c82d..1c91ef6d1d 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt @@ -39,6 +39,7 @@ import org.partiql.types.StaticType import org.partiql.types.StaticType.Companion.ANY import org.partiql.types.StaticType.Companion.DECIMAL import org.partiql.types.StaticType.Companion.INT +import org.partiql.types.StaticType.Companion.INT2 import org.partiql.types.StaticType.Companion.INT4 import org.partiql.types.StaticType.Companion.INT8 import org.partiql.types.StaticType.Companion.unionOf @@ -167,11 +168,13 @@ class PlanTyperTestsPorted { val TYPE_BOOL = StaticType.BOOL private val TYPE_AWS_DDB_PETS_ID = StaticType.INT4 private val TYPE_AWS_DDB_PETS_BREED = StaticType.STRING + private val TYPE_AWS_DDB_PETS_TAG = StaticType.INT2 val TABLE_AWS_DDB_PETS = BagType( elementType = StructType( fields = mapOf( "id" to TYPE_AWS_DDB_PETS_ID, - "breed" to TYPE_AWS_DDB_PETS_BREED + "breed" to TYPE_AWS_DDB_PETS_BREED, + "tag" to TYPE_AWS_DDB_PETS_TAG, ), contentClosed = true, constraints = setOf( @@ -185,7 +188,8 @@ class PlanTyperTestsPorted { elementType = StructType( fields = mapOf( "id" to TYPE_AWS_DDB_PETS_ID, - "breed" to TYPE_AWS_DDB_PETS_BREED + "breed" to TYPE_AWS_DDB_PETS_BREED, + "tag" to TYPE_AWS_DDB_PETS_TAG, ), contentClosed = true, constraints = setOf( @@ -289,6 +293,39 @@ class PlanTyperTestsPorted { @JvmStatic fun structs() = listOf() + @JvmStatic + fun extendedCastTests() = listOf( + SuccessTestCase( + name = "CAST INT4 TO INT2", + catalog = CATALOG_AWS, + query = "CAST((SELECT t.id FROM ddb.pets AS t) AS INT2)", + expected = INT2 + ), + SuccessTestCase( + name = "CAST BOOL TO INT2", + catalog = CATALOG_AWS, + query = "CAST(true AS INT2)", + expected = INT2 + ), + SuccessTestCase( + name = "CAST INT2 TO INT4", + catalog = CATALOG_AWS, + query = "CAST((SELECT t.tag FROM ddb.pets AS t) AS INT4)", + expected = INT4 + ), + SuccessTestCase( + name = "CAST INT8 literal to INT2", + query = "CAST(343434534534 AS INT2)", + expected = INT2 + ), + SuccessTestCase( + name = "CAST STRING to INT2", + catalog = CATALOG_AWS, + query = "CAST((SELECT t.breed FROM ddb.pets AS t) AS INT2)", + expected = INT2 + ), + ) + @JvmStatic fun decimalCastCases() = listOf( SuccessTestCase( @@ -3523,6 +3560,11 @@ class PlanTyperTestsPorted { @ArgumentsSource(TestProvider::class) fun test(tc: TestCase) = runTest(tc) + @ParameterizedTest + @MethodSource("extendedCastTests") + @Execution(ExecutionMode.CONCURRENT) + fun testCastCase(tc: TestCase) = runTest(tc) + @ParameterizedTest @MethodSource("collections") @Execution(ExecutionMode.CONCURRENT) @@ -3843,7 +3885,7 @@ class PlanTyperTestsPorted { name = "Project all implicitly", catalog = CATALOG_AWS, catalogPath = listOf("ddb"), - query = "SELECT id, breed FROM pets", + query = "SELECT id, breed, tag FROM pets", expected = TABLE_AWS_DDB_PETS ), TestCase.SuccessTestCase( diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/aws/ddb/pets.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/aws/ddb/pets.ion index 11ec580288..af309ccbe8 100644 --- a/partiql-planner/src/testFixtures/resources/catalogs/default/aws/ddb/pets.ion +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/aws/ddb/pets.ion @@ -11,6 +11,10 @@ { name: "breed", type: "string", + }, + { + name: "tag", + type: "int16", } ] }