eason-yuchen-liu commented on code in PR #54601:
URL: https://github.com/apache/spark/pull/54601#discussion_r2881604853
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/ExpandExec.scala:
##########
@@ -57,31 +57,13 @@ case class ExpandExec(
val numOutputRows = longMetric("numOutputRows")
child.execute().mapPartitionsWithIndexInternal { (index, iter) =>
- val groups = projections.map(projection).toArray
+ val groups = projections.map(projection)
groups.foreach(_.initialize(index))
- new Iterator[InternalRow] {
- private[this] var result: InternalRow = _
- private[this] var idx = -1 // -1 means the initial state
- private[this] var input: InternalRow = _
-
- override final def hasNext: Boolean = (-1 < idx && idx <
groups.length) || iter.hasNext
-
- override final def next(): InternalRow = {
- if (idx <= 0) {
- // in the initial (-1) or beginning(0) of a new input row, fetch
the next input tuple
- input = iter.next()
- idx = 0
- }
-
- result = groups(idx)(input)
- idx += 1
-
- if (idx == groups.length && iter.hasNext) {
- idx = 0
- }
-
+ val groupIterator = groups.iterator
+ iter.flatMap { input =>
+ groupIterator.map { group =>
Review Comment:
Right was think of object reuse but it will not work. Reverting the change.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]