You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/05 03:26:20 UTC

[GitHub] [arrow] davisusanibar opened a new pull request, #12794: ARROW-15578: [Java][Doc] Document C Data and how to interface with other languages

davisusanibar opened a new pull request, #12794:
URL: https://github.com/apache/arrow/pull/12794

   Document C Data and how to interface with other languages
   - Java - Python
   - Java - C++


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] WIP - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
davisusanibar commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r844444199


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {
+        // Mark released
+        schema->release = NULL;
+    }
+
+    void export_int32_type(struct ArrowSchema* schema) {
+        *schema = (struct ArrowSchema) {
+                // Type description
+                .format = "l",
+                .name = "",
+                .metadata = NULL,
+                .flags = 0,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_type
+        };
+        std::cout << "C Data - Schema Pointer = " << schema << std::endl;
+    }
+
+    static void release_int32_array(struct ArrowArray* array) {
+        assert(array->n_buffers == 2);
+        // Free the buffers and the buffers array
+        free((void *) array->buffers[1]);
+        free(array->buffers);
+        // Mark released
+        array->release = NULL;
+    }
+
+    void export_int32_array(struct ArrowArray* array) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+
+        auto maybe_array = builder.Finish();
+        std::shared_ptr<arrow::Array> array_arrow = *maybe_array;
+        auto int64_array = std::static_pointer_cast<arrow::Int64Array>(array_arrow);
+        const int64_t* data = int64_array->raw_values();
+        std::cout << "Data To Exchange Pointer = " << data << std::endl;
+        for (int j = 0; j < int64_array->length(); j++){
+            std::cout << "Data To Exchange Value[" << j << "] = " << data[j] << std::endl;
+        }
+
+        *array = (struct ArrowArray) {
+                // Data description
+                .length = int64_array->length(),
+                .offset = 0,
+                .null_count = 0,
+                .n_buffers = 2,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_array
+        };
+
+        // Allocate list of buffers
+        array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
+        assert(array->buffers != NULL);
+        array->buffers[0] = NULL;  // no nulls, null bitmap can be omitted
+        array->buffers[1] = data;
+
+        std::cout << "C Data - Array Pointer = " << array << std::endl;
+        std::cout << "C Data - Array Data Pointer Buffer array->buffers[1] = " << array->buffers[1] << std::endl;
+    }
+
+**Java Side**
+
+Define Java code CDataInterfaceLibraryConfig.java that consume by JNI C++ functions exported through
+C Data Interface:
+
+.. 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>cpp-java-cdata</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-c-data</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-memory-netty</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+        </dependencies>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataInterfaceLibrary",
+            value = @Platform(
+                    include = {"CDataInterfaceLibrary.h"},
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataInterfaceLibraryConfig implements InfoMapper {
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibrary.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataInterfaceLibrary.dylib
+    macosx-x86_64/libjniCDataInterfaceLibrary.dylib:
+            libjniCDataInterfaceLibrary.dylib (compatibility version 0.0.0, current version 0.0.0)
+            @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+            /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+            /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterfaceV5 {
+
+        public static void main(String[] args) {
+            CDataInterfaceLibrary.ArrowSchema arrowSchema = new CDataInterfaceLibrary.ArrowSchema();
+            CDataInterfaceLibrary.export_int32_type(arrowSchema);
+
+            ArrowSchema arrow_schema = ArrowSchema.wrap(arrowSchema.address());

Review Comment:
   Changed on this way, thank you



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] lidavidm commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
lidavidm commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845205278


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,212 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    $ git clone https://github.com/apache/arrow.git
+    $ cd arrow/cpp
+    $ mkdir build   # from inside the `cpp` subdirectory
+    $ cd build
+    $ cmake .. --preset ninja-debug-minimal
+    $ cmake --build .
+    $ tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.cpp that export function **fillCArray** for third party
+consumers like Java:

Review Comment:
   ```suggestion
   Implement a function in CDataCppBridge.cpp that exports an array via the C Data Interface:
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] WIP - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
davisusanibar commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r844442638


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:

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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] WIP - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
davisusanibar commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r844443028


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {
+        // Mark released
+        schema->release = NULL;
+    }
+
+    void export_int32_type(struct ArrowSchema* schema) {
+        *schema = (struct ArrowSchema) {
+                // Type description
+                .format = "l",
+                .name = "",
+                .metadata = NULL,
+                .flags = 0,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_type
+        };
+        std::cout << "C Data - Schema Pointer = " << schema << std::endl;
+    }
+
+    static void release_int32_array(struct ArrowArray* array) {
+        assert(array->n_buffers == 2);
+        // Free the buffers and the buffers array
+        free((void *) array->buffers[1]);
+        free(array->buffers);
+        // Mark released
+        array->release = NULL;
+    }
+
+    void export_int32_array(struct ArrowArray* array) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+
+        auto maybe_array = builder.Finish();
+        std::shared_ptr<arrow::Array> array_arrow = *maybe_array;
+        auto int64_array = std::static_pointer_cast<arrow::Int64Array>(array_arrow);
+        const int64_t* data = int64_array->raw_values();
+        std::cout << "Data To Exchange Pointer = " << data << std::endl;
+        for (int j = 0; j < int64_array->length(); j++){
+            std::cout << "Data To Exchange Value[" << j << "] = " << data[j] << std::endl;
+        }
+
+        *array = (struct ArrowArray) {
+                // Data description
+                .length = int64_array->length(),
+                .offset = 0,
+                .null_count = 0,
+                .n_buffers = 2,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_array
+        };
+
+        // Allocate list of buffers
+        array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
+        assert(array->buffers != NULL);
+        array->buffers[0] = NULL;  // no nulls, null bitmap can be omitted
+        array->buffers[1] = data;
+
+        std::cout << "C Data - Array Pointer = " << array << std::endl;
+        std::cout << "C Data - Array Data Pointer Buffer array->buffers[1] = " << array->buffers[1] << std::endl;
+    }
+
+**Java Side**
+
+Define Java code CDataInterfaceLibraryConfig.java that consume by JNI C++ functions exported through
+C Data Interface:
+
+.. 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>cpp-java-cdata</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-c-data</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-memory-netty</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+        </dependencies>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataInterfaceLibrary",

Review Comment:
   Changed



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {

Review Comment:
   Deleted



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {
+        // Mark released
+        schema->release = NULL;
+    }
+
+    void export_int32_type(struct ArrowSchema* schema) {
+        *schema = (struct ArrowSchema) {
+                // Type description
+                .format = "l",
+                .name = "",
+                .metadata = NULL,
+                .flags = 0,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_type
+        };
+        std::cout << "C Data - Schema Pointer = " << schema << std::endl;
+    }
+
+    static void release_int32_array(struct ArrowArray* array) {
+        assert(array->n_buffers == 2);
+        // Free the buffers and the buffers array
+        free((void *) array->buffers[1]);
+        free(array->buffers);
+        // Mark released
+        array->release = NULL;
+    }
+
+    void export_int32_array(struct ArrowArray* array) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+
+        auto maybe_array = builder.Finish();
+        std::shared_ptr<arrow::Array> array_arrow = *maybe_array;
+        auto int64_array = std::static_pointer_cast<arrow::Int64Array>(array_arrow);
+        const int64_t* data = int64_array->raw_values();
+        std::cout << "Data To Exchange Pointer = " << data << std::endl;
+        for (int j = 0; j < int64_array->length(); j++){
+            std::cout << "Data To Exchange Value[" << j << "] = " << data[j] << std::endl;
+        }
+
+        *array = (struct ArrowArray) {
+                // Data description
+                .length = int64_array->length(),
+                .offset = 0,
+                .null_count = 0,
+                .n_buffers = 2,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_array
+        };
+
+        // Allocate list of buffers
+        array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
+        assert(array->buffers != NULL);
+        array->buffers[0] = NULL;  // no nulls, null bitmap can be omitted
+        array->buffers[1] = data;
+
+        std::cout << "C Data - Array Pointer = " << array << std::endl;
+        std::cout << "C Data - Array Data Pointer Buffer array->buffers[1] = " << array->buffers[1] << std::endl;
+    }
+
+**Java Side**
+
+Define Java code CDataInterfaceLibraryConfig.java that consume by JNI C++ functions exported through
+C Data Interface:
+
+.. 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>cpp-java-cdata</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-c-data</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-memory-netty</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+        </dependencies>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataInterfaceLibrary",
+            value = @Platform(
+                    include = {"CDataInterfaceLibrary.h"},
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataInterfaceLibraryConfig implements InfoMapper {
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibrary.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataInterfaceLibrary.dylib
+    macosx-x86_64/libjniCDataInterfaceLibrary.dylib:
+            libjniCDataInterfaceLibrary.dylib (compatibility version 0.0.0, current version 0.0.0)
+            @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+            /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+            /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterfaceV5 {
+
+        public static void main(String[] args) {
+            CDataInterfaceLibrary.ArrowSchema arrowSchema = new CDataInterfaceLibrary.ArrowSchema();

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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
davisusanibar commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845369437


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,212 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    $ git clone https://github.com/apache/arrow.git
+    $ cd arrow/cpp
+    $ mkdir build   # from inside the `cpp` subdirectory
+    $ cd build
+    $ cmake .. --preset ninja-debug-minimal
+    $ cmake --build .
+    $ tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.cpp that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void FillInt64Array(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>java-cdata-example</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.cpp"

Review Comment:
   Sorry, my mistake. Base on this [reference](https://github.com/bytedeco/javacpp#accessing-native-apis) we declare the file *.h as a header and define function FillInt64Array to export.
   
   



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,212 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    $ git clone https://github.com/apache/arrow.git
+    $ cd arrow/cpp
+    $ mkdir build   # from inside the `cpp` subdirectory
+    $ cd build
+    $ cmake .. --preset ninja-debug-minimal
+    $ cmake --build .
+    $ tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.cpp that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void FillInt64Array(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,

Review Comment:
   Added



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;

Review Comment:
   Added



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] WIP - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
davisusanibar commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r844443988


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {
+        // Mark released
+        schema->release = NULL;
+    }
+
+    void export_int32_type(struct ArrowSchema* schema) {
+        *schema = (struct ArrowSchema) {
+                // Type description
+                .format = "l",
+                .name = "",
+                .metadata = NULL,
+                .flags = 0,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_type
+        };
+        std::cout << "C Data - Schema Pointer = " << schema << std::endl;
+    }
+
+    static void release_int32_array(struct ArrowArray* array) {
+        assert(array->n_buffers == 2);
+        // Free the buffers and the buffers array
+        free((void *) array->buffers[1]);
+        free(array->buffers);
+        // Mark released
+        array->release = NULL;
+    }
+
+    void export_int32_array(struct ArrowArray* array) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+
+        auto maybe_array = builder.Finish();
+        std::shared_ptr<arrow::Array> array_arrow = *maybe_array;
+        auto int64_array = std::static_pointer_cast<arrow::Int64Array>(array_arrow);
+        const int64_t* data = int64_array->raw_values();
+        std::cout << "Data To Exchange Pointer = " << data << std::endl;
+        for (int j = 0; j < int64_array->length(); j++){
+            std::cout << "Data To Exchange Value[" << j << "] = " << data[j] << std::endl;
+        }
+
+        *array = (struct ArrowArray) {
+                // Data description
+                .length = int64_array->length(),
+                .offset = 0,
+                .null_count = 0,
+                .n_buffers = 2,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_array
+        };
+
+        // Allocate list of buffers
+        array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
+        assert(array->buffers != NULL);
+        array->buffers[0] = NULL;  // no nulls, null bitmap can be omitted
+        array->buffers[1] = data;
+
+        std::cout << "C Data - Array Pointer = " << array << std::endl;
+        std::cout << "C Data - Array Data Pointer Buffer array->buffers[1] = " << array->buffers[1] << std::endl;
+    }
+
+**Java Side**
+
+Define Java code CDataInterfaceLibraryConfig.java that consume by JNI C++ functions exported through
+C Data Interface:
+
+.. 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>cpp-java-cdata</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-c-data</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-memory-netty</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+        </dependencies>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataInterfaceLibrary",
+            value = @Platform(
+                    include = {"CDataInterfaceLibrary.h"},
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataInterfaceLibraryConfig implements InfoMapper {
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibrary.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataInterfaceLibrary.dylib
+    macosx-x86_64/libjniCDataInterfaceLibrary.dylib:
+            libjniCDataInterfaceLibrary.dylib (compatibility version 0.0.0, current version 0.0.0)
+            @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+            /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+            /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterfaceV5 {
+
+        public static void main(String[] args) {
+            CDataInterfaceLibrary.ArrowSchema arrowSchema = new CDataInterfaceLibrary.ArrowSchema();
+            CDataInterfaceLibrary.export_int32_type(arrowSchema);
+
+            ArrowSchema arrow_schema = ArrowSchema.wrap(arrowSchema.address());
+            System.out.println("Java C Data - Schema Pointer = = " + Long.toHexString(arrowSchema.address()));
+
+            CDataInterfaceLibrary.ArrowArray arrowArray = new CDataInterfaceLibrary.ArrowArray();
+            CDataInterfaceLibrary.export_int32_array(arrowArray);
+
+            ArrowArray arrow_array = ArrowArray.wrap(arrowArray.address());
+            System.out.println("Java C Data - Array Pointer = " + Long.toHexString(arrowArray.address()));
+            System.out.println("Java C Data - Array Data Pointer Buffer array->buffers[1] = " + Long.toHexString(arrowArray.buffers(1).address()));
+
+            BufferAllocator allocator = new RootAllocator();
+            BigIntVector bigIntVector = (BigIntVector) Data.importVector(allocator, arrow_array, arrow_schema, null);
+            System.out.println("Java C Data - BigIntVector: " + bigIntVector);
+
+            CDataInterfaceLibrary.release_int32_type(arrowSchema);
+            CDataInterfaceLibrary.release_int32_array(arrowArray);

Review Comment:
   ArrowArray and ArrowSchema release these after Data.importVector finalize



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] github-actions[bot] commented on pull request #12794: ARROW-15578: [Java][Doc] WIP - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #12794:
URL: https://github.com/apache/arrow/pull/12794#issuecomment-1088228871

   https://issues.apache.org/jira/browse/ARROW-15578


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] ursabot commented on pull request #12794: ARROW-15578: [Java][Doc] Document C Data Interface and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #12794:
URL: https://github.com/apache/arrow/pull/12794#issuecomment-1093404875

   Benchmark runs are scheduled for baseline = b7f7bad55a172b416c99640003a2e0eb9414c6c9 and contender = f0b5c49a0d60b5240b584ea27773a210aa7cead2. f0b5c49a0d60b5240b584ea27773a210aa7cead2 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/6182414d953f443584928f6ba50341a2...af754f90443849adb39662dc890f3752/)
   [Finished :arrow_down:0.21% :arrow_up:0.0%] [test-mac-arm](https://conbench.ursa.dev/compare/runs/4cc9ca65c3964de2a290b3b601f55d06...607f028c2bf748a98e6bf822ac86eb84/)
   [Failed :arrow_down:0.71% :arrow_up:0.0%] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/a7ede7e4e7724d68bf352352a4db7bdc...2805c3772ff64fe48bcd3ea35a8bd022/)
   [Finished :arrow_down:0.09% :arrow_up:0.09%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/d16404951fa54850a3870e55ab9cddec...b6ddc2217def48bdad6e0d85194a3ecf/)
   Buildkite builds:
   [Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ec2-t3-xlarge-us-east-2/builds/472| `f0b5c49a` ec2-t3-xlarge-us-east-2>
   [Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-test-mac-arm/builds/457| `f0b5c49a` test-mac-arm>
   [Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-i9-9960x/builds/458| `f0b5c49a` ursa-i9-9960x>
   [Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-thinkcentre-m75q/builds/467| `f0b5c49a` ursa-thinkcentre-m75q>
   [Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ec2-t3-xlarge-us-east-2/builds/471| `b7f7bad5` ec2-t3-xlarge-us-east-2>
   [Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-test-mac-arm/builds/456| `b7f7bad5` test-mac-arm>
   [Failed] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-i9-9960x/builds/457| `b7f7bad5` ursa-i9-9960x>
   [Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-thinkcentre-m75q/builds/466| `b7f7bad5` ursa-thinkcentre-m75q>
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
davisusanibar commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845195963


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;

Review Comment:
   C Data download that for transitive dependencies



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] lidavidm closed pull request #12794: ARROW-15578: [Java][Doc] Document C Data Interface and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
lidavidm closed pull request #12794: ARROW-15578: [Java][Doc] Document C Data Interface and how to interface with other languages
URL: https://github.com/apache/arrow/pull/12794


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] WIP - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
davisusanibar commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r844442472


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.

Review Comment:
   Deleted



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:

Review Comment:
   Added



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] lidavidm commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
lidavidm commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845201056


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterface {
+        public static void main(String[] args) {
+            try(
+                BufferAllocator allocator = new RootAllocator();
+                ArrowSchema arrowSchema = ArrowSchema.allocateNew(allocator);
+                ArrowArray arrowArray = ArrowArray.allocateNew(allocator)
+            ){
+                CDataJavaToCppExample.fillCArray(
+                        arrowSchema.memoryAddress(), arrowArray.memoryAddress());
+                try(
+                    BigIntVector bigIntVector = (BigIntVector) Data.importVector(
+                            allocator, arrowArray, arrowSchema, null)
+                ){
+                    System.out.println("Java using C Data Interface to read Array Filled by C++: "
+                            + bigIntVector);
+                }

Review Comment:
   That doesn't actually call release. So we do need to call release here.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] lidavidm commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
lidavidm commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845205647


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,212 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    $ git clone https://github.com/apache/arrow.git
+    $ cd arrow/cpp
+    $ mkdir build   # from inside the `cpp` subdirectory
+    $ cd build
+    $ cmake .. --preset ninja-debug-minimal
+    $ cmake --build .
+    $ tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.cpp that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void FillInt64Array(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,

Review Comment:
   ```suggestion
   For this example, we will use `JavaCPP`_ to call our C++ function from Java,
   ```



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,212 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    $ git clone https://github.com/apache/arrow.git
+    $ cd arrow/cpp
+    $ mkdir build   # from inside the `cpp` subdirectory
+    $ cd build
+    $ cmake .. --preset ninja-debug-minimal
+    $ cmake --build .
+    $ tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.cpp that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void FillInt64Array(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,

Review Comment:
   ```suggestion
   For this example, we will use `JavaCPP`_ to call our C++ function from Java,
   ```



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,212 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    $ git clone https://github.com/apache/arrow.git
+    $ cd arrow/cpp
+    $ mkdir build   # from inside the `cpp` subdirectory
+    $ cd build
+    $ cmake .. --preset ninja-debug-minimal
+    $ cmake --build .
+    $ tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.cpp that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void FillInt64Array(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>java-cdata-example</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.cpp"

Review Comment:
   Hmm. We should have separate header/C++ files then, we shouldn't include a source file.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] lidavidm commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
lidavidm commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845209743


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,212 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    $ git clone https://github.com/apache/arrow.git
+    $ cd arrow/cpp
+    $ mkdir build   # from inside the `cpp` subdirectory
+    $ cd build
+    $ cmake .. --preset ninja-debug-minimal
+    $ cmake --build .
+    $ tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.cpp that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void FillInt64Array(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>java-cdata-example</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.cpp"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    # Compile our Java code
+    $ javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    # Generate CDataInterfaceLibrary
+    $ java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    # Generate libjniCDataInterfaceLibrary.dylib
+    $ java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    # Validate libjniCDataInterfaceLibrary.dylib created
+    $ otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to test our bridge:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterface {
+        public static void main(String[] args) {
+            try(
+                BufferAllocator allocator = new RootAllocator();
+                ArrowSchema arrowSchema = ArrowSchema.allocateNew(allocator);
+                ArrowArray arrowArray = ArrowArray.allocateNew(allocator)
+            ){
+                CDataJavaToCppExample.FillInt64Array(
+                        arrowSchema.memoryAddress(), arrowArray.memoryAddress());
+                try(
+                    BigIntVector bigIntVector = (BigIntVector) Data.importVector(
+                            allocator, arrowArray, arrowSchema, null)
+                ){
+                    System.out.println("C++-allocated array: "
+                            + bigIntVector);

Review Comment:
   ```suggestion
                       System.out.println("C++-allocated array: " + bigIntVector);
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] lidavidm commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
lidavidm commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845065578


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib

Review Comment:
   ```suggestion
       $ git clone https://github.com/apache/arrow.git
       $ cd arrow/cpp
       $ mkdir build   # from inside the `cpp` subdirectory
       $ cd build
       $ cmake .. --preset ninja-debug-minimal
       $ cmake --build .
       $ tree debug/
       debug/
       ├── libarrow.800.0.0.dylib
       ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
       └── libarrow.dylib -> libarrow.800.dylib
   ```



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterface {
+        public static void main(String[] args) {
+            try(
+                BufferAllocator allocator = new RootAllocator();
+                ArrowSchema arrowSchema = ArrowSchema.allocateNew(allocator);
+                ArrowArray arrowArray = ArrowArray.allocateNew(allocator)
+            ){
+                CDataJavaToCppExample.fillCArray(
+                        arrowSchema.memoryAddress(), arrowArray.memoryAddress());
+                try(
+                    BigIntVector bigIntVector = (BigIntVector) Data.importVector(
+                            allocator, arrowArray, arrowSchema, null)
+                ){
+                    System.out.println("Java using C Data Interface to read Array Filled by C++: "
+                            + bigIntVector);
+                }

Review Comment:
   We should call `release` on the array and schema right?



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>

Review Comment:
   Is it possible to use a released version of arrow? That way we can even skip the compilation instructions above



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterface {
+        public static void main(String[] args) {
+            try(
+                BufferAllocator allocator = new RootAllocator();
+                ArrowSchema arrowSchema = ArrowSchema.allocateNew(allocator);
+                ArrowArray arrowArray = ArrowArray.allocateNew(allocator)
+            ){
+                CDataJavaToCppExample.fillCArray(
+                        arrowSchema.memoryAddress(), arrowArray.memoryAddress());
+                try(
+                    BigIntVector bigIntVector = (BigIntVector) Data.importVector(
+                            allocator, arrowArray, arrowSchema, null)
+                ){
+                    System.out.println("Java using C Data Interface to read Array Filled by C++: "

Review Comment:
   ```suggestion
                       System.out.println("C++-allocated array: "
   ```



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterface {
+        public static void main(String[] args) {
+            try(
+                BufferAllocator allocator = new RootAllocator();
+                ArrowSchema arrowSchema = ArrowSchema.allocateNew(allocator);
+                ArrowArray arrowArray = ArrowArray.allocateNew(allocator)
+            ){
+                CDataJavaToCppExample.fillCArray(
+                        arrowSchema.memoryAddress(), arrowArray.memoryAddress());
+                try(
+                    BigIntVector bigIntVector = (BigIntVector) Data.importVector(
+                            allocator, arrowArray, arrowSchema, null)
+                ){
+                    System.out.println("Java using C Data Interface to read Array Filled by C++: "
+                            + bigIntVector);
+                }

Review Comment:
   Or hmm. Does closing the vector also close the array for you?



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)

Review Comment:
   ```suggestion
   .. code-block:: shell
   
       # Compile our Java code
       $ javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
   
       # Generate CDataInterfaceLibrary
       $ java -jar javacpp-1.5.7.jar CDataJavaConfig.java
   
       # Generate libjniCDataInterfaceLibrary.dylib
       $ java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
   
       # Validate libjniCDataInterfaceLibrary.dylib created
       $ otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
       macosx-x86_64/libjniCDataJavaToCppExample.dylib:
           libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
           @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
           /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
           /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
   ```



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>

Review Comment:
   nit: why the "v2"?



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;

Review Comment:
   We need to depend on `arrow-vector` in our pom right?



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;

Review Comment:
   ```suggestion
           std::shared_ptr<arrow::Array> array = *builder.Finish();
   ```



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:

Review Comment:
   ```suggestion
   Let's create a Java class to test our bridge:
   ```



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party

Review Comment:
   Ah - because it's in a header, it gets compiled into the javacpp generated sources?



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){

Review Comment:
   ```suggestion
       void FillInt64Array(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr) {
   ```
   



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
davisusanibar commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845198421


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterface {
+        public static void main(String[] args) {
+            try(
+                BufferAllocator allocator = new RootAllocator();
+                ArrowSchema arrowSchema = ArrowSchema.allocateNew(allocator);
+                ArrowArray arrowArray = ArrowArray.allocateNew(allocator)
+            ){
+                CDataJavaToCppExample.fillCArray(
+                        arrowSchema.memoryAddress(), arrowArray.memoryAddress());
+                try(
+                    BigIntVector bigIntVector = (BigIntVector) Data.importVector(
+                            allocator, arrowArray, arrowSchema, null)
+                ){
+                    System.out.println("Java using C Data Interface to read Array Filled by C++: "
+                            + bigIntVector);
+                }

Review Comment:
   It is doing at the end of [ImportVector](https://github.com/apache/arrow/blob/e379ee1f5a3c4de2defbe631f2cbf5567e574f1d/java/c/src/main/java/org/apache/arrow/c/ArrayImporter.java#L63) by c data library



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
davisusanibar commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845193872


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party

Review Comment:
   Changed to *.cpp for more readable, and yes it is used by javacpp generated sources



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>

Review Comment:
   Changed



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>

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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] lidavidm commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
lidavidm commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845200185


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,213 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data without copying or serialization within the same process
+through the :ref:`c-data-interface`, even between different language runtimes.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+Example: Share an Int64 array from C++ to Java:
+
+**C++ Side**
+
+Use this guide to :doc:`compile arrow <../developers/cpp/building.rst>` library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define C++ code CDataCppBridge.h that export function **fillCArray** for third party
+consumers like Java:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+    #include <arrow/c/bridge.h>
+
+    using arrow::Int64Builder;
+
+    void fillCArray(const uintptr_t c_schema_ptr, const uintptr_t c_array_ptr){
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+        builder.Append(9);
+        builder.Append(10);
+        std::shared_ptr<arrow::Array> array = *builder.Finish();;
+
+        struct ArrowSchema* c_schema = reinterpret_cast<struct ArrowSchema*>(c_schema_ptr);
+        auto c_schema_status = arrow::ExportType(*array->type(), c_schema);
+        if (!c_schema_status.ok()) c_schema_status.Abort();
+
+        struct ArrowArray* c_array = reinterpret_cast<struct ArrowArray*>(c_array_ptr);
+        auto c_array_status = arrow::ExportArray(*array, c_array);
+        if (!c_array_status.ok()) c_array_status.Abort();
+    }
+
+**Java Side**
+
+For this example, we will use `JavaCPP`_ to call our main C++ **fillCArray** function from Java,
+without writing JNI bindings ourselves.
+
+.. 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>cdatav2</artifactId>
+        <version>1.0-SNAPSHOT</version>
+
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+            <arrow.version>8.0.0.dev254</arrow.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <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>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataJavaToCppExample",
+            value = @Platform(
+                    include = {
+                            "CDataCppBridge.h"
+                    },
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataJavaConfig implements InfoMapper {
+
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataJavaConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataJavaToCppExample.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataJavaToCppExample.dylib
+    macosx-x86_64/libjniCDataJavaToCppExample.dylib:
+        libjniCDataJavaToCppExample.dylib (compatibility version 0.0.0, current version 0.0.0)
+        @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;

Review Comment:
   It is better to be explicit about dependencies (some projects will even check that you depend on any API you use, even if it's in transitive dependencies)



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] davisusanibar commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
davisusanibar commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r845199308


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {
+        // Mark released
+        schema->release = NULL;
+    }
+
+    void export_int32_type(struct ArrowSchema* schema) {
+        *schema = (struct ArrowSchema) {
+                // Type description
+                .format = "l",
+                .name = "",
+                .metadata = NULL,
+                .flags = 0,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_type
+        };
+        std::cout << "C Data - Schema Pointer = " << schema << std::endl;
+    }
+
+    static void release_int32_array(struct ArrowArray* array) {
+        assert(array->n_buffers == 2);
+        // Free the buffers and the buffers array
+        free((void *) array->buffers[1]);
+        free(array->buffers);
+        // Mark released
+        array->release = NULL;
+    }
+
+    void export_int32_array(struct ArrowArray* array) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+
+        auto maybe_array = builder.Finish();
+        std::shared_ptr<arrow::Array> array_arrow = *maybe_array;
+        auto int64_array = std::static_pointer_cast<arrow::Int64Array>(array_arrow);
+        const int64_t* data = int64_array->raw_values();
+        std::cout << "Data To Exchange Pointer = " << data << std::endl;
+        for (int j = 0; j < int64_array->length(); j++){
+            std::cout << "Data To Exchange Value[" << j << "] = " << data[j] << std::endl;
+        }
+
+        *array = (struct ArrowArray) {
+                // Data description
+                .length = int64_array->length(),
+                .offset = 0,
+                .null_count = 0,
+                .n_buffers = 2,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_array
+        };
+
+        // Allocate list of buffers
+        array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
+        assert(array->buffers != NULL);
+        array->buffers[0] = NULL;  // no nulls, null bitmap can be omitted
+        array->buffers[1] = data;
+
+        std::cout << "C Data - Array Pointer = " << array << std::endl;
+        std::cout << "C Data - Array Data Pointer Buffer array->buffers[1] = " << array->buffers[1] << std::endl;
+    }
+
+**Java Side**
+
+Define Java code CDataInterfaceLibraryConfig.java that consume by JNI C++ functions exported through
+C Data Interface:

Review Comment:
   Added



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] lidavidm commented on a diff in pull request #12794: ARROW-15578: [Java][Doc] WIP - Document C Data and how to interface with other languages

Posted by GitBox <gi...@apache.org>.
lidavidm commented on code in PR #12794:
URL: https://github.com/apache/arrow/pull/12794#discussion_r842708704


##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.

Review Comment:
   ```suggestion
   Arrow supports exchanging data without copying or serialization within the same process through the :ref:`c-data-interface`, even between different language runtimes.
   ```



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:

Review Comment:
   Link to the C++ build docs as well



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {
+        // Mark released
+        schema->release = NULL;
+    }
+
+    void export_int32_type(struct ArrowSchema* schema) {
+        *schema = (struct ArrowSchema) {
+                // Type description
+                .format = "l",
+                .name = "",
+                .metadata = NULL,
+                .flags = 0,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_type
+        };
+        std::cout << "C Data - Schema Pointer = " << schema << std::endl;
+    }
+
+    static void release_int32_array(struct ArrowArray* array) {
+        assert(array->n_buffers == 2);
+        // Free the buffers and the buffers array
+        free((void *) array->buffers[1]);
+        free(array->buffers);
+        // Mark released
+        array->release = NULL;
+    }
+
+    void export_int32_array(struct ArrowArray* array) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+
+        auto maybe_array = builder.Finish();
+        std::shared_ptr<arrow::Array> array_arrow = *maybe_array;
+        auto int64_array = std::static_pointer_cast<arrow::Int64Array>(array_arrow);
+        const int64_t* data = int64_array->raw_values();
+        std::cout << "Data To Exchange Pointer = " << data << std::endl;
+        for (int j = 0; j < int64_array->length(); j++){
+            std::cout << "Data To Exchange Value[" << j << "] = " << data[j] << std::endl;
+        }
+
+        *array = (struct ArrowArray) {
+                // Data description
+                .length = int64_array->length(),
+                .offset = 0,
+                .null_count = 0,
+                .n_buffers = 2,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_array
+        };
+
+        // Allocate list of buffers
+        array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
+        assert(array->buffers != NULL);
+        array->buffers[0] = NULL;  // no nulls, null bitmap can be omitted
+        array->buffers[1] = data;
+
+        std::cout << "C Data - Array Pointer = " << array << std::endl;
+        std::cout << "C Data - Array Data Pointer Buffer array->buffers[1] = " << array->buffers[1] << std::endl;
+    }
+
+**Java Side**
+
+Define Java code CDataInterfaceLibraryConfig.java that consume by JNI C++ functions exported through
+C Data Interface:

Review Comment:
   "For this example, we will use javacpp (link to project) to call our main C++ function from Java, without writing JNI bindings ourselves."



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {
+        // Mark released
+        schema->release = NULL;
+    }
+
+    void export_int32_type(struct ArrowSchema* schema) {
+        *schema = (struct ArrowSchema) {
+                // Type description
+                .format = "l",
+                .name = "",
+                .metadata = NULL,
+                .flags = 0,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_type
+        };
+        std::cout << "C Data - Schema Pointer = " << schema << std::endl;
+    }
+
+    static void release_int32_array(struct ArrowArray* array) {
+        assert(array->n_buffers == 2);
+        // Free the buffers and the buffers array
+        free((void *) array->buffers[1]);
+        free(array->buffers);
+        // Mark released
+        array->release = NULL;
+    }
+
+    void export_int32_array(struct ArrowArray* array) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+
+        auto maybe_array = builder.Finish();
+        std::shared_ptr<arrow::Array> array_arrow = *maybe_array;
+        auto int64_array = std::static_pointer_cast<arrow::Int64Array>(array_arrow);
+        const int64_t* data = int64_array->raw_values();
+        std::cout << "Data To Exchange Pointer = " << data << std::endl;
+        for (int j = 0; j < int64_array->length(); j++){
+            std::cout << "Data To Exchange Value[" << j << "] = " << data[j] << std::endl;
+        }
+
+        *array = (struct ArrowArray) {
+                // Data description
+                .length = int64_array->length(),
+                .offset = 0,
+                .null_count = 0,
+                .n_buffers = 2,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_array
+        };
+
+        // Allocate list of buffers
+        array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
+        assert(array->buffers != NULL);
+        array->buffers[0] = NULL;  // no nulls, null bitmap can be omitted
+        array->buffers[1] = data;
+
+        std::cout << "C Data - Array Pointer = " << array << std::endl;
+        std::cout << "C Data - Array Data Pointer Buffer array->buffers[1] = " << array->buffers[1] << std::endl;
+    }
+
+**Java Side**
+
+Define Java code CDataInterfaceLibraryConfig.java that consume by JNI C++ functions exported through
+C Data Interface:
+
+.. 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>cpp-java-cdata</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-c-data</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-memory-netty</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+        </dependencies>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataInterfaceLibrary",
+            value = @Platform(
+                    include = {"CDataInterfaceLibrary.h"},
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataInterfaceLibraryConfig implements InfoMapper {
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibrary.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataInterfaceLibrary.dylib
+    macosx-x86_64/libjniCDataInterfaceLibrary.dylib:
+            libjniCDataInterfaceLibrary.dylib (compatibility version 0.0.0, current version 0.0.0)
+            @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+            /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+            /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterfaceV5 {
+
+        public static void main(String[] args) {
+            CDataInterfaceLibrary.ArrowSchema arrowSchema = new CDataInterfaceLibrary.ArrowSchema();
+            CDataInterfaceLibrary.export_int32_type(arrowSchema);
+
+            ArrowSchema arrow_schema = ArrowSchema.wrap(arrowSchema.address());
+            System.out.println("Java C Data - Schema Pointer = = " + Long.toHexString(arrowSchema.address()));
+
+            CDataInterfaceLibrary.ArrowArray arrowArray = new CDataInterfaceLibrary.ArrowArray();
+            CDataInterfaceLibrary.export_int32_array(arrowArray);
+
+            ArrowArray arrow_array = ArrowArray.wrap(arrowArray.address());
+            System.out.println("Java C Data - Array Pointer = " + Long.toHexString(arrowArray.address()));
+            System.out.println("Java C Data - Array Data Pointer Buffer array->buffers[1] = " + Long.toHexString(arrowArray.buffers(1).address()));
+
+            BufferAllocator allocator = new RootAllocator();
+            BigIntVector bigIntVector = (BigIntVector) Data.importVector(allocator, arrow_array, arrow_schema, null);
+            System.out.println("Java C Data - BigIntVector: " + bigIntVector);
+
+            CDataInterfaceLibrary.release_int32_type(arrowSchema);
+            CDataInterfaceLibrary.release_int32_array(arrowArray);

Review Comment:
   Why aren't we using the release callback of the C Data Interface objects?



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {
+        // Mark released
+        schema->release = NULL;
+    }
+
+    void export_int32_type(struct ArrowSchema* schema) {
+        *schema = (struct ArrowSchema) {
+                // Type description
+                .format = "l",
+                .name = "",
+                .metadata = NULL,
+                .flags = 0,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_type
+        };
+        std::cout << "C Data - Schema Pointer = " << schema << std::endl;
+    }
+
+    static void release_int32_array(struct ArrowArray* array) {
+        assert(array->n_buffers == 2);
+        // Free the buffers and the buffers array
+        free((void *) array->buffers[1]);
+        free(array->buffers);
+        // Mark released
+        array->release = NULL;
+    }
+
+    void export_int32_array(struct ArrowArray* array) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+
+        auto maybe_array = builder.Finish();
+        std::shared_ptr<arrow::Array> array_arrow = *maybe_array;
+        auto int64_array = std::static_pointer_cast<arrow::Int64Array>(array_arrow);
+        const int64_t* data = int64_array->raw_values();
+        std::cout << "Data To Exchange Pointer = " << data << std::endl;
+        for (int j = 0; j < int64_array->length(); j++){
+            std::cout << "Data To Exchange Value[" << j << "] = " << data[j] << std::endl;
+        }
+
+        *array = (struct ArrowArray) {
+                // Data description
+                .length = int64_array->length(),
+                .offset = 0,
+                .null_count = 0,
+                .n_buffers = 2,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_array
+        };
+
+        // Allocate list of buffers
+        array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
+        assert(array->buffers != NULL);
+        array->buffers[0] = NULL;  // no nulls, null bitmap can be omitted
+        array->buffers[1] = data;
+
+        std::cout << "C Data - Array Pointer = " << array << std::endl;
+        std::cout << "C Data - Array Data Pointer Buffer array->buffers[1] = " << array->buffers[1] << std::endl;
+    }
+
+**Java Side**
+
+Define Java code CDataInterfaceLibraryConfig.java that consume by JNI C++ functions exported through
+C Data Interface:
+
+.. 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>cpp-java-cdata</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-c-data</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-memory-netty</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+        </dependencies>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataInterfaceLibrary",
+            value = @Platform(
+                    include = {"CDataInterfaceLibrary.h"},
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataInterfaceLibraryConfig implements InfoMapper {
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibrary.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataInterfaceLibrary.dylib
+    macosx-x86_64/libjniCDataInterfaceLibrary.dylib:
+            libjniCDataInterfaceLibrary.dylib (compatibility version 0.0.0, current version 0.0.0)
+            @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+            /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+            /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterfaceV5 {
+
+        public static void main(String[] args) {
+            CDataInterfaceLibrary.ArrowSchema arrowSchema = new CDataInterfaceLibrary.ArrowSchema();
+            CDataInterfaceLibrary.export_int32_type(arrowSchema);
+
+            ArrowSchema arrow_schema = ArrowSchema.wrap(arrowSchema.address());

Review Comment:
   I think in general, this example isn't structured correctly. The specification states that the consumer is expected to allocate the array. So what we should do is:
   
   1. Use ArrowSchema.allocateNew to create the structure
   2. Pass the address via javacpp to the JNI function, which populates the structure
   
   We shouldn't be defining our own ArrowSchema class here, and we shouldn't be expecting the C++ code to allocate the ArrowSchema itself.



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?

Review Comment:
   ```suggestion
   Example: share an Int32 array from C++ to Java:
   ```



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {
+        // Mark released
+        schema->release = NULL;
+    }
+
+    void export_int32_type(struct ArrowSchema* schema) {
+        *schema = (struct ArrowSchema) {
+                // Type description
+                .format = "l",
+                .name = "",
+                .metadata = NULL,
+                .flags = 0,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_type
+        };
+        std::cout << "C Data - Schema Pointer = " << schema << std::endl;
+    }
+
+    static void release_int32_array(struct ArrowArray* array) {
+        assert(array->n_buffers == 2);
+        // Free the buffers and the buffers array
+        free((void *) array->buffers[1]);
+        free(array->buffers);
+        // Mark released
+        array->release = NULL;
+    }
+
+    void export_int32_array(struct ArrowArray* array) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+
+        auto maybe_array = builder.Finish();
+        std::shared_ptr<arrow::Array> array_arrow = *maybe_array;
+        auto int64_array = std::static_pointer_cast<arrow::Int64Array>(array_arrow);
+        const int64_t* data = int64_array->raw_values();
+        std::cout << "Data To Exchange Pointer = " << data << std::endl;
+        for (int j = 0; j < int64_array->length(); j++){
+            std::cout << "Data To Exchange Value[" << j << "] = " << data[j] << std::endl;
+        }
+
+        *array = (struct ArrowArray) {
+                // Data description
+                .length = int64_array->length(),
+                .offset = 0,
+                .null_count = 0,
+                .n_buffers = 2,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_array
+        };
+
+        // Allocate list of buffers
+        array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
+        assert(array->buffers != NULL);
+        array->buffers[0] = NULL;  // no nulls, null bitmap can be omitted
+        array->buffers[1] = data;
+
+        std::cout << "C Data - Array Pointer = " << array << std::endl;
+        std::cout << "C Data - Array Data Pointer Buffer array->buffers[1] = " << array->buffers[1] << std::endl;
+    }
+
+**Java Side**
+
+Define Java code CDataInterfaceLibraryConfig.java that consume by JNI C++ functions exported through
+C Data Interface:
+
+.. 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>cpp-java-cdata</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-c-data</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-memory-netty</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+        </dependencies>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataInterfaceLibrary",

Review Comment:
   I would rather name this something like "CDataInterfaceExample"



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {
+        // Mark released
+        schema->release = NULL;
+    }
+
+    void export_int32_type(struct ArrowSchema* schema) {
+        *schema = (struct ArrowSchema) {
+                // Type description
+                .format = "l",
+                .name = "",
+                .metadata = NULL,
+                .flags = 0,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_type
+        };
+        std::cout << "C Data - Schema Pointer = " << schema << std::endl;
+    }
+
+    static void release_int32_array(struct ArrowArray* array) {
+        assert(array->n_buffers == 2);
+        // Free the buffers and the buffers array
+        free((void *) array->buffers[1]);
+        free(array->buffers);
+        // Mark released
+        array->release = NULL;
+    }
+
+    void export_int32_array(struct ArrowArray* array) {
+        arrow::Int64Builder builder;
+        builder.Append(1);
+        builder.Append(2);
+        builder.Append(3);
+        builder.AppendNull();
+        builder.Append(5);
+        builder.Append(6);
+        builder.Append(7);
+        builder.Append(8);
+
+        auto maybe_array = builder.Finish();
+        std::shared_ptr<arrow::Array> array_arrow = *maybe_array;
+        auto int64_array = std::static_pointer_cast<arrow::Int64Array>(array_arrow);
+        const int64_t* data = int64_array->raw_values();
+        std::cout << "Data To Exchange Pointer = " << data << std::endl;
+        for (int j = 0; j < int64_array->length(); j++){
+            std::cout << "Data To Exchange Value[" << j << "] = " << data[j] << std::endl;
+        }
+
+        *array = (struct ArrowArray) {
+                // Data description
+                .length = int64_array->length(),
+                .offset = 0,
+                .null_count = 0,
+                .n_buffers = 2,
+                .n_children = 0,
+                .children = NULL,
+                .dictionary = NULL,
+                // Bookkeeping
+                .release = &release_int32_array
+        };
+
+        // Allocate list of buffers
+        array->buffers = (const void**) malloc(sizeof(void*) * array->n_buffers);
+        assert(array->buffers != NULL);
+        array->buffers[0] = NULL;  // no nulls, null bitmap can be omitted
+        array->buffers[1] = data;
+
+        std::cout << "C Data - Array Pointer = " << array << std::endl;
+        std::cout << "C Data - Array Data Pointer Buffer array->buffers[1] = " << array->buffers[1] << std::endl;
+    }
+
+**Java Side**
+
+Define Java code CDataInterfaceLibraryConfig.java that consume by JNI C++ functions exported through
+C Data Interface:
+
+.. 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>cpp-java-cdata</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <properties>
+            <maven.compiler.source>8</maven.compiler.source>
+            <maven.compiler.target>8</maven.compiler.target>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.bytedeco</groupId>
+                <artifactId>javacpp</artifactId>
+                <version>1.5.7</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-c-data</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.arrow</groupId>
+                <artifactId>arrow-memory-netty</artifactId>
+                <version>7.0.0</version>
+            </dependency>
+        </dependencies>
+    </project>
+
+.. code-block:: java
+
+    import org.bytedeco.javacpp.annotation.Platform;
+    import org.bytedeco.javacpp.annotation.Properties;
+    import org.bytedeco.javacpp.tools.InfoMap;
+    import org.bytedeco.javacpp.tools.InfoMapper;
+
+    @Properties(
+            target = "CDataInterfaceLibrary",
+            value = @Platform(
+                    include = {"CDataInterfaceLibrary.h"},
+                    compiler = {"cpp11"},
+                    linkpath = {"/arrow/cpp/build/debug/"},
+                    link = {"arrow"}
+            )
+    )
+    public class CDataInterfaceLibraryConfig implements InfoMapper {
+        @Override
+        public void map(InfoMap infoMap) {
+        }
+    }
+
+.. code-block:: shell
+
+    // Compile our Java code
+    javac -cp javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate CDataInterfaceLibrary
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibraryConfig.java
+
+    // Generate libjniCDataInterfaceLibrary.dylib
+    java -jar javacpp-1.5.7.jar CDataInterfaceLibrary.java
+
+    // Validate libjniCDataInterfaceLibrary.dylib created
+    otool -L macosx-x86_64/libjniCDataInterfaceLibrary.dylib
+    macosx-x86_64/libjniCDataInterfaceLibrary.dylib:
+            libjniCDataInterfaceLibrary.dylib (compatibility version 0.0.0, current version 0.0.0)
+            @rpath/libarrow.800.dylib (compatibility version 800.0.0, current version 800.0.0)
+            /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
+            /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
+
+**Java Test**
+
+Let's create a Java class to Test C Data Interface from Java to C++:
+
+.. 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.BigIntVector;
+
+    public class TestCDataInterfaceV5 {
+
+        public static void main(String[] args) {
+            CDataInterfaceLibrary.ArrowSchema arrowSchema = new CDataInterfaceLibrary.ArrowSchema();

Review Comment:
   Can we pick different names for these variables? It gets very confusing to have lots of things with the same name.



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.

Review Comment:
   I don't think this paragraph is necessary (and it doesn't belong in this section in either case)



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:
+
+.. code-block:: cpp
+
+    #include <iostream>
+    #include <arrow/api.h>
+
+    #define ARROW_FLAG_DICTIONARY_ORDERED 1
+    #define ARROW_FLAG_NULLABLE 2
+    #define ARROW_FLAG_MAP_KEYS_SORTED 4
+
+    using arrow::Int64Builder;
+
+    struct ArrowSchema {
+        // Array type description
+        const char* format;
+        const char* name;
+        const char* metadata;
+        int64_t flags;
+        int64_t n_children;
+        struct ArrowSchema** children;
+        struct ArrowSchema* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowSchema*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    struct ArrowArray {
+        // Array data description
+        int64_t length;
+        int64_t null_count;
+        int64_t offset;
+        int64_t n_buffers;
+        int64_t n_children;
+        const void** buffers;
+        struct ArrowArray** children;
+        struct ArrowArray* dictionary;
+
+        // Release callback
+        void (*release)(struct ArrowArray*);
+        // Opaque producer-specific data
+        void* private_data;
+    };
+
+    static void release_int32_type(struct ArrowSchema* schema) {

Review Comment:
   Please follow Arrow coding conventions here.



##########
docs/source/java/cdata.rst:
##########
@@ -0,0 +1,313 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+================
+C Data Interface
+================
+
+.. contents::
+
+Arrow supports exchanging data within the same process through the :ref:`c-data-interface`.
+
+Java to Python
+--------------
+
+Use this guide to implement :doc:`Java to Python <../python/integration/python_java.rst>`
+communication using the C Data Interface.
+
+Java to C++
+-----------
+
+The C Data Interface is a protocol implemented in Arrow to exchange data within different
+environments without the cost of marshaling and copying data.
+
+Example: How to expose an int32 array using C Data Interface?
+
+**C++ Side**
+
+Compile arrow minimal library:
+
+.. code-block:: shell
+
+    git clone https://github.com/apache/arrow.git
+    cd arrow/cpp
+    cmake --preset -N ninja-debug-minimal
+    mkdir build   # from inside the `cpp` subdirectory
+    cd build
+    cmake .. --preset ninja-debug-minimal
+    cmake --build .
+    tree debug/
+    debug/
+    ├── libarrow.800.0.0.dylib
+    ├── libarrow.800.dylib -> libarrow.800.0.0.dylib
+    └── libarrow.dylib -> libarrow.800.dylib
+
+Define c++ code CDataInterfaceLibrary.h that export functions for third party like Java consumer:

Review Comment:
   We should just use `bridge.h` we should not tell people to reimplement everything



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org