lidavidm commented on code in PR #43053:
URL: https://github.com/apache/arrow/pull/43053#discussion_r1694820997
##########
java/c/src/test/python/integration_tests.py:
##########
@@ -190,6 +190,17 @@ def round_trip_reader(self, schema, batches):
def test_string_array(self):
self.round_trip_array(lambda: pa.array([None, "a", "bb", "ccc"]))
+ def test_string_slice_array(self):
+ data = pa.array(["foo", "bar", "baz1", "baz223", "baz23445",
"baz2121", "12312baz"])
Review Comment:
Can we include some null and empty strings? (Both before and after the slice
point)
##########
java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java:
##########
@@ -951,6 +952,130 @@ public void testImportReleasedArray() {
}
}
+ private FieldVector getSlicedVector(FieldVector vector, int offset) {
+ // Consumer allocates empty structures
+ try (ArrowSchema consumerArrowSchema = ArrowSchema.allocateNew(allocator);
+ ArrowArray consumerArrowArray = ArrowArray.allocateNew(allocator)) {
+
+ // Producer creates structures from existing memory pointers
+ try (ArrowSchema arrowSchema =
ArrowSchema.wrap(consumerArrowSchema.memoryAddress());
+ ArrowArray arrowArray =
ArrowArray.wrap(consumerArrowArray.memoryAddress())) {
+ // Producer exports vector into the C Data Interface structures
+ Data.exportVector(allocator, vector, null, arrowArray, arrowSchema);
+ }
+ // consumerArrowArray.snapshot().offset = offset;
+
+ // Consumer imports vector
+ FieldVector imported =
+ Data.importVector(childAllocator, consumerArrowArray,
consumerArrowSchema, null);
+ if (!(imported instanceof NullVector)) {
+ assertEquals(childAllocator, imported.getAllocator());
+ }
+
+ // Check that transfers work
+ TransferPair pair = imported.getTransferPair(allocator);
+ pair.transfer();
+ return (FieldVector) pair.getTo();
+ }
+ }
+
+ @Test
+ public void testSliceVarCharVector2() {
+ try (final VarCharVector vector = new VarCharVector("v", allocator);
+ VarCharVector target = new VarCharVector("v", allocator)) {
+ setVector(vector, "foo", "bar", "baz1", "baz223", "baz23445", "baz2121",
"12312baz");
+ // slice information
+ final int startIndex = 2;
+ final int length = 3;
+ // create a sliced vector manually to mimic C++ slice behavior
+ VarCharVector slicedVector = (VarCharVector) getSlicedVector(vector,
startIndex);
+ vector.splitAndTransferTo(startIndex, length, target);
Review Comment:
I don't think this is actually a slice?
##########
java/c/src/test/python/integration_tests.py:
##########
@@ -190,6 +190,17 @@ def round_trip_reader(self, schema, batches):
def test_string_array(self):
self.round_trip_array(lambda: pa.array([None, "a", "bb", "ccc"]))
+ def test_string_slice_array(self):
+ data = pa.array(["foo", "bar", "baz1", "baz223", "baz23445",
"baz2121", "12312baz"])
Review Comment:
I'd also like to see a case where the sliced array is empty.
##########
java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java:
##########
@@ -951,6 +952,130 @@ public void testImportReleasedArray() {
}
}
+ private FieldVector getSlicedVector(FieldVector vector, int offset) {
+ // Consumer allocates empty structures
+ try (ArrowSchema consumerArrowSchema = ArrowSchema.allocateNew(allocator);
+ ArrowArray consumerArrowArray = ArrowArray.allocateNew(allocator)) {
+
+ // Producer creates structures from existing memory pointers
+ try (ArrowSchema arrowSchema =
ArrowSchema.wrap(consumerArrowSchema.memoryAddress());
+ ArrowArray arrowArray =
ArrowArray.wrap(consumerArrowArray.memoryAddress())) {
+ // Producer exports vector into the C Data Interface structures
+ Data.exportVector(allocator, vector, null, arrowArray, arrowSchema);
+ }
+ // consumerArrowArray.snapshot().offset = offset;
Review Comment:
this is commented out?
##########
java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java:
##########
@@ -951,6 +952,86 @@ public void testImportReleasedArray() {
}
}
+ @Test
Review Comment:
I'm still not sure about the tests here, I think the way we should do it is
by manually tweaking the Snapshot instance
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]