Skip to content

Commit db7447d

Browse files
committed
feat(parquet): add ParquetReadOptions fluent options class
1 parent 0c2abea commit db7447d

2 files changed

Lines changed: 85 additions & 4 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 org.apache.arrow.vector.types.pojo.Schema;
23+
24+
/**
25+
* Configuration knobs for parquet sources passed to {@link SessionContext#registerParquet(String,
26+
* String, ParquetReadOptions)} and {@link SessionContext#readParquet(String, ParquetReadOptions)}.
27+
*
28+
* <p>Mirrors a subset of DataFusion's {@code ParquetReadOptions}. All setters return {@code this}
29+
* for fluent chaining. Defaults: {@code fileExtension = ".parquet"}; all other fields {@code null}
30+
* (meaning the SessionConfig default is used, or the schema is inferred from the file).
31+
*/
32+
public final class ParquetReadOptions {
33+
34+
private String fileExtension = ".parquet";
35+
private Boolean parquetPruning;
36+
private Boolean skipMetadata;
37+
private Long metadataSizeHint;
38+
private Schema schema;
39+
40+
public ParquetReadOptions fileExtension(String ext) {
41+
this.fileExtension = ext;
42+
return this;
43+
}
44+
45+
public ParquetReadOptions parquetPruning(boolean v) {
46+
this.parquetPruning = v;
47+
return this;
48+
}
49+
50+
public ParquetReadOptions skipMetadata(boolean v) {
51+
this.skipMetadata = v;
52+
return this;
53+
}
54+
55+
public ParquetReadOptions metadataSizeHint(long bytes) {
56+
this.metadataSizeHint = bytes;
57+
return this;
58+
}
59+
60+
public ParquetReadOptions schema(Schema schema) {
61+
this.schema = schema;
62+
return this;
63+
}
64+
65+
String fileExtension() {
66+
return fileExtension;
67+
}
68+
69+
Boolean parquetPruning() {
70+
return parquetPruning;
71+
}
72+
73+
Boolean skipMetadata() {
74+
return skipMetadata;
75+
}
76+
77+
Long metadataSizeHint() {
78+
return metadataSizeHint;
79+
}
80+
81+
Schema schema() {
82+
return schema;
83+
}
84+
}

‎src/test/java/org/apache/datafusion/ParquetReadOptionsTest.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ void defaultsMatchDataFusion() {
4747
@Test
4848
void fluentSettersChainAndMutate() {
4949
Schema schema =
50-
new Schema(
51-
List.of(
52-
new Field(
53-
"x", FieldType.nullable(new ArrowType.Int(32, true)), null)));
50+
new Schema(List.of(new Field("x", FieldType.nullable(new ArrowType.Int(32, true)), null)));
5451

5552
ParquetReadOptions opts =
5653
new ParquetReadOptions()

0 commit comments

Comments
 (0)