Skip to content
Snippets Groups Projects
Commit 8cdb81fa authored by Koert Kuipers's avatar Koert Kuipers Committed by Wenchen Fan
Browse files

[SPARK-15204][SQL] improve nullability inference for Aggregator

## What changes were proposed in this pull request?

TypedAggregateExpression sets nullable based on the schema of the outputEncoder

## How was this patch tested?

Add test in DatasetAggregatorSuite

Author: Koert Kuipers <koert@tresata.com>

Closes #13532 from koertkuipers/feat-aggregator-nullable.
parent 88134e73
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,8 @@ object TypedAggregateExpression {
bufferDeserializer,
outputEncoder.serializer,
outputEncoder.deserializer.dataType,
outputType)
outputType,
!outputEncoder.flat || outputEncoder.schema.head.nullable)
}
}
......@@ -65,9 +66,8 @@ case class TypedAggregateExpression(
bufferDeserializer: Expression,
outputSerializer: Seq[Expression],
outputExternalType: DataType,
dataType: DataType) extends DeclarativeAggregate with NonSQLExpression {
override def nullable: Boolean = true
dataType: DataType,
nullable: Boolean) extends DeclarativeAggregate with NonSQLExpression {
override def deterministic: Boolean = true
......
......@@ -305,4 +305,13 @@ class DatasetAggregatorSuite extends QueryTest with SharedSQLContext {
val ds = Seq(1, 2, 3).toDS()
checkDataset(ds.select(MapTypeBufferAgg.toColumn), 1)
}
test("SPARK-15204 improve nullability inference for Aggregator") {
val ds1 = Seq(1, 3, 2, 5).toDS()
assert(ds1.select(typed.sum((i: Int) => i)).schema.head.nullable === false)
val ds2 = Seq(AggData(1, "a"), AggData(2, "a")).toDS()
assert(ds2.select(SeqAgg.toColumn).schema.head.nullable === true)
val ds3 = sql("SELECT 'Some String' AS b, 1279869254 AS a").as[AggData]
assert(ds3.select(NameAgg.toColumn).schema.head.nullable === true)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment