davisusanibar commented on code in PR #13788:
URL: https://github.com/apache/arrow/pull/13788#discussion_r937130417
##########
docs/source/java/cdata.rst:
##########
@@ -33,7 +33,10 @@ Python communication using the C Data Interface.
Java to C++
-----------
-Example: Share an Int64 array from C++ to Java:
+Share an Int64 array from C++ to Java
+=====================================
Review Comment:
Updated
##########
docs/source/java/cdata.rst:
##########
@@ -220,4 +223,259 @@ Let's create a Java class to test our bridge:
C++-allocated array: [1, 2, 3, null, 5, 6, 7, 8, 9, 10]
+Share an Int32 array from Java to C++
+=====================================
+
+Example: ``Share an Int32 array from Java to C++``:
+
+**Java Side**
+
+For this example, we will export a Java jar with all dependencies needed to
+be readable by C++.
+
+.. code-block:: xml
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.example</groupId>
+ <artifactId>cpptojava</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <properties>
+ <maven.compiler.source>11</maven.compiler.source>
+ <maven.compiler.target>11</maven.compiler.target>
+ <arrow.version>8.0.0</arrow.version>
+ </properties>
+ <repositories>
+ <repository>
+ <id>arrow-nightly</id>
+ <url>https://nightlies.apache.org/arrow/java</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-c-data</artifactId>
+ <version>${arrow.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-memory-netty</artifactId>
+ <version>${arrow.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>
+ ToBeCalledByCpp
+ </mainClass>
+ </manifest>
+ </archive>
+ <descriptorRefs>
+
<descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </project>
+
+.. code-block:: java
+
+ import org.apache.arrow.c.ArrowArray;
+ import org.apache.arrow.c.ArrowSchema;
+ import org.apache.arrow.c.Data;
+ import org.apache.arrow.memory.BufferAllocator;
+ import org.apache.arrow.memory.RootAllocator;
+ import org.apache.arrow.vector.FieldVector;
+ import org.apache.arrow.vector.IntVector;
+ import org.apache.arrow.vector.VectorSchemaRoot;
+
+ import java.util.Arrays;
+
+ public class ToBeCalledByCpp {
+ final static BufferAllocator allocator = new RootAllocator();
+
+ public static void fillfieldvectorfromjavatocpp(long schema_id, long
array_id){
+ try (ArrowArray arrow_array = ArrowArray.wrap(array_id);
+ ArrowSchema arrow_schema = ArrowSchema.wrap(schema_id) ) {
+ Data.exportVector(allocator, populateFieldVectorToExport(),
null, arrow_array, arrow_schema);
+ }
+ }
+
+ public static FieldVector populateFieldVectorToExport(){
+ IntVector intVector = new IntVector("int-to-export", allocator);
+ intVector.allocateNew(3);
+ intVector.setSafe(0, 1);
+ intVector.setSafe(1, 2);
+ intVector.setSafe(2, 3);
+ intVector.setValueCount(3);
+ System.out.println("[Java - side]: FieldVector: \n" + intVector);
+ return intVector;
+ }
+
+ public static void fillvectorschemarootfromjavatocpp(long schema_id,
long array_id){
+ try (ArrowArray arrow_array = ArrowArray.wrap(array_id);
+ ArrowSchema arrow_schema = ArrowSchema.wrap(schema_id) ) {
+ Data.exportVectorSchemaRoot(allocator,
populateVectorSchemaRootToExport(), null, arrow_array, arrow_schema);
+ }
+ }
+
+ public static VectorSchemaRoot populateVectorSchemaRootToExport(){
+ IntVector intVector = new IntVector("age-to-export", allocator);
+ intVector.setSafe(0, 10);
+ intVector.setSafe(1, 20);
+ intVector.setSafe(2, 30);
+ VectorSchemaRoot root = new
VectorSchemaRoot(Arrays.asList(intVector));
+ root.setRowCount(3);
+ System.out.println("[Java - side] VectorSchemaRoot: \n" +
root.contentToTSVString());
+ return root;
+ }
+
+ public static void main(String[] args) {
Review Comment:
Deleted
##########
docs/source/java/cdata.rst:
##########
@@ -220,4 +223,259 @@ Let's create a Java class to test our bridge:
C++-allocated array: [1, 2, 3, null, 5, 6, 7, 8, 9, 10]
+Share an Int32 array from Java to C++
+=====================================
+
+Example: ``Share an Int32 array from Java to C++``:
+
+**Java Side**
+
+For this example, we will export a Java jar with all dependencies needed to
+be readable by C++.
+
+.. code-block:: xml
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.example</groupId>
+ <artifactId>cpptojava</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <properties>
+ <maven.compiler.source>11</maven.compiler.source>
+ <maven.compiler.target>11</maven.compiler.target>
+ <arrow.version>8.0.0</arrow.version>
+ </properties>
+ <repositories>
+ <repository>
+ <id>arrow-nightly</id>
+ <url>https://nightlies.apache.org/arrow/java</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-c-data</artifactId>
+ <version>${arrow.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-memory-netty</artifactId>
+ <version>${arrow.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>
+ ToBeCalledByCpp
+ </mainClass>
+ </manifest>
+ </archive>
+ <descriptorRefs>
+
<descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </project>
+
+.. code-block:: java
+
+ import org.apache.arrow.c.ArrowArray;
+ import org.apache.arrow.c.ArrowSchema;
+ import org.apache.arrow.c.Data;
+ import org.apache.arrow.memory.BufferAllocator;
+ import org.apache.arrow.memory.RootAllocator;
+ import org.apache.arrow.vector.FieldVector;
+ import org.apache.arrow.vector.IntVector;
+ import org.apache.arrow.vector.VectorSchemaRoot;
+
+ import java.util.Arrays;
+
+ public class ToBeCalledByCpp {
+ final static BufferAllocator allocator = new RootAllocator();
+
+ public static void fillfieldvectorfromjavatocpp(long schema_id, long
array_id){
+ try (ArrowArray arrow_array = ArrowArray.wrap(array_id);
+ ArrowSchema arrow_schema = ArrowSchema.wrap(schema_id) ) {
+ Data.exportVector(allocator, populateFieldVectorToExport(),
null, arrow_array, arrow_schema);
+ }
+ }
+
+ public static FieldVector populateFieldVectorToExport(){
+ IntVector intVector = new IntVector("int-to-export", allocator);
+ intVector.allocateNew(3);
+ intVector.setSafe(0, 1);
+ intVector.setSafe(1, 2);
+ intVector.setSafe(2, 3);
+ intVector.setValueCount(3);
+ System.out.println("[Java - side]: FieldVector: \n" + intVector);
+ return intVector;
+ }
+
+ public static void fillvectorschemarootfromjavatocpp(long schema_id,
long array_id){
Review Comment:
Changed
--
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]