cloud-fan commented on a change in pull request #29104: URL: https://github.com/apache/spark/pull/29104#discussion_r460668756
########## File path: sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala ########## @@ -323,11 +373,19 @@ private[joins] object UnsafeHashedRelation { // Create a mapping of buildKeys -> rows val keyGenerator = UnsafeProjection.create(key) var numFields = 0 + val isOriginalInputEmpty = !input.hasNext + var allNullColumnKeyExistsInOriginalInput: Boolean = false while (input.hasNext) { Review comment: we can stop the loop when `allNullColumnKeyExistsInOriginalInput` is true. ########## File path: sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala ########## @@ -896,22 +967,29 @@ private[joins] object LongHashedRelation { // Create a mapping of key -> rows var numFields = 0 + val isOriginalInputEmpty: Boolean = !input.hasNext + var allNullColumnKeyExistsInOriginalInput: Boolean = false while (input.hasNext) { val unsafeRow = input.next().asInstanceOf[UnsafeRow] numFields = unsafeRow.numFields() val rowKey = keyGenerator(unsafeRow) if (!rowKey.isNullAt(0)) { val key = rowKey.getLong(0) map.append(key, unsafeRow) + } else if (!allNullColumnKeyExistsInOriginalInput) { + allNullColumnKeyExistsInOriginalInput = true } } map.optimize() new LongHashedRelation(numFields, map) + .setOriginalInputEmtpy(isOriginalInputEmpty) + .setAllNullColumnKeyExistsInOriginalInput(allNullColumnKeyExistsInOriginalInput) + .asInstanceOf[LongHashedRelation] } } /** The HashedRelationBroadcastMode requires that rows are broadcasted as a HashedRelation. */ -case class HashedRelationBroadcastMode(key: Seq[Expression]) +case class HashedRelationBroadcastMode(key: Seq[Expression], isNullAware: Boolean = false) Review comment: Shall we have more hash relation implementations? 1. If the original input is empty, return a `EmptyHashedRelation` 2. If there is any null key, return `EmptyHashedRelationWithNullKeys` 3. return `UnsafeHashedRelation` or `LongHashRelation`. I think it's a bit confusing to introduce the "original input" concept to hashed relation. ########## File path: sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala ########## @@ -896,22 +967,29 @@ private[joins] object LongHashedRelation { // Create a mapping of key -> rows var numFields = 0 + val isOriginalInputEmpty: Boolean = !input.hasNext + var allNullColumnKeyExistsInOriginalInput: Boolean = false while (input.hasNext) { Review comment: ditto ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org