forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dataset Java API: Allow passing dataset read options when creating fi…
…le format (apache#30)
- Loading branch information
1 parent
816d602
commit 397ef98
Showing
12 changed files
with
331 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
java/dataset/src/main/java/org/apache/arrow/dataset/file/format/CsvFileFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.dataset.file.format; | ||
|
||
import org.apache.arrow.dataset.file.JniWrapper; | ||
import org.apache.arrow.util.Preconditions; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
public class CsvFileFormat extends FileFormatBase { | ||
public CsvFileFormat(char delimiter) { | ||
super(createCsvFileFormat(delimiter)); | ||
} | ||
|
||
// Typically for Spark config parsing | ||
public static CsvFileFormat create(Map<String, String> options) { | ||
String delimiter = getOptionValue(options, "delimiter", ","); | ||
Preconditions.checkArgument(delimiter.length() == 1, "Parameter \"delimiter\" must have length 1"); | ||
return new CsvFileFormat(delimiter.charAt(0)); | ||
} | ||
|
||
public static CsvFileFormat createDefault() { | ||
return create(Collections.emptyMap()); | ||
} | ||
|
||
private static long createCsvFileFormat(char delimiter) { | ||
return JniWrapper.get().createCsvFileFormat(delimiter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
java/dataset/src/main/java/org/apache/arrow/dataset/file/format/FileFormatBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.dataset.file.format; | ||
|
||
import org.apache.arrow.dataset.file.JniWrapper; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.StringTokenizer; | ||
|
||
public abstract class FileFormatBase implements FileFormat { | ||
|
||
private final long nativeInstanceId; | ||
private boolean closed = false; | ||
|
||
public FileFormatBase(long nativeInstanceId) { | ||
this.nativeInstanceId = nativeInstanceId; | ||
} | ||
|
||
protected static String getOptionValue(Map<String, String> options, String key, String fallbackValue) { | ||
return options.getOrDefault(key, fallbackValue); | ||
} | ||
|
||
protected static String[] parseStringArray(String commaSeparated) { | ||
final StringTokenizer tokenizer = new StringTokenizer(commaSeparated, ","); | ||
final List<String> tokens = new ArrayList<>(); | ||
while (tokenizer.hasMoreTokens()) { | ||
tokens.add(tokenizer.nextToken()); | ||
} | ||
return tokens.toArray(new String[0]); | ||
} | ||
|
||
@Override | ||
public long id() { | ||
return nativeInstanceId; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
if (closed) { | ||
return; | ||
} | ||
closed = true; | ||
JniWrapper.get().releaseFileFormatInstance(nativeInstanceId); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
java/dataset/src/main/java/org/apache/arrow/dataset/file/format/ParquetFileFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.dataset.file.format; | ||
|
||
import org.apache.arrow.dataset.file.JniWrapper; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
public class ParquetFileFormat extends FileFormatBase { | ||
private final String[] dictColumns; | ||
|
||
public ParquetFileFormat(String[] dictColumns) { | ||
super(createParquetFileFormat(dictColumns)); | ||
this.dictColumns = dictColumns; | ||
} | ||
|
||
// Typically for Spark config parsing | ||
public static ParquetFileFormat create(Map<String, String> options) { | ||
return new ParquetFileFormat(parseStringArray(getOptionValue(options, "dictColumns", "")) | ||
); | ||
} | ||
|
||
public static ParquetFileFormat createDefault() { | ||
return create(Collections.emptyMap()); | ||
} | ||
|
||
private static long createParquetFileFormat(String[] dictColumns) { | ||
return JniWrapper.get().createParquetFileFormat(dictColumns); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.