-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-17297: [Java][Doc] Adding documentation to interact between C++ to Java via C Data Interface #13788
ARROW-17297: [Java][Doc] Adding documentation to interact between C++ to Java via C Data Interface #13788
Conversation
Can you create a JIRA? This isn't minor |
docs/source/java/cdata.rst
Outdated
@@ -33,7 +33,10 @@ Python communication using the C Data Interface. | |||
Java to C++ | |||
----------- | |||
|
|||
Example: Share an Int64 array from C++ to Java: | |||
Share an Int64 array from C++ to Java | |||
===================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the wrong level of header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
docs/source/java/cdata.rst
Outdated
return root; | ||
} | ||
|
||
public static void main(String[] args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need a main method, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted
|
Co-authored-by: David Li <[email protected]>
docs/source/java/cdata.rst
Outdated
|
||
.. code-block:: java | ||
|
||
import org.apache.arrow.c.ArrowArray; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, but everything is indented one space too many here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's actually true of all the code blocks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
docs/source/java/cdata.rst
Outdated
int status = JNI_CreateJavaVM(jvm, (void **) &env, &vm_args); | ||
if (status < 0) { | ||
std::cout << "\n<<<<< Unable to Launch JVM >>>>>\n" << std::endl; | ||
std::abort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requires #include <cstdlib>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I suppose the abort
isn't necessary, maybe just explicitly return nullptr
and it'll exit in main()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
docs/source/java/cdata.rst
Outdated
jclass javaClassToBeCalledByCpp = NULL; | ||
javaClassToBeCalledByCpp = env->FindClass("ToBeCalledByCpp"); | ||
if (javaClassToBeCalledByCpp != NULL) { | ||
jmethodID fillVector = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the other uses of NULL to be nullptr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though, why separate the declaration and assignment? Just do it in one line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
docs/source/java/cdata.rst
Outdated
find_package(JNI REQUIRED) | ||
find_package(Arrow REQUIRED) | ||
message(STATUS "Arrow version: ${ARROW_VERSION}") | ||
message(${ARROW_FULL_SO_VERSION}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be updated like the line above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message not needed, deleted
docs/source/java/cdata.rst
Outdated
JNIEnv *env; | ||
JavaVM *jvm; | ||
env = CreateVM(&jvm); | ||
if (env == nullptr) return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use EXIT_FAILURE here too as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
docs/source/java/cdata.rst
Outdated
struct ArrowSchema arrowSchema; | ||
struct ArrowArray arrowArray; | ||
std::cout << "\n<<<<< C++ to Java for Arrays >>>>>\n" << std::endl; | ||
env->CallStaticVoidMethod(javaClassToBeCalledByCpp, fillVector, reinterpret_cast<uintptr_t>(&arrowSchema), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would wrap lines to be a little shorter here if possible to make sure it's readable in Sphinx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
Co-authored-by: David Li <[email protected]>
docs/source/java/cdata.rst
Outdated
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to use Java 11 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted
docs/source/java/cdata.rst
Outdated
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<arrow.version>8.0.0</arrow.version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to 9.0.0?
docs/source/java/cdata.rst
Outdated
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<arrow.version>8.0.0</arrow.version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well update to 9.0.0 now
docs/source/java/cdata.rst
Outdated
<repositories> | ||
<repository> | ||
<id>arrow-nightly</id> | ||
<url>https://nightlies.apache.org/arrow/java</url> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use nightlies right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted
docs/source/java/cdata.rst
Outdated
<archive> | ||
<manifest> | ||
<mainClass> | ||
ToBeCalledByCpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the mainClass config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted
docs/source/java/cdata.rst
Outdated
struct ArrowArray arrowArray; | ||
std::cout << "\n<<<<< C++ to Java for RecordBatch >>>>>\n" << std::endl; | ||
env->CallStaticVoidMethod(javaClassToBeCalledByCpp, fillVectorSchemaRoot, | ||
static_cast<long>(reinterpret_cast<uintptr_t>(&arrowSchema)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need the static_cast<long>
above as well then?
(Also, shouldn't it be jlong
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these kind of declaration work well (I don't know what of this should I use?)
env->CallStaticVoidMethod(javaClassToBeCalledByCpp, fillVector,
static_cast<long>(reinterpret_cast<uintptr_t>(&arrowSchema)),
static_cast<long>(reinterpret_cast<uintptr_t>(&arrowArray)));
env->CallStaticVoidMethod(javaClassToBeCalledByCpp, fillVector,
reinterpret_cast<uintptr_t>(&arrowSchema),
reinterpret_cast<uintptr_t>(&arrowArray));
env->CallStaticVoidMethod(javaClassToBeCalledByCpp, fillVector,
(long)(&arrowSchema),
(long)(&arrowArray));
env->CallStaticVoidMethod(javaClassToBeCalledByCpp, fillVector,
(jlong)(&arrowSchema),
(jlong)(&arrowArray));
env->CallStaticVoidMethod(javaClassToBeCalledByCpp, fillVector,
(uintptr_t)(&arrowSchema),
(uintptr_t)(&arrowArray));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be the most compliant, I think it should be:
env->CallStaticVoidMethod(javaClassToBeCalledByCpp, fillVector,
static_cast<jlong>(reinterpret_cast<uintptr_t>(&arrowSchema)),
static_cast<jlong>(reinterpret_cast<uintptr_t>(&arrowArray)));
(note jlong not long)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
docs/source/java/cdata.rst
Outdated
struct ArrowArray arrowArray; | ||
std::cout << "\n<<<<< C++ to Java for RecordBatch >>>>>\n" << std::endl; | ||
env->CallStaticVoidMethod(javaClassToBeCalledByCpp, fillVectorSchemaRoot, | ||
static_cast<long>(reinterpret_cast<uintptr_t>(&arrowSchema)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be the most compliant, I think it should be:
env->CallStaticVoidMethod(javaClassToBeCalledByCpp, fillVector,
static_cast<jlong>(reinterpret_cast<uintptr_t>(&arrowSchema)),
static_cast<jlong>(reinterpret_cast<uintptr_t>(&arrowArray)));
(note jlong not long)
docs/source/java/cdata.rst
Outdated
} | ||
} | ||
|
||
public static FieldVector populateFieldVectorToExport(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you make this private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
docs/source/java/cdata.rst
Outdated
} | ||
} | ||
|
||
public static VectorSchemaRoot populateVectorSchemaRootToExport(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
public class ToBeCalledByCpp { | ||
final static BufferAllocator allocator = new RootAllocator(); | ||
|
||
public static void fillVector(long schemaAddress, long arrayAddress){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add small docstring describing the two public methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
Co-authored-by: Antoine Pitrou <[email protected]>
…itory and Java 11 version references
Co-authored-by: David Li <[email protected]>
Lint issues are addressed by #13809 |
Benchmark runs are scheduled for baseline = bc7de40 and contender = d26489c. d26489c is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Adding documentation to interact between C++ to Java via C Data Interface for: