@@ -72,6 +72,24 @@ void writeCsvRoundTripsRowCount(@TempDir Path tempDir) throws Exception {
7272 assertEquals (3L , countRowsAt (out , new CsvReadOptions ()));
7373 }
7474
75+ @ Test
76+ void writeCsvDefaultsToDirectoryEvenWithExtensionInPath (@ TempDir Path tempDir ) throws Exception {
77+ // The Javadoc promises "directory unless overridden via singleFileOutput(true)". DataFusion's
78+ // own DataFrameWriteOptions defaults to Automatic mode, where an extension in the path
79+ // (".csv" here) silently flips the output to a single file. The native handler explicitly
80+ // pins the default to directory mode so this contract holds regardless of path shape.
81+ Path src = writeCsv (tempDir , "src.csv" , "id,name\n 1,alice\n 2,bob\n 3,carol\n " );
82+ Path out = tempDir .resolve ("out.csv" );
83+
84+ try (SessionContext ctx = new SessionContext ();
85+ DataFrame df = ctx .readCsv (src .toAbsolutePath ().toString ())) {
86+ df .writeCsv (out .toString ());
87+ }
88+
89+ assertTrue (Files .isDirectory (out ), "expected directory output at " + out + ", got a file" );
90+ assertEquals (3L , countRowsAt (out , new CsvReadOptions ()));
91+ }
92+
7593 @ Test
7694 void writeCsvSingleFileProducesOneFile (@ TempDir Path tempDir ) throws Exception {
7795 Path src = writeCsv (tempDir , "src.csv" , "id,name\n 1,alice\n 2,bob\n 3,carol\n " );
@@ -111,8 +129,7 @@ void writeCsvWithGzipCompressionRoundTrips(@TempDir Path tempDir) throws Excepti
111129 try (SessionContext ctx = new SessionContext ();
112130 DataFrame df = ctx .readCsv (src .toAbsolutePath ().toString ())) {
113131 df .writeCsv (
114- out .toString (),
115- new CsvWriteOptions ().fileCompressionType (FileCompressionType .GZIP ));
132+ out .toString (), new CsvWriteOptions ().fileCompressionType (FileCompressionType .GZIP ));
116133 }
117134
118135 try (Stream <Path > stream = Files .walk (out )) {
@@ -126,9 +143,7 @@ void writeCsvWithGzipCompressionRoundTrips(@TempDir Path tempDir) throws Excepti
126143 }
127144
128145 CsvReadOptions readOpts =
129- new CsvReadOptions ()
130- .fileCompressionType (FileCompressionType .GZIP )
131- .fileExtension (".csv.gz" );
146+ new CsvReadOptions ().fileCompressionType (FileCompressionType .GZIP ).fileExtension (".csv.gz" );
132147 assertEquals (4L , countRowsAt (out , readOpts ));
133148 }
134149
0 commit comments