-
Notifications
You must be signed in to change notification settings - Fork 106
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
feat(java/driver/jni): add JNI bindings to native driver manager #2401
Open
lidavidm
wants to merge
9
commits into
apache:main
Choose a base branch
from
lidavidm:gh-2027
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2ba5aa4
feat(java/driver/jni): add JNI bindings to native driver manager
lidavidm 216a5b3
updates
lidavidm f1769f1
updates
lidavidm 64a33eb
encapsulate
lidavidm d73e35b
javah!
lidavidm bcc27c1
expand tests and simplify
lidavidm 0e0b809
some comments
lidavidm 14a2a40
add build script
lidavidm 5207225
Fix
lidavidm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env bash | ||
# 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. | ||
|
||
set -ex | ||
|
||
: ${ADBC_CMAKE_ARGS:=""} | ||
: ${CMAKE_BUILD_TYPE:=Debug} | ||
|
||
main() { | ||
local -r source_dir=${1} | ||
local -r build_dir=${2} | ||
local -r install_dir=${3} | ||
|
||
mkdir -p "${build_dir}" | ||
pushd "${build_dir}" | ||
|
||
set -x | ||
cmake "${source_dir}/java" \ | ||
${ADBC_CMAKE_ARGS} \ | ||
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ | ||
-DCMAKE_INSTALL_PREFIX="${source_dir}/java/driver/jni/src/main/resources/" \ | ||
-DCMAKE_PREFIX_PATH="${install_dir}/lib/cmake/" | ||
set +x | ||
|
||
cmake --build . --target install -j | ||
|
||
popd | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# 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. | ||
|
||
cmake_minimum_required(VERSION 3.16) | ||
message(STATUS "Building using CMake version: ${CMAKE_VERSION}") | ||
|
||
# find_package() uses <PackageName>_ROOT variables. | ||
# https://cmake.org/cmake/help/latest/policy/CMP0074.html | ||
if(POLICY CMP0074) | ||
cmake_policy(SET CMP0074 NEW) | ||
endif() | ||
|
||
project(adbc-java) | ||
|
||
if("${CMAKE_CXX_STANDARD}" STREQUAL "") | ||
set(CMAKE_CXX_STANDARD 17) | ||
endif() | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
include(GNUInstallDirs) | ||
|
||
# Dependencies | ||
|
||
find_package(Java REQUIRED) | ||
find_package(JNI REQUIRED) | ||
|
||
include(UseJava) | ||
|
||
# ADBC_ARCH_DIR is derived from the architecture. The user can override this | ||
# variable if auto-detection fails. | ||
if("${ADBC_ARCH_DIR}" STREQUAL "") | ||
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64") | ||
set(ADBC_ARCH_DIR "aarch_64") | ||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386") | ||
set(ADBC_ARCH_DIR "x86_64") | ||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64") | ||
set(ADBC_ARCH_DIR "aarch_64") | ||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64") | ||
set(ADBC_ARCH_DIR "x86_64") | ||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") | ||
set(ADBC_ARCH_DIR "x86_64") | ||
else() | ||
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") | ||
endif() | ||
endif() | ||
|
||
add_subdirectory(driver/jni) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# 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. | ||
|
||
find_package(AdbcDriverManager) | ||
|
||
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/target/headers/org_apache_arrow_adbc_driver_jni_impl_NativeAdbc.h | ||
COMMENT "Generate JNI headers" | ||
# Force Maven to actually re-run the command | ||
COMMAND rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/target/headers | ||
${CMAKE_CURRENT_SOURCE_DIR}/target/maven-status | ||
COMMAND mvn --file ${CMAKE_CURRENT_SOURCE_DIR}/../.. -Pjni,javah | ||
compile --also-make --projects :adbc-driver-jni | ||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java/org/apache/arrow/adbc/driver/jni/impl/NativeAdbc.java | ||
) | ||
|
||
add_library(adbc_driver_jni SHARED | ||
src/main/cpp/jni_wrapper.cc | ||
${CMAKE_CURRENT_SOURCE_DIR}/target/headers/org_apache_arrow_adbc_driver_jni_impl_NativeAdbc.h | ||
) | ||
target_include_directories(adbc_driver_jni | ||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/target/headers) | ||
target_link_libraries(adbc_driver_jni JNI::JNI | ||
AdbcDriverManager::adbc_driver_manager_static) | ||
|
||
set(ADBC_DRIVER_JNI_C_LIBDIR "adbc_driver_jni/${ADBC_ARCH_DIR}") | ||
set(ADBC_DRIVER_JNI_C_BINDIR "adbc_driver_jni/${ADBC_ARCH_DIR}") | ||
|
||
install(TARGETS adbc_driver_jni | ||
LIBRARY DESTINATION ${ADBC_DRIVER_JNI_C_LIBDIR} | ||
RUNTIME DESTINATION ${ADBC_DRIVER_JNI_C_BINDIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<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> | ||
<parent> | ||
<groupId>org.apache.arrow.adbc</groupId> | ||
<artifactId>arrow-adbc-java-root</artifactId> | ||
<version>0.17.0-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>adbc-driver-jni</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Arrow ADBC Driver Native</name> | ||
<description>An ADBC driver wrapping the native driver manager.</description> | ||
|
||
<dependencies> | ||
<!-- Arrow --> | ||
<dependency> | ||
<groupId>org.apache.arrow</groupId> | ||
<artifactId>arrow-c-data</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.arrow</groupId> | ||
<artifactId>arrow-memory-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.arrow</groupId> | ||
<artifactId>arrow-memory-netty</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.arrow</groupId> | ||
<artifactId>arrow-vector</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.arrow.adbc</groupId> | ||
<artifactId>adbc-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.arrow.adbc</groupId> | ||
<artifactId>adbc-driver-manager</artifactId> | ||
</dependency> | ||
|
||
<!-- Static analysis and linting --> | ||
<dependency> | ||
<groupId>org.checkerframework</groupId> | ||
<artifactId>checker-qual</artifactId> | ||
</dependency> | ||
|
||
<!-- Testing --> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration combine.self="append"> | ||
<systemPropertyVariables> | ||
<arrow.test.dataRoot>${project.basedir}/../../../testing/data</arrow.test.dataRoot> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<!-- Invoked by CMake to generate headers. --> | ||
<!-- You must first build the project (without JNI enabled). --> | ||
<id>javah</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<compilerArgs> | ||
<arg>-h</arg> | ||
<arg>${project.basedir}/target/headers</arg> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
CMake projects
add_jar()
https://cmake.org/cmake/help/latest/module/UseJava.html#creating-and-installing-jars .Does it help this?
FYI: apache/arrow-java uses
add_jar()
when I prepared it: https://github.com/apache/arrow-java/blob/d304da5f872615346557e947ca5b04e9e23e8b87/dataset/CMakeLists.txt#L24-L32There 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 what I originally did! 😂
But it has some problems. CMake can't resolve the Maven dependency tree. So the files we pass to
add_jar
have to be able to compile without any dependencies, including any dependencies on other ADBC classes. That meant duplicating code or writing slightly unnatural code in Java. So @laurentgo here suggested using CMake to invoke Maven to generate the headers instead.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.
Oh, sorry!