Skip to content

Commit e81a501

Browse files
committed
[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. ## How was this patch tested? - A new unit test in PruneFileSourcePartitionsSuite - Unit test suites touched by SPARK-14581: JoinOptimizationSuite, FilterPushdownSuite, ColumnPruningSuite, and PruneFiltersSuite Closes #23507 from jzhuge/SPARK-26576. Authored-by: John Zhuge <jzhuge@apache.org> Signed-off-by: gatorsmile <gatorsmile@gmail.com> (cherry picked from commit b9eb0e8)
1 parent 3bd77aa commit e81a501

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
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
@@ -68,9 +68,6 @@ object PhysicalOperation extends PredicateHelper {
6868
val substitutedCondition = substitute(aliases)(condition)
6969
(fields, filters ++ splitConjunctivePredicates(substitutedCondition), other, aliases)
7070

71-
case h: ResolvedHint =>
72-
collectProjectsAndFilters(h.child)
73-
7471
case other =>
7572
(None, Nil, other, Map.empty)
7673
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
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._
@@ -25,7 +27,10 @@ import org.apache.spark.sql.catalyst.plans.logical.{Filter, LogicalPlan, Project
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,15 @@ 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.sparkPlan.collect { case j: BroadcastHashJoinExec => j } should have size 1
107+
}
108+
}
109+
}
94110
}

0 commit comments

Comments
 (0)