Skip to content

Commit 38553b1

Browse files
committed
Reject non zero offset
Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent fa20039 commit 38553b1

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎c/src/main/java/org/apache/arrow/c/ArrayImporter.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ private void importChild(ArrayImporter parent, ArrowArray src) {
8383
}
8484

8585
private void doImport(ArrowArray.Snapshot snapshot) {
86+
checkState(
87+
snapshot.offset == 0,
88+
"ArrowArray struct has non-zero offset (%s), which is not supported",
89+
snapshot.offset);
90+
8691
// First import children (required for reconstituting parent array data)
8792
long[] children =
8893
NativeUtil.toJavaArray(snapshot.children, checkedCastToInt(snapshot.n_children));

‎c/src/main/java/org/apache/arrow/c/Data.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
/**
3636
* Functions for working with the C data interface.
3737
*
38-
* <p>This API is EXPERIMENTAL. Note that currently only 64bit systems are supported.
38+
* <p>This API is EXPERIMENTAL. Note that currently only 64bit systems are supported. Importing
39+
* {@link ArrowArray ArrowArrays} with a non-zero offset is not supported.
3940
*/
4041
public final class Data {
4142

‎c/src/test/java/org/apache/arrow/c/RoundtripTest.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,27 @@ public void testImportReleasedArray() {
10511051
}
10521052
}
10531053

1054+
@Test
1055+
public void testImportArrayWithNonZeroOffset() {
1056+
try (IntVector source = new IntVector("source", allocator);
1057+
IntVector destination = new IntVector("destination", allocator);
1058+
ArrowArray array = ArrowArray.allocateNew(allocator)) {
1059+
setVector(source, 1, 2, 3);
1060+
Data.exportVector(allocator, source, null, array);
1061+
1062+
ArrowArray.Snapshot snapshot = array.snapshot();
1063+
snapshot.offset = 1;
1064+
array.save(snapshot);
1065+
1066+
Exception e =
1067+
assertThrows(
1068+
IllegalStateException.class,
1069+
() -> Data.importIntoVector(allocator, array, destination, null));
1070+
assertEquals(
1071+
"ArrowArray struct has non-zero offset (1), which is not supported", e.getMessage());
1072+
}
1073+
}
1074+
10541075
@Test
10551076
public void testArrayStructReuse() {
10561077
// Consumer allocates empty structures

‎docs/source/cdata.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ C Data Interface
2222
Arrow supports exchanging data without copying or serialization within the same process
2323
through :external+arrow:ref:`c-data-interface`, even between different language runtimes.
2424

25+
.. note::
26+
27+
The Arrow Java C Data Interface implementation does not support importing arrays with
28+
a non-zero offset.
29+
2530
Java to Python
2631
--------------
2732

0 commit comments

Comments
 (0)