Skip to content

Commit aefdd9f

Browse files
committed
feat(write): add ParquetWriteOptions
1 parent f61b10f commit aefdd9f

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.datafusion;
21+
22+
/**
23+
* Configuration knobs for writing parquet, passed to {@link DataFrame#writeParquet(String,
24+
* ParquetWriteOptions)}.
25+
*
26+
* <p>Mirrors a subset of DataFusion's {@code DataFrameWriteOptions} and {@code
27+
* TableParquetOptions}. All setters return {@code this} for fluent chaining. Defaults: all fields
28+
* {@code null} (meaning the DataFusion default is used).
29+
*
30+
* <p>Path semantics: when {@link #singleFileOutput(boolean)} is {@code true}, the path passed to
31+
* {@code writeParquet} is the literal output filename. When left unset (the default), the path is a
32+
* directory that DataFusion populates with one or more part-files.
33+
*/
34+
public final class ParquetWriteOptions {
35+
36+
private String compression;
37+
private Boolean singleFileOutput;
38+
39+
/**
40+
* Compression codec spec, passed verbatim to DataFusion. Examples: {@code "snappy"}, {@code
41+
* "zstd(3)"}, {@code "gzip(6)"}, {@code "lz4"}, {@code "uncompressed"}. Invalid values surface as
42+
* {@link RuntimeException} at write time.
43+
*/
44+
public ParquetWriteOptions compression(String spec) {
45+
this.compression = spec;
46+
return this;
47+
}
48+
49+
/**
50+
* When {@code true}, write to a single file at the supplied path. When left unset (the default),
51+
* the path is treated as a directory and DataFusion writes one or more part-files.
52+
*/
53+
public ParquetWriteOptions singleFileOutput(boolean v) {
54+
this.singleFileOutput = v;
55+
return this;
56+
}
57+
58+
String compression() {
59+
return compression;
60+
}
61+
62+
Boolean singleFileOutput() {
63+
return singleFileOutput;
64+
}
65+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.datafusion;
21+
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertNull;
24+
25+
import org.junit.jupiter.api.Test;
26+
27+
class ParquetWriteOptionsTest {
28+
29+
@Test
30+
void defaultsAreAllNull() {
31+
ParquetWriteOptions opts = new ParquetWriteOptions();
32+
assertNull(opts.compression());
33+
assertNull(opts.singleFileOutput());
34+
}
35+
36+
@Test
37+
void fluentSettersChainAndMutate() {
38+
ParquetWriteOptions opts =
39+
new ParquetWriteOptions().compression("zstd(3)").singleFileOutput(true);
40+
41+
assertEquals("zstd(3)", opts.compression());
42+
assertEquals(Boolean.TRUE, opts.singleFileOutput());
43+
}
44+
}

0 commit comments

Comments
 (0)