-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-37203][SQL] Fix NotSerializableException when observe with TypedImperativeAggregate #34474
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 4 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 |
|---|---|---|
|
|
@@ -621,6 +621,17 @@ abstract class TypedImperativeAggregate[T] extends ImperativeAggregate { | |
| buffer(mutableAggBufferOffset) = serialize(getBufferObject(buffer)) | ||
| } | ||
|
|
||
| /** | ||
| * In-place replaces SparkSQL internally supported underlying storage format (BinaryType), | ||
| * with the aggregation buffer object stored at buffer's index `mutableAggBufferOffset`. | ||
|
Contributor
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.
|
||
| * | ||
| * This is only called when AggregatingAccumulator running on driver, after the framework | ||
| * shuffle in aggregate buffers. | ||
|
Contributor
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. This is nothing to do with shuffle |
||
| */ | ||
| final def deserializeAggregateBufferInPlace(buffer: InternalRow): Unit = { | ||
| buffer(mutableAggBufferOffset) = deserialize(buffer.getBinary(inputAggBufferOffset)) | ||
| } | ||
|
|
||
| /** | ||
| * Merge an input buffer into the aggregation buffer, where both buffers contain the deserialized | ||
| * java object. This function is used by aggregating accumulators. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,6 +156,15 @@ class AggregatingAccumulator private( | |
| case agg: AggregatingAccumulator => | ||
| val buffer = getOrCreateBuffer() | ||
| val otherBuffer = agg.buffer | ||
| // If AggregatingAccumulator runs on driver, | ||
| // we should deserialize all TypedImperativeAggregate. | ||
| if (isAtDriverSide) { | ||
|
Contributor
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. We don't need to add a new code. We can just change the existing code to |
||
| var i = 0 | ||
| while (i < typedImperatives.length) { | ||
| typedImperatives(i).deserializeAggregateBufferInPlace(otherBuffer) | ||
| i += 1 | ||
| } | ||
| } | ||
| mergeProjection.target(buffer)(joinedRow.withRight(otherBuffer)) | ||
| var i = 0 | ||
| while (i < imperatives.length) { | ||
|
|
@@ -188,6 +197,18 @@ class AggregatingAccumulator private( | |
| resultProjection(input) | ||
| } | ||
|
|
||
| override def withBufferSerialized(): AggregatingAccumulator = { | ||
| if (!isAtDriverSide) { | ||
|
Contributor
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. I think we can do |
||
| var i = 0 | ||
| // AggregatingAccumulator runs on executor, we should serialize all TypedImperativeAggregate. | ||
| while (i < typedImperatives.length) { | ||
| typedImperatives(i).serializeAggregateBufferInPlace(buffer) | ||
| i += 1 | ||
| } | ||
| } | ||
| this | ||
| } | ||
|
|
||
| /** | ||
| * Get the output schema of the aggregating accumulator. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -754,6 +754,17 @@ class DatasetSuite extends QueryTest | |
| assert(err2.getMessage.contains("Name must not be empty")) | ||
| } | ||
|
|
||
| test("SPARK-37203: Fix NotSerializableException when observe with percentile_approx") { | ||
| val namedObservation = Observation("named") | ||
|
|
||
| val df = spark.range(100) | ||
| val observed_df = df.observe( | ||
|
Contributor
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. can we test a DataFrame with no data?
Contributor
Author
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. OK |
||
| namedObservation, percentile_approx($"id", lit(0.5), lit(100)).as("percentile_approx_val")) | ||
|
|
||
| observed_df.collect() | ||
| assert(namedObservation.get === Map("percentile_approx_val" -> 49)) | ||
| } | ||
|
|
||
| test("sample with replacement") { | ||
| val n = 100 | ||
| val data = sparkContext.parallelize(1 to n, 2).toDS() | ||
|
|
||
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.