diff --git a/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java b/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java index 56810b0452477..dc7069b0934c5 100644 --- a/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java +++ b/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java @@ -91,7 +91,8 @@ void export(ArrowArray array, FieldVector vector, DictionaryProvider dictionaryP if (buffers != null) { data.buffers = new ArrayList<>(buffers.size()); - data.buffers_ptrs = allocator.buffer((long) (vector.getExportedCDataBuffers()) * Long.BYTES); + data.buffers_ptrs = + allocator.buffer((long) (vector.getExportedCDataBuffers()) * Long.BYTES); vector.exportCDataBuffers(data.buffers, data.buffers_ptrs, NULL); } diff --git a/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java b/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java index abdbb6e568184..2603a5b85dc89 100644 --- a/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java +++ b/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java @@ -23,7 +23,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.AutoCloseables; @@ -235,10 +234,11 @@ private List visitVariableWidthView(ArrowType type) { final long variadicSizeBufferCapacity = numOfVariadicBuffers * Long.BYTES; List buffers = new ArrayList<>(); - try (ArrowBuf variadicSizeBuffer = importBuffer(type, variadicSizeBufferIndex, - variadicSizeBufferCapacity)) { + try (ArrowBuf variadicSizeBuffer = + importBuffer(type, variadicSizeBufferIndex, variadicSizeBufferCapacity)) { ArrowBuf maybeValidityBuffer = maybeImportBitmap(type); - try (ArrowBuf view = importFixedBytes(type, viewBufferIndex, BaseVariableWidthViewVector.ELEMENT_SIZE)) { + try (ArrowBuf view = + importFixedBytes(type, viewBufferIndex, BaseVariableWidthViewVector.ELEMENT_SIZE)) { view.getReferenceManager().retain(); buffers.add(maybeValidityBuffer); buffers.add(view); @@ -402,6 +402,7 @@ public List visit(ArrowType.Duration type) { @Override public List visit(ArrowType.ListView type) { - throw new UnsupportedOperationException("Importing buffers for view type: " + type + " not supported"); + throw new UnsupportedOperationException( + "Importing buffers for view type: " + type + " not supported"); } } diff --git a/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java b/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java index 079ff5c09caf4..6591d1f730990 100644 --- a/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java @@ -538,27 +538,41 @@ private String generateString(String str, int repetition) { public void testViewVector() { // ViewVarCharVector with short strings try (final ViewVarCharVector vector = new ViewVarCharVector("v1", allocator)) { - setVector(vector, "abc".getBytes(StandardCharsets.UTF_8), "def".getBytes(StandardCharsets.UTF_8), null); + setVector( + vector, + "abc".getBytes(StandardCharsets.UTF_8), + "def".getBytes(StandardCharsets.UTF_8), + null); assertTrue(roundtrip(vector, ViewVarCharVector.class)); } // ViewVarCharVector with long strings try (final ViewVarCharVector vector = new ViewVarCharVector("v2", allocator)) { - setVector(vector, "01234567890123".getBytes(StandardCharsets.UTF_8), - "01234567890123567".getBytes(StandardCharsets.UTF_8), null); + setVector( + vector, + "01234567890123".getBytes(StandardCharsets.UTF_8), + "01234567890123567".getBytes(StandardCharsets.UTF_8), + null); assertTrue(roundtrip(vector, ViewVarCharVector.class)); } // ViewVarBinaryVector with short values try (final ViewVarBinaryVector vector = new ViewVarBinaryVector("v3", allocator)) { - setVector(vector, "abc".getBytes(StandardCharsets.UTF_8), "def".getBytes(StandardCharsets.UTF_8), null); + setVector( + vector, + "abc".getBytes(StandardCharsets.UTF_8), + "def".getBytes(StandardCharsets.UTF_8), + null); assertTrue(roundtrip(vector, ViewVarBinaryVector.class)); } // ViewVarBinaryVector with long values try (final ViewVarBinaryVector vector = new ViewVarBinaryVector("v4", allocator)) { - setVector(vector, "01234567890123".getBytes(StandardCharsets.UTF_8), - "01234567890123567".getBytes(StandardCharsets.UTF_8), null); + setVector( + vector, + "01234567890123".getBytes(StandardCharsets.UTF_8), + "01234567890123567".getBytes(StandardCharsets.UTF_8), + null); assertTrue(roundtrip(vector, ViewVarBinaryVector.class)); } diff --git a/java/c/src/test/java/org/apache/arrow/c/StreamTest.java b/java/c/src/test/java/org/apache/arrow/c/StreamTest.java index d4aba49393287..95363fcc3287f 100644 --- a/java/c/src/test/java/org/apache/arrow/c/StreamTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/StreamTest.java @@ -138,8 +138,11 @@ public void roundtripStrings() throws Exception { @Test public void roundtripStringViews() throws Exception { - final Schema schema = new Schema(Arrays.asList(Field.nullable("ints", new ArrowType.Int(32, true)), - Field.nullable("string_views", new ArrowType.Utf8View()))); + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("ints", new ArrowType.Int(32, true)), + Field.nullable("string_views", new ArrowType.Utf8View()))); final List batches = new ArrayList<>(); try (final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final IntVector ints = (IntVector) root.getVector(0); @@ -175,8 +178,11 @@ public void roundtripStringViews() throws Exception { @Test public void roundtripBinaryViews() throws Exception { - final Schema schema = new Schema(Arrays.asList(Field.nullable("ints", new ArrowType.Int(32, true)), - Field.nullable("binary_views", new ArrowType.BinaryView()))); + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("ints", new ArrowType.Int(32, true)), + Field.nullable("binary_views", new ArrowType.BinaryView()))); final List batches = new ArrayList<>(); try (final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final IntVector ints = (IntVector) root.getVector(0); @@ -189,10 +195,13 @@ public void roundtripBinaryViews() throws Exception { ints.setSafe(2, 4); ints.setSafe(3, 8); strs.setSafe(0, new byte[0]); - strs.setSafe(1, new byte[]{97}); + strs.setSafe(1, new byte[] {97}); strs.setSafe(2, new byte[] {98, 99, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 98, 99}); - strs.setSafe(3, new byte[] {100, 101, 102, 103, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, - 100, 101, 102, 103}); + strs.setSafe( + 3, + new byte[] { + 100, 101, 102, 103, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 100, 101, 102, 103 + }); root.setRowCount(4); batches.add(unloader.getRecordBatch()); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java index bae0e01a7467a..2afdcf8b73568 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java @@ -530,8 +530,9 @@ public List getFieldBuffers() { /** Set the reader and writer indexes for the inner buffers. */ /** - * Retrieves the export buffer count for the C Data Interface. - * The exported buffers are the validity and value buffers. + * Retrieves the export buffer count for the C Data Interface. The exported buffers are the + * validity and value buffers. + * * @return the number of buffers to be exported */ @Override @@ -539,9 +540,7 @@ public int getExportedCDataBuffers() { return 2; } - /** - * Set the reader and writer indexes for the inner buffers. - */ + /** Set the reader and writer indexes for the inner buffers. */ private void setReaderAndWriterIndex() { validityBuffer.readerIndex(0); valueBuffer.readerIndex(0); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java index bc778368a5c89..270bc14f8b058 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java @@ -340,10 +340,11 @@ public List getFieldBuffers() { } /** - * Retrieves the export buffer count for the C Data Interface. - * The exported buffers are the validity buffer, offset, and value buffers. + * Retrieves the export buffer count for the C Data Interface. The exported buffers are the + * validity buffer, offset, and value buffers. + * * @return the number of buffers to be exported - */ + */ @Override public int getExportedCDataBuffers() { return 3; diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java index 4079ecab47349..6af6ce6ed0470 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java @@ -356,8 +356,9 @@ public List getFieldBuffers() { } /** - * Retrieves the export buffer count for the C Data Interface. - * The exported buffers are the validity, offset and value buffers. + * Retrieves the export buffer count for the C Data Interface. The exported buffers are the + * validity, offset and value buffers. + * * @return the number of buffers to be exported */ @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java index b75aef175d985..e2d6b3c214fac 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java @@ -1670,24 +1670,17 @@ public OUT accept(VectorVisitor visitor, IN value) { } /** - * Retrieves the export buffer count for the C Data Interface. - * For Variadic types, an additional buffer is kept to store - * the size of each variadic buffer since that information - * cannot be retrieved in the C Data import. - * When there are dataBuffers, the count is set to 3 + dataBuffers.size(). - * Three is formed by validity, view, and variadic size buffer. - * If it is not the case, i.e., the dataBuffer is not present; - * four buffers are required. - * They are view buffer, validity buffer, - * empty data buffer, and variadic size buffer. - * Note that the Java library only allocates data buffers - * when long strings are present. - * In the C Data Interface, - * the binary view import expects at least three buffers. - * The variadic size buffer is merely allocated to determine the - * number of elements per each variadic buffer, and it is not part - * of the imported data. - * Thus, an empty data buffer is allocated to meet this requirement. + * Retrieves the export buffer count for the C Data Interface. For Variadic types, an additional + * buffer is kept to store the size of each variadic buffer since that information cannot be + * retrieved in the C Data import. When there are dataBuffers, the count is set to 3 + + * dataBuffers.size(). Three is formed by validity, view, and variadic size buffer. If it is not + * the case, i.e., the dataBuffer is not present; four buffers are required. They are view buffer, + * validity buffer, empty data buffer, and variadic size buffer. Note that the Java library only + * allocates data buffers when long strings are present. In the C Data Interface, the binary view + * import expects at least three buffers. The variadic size buffer is merely allocated to + * determine the number of elements per each variadic buffer, and it is not part of the imported + * data. Thus, an empty data buffer is allocated to meet this requirement. + * * @return the number of buffers to be exported */ @Override @@ -1700,13 +1693,13 @@ public int getExportedCDataBuffers() { } /** - * Get the data buffer of the vector. - * Note that an additional buffer is appended to store - * the size of each variadic buffer's size. + * Get the data buffer of the vector. Note that an additional buffer is appended to store the size + * of each variadic buffer's size. + * * @param buffers list of buffers to be exported * @param buffersPtr buffer to store the pointers to the exported buffers * @param nullValue null value - */ + */ @Override public void exportCDataBuffers(List buffers, ArrowBuf buffersPtr, long nullValue) { exportBuffer(validityBuffer, buffers, buffersPtr, nullValue, true); @@ -1745,7 +1738,8 @@ public void exportCDataBuffers(List buffers, ArrowBuf buffersPtr, long for (int i = 0; i < valueCount; i++) { int length = getValueLength(i); if (length > 12) { - final int bufIndex = viewBuffer.getInt(((long) i * ELEMENT_SIZE) + LENGTH_WIDTH + PREFIX_WIDTH); + final int bufIndex = + viewBuffer.getInt(((long) i * ELEMENT_SIZE) + LENGTH_WIDTH + PREFIX_WIDTH); long variadicSizeBufIndex = (long) bufIndex * Long.BYTES; long currentBufLength = variadicSizeBuffer.getLong(variadicSizeBufIndex); variadicSizeBuffer.setLong(variadicSizeBufIndex, currentBufLength + length); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/ExtensionTypeVector.java b/java/vector/src/main/java/org/apache/arrow/vector/ExtensionTypeVector.java index 44edaaff60c95..14dcd0f6aa3e9 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/ExtensionTypeVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/ExtensionTypeVector.java @@ -232,6 +232,7 @@ public List getFieldBuffers() { /** * Retrieves the export buffer count for the C Data Interface. + * * @return the number of buffers to be exported */ @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/FieldVector.java b/java/vector/src/main/java/org/apache/arrow/vector/FieldVector.java index 51d32343dea57..d6c237a0da3b5 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/FieldVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/FieldVector.java @@ -58,8 +58,9 @@ public interface FieldVector extends ValueVector { /** * Retrieves the export buffer count for the C Data Interface. + * * @return the number of variadic buffers - */ + */ int getExportedCDataBuffers(); /** diff --git a/java/vector/src/main/java/org/apache/arrow/vector/NullVector.java b/java/vector/src/main/java/org/apache/arrow/vector/NullVector.java index 69cd7b601b461..4a493edf3e7a5 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/NullVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/NullVector.java @@ -222,8 +222,8 @@ public List getFieldBuffers() { } /** - * Retrieves the export buffer count for the C Data Interface. - * No buffers are exported. + * Retrieves the export buffer count for the C Data Interface. No buffers are exported. + * * @return the number of buffers to be exported */ @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java index b1ff80274ef31..d2fdaa538bd04 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java @@ -187,8 +187,9 @@ public List getFieldBuffers() { } /** - * Retrieves the export buffer count for the C Data Interface. - * The exported buffer is the validity buffer. + * Retrieves the export buffer count for the C Data Interface. The exported buffer is the validity + * buffer. + * * @return the number of buffers to be exported */ public int getExportedCDataBuffers() { diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java index b32dec4f30f5d..0e17e5d20aca9 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java @@ -282,8 +282,9 @@ public List getFieldBuffers() { } /** - * Retrieves the export buffer count for the C Data Interface. - * The exported buffers are the validity and offset buffers. + * Retrieves the export buffer count for the C Data Interface. The exported buffers are the + * validity and offset buffers. + * * @return the number of buffers to be exported */ @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java index 96f7224595923..d42700093ee18 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java @@ -239,8 +239,9 @@ public List getFieldBuffers() { } /** - * Retrieves the export buffer count for the C Data Interface. - * The exported buffers are the validity and offset buffers. + * Retrieves the export buffer count for the C Data Interface. The exported buffers are the + * validity and offset buffers. + * * @return the number of buffers to be exported */ @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListViewVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListViewVector.java index 7d15f7e0694fa..3108a71d9ac7c 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListViewVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListViewVector.java @@ -237,8 +237,9 @@ public List getFieldBuffers() { } /** - * Retrieves the export buffer count for the C Data Interface. - * The exported buffers are the validity, offset and size buffers. + * Retrieves the export buffer count for the C Data Interface. The exported buffers are the + * validity, offset and size buffers. + * * @return the number of buffers to be exported */ @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java index 627272343781d..cd8b372747056 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/StructVector.java @@ -179,8 +179,9 @@ public List getFieldBuffers() { } /** - * Retrieves the export buffer count for the C Data Interface. - * The exported buffer is the validity buffer. + * Retrieves the export buffer count for the C Data Interface. The exported buffer is the validity + * buffer. + * * @return the number of buffers to be exported */ @Override