Skip to content
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

[SPARK-10539][SQL]Project should not be pushed down through Intersect or Except #8742

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,12 @@ object SetOperationPushDown extends Rule[LogicalPlan] {
Filter(condition, left),
Filter(pushToRight(condition, rewrites), right))

// Push down projection into intersect
case Project(projectList, i @ Intersect(left, right)) =>
val rewrites = buildRewrites(i)
Intersect(
Project(projectList, left),
Project(projectList.map(pushToRight(_, rewrites)), right))

// Push down filter into except
case Filter(condition, e @ Except(left, right)) =>
val rewrites = buildRewrites(e)
Except(
Filter(condition, left),
Filter(pushToRight(condition, rewrites), right))

// Push down projection into except
case Project(projectList, e @ Except(left, right)) =>
val rewrites = buildRewrites(e)
Except(
Project(projectList, left),
Project(projectList.map(pushToRight(_, rewrites)), right))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,22 @@ class SetOperationPushDownSuite extends PlanTest {
comparePlans(exceptOptimized, exceptCorrectAnswer)
}

test("union/intersect/except: project to each side") {
test("union: project to each side") {
val unionQuery = testUnion.select('a)
val unionOptimized = Optimize.execute(unionQuery.analyze)
val unionCorrectAnswer =
Union(testRelation.select('a), testRelation2.select('d)).analyze
comparePlans(unionOptimized, unionCorrectAnswer)
}

test("SPARK-10539: Project should not be pushed down through Intersect or Except") {
val intersectQuery = testIntersect.select('b, 'c)
val exceptQuery = testExcept.select('a, 'b, 'c)

val unionOptimized = Optimize.execute(unionQuery.analyze)
val intersectOptimized = Optimize.execute(intersectQuery.analyze)
val exceptOptimized = Optimize.execute(exceptQuery.analyze)

val unionCorrectAnswer =
Union(testRelation.select('a), testRelation2.select('d)).analyze
val intersectCorrectAnswer =
Intersect(testRelation.select('b, 'c), testRelation2.select('e, 'f)).analyze
val exceptCorrectAnswer =
Except(testRelation.select('a, 'b, 'c), testRelation2.select('d, 'e, 'f)).analyze

comparePlans(unionOptimized, unionCorrectAnswer)
comparePlans(intersectOptimized, intersectCorrectAnswer)
comparePlans(exceptOptimized, exceptCorrectAnswer) }
comparePlans(intersectOptimized, intersectQuery.analyze)
comparePlans(exceptOptimized, exceptQuery.analyze)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -907,4 +907,13 @@ class DataFrameSuite extends QueryTest with SharedSQLContext {
assert(row.getDouble(1) - row.getDouble(3) === 0.0 +- 0.001)
}
}

test("SPARK-10539: Project should not be pushed down through Intersect or Except") {
val df1 = (1 to 100).map(Tuple1.apply).toDF("i")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sqlContext.range(100)

val df2 = (1 to 30).map(Tuple1.apply).toDF("i")
val intersect = df1.intersect(df2)
val except = df1.except(df2)
assert(intersect.count() === 30)
assert(except.count() === 70)
}
}