Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5643#discussion_r29020571
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/BroadcastLeftSemiJoinHash.scala
 ---
    @@ -32,36 +32,72 @@ 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 =
    +    InterpretedPredicate.create(
    +      condition
    +        .map(c => BindReferences.bindReference(c, left.output ++ 
right.output))
    +        .getOrElse(Literal(true)))
    +
       override def execute(): RDD[Row] = {
         val buildIter= buildPlan.execute().map(_.copy()).collect().toIterator
    -    val hashSet = new java.util.HashSet[Row]()
    +    val hashMap = new java.util.HashMap[Row, 
scala.collection.mutable.Set[Row]]()
         var currentRow: Row = 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) {
    -          hashSet.add(rowKey)
    +    condition match {
    +      case None =>
    +        while (buildIter.hasNext) {
    +          currentRow = buildIter.next()
    +          val rowKey = buildSideKeyGenerator(currentRow)
    +          if (!rowKey.anyNull) {
    +            if (!hashMap.containsKey(rowKey)) {
    +              hashMap.put(rowKey, null)
    +            }
    +          }
    +        }
    +      case Some(_) =>
    +        while (buildIter.hasNext) {
    +          currentRow = buildIter.next()
    +          val rowKey = buildSideKeyGenerator(currentRow)
    +          if (!rowKey.anyNull) {
    +            if (!hashMap.containsKey(rowKey)) {
    +              val rowSet = scala.collection.mutable.HashSet[Row]()
    +              rowSet.add(currentRow.copy())
    +              hashMap.put(rowKey, rowSet)
    +            } else {
    +              hashMap.get(rowKey).add(currentRow.copy())
    +            }
    +          }
             }
    -      }
         }
     
    -    val broadcastedRelation = sparkContext.broadcast(hashSet)
    +    val broadcastedRelation = sparkContext.broadcast(hashMap)
     
         streamedPlan.execute().mapPartitions { streamIter =>
           val joinKeys = streamSideKeyGenerator()
    -      streamIter.filter(current => {
    -        !joinKeys(current).anyNull && 
broadcastedRelation.value.contains(joinKeys.currentValue)
    -      })
    +      val joinedRow = new JoinedRow
    +      condition match {
    +        case None =>
    +          streamIter.filter(current => {
    +            !joinKeys(current).anyNull &&
    --- End diff --
    
    Ok, my bad.


---
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]

Reply via email to