Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/5643#discussion_r32993449
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/BroadcastLeftSemiJoinHash.scala
---
@@ -32,37 +32,60 @@ case class BroadcastLeftSemiJoinHash(
leftKeys: Seq[Expression],
rightKeys: Seq[Expression],
left: SparkPlan,
- right: SparkPlan) extends BinaryNode with HashJoin {
+ right: SparkPlan,
+ condition: Option[Expression]) extends BinaryNode with HashJoin {
override val buildSide: BuildSide = BuildRight
override def output: Seq[Attribute] = left.output
+ @transient private lazy val boundCondition =
+ newPredicate(condition.getOrElse(Literal(true)), left.output ++
right.output)
+
protected override def doExecute(): RDD[InternalRow] = {
val buildIter = buildPlan.execute().map(_.copy()).collect().toIterator
- val hashSet = new java.util.HashSet[InternalRow]()
- var currentRow: InternalRow = null
- // Create a Hash set of buildKeys
- while (buildIter.hasNext) {
- currentRow = buildIter.next()
- val rowKey = buildSideKeyGenerator(currentRow)
- if (!rowKey.anyNull) {
- val keyExists = hashSet.contains(rowKey)
- if (!keyExists) {
- // rowKey may be not serializable (from codegen)
- hashSet.add(rowKey.copy())
+ condition match {
+ case None =>
+ val hashSet = new java.util.HashSet[InternalRow]()
+ var currentRow: InternalRow = null
+
+ // Create a Hash set of buildKeys
+ while (buildIter.hasNext) {
+ currentRow = buildIter.next()
+ val rowKey = buildSideKeyGenerator(currentRow)
+ if (!rowKey.anyNull) {
+ val keyExists = hashSet.contains(rowKey)
+ if (!keyExists) {
+ // rowKey may be not serializable (from codegen)
+ hashSet.add(rowKey.copy())
+ }
+ }
}
- }
- }
- val broadcastedRelation = sparkContext.broadcast(hashSet)
+ val broadcastedRelation = sparkContext.broadcast(hashSet)
- streamedPlan.execute().mapPartitions { streamIter =>
- val joinKeys = streamSideKeyGenerator()
- streamIter.filter(current => {
- !joinKeys(current).anyNull &&
broadcastedRelation.value.contains(joinKeys.currentValue)
- })
+ streamedPlan.execute().mapPartitions { streamIter =>
+ val joinKeys = streamSideKeyGenerator()
+ streamIter.filter(current => {
+ !joinKeys(current).anyNull &&
broadcastedRelation.value.contains(joinKeys.currentValue)
+ })
+ }
+ case _ =>
--- End diff --
Using pattern matching here makes this a little hard to understand as I
don't think its very obvious that `case _ =>` implies there is a non equijoin
condition and thus we need to build a full hashtable instead of a hash set.
Perhaps name the variable `nonEquiJoinCondition` and use `isDefined` in an `if`
statement. Some more comments would also be helpful.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]