Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7948#discussion_r36272417
  
    --- Diff: 
sql/core/src/main/java/org/apache/spark/sql/execution/UnsafeKVExternalSorter.java
 ---
    @@ -82,8 +82,15 @@ public UnsafeKVExternalSorter(StructType keySchema, 
StructType valueSchema,
             pageSizeBytes);
         } else {
           // Insert the records into the in-memory sorter.
    +      // We will use the number of elements in the map as the initialSize 
of the
    +      // UnsafeInMemorySorter. Because UnsafeInMemorySorter does not 
accept 0 as the initialSize,
    +      // we will use 1 as its initial size if the map is empty.
    +      int initialSoeterSize = map.numElements();
    +      if (initialSoeterSize == 0) {
    +        initialSoeterSize = 1;
    +      }
           final UnsafeInMemorySorter inMemSorter = new UnsafeInMemorySorter(
    -        taskMemoryManager, recordComparator, prefixComparator, 
map.numElements());
    +        taskMemoryManager, recordComparator, prefixComparator, 
initialSoeterSize);
    --- End diff --
    
    Could also do `Math.max(1, map.numElements)` if you want a one-liner.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to