Skip to content

Commit de2e82a

Browse files
authored
fix: row_range vs row_indices pushdown in JNI (#3514)
1 parent 0750fd2 commit de2e82a

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

java/vortex-jni/src/main/java/dev/vortex/api/ScanOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public interface ScanOptions {
3434
*/
3535
Optional<Expression> predicate();
3636

37+
/**
38+
* Optional start (inclusive) and end (exclusive) row indices to select a range of rows
39+
* in the scan.
40+
*/
41+
Optional<long[]> rowRange();
42+
3743
/**
3844
* Optional row indices to select specific rows.
3945
* These must be sorted in ascending order.

java/vortex-jni/src/main/java/dev/vortex/jni/JNIFile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ public ArrayIterator newScan(ScanOptions options) {
4747
}
4848

4949
long[] rowIndices = options.rowIndices().orElse(null);
50+
long[] rowRange = options.rowRange().orElse(null);
5051

5152
return new JNIArrayIterator(
52-
NativeFileMethods.scan(pointer.getAsLong(), options.columns(), predicateProto, rowIndices));
53+
NativeFileMethods.scan(pointer.getAsLong(), options.columns(), predicateProto, rowRange, rowIndices));
5354
}
5455

5556
@Override

java/vortex-jni/src/main/java/dev/vortex/jni/NativeFileMethods.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,10 @@ private NativeFileMethods() {}
4949
*/
5050
public static native void close(long pointer);
5151

52-
public static native long scan(long pointer, List<String> columns, byte[] predicateProto, long[] rowIndices);
52+
/**
53+
* Build a new native scan operator that will materialize Arrays from the file, pushing down the optional
54+
* predicate, row range or row indices to perform data skipping.
55+
*/
56+
public static native long scan(
57+
long pointer, List<String> columns, byte[] predicateProto, long[] rowRange, long[] rowIndices);
5358
}

java/vortex-spark/src/main/java/dev/vortex/spark/ArrowUtils.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@
2020
import dev.vortex.relocated.org.apache.arrow.vector.types.TimeUnit;
2121
import dev.vortex.relocated.org.apache.arrow.vector.types.pojo.ArrowType;
2222
import dev.vortex.relocated.org.apache.arrow.vector.types.pojo.Field;
23+
import java.util.stream.Collectors;
2324
import org.apache.spark.sql.types.DataType;
2425
import org.apache.spark.sql.types.DataTypes;
2526
import org.apache.spark.sql.types.Metadata;
2627
import org.apache.spark.sql.types.StructField;
2728

28-
import java.util.stream.Collectors;
29-
3029
public final class ArrowUtils {
31-
private ArrowUtils() {
32-
}
30+
private ArrowUtils() {}
3331

3432
public static DataType fromArrowField(Field field) {
3533
switch (field.getType().getTypeID()) {

vortex-jni/src/file.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ pub extern "system" fn Java_dev_vortex_jni_NativeFileMethods_scan(
121121
pointer: jlong,
122122
project_cols: JObject,
123123
predicate: JByteArray,
124+
row_range: JLongArray,
124125
row_indices: JLongArray,
125126
) -> jlong {
126127
// Return a new pointer to some native memory for the scan.
@@ -166,6 +167,15 @@ pub extern "system" fn Java_dev_vortex_jni_NativeFileMethods_scan(
166167
scan_builder = scan_builder.with_row_indices(indices_buffer);
167168
}
168169

170+
if !row_range.is_null() {
171+
let indices = unsafe { env.get_array_elements(&row_range, ReleaseMode::NoCopyBack) }?;
172+
let start_idx =
173+
u64::try_from(indices[0]).map_err(|_| vortex_err!("i64 row_index overflow"))?;
174+
let end_idx =
175+
u64::try_from(indices[1]).map_err(|_| vortex_err!("i64 row_index overflow"))?;
176+
scan_builder = scan_builder.with_row_range(start_idx..end_idx);
177+
}
178+
169179
Ok(NativeArrayIterator::new(Box::new(scan_builder.into_array_iter()?)).into_raw())
170180
})
171181
}

vortex-layout/src/scan/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ impl<A: 'static + Send + Sync> ScanBuilder<A> {
7676
self
7777
}
7878

79-
pub fn with_some_row_range(mut self, row_range: Option<Range<u64>>) -> Self {
80-
self.row_range = row_range;
81-
self
82-
}
83-
8479
pub fn with_selection(mut self, selection: Selection) -> Self {
8580
self.selection = selection;
8681
self

0 commit comments

Comments
 (0)