Skip to content

Commit

Permalink
GDV-7: Add Java APIs (apache#23)
Browse files Browse the repository at this point in the history
GDV-7: Gandiva Java APIs

Added the JNI Implementation of the Java APIs
Added Java based unit and integration tests
Use cmake to build gandiva_jni
Added pom.xml to build Java files
  • Loading branch information
vvellanki committed Jun 12, 2018
1 parent 19ec133 commit a29e60a
Show file tree
Hide file tree
Showing 5 changed files with 578 additions and 41 deletions.
29 changes: 0 additions & 29 deletions cpp/src/gandiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,6 @@ set(GANDIVA_BC_INSTALL_DIR
set(GANDIVA_BC_INSTALL_PATH ${GANDIVA_BC_INSTALL_DIR}/${GANDIVA_BC_FILE_NAME})
set(GANDIVA_BC_OUTPUT_PATH ${CMAKE_BINARY_DIR}/irhelpers.bc)

add_library(gandiva SHARED ${CMAKE_SOURCE_DIR}/include/gandiva/status.h)
target_link_libraries(gandiva PUBLIC gandiva_codegen gandiva_jni)

add_subdirectory(codegen)
add_subdirectory(jni)
add_subdirectory(precompiled)

# Set version for the library.
set(GANDIVA_VERSION_MAJOR 0)
set(GANDIVA_VERSION_MINOR 1)
set(GANDIVA_VERSION_PATCH 0)
set(GANDIVA_VERSION ${GANDIVA_VERSION_MAJOR}.${GANDIVA_VERSION_MINOR}.${GANDIVA_VERSION_PATCH})

set_target_properties(gandiva PROPERTIES
VERSION ${GANDIVA_VERSION}
SOVERSION ${GANDIVA_VERSION_MAJOR}
)

# install for gandiva
include(GNUInstallDirs)

# install libgandiva
install(
TARGETS gandiva
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# install the header files.
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/gandiva
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
44 changes: 35 additions & 9 deletions cpp/src/gandiva/codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

project(gandiva_codegen)
project(gandiva)

# Find arrow
find_package(ARROW)
Expand All @@ -22,7 +22,7 @@ find_package(Boost REQUIRED)
set(BC_FILE_PATH_CC "${CMAKE_CURRENT_BINARY_DIR}/bc_file_path.cc")
configure_file(bc_file_path.cc.in ${BC_FILE_PATH_CC})

add_library(gandiva_codegen SHARED
add_library(gandiva SHARED
annotator.cc
engine.cc
expr_decomposer.cc
Expand All @@ -34,29 +34,55 @@ add_library(gandiva_codegen SHARED
tree_expr_builder.cc
${BC_FILE_PATH_CC})

# For users of gandiva_codegen library (including integ tests), include-dir is :
# For users of gandiva library (including integ tests), include-dir is :
# /usr/**/include dir after install,
# cpp/include during build
# For building gandiva_codegen library itself, include-dir (in addition to above) is :
# For building gandiva library itself, include-dir (in addition to above) is :
# cpp/src
target_include_directories(gandiva_codegen
target_include_directories(gandiva
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
PRIVATE
${CMAKE_SOURCE_DIR}/src
)

# ARROW is a public dependency i.e users of gandiva_codegen also will have a dependency on arrow.
target_link_libraries(gandiva_codegen
# ARROW is a public dependency i.e users of gandiva also will have a dependency on arrow.
target_link_libraries(gandiva
PUBLIC
ARROW::ARROW
PRIVATE
Boost::boost)

# LLVM is a private dependency i.e users of gandiva_codegen will not need to include llvm headers
# LLVM is a private dependency i.e users of gandiva will not need to include llvm headers
# or link with llvm libraries.
target_link_llvm(gandiva_codegen PRIVATE)
target_link_llvm(gandiva PRIVATE)

# Set version for the library.
set(GANDIVA_VERSION_MAJOR 0)
set(GANDIVA_VERSION_MINOR 1)
set(GANDIVA_VERSION_PATCH 0)
set(GANDIVA_VERSION ${GANDIVA_VERSION_MAJOR}.${GANDIVA_VERSION_MINOR}.${GANDIVA_VERSION_PATCH})

set_target_properties(gandiva PROPERTIES
VERSION ${GANDIVA_VERSION}
SOVERSION ${GANDIVA_VERSION_MAJOR}
)

# install for gandiva
include(GNUInstallDirs)

# install libgandiva
install(
TARGETS gandiva
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# install the header files.
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/gandiva
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

#args: label test-file src-files
add_gandiva_unit_test(dex_llvm_test.cc)
Expand Down
18 changes: 15 additions & 3 deletions cpp/src/gandiva/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ project(gandiva_jni)
set(Protobuf_USE_STATIC_LIBS, ON)
find_package(Protobuf REQUIRED)

# Find JNI
find_package(JNI REQUIRED)

# generate the protobuf files from the proto definition.
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${CMAKE_SOURCE_DIR}/../proto/Types.proto)

add_library(gandiva_jni STATIC
#jni.cc
# Create the jni header file (from the java class).
set(JNI_HEADERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/java")
add_subdirectory(../../../java ./java)

add_library(gandiva_jni SHARED
native_builder.cc
${PROTO_SRCS}
${PROTO_HDRS})
add_dependencies(gandiva_jni gandiva_java)

# For users of gandiva_jni library (including integ tests), include-dir is :
# /usr/**/include dir after install,
Expand All @@ -35,12 +43,16 @@ target_include_directories(gandiva_jni
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
${JNI_HEADERS_DIR}
PRIVATE
${JNI_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src
)

# ARROW is a public dependency i.e users of gandiva also will have a dependency on arrow.
# PROTOBUF is a public dependency i.e users of gandiva also will have a dependency on arrow.
target_link_libraries(gandiva_jni
PRIVATE
protobuf::libprotobuf
gandiva
)
50 changes: 50 additions & 0 deletions cpp/src/gandiva/jni/module_holder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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
*/

#ifndef JNI_MODULE_HOLDER_H
#define JNI_MODULE_HOLDER_H

#include <utility>
#include <memory>

#include "gandiva/arrow.h"
#include "gandiva/projector.h"

namespace gandiva {

class ProjectorHolder {
public:
ProjectorHolder(SchemaPtr schema,
FieldVector ret_types,
std::shared_ptr<Projector> projector)
: schema_(schema),
ret_types_(ret_types),
projector_(std::move(projector)) {}

SchemaPtr schema() { return schema_; }
FieldVector rettypes() { return ret_types_; }
std::shared_ptr<Projector> projector() { return projector_; }

private:
SchemaPtr schema_;
FieldVector ret_types_;
std::shared_ptr<Projector> projector_;
};

} // namespace gandiva

#endif // JNI_MODULE_HOLDER_H
Loading

0 comments on commit a29e60a

Please sign in to comment.