Skip to content

Commit b9eb0e8

Browse files
jzhugegatorsmile
authored andcommitted
[SPARK-26576][SQL] Broadcast hint not applied to partitioned table
## What changes were proposed in this pull request? Make sure broadcast hint is applied to partitioned tables. Since the issue exists in branch 2.0 to 2.4, but not in master, I created this PR for branch-2.4. ## How was this patch tested? - A new unit test in PruneFileSourcePartitionsSuite - Unit test suites touched by SPARK-14581: JoinOptimizationSuite, FilterPushdownSuite, ColumnPruningSuite, and PruneFiltersSuite cloud-fan davies rxin Closes apache#23507 from jzhuge/SPARK-26576. Authored-by: John Zhuge <jzhuge@apache.org> Signed-off-by: gatorsmile <gatorsmile@gmail.com>
1 parent da0b69f commit b9eb0e8

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ object PhysicalOperation extends PredicateHelper {
6666
val substitutedCondition = substitute(aliases)(condition)
6767
(fields, filters ++ splitConjunctivePredicates(substitutedCondition), other, aliases)
6868

69-
case h: ResolvedHint =>
70-
collectProjectsAndFilters(h.child)
71-
7269
case other =>
7370
(None, Nil, other, Map.empty)
7471
}

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/PruneFileSourcePartitionsSuite.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@
1717

1818
package org.apache.spark.sql.hive.execution
1919

20+
import org.scalatest.Matchers._
21+
2022
import org.apache.spark.sql.QueryTest
2123
import org.apache.spark.sql.catalyst.TableIdentifier
2224
import org.apache.spark.sql.catalyst.dsl.expressions._
2325
import org.apache.spark.sql.catalyst.dsl.plans._
24-
import org.apache.spark.sql.catalyst.plans.logical.{Filter, LogicalPlan, Project}
26+
import org.apache.spark.sql.catalyst.plans.logical.{Filter, LogicalPlan, Project, ResolvedHint}
2527
import org.apache.spark.sql.catalyst.rules.RuleExecutor
2628
import org.apache.spark.sql.execution.datasources.{CatalogFileIndex, HadoopFsRelation, LogicalRelation, PruneFileSourcePartitions}
2729
import org.apache.spark.sql.execution.datasources.parquet.ParquetFileFormat
30+
import org.apache.spark.sql.execution.joins.BroadcastHashJoinExec
31+
import org.apache.spark.sql.functions.broadcast
2832
import org.apache.spark.sql.hive.test.TestHiveSingleton
33+
import org.apache.spark.sql.internal.SQLConf
2934
import org.apache.spark.sql.test.SQLTestUtils
3035
import org.apache.spark.sql.types.StructType
3136

@@ -91,4 +96,16 @@ class PruneFileSourcePartitionsSuite extends QueryTest with SQLTestUtils with Te
9196
assert(size2 < tableStats.get.sizeInBytes)
9297
}
9398
}
99+
100+
test("SPARK-26576 Broadcast hint not applied to partitioned table") {
101+
withTable("tbl") {
102+
withSQLConf(SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1") {
103+
spark.range(10).selectExpr("id", "id % 3 as p").write.partitionBy("p").saveAsTable("tbl")
104+
val df = spark.table("tbl")
105+
val qe = df.join(broadcast(df), "p").queryExecution
106+
qe.optimizedPlan.collect { case _: ResolvedHint => } should have size 1
107+
qe.sparkPlan.collect { case j: BroadcastHashJoinExec => j } should have size 1
108+
}
109+
}
110+
}
94111
}

0 commit comments

Comments
 (0)