-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19471][SQL]AggregationIterator does not initialize the generated result projection before using it #18920
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import org.apache.spark.sql.catalyst.expressions.aggregate._ | |
| * is used to generate result. | ||
| */ | ||
| abstract class AggregationIterator( | ||
| partIndex: Int, | ||
| groupingExpressions: Seq[NamedExpression], | ||
| inputAttributes: Seq[Attribute], | ||
| aggregateExpressions: Seq[AggregateExpression], | ||
|
|
@@ -229,6 +230,7 @@ abstract class AggregationIterator( | |
| allImperativeAggregateFunctions(i).eval(currentBuffer)) | ||
| i += 1 | ||
| } | ||
| resultProjection.initialize(partIndex) | ||
| resultProjection(joinedRow(currentGroupingKey, aggregateResult)) | ||
| } | ||
| } else if (modes.contains(Partial) || modes.contains(PartialMerge)) { | ||
|
|
@@ -251,12 +253,14 @@ abstract class AggregationIterator( | |
| typedImperativeAggregates(i).serializeAggregateBufferInPlace(currentBuffer) | ||
| i += 1 | ||
| } | ||
| resultProjection.initialize(partIndex) | ||
|
||
| resultProjection(joinedRow(currentGroupingKey, currentBuffer)) | ||
| } | ||
| } else { | ||
| // Grouping-only: we only output values based on grouping expressions. | ||
| val resultProjection = UnsafeProjection.create(resultExpressions, groupingAttributes) | ||
| (currentGroupingKey: UnsafeRow, currentBuffer: InternalRow) => { | ||
| resultProjection.initialize(partIndex) | ||
|
||
| resultProjection(currentGroupingKey) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -449,6 +449,28 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext { | |
| ).foreach(assertValuesDoNotChangeAfterCoalesceOrUnion(_)) | ||
| } | ||
|
|
||
| private def assertNoExceptions(c: Column): Unit = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you submit a follow-up PR to move this test case to |
||
| for ((wholeStage, useObjectHashAgg) <- Seq((true, false), (false, false), (false, true))) { | ||
| withSQLConf( | ||
| (SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key, wholeStage.toString), | ||
| (SQLConf.USE_OBJECT_HASH_AGG.key, useObjectHashAgg.toString)) { | ||
| val df = Seq(("1", 1), ("1", 2), ("2", 3), ("2", 4)).toDF("x", "y") | ||
| // HashAggregate | ||
|
||
| df.groupBy("x").agg(c, sum("y")).collect() | ||
| // ObjectHashAggregate and SortAggregate | ||
| df.groupBy("x").agg(c, collect_list("y")).collect() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-19471: AggregationIterator does not initialize the generated result projection" + | ||
| " before using it") { | ||
| Seq( | ||
| monotonically_increasing_id(), spark_partition_id(), | ||
| rand(Random.nextLong()), randn(Random.nextLong()) | ||
| ).foreach(assertNoExceptions(_)) | ||
|
||
| } | ||
|
|
||
| test("SPARK-21281 use string types by default if array and map have no argument") { | ||
| val ds = spark.range(1) | ||
| var expectedSchema = new StructType() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move it to line 221