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/07 14:18:29 UTC

[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

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