Github user Sephiroth-Lin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5643#discussion_r31304130
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/joins/BroadcastLeftSemiJoinHash.scala
 ---
    @@ -32,36 +32,59 @@ 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[Row] = {
         val buildIter= buildPlan.execute().map(_.copy()).collect().toIterator
    -    val hashSet = new java.util.HashSet[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 =>
    +        val hashSet = new java.util.HashSet[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)
    +            }
    +          }
             }
    -      }
    -    }
     
    -    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 _ =>
    +        val hashRelation = HashedRelation(buildIter, buildSideKeyGenerator)
    +        val broadcastedRelation = sparkContext.broadcast(hashRelation)
    +
    +        streamedPlan.execute().mapPartitions { streamIter =>
    +          val joinKeys = streamSideKeyGenerator()
    +          val joinedRow = new JoinedRow
    +
    +          streamIter.filter(current => {
    +            val rowBuffer = 
broadcastedRelation.value.get(joinKeys.currentValue)
    --- End diff --
    
    we need to apply first before we get currentValue, or will get null for the 
first row.


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