File tree Expand file tree Collapse file tree
main/java/org/apache/datafusion
test/java/org/apache/datafusion Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -98,9 +98,9 @@ public SessionContextBuilder tempDirectory(String path) {
9898 }
9999
100100 /**
101- * Disable on-disk spill entirely. Queries that need spill fail with a {@link RuntimeException}
102- * carrying DataFusion's "resources exhausted" message rather than going to disk; useful for
103- * memory-only execution profiles or environments without writable disk.
101+ * Disable on-disk spill entirely. Queries that need spill fail with a {@link
102+ * ResourcesExhaustedException} rather than going to disk; useful for memory-only execution
103+ * profiles or environments without writable disk.
104104 *
105105 * <p>Mutually exclusive with {@link #tempDirectory(String)} — the combination throws at {@link
106106 * #build()} time. {@link #maxTempDirectorySize(long)} is allowed alongside this setter but is a
@@ -114,8 +114,8 @@ public SessionContextBuilder disableSpill() {
114114 /**
115115 * Cap the cumulative bytes used by spill files under {@link #tempDirectory(String)}. Mirrors
116116 * upstream {@code RuntimeEnvBuilder::with_max_temp_directory_size} 1:1. Once exceeded, queries
117- * that need more spill space fail with a {@link RuntimeException} carrying DataFusion's
118- * "resources exhausted" message. Combinable with {@link #disableSpill()} but a no-op there.
117+ * that need more spill space fail with a {@link ResourcesExhaustedException}. Combinable with
118+ * {@link #disableSpill()} but a no-op there.
119119 *
120120 * <p>{@code 0} is accepted — upstream documents zero as legal and equivalent to "no spill
121121 * allowed". Negative values are rejected.
Original file line number Diff line number Diff line change @@ -437,4 +437,29 @@ void tempDirectoryStaysOnLegacyField() throws Exception {
437437 assertEquals ("/tmp/df" , parsed .getTempDirectory ());
438438 assertFalse (parsed .hasDiskManager ());
439439 }
440+
441+ @ Test
442+ void disableSpillUnderMemoryPressureThrowsResourcesExhausted () throws java .io .IOException {
443+ // Pin the Javadoc claim on disableSpill() / maxTempDirectorySize that
444+ // out-of-memory queries surface as ResourcesExhaustedException -- not
445+ // the parent DataFusionException, not a generic RuntimeException. A 1 MiB
446+ // pool plus a 200k-row sort plus no spill forces the OOM path
447+ // deterministically.
448+ try (BufferAllocator allocator = new RootAllocator ();
449+ SessionContext ctx =
450+ SessionContext .builder ().memoryLimit (1L << 20 , 1.0 ).disableSpill ().build ()) {
451+ DataFusionException e =
452+ assertThrows (
453+ DataFusionException .class ,
454+ () -> {
455+ try (DataFrame df =
456+ ctx .sql ("SELECT i FROM generate_series(1, 200000) AS t(i) ORDER BY i DESC" )) {
457+ df .collect (allocator ).close ();
458+ }
459+ });
460+ assertTrue (
461+ e instanceof ResourcesExhaustedException ,
462+ "expected ResourcesExhaustedException, got " + e .getClass ().getName ());
463+ }
464+ }
440465}
You can’t perform that action at this time.
0 commit comments