aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/java
diff options
context:
space:
mode:
authorDavies Liu <davies@databricks.com>2016-01-05 18:46:52 -0800
committerDavies Liu <davies.liu@gmail.com>2016-01-05 18:46:52 -0800
commit70fe6ce52f26904aa53bd20409db69b52bccf315 (patch)
treec4669d8395ba2572c1aab3c3bd3197aadb8126d3 /core/src/test/java
parent0d42292f6a2dbe626e8f6a50e6c61dd79533f235 (diff)
downloadspark-70fe6ce52f26904aa53bd20409db69b52bccf315.tar.gz
spark-70fe6ce52f26904aa53bd20409db69b52bccf315.tar.bz2
spark-70fe6ce52f26904aa53bd20409db69b52bccf315.zip
[SPARK-12659] fix NPE in UnsafeExternalSorter (used by cartesian product)
Cartesian product use UnsafeExternalSorter without comparator to do spilling, it will NPE if spilling happens. This bug also hitted by #10605 cc JoshRosen Author: Davies Liu <davies@databricks.com> Closes #10606 from davies/fix_spilling.
Diffstat (limited to 'core/src/test/java')
-rw-r--r--core/src/test/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorterSuite.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/src/test/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorterSuite.java b/core/src/test/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorterSuite.java
index e0ee281e98..32f5a1a7e6 100644
--- a/core/src/test/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorterSuite.java
+++ b/core/src/test/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorterSuite.java
@@ -370,6 +370,37 @@ public class UnsafeExternalSorterSuite {
}
@Test
+ public void forcedSpillingWithoutComparator() throws Exception {
+ final UnsafeExternalSorter sorter = UnsafeExternalSorter.create(
+ taskMemoryManager,
+ blockManager,
+ taskContext,
+ null,
+ null,
+ /* initialSize */ 1024,
+ pageSizeBytes);
+ long[] record = new long[100];
+ int recordSize = record.length * 8;
+ int n = (int) pageSizeBytes / recordSize * 3;
+ int batch = n / 4;
+ for (int i = 0; i < n; i++) {
+ record[0] = (long) i;
+ sorter.insertRecord(record, Platform.LONG_ARRAY_OFFSET, recordSize, 0);
+ if (i % batch == batch - 1) {
+ sorter.spill();
+ }
+ }
+ UnsafeSorterIterator iter = sorter.getIterator();
+ for (int i = 0; i < n; i++) {
+ iter.hasNext();
+ iter.loadNext();
+ assert(Platform.getLong(iter.getBaseObject(), iter.getBaseOffset()) == i);
+ }
+ sorter.cleanupResources();
+ assertSpillFilesWereCleanedUp();
+ }
+
+ @Test
public void testPeakMemoryUsed() throws Exception {
final long recordLengthBytes = 8;
final long pageSizeBytes = 256;