Skip to content

Commit 5c54a24

Browse files
authored
Expose sortRegions option in Spark API (#35)
1 parent f85c560 commit 5c54a24

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

apis/spark/src/main/java/io/tiledb/libvcfnative/VCFReader.java

+9
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ public VCFReader setBedFile(String uri) {
144144
return this;
145145
}
146146

147+
public VCFReader setSortRegions(boolean sortRegions) {
148+
int rc = LibVCFNative.tiledb_vcf_reader_set_sort_regions(readerPtr, sortRegions);
149+
if (rc != 0) {
150+
String msg = getLastErrorMessage();
151+
throw new RuntimeException("Error setting sort regions parameter: " + msg);
152+
}
153+
return this;
154+
}
155+
147156
public VCFReader setRangePartition(int numPartitions, int partition) {
148157
int rc =
149158
LibVCFNative.tiledb_vcf_reader_set_region_partition(readerPtr, partition, numPartitions);

apis/spark/src/main/java/io/tiledb/vcf/VCFDataSourceOptions.java

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public Optional<String[]> getRanges() {
4949
return Optional.empty();
5050
}
5151

52+
/** @return Whether or not to sort the regions */
53+
public Optional<Boolean> getSortRegions() {
54+
if (options.containsKey("sortRegions")) {
55+
return Optional.of(Boolean.parseBoolean(options.get("sortRegions")));
56+
}
57+
return Optional.empty();
58+
}
59+
5260
/** @return Optional maximum memory budget (MB) */
5361
public Optional<Integer> getMemoryBudget() {
5462
if (options.containsKey("memory")) {

apis/spark/src/main/java/io/tiledb/vcf/VCFInputPartitionReader.java

+6
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ private void initVCFReader() {
234234
vcfReader.setBedFile(bedURI.get().toString());
235235
}
236236

237+
// Set sort regions
238+
Optional<Boolean> sortRegions = options.getSortRegions();
239+
if (sortRegions.isPresent()) {
240+
vcfReader.setSortRegions(sortRegions.get().booleanValue());
241+
}
242+
237243
// Set logical partition in array
238244
vcfReader.setRangePartition(
239245
rangePartitionInfo.getNumPartitions(), rangePartitionInfo.getIndex());

0 commit comments

Comments
 (0)