Github user viirya commented on a diff in the pull request: https://github.com/apache/spark/pull/19862#discussion_r154568281 --- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/execution/UnsafeExternalRowSorter.java --- @@ -159,6 +154,12 @@ public boolean hasNext() { @Override public UnsafeRow next() { try { + if (!alreadyCalculated) { + while (inputIterator.hasNext()) { + insertRow(inputIterator.next()); + } + alreadyCalculated = true; + } sortedIterator.loadNext(); --- End diff -- `sortedIterator` is already assigned at L143. When you insert rows when first time to call `next`, can the `sortedIterator` correctly return sorted elements?
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org