diff --git a/partiql-ast/src/test/kotlin/org/partiql/ast/normalize/NormalizeTest.kt b/partiql-ast/src/test/kotlin/org/partiql/ast/normalize/NormalizeTest.kt index a2c7e86db3..566e3669ee 100644 --- a/partiql-ast/src/test/kotlin/org/partiql/ast/normalize/NormalizeTest.kt +++ b/partiql-ast/src/test/kotlin/org/partiql/ast/normalize/NormalizeTest.kt @@ -7,4 +7,4 @@ class NormalizeTest { @Test fun normalize() { } -} \ No newline at end of file +} diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/typer/PlanTyper.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/typer/PlanTyper.kt index 4651006757..369dcf5474 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/typer/PlanTyper.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/typer/PlanTyper.kt @@ -811,7 +811,13 @@ internal class PlanTyper( // Found a match! val newAgg = aggResolved(match.signature) val newArgs = rewriteFnArgs(match.mapping, args) - var type = newAgg.signature.returns.toStaticType() + val returns = newAgg.signature.returns + + // Return type with calculated nullability + var type = when { + newAgg.signature.isNullable -> returns.toStaticType() + else -> returns.toNonNullStaticType() + } // Some operators can return MISSING during runtime if (match.isMissable) { diff --git a/partiql-planner/src/testFixtures/resources/tests/aggregations.ion b/partiql-planner/src/testFixtures/resources/tests/aggregations.ion index 718578921d..2badeb8dd6 100644 --- a/partiql-planner/src/testFixtures/resources/tests/aggregations.ion +++ b/partiql-planner/src/testFixtures/resources/tests/aggregations.ion @@ -116,7 +116,10 @@ suite::{ fields: [ { name: "avg", - type: "int32" + type: [ + "int32", + "null" + ], }, ], }, @@ -150,7 +153,10 @@ suite::{ fields: [ { name: "min", - type: "int32" + type: [ + "int32", + "null" + ], }, ], }, @@ -167,7 +173,10 @@ suite::{ fields: [ { name: "max", - type: "int32" + type: [ + "int32", + "null" + ], }, ], }, @@ -184,7 +193,10 @@ suite::{ fields: [ { name: "sum", - type: "int32" + type: [ + "int32", + "null" + ], }, ], }, @@ -224,7 +236,10 @@ suite::{ fields: [ { name: "_1", - type: "float32" + type: [ + "float32", + "null" + ], }, { name: "y", @@ -250,7 +265,10 @@ suite::{ fields: [ { name: "_1", - type: "float32" + type: [ + "float32", + "null" + ], }, { name: "a",