Skip to content

Commit

Permalink
[SPARK-19314][SS][CATALYST] Do not allow sort before aggregation in S…
Browse files Browse the repository at this point in the history
…tructured Streaming plan

## What changes were proposed in this pull request?

Sort in a streaming plan should be allowed only after a aggregation in complete mode. Currently it is incorrectly allowed when present anywhere in the plan. It gives unpredictable potentially incorrect results.

## How was this patch tested?
New test

Author: Tathagata Das <[email protected]>

Closes #16662 from tdas/SPARK-19314.

(cherry picked from commit 552e5f0)
Signed-off-by: Tathagata Das <[email protected]>
  • Loading branch information
tdas committed Jan 20, 2017
1 parent 9fc053c commit 4c2065d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ object UnsupportedOperationChecker {
* data.
*/
def containsCompleteData(subplan: LogicalPlan): Boolean = {
val aggs = plan.collect { case a@Aggregate(_, _, _) if a.isStreaming => a }
val aggs = subplan.collect { case a@Aggregate(_, _, _) if a.isStreaming => a }
// Either the subplan has no streaming source, or it has aggregation with Complete mode
!subplan.isStreaming || (aggs.nonEmpty && outputMode == InternalOutputModes.Complete)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,17 @@ class UnsupportedOperationsSuite extends SparkFunSuite {
_.intersect(_),
streamStreamSupported = false)

// Sort: supported only on batch subplans and on aggregation + complete output mode
// Sort: supported only on batch subplans and after aggregation on streaming plan + complete mode
testUnaryOperatorInStreamingPlan("sort", Sort(Nil, true, _))
assertSupportedInStreamingPlan(
"sort - sort over aggregated data in Complete output mode",
"sort - sort after aggregation in Complete output mode",
streamRelation.groupBy()(Count("*")).sortBy(),
Complete)
assertNotSupportedInStreamingPlan(
"sort - sort before aggregation in Complete output mode",
streamRelation.sortBy().groupBy()(Count("*")),
Complete,
Seq("sort", "aggregat", "complete"))
assertNotSupportedInStreamingPlan(
"sort - sort over aggregated data in Update output mode",
streamRelation.groupBy()(Count("*")).sortBy(),
Expand Down

0 comments on commit 4c2065d

Please sign in to comment.