Skip to content
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] Fill two incompatible gaps between C++ and Java #279

Merged
merged 19 commits into from
Nov 14, 2023
Merged
21 changes: 15 additions & 6 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
branches:
- main
paths:
- 'cpp/include/**'
- 'java/**'
- '.github/workflows/java.yml'
pull_request:
Expand Down Expand Up @@ -37,10 +36,10 @@ jobs:
sudo apt-get install -y /tmp/apache-arrow-apt-source-latest-"$(lsb_release --codename --short)".deb
sudo apt-get update -y
# TODO: ISSUE-241
sudo apt install -y libarrow-dev=13.0.0-1 \
libarrow-dataset-dev=13.0.0-1 \
libarrow-acero-dev=13.0.0-1 \
libparquet-dev=13.0.0-1
sudo apt install -y libarrow-dev=14.0.1-1 \
libarrow-dataset-dev=14.0.1-1 \
libarrow-acero-dev=14.0.1-1 \
libparquet-dev=14.0.1-1
sudo apt-get install libcurl4-openssl-dev -y
sudo apt-get install llvm-11 clang-11 lld-11 libclang-11-dev libz-dev -y

Expand All @@ -51,9 +50,19 @@ jobs:
mvn spotless:check
popd

- name: Build and Install cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can change the gar version to v0.10.0, https://github.com/alibaba/GraphAr/blob/77f547ac14a786b6f557456cec3bb17e19256602/java/cmake/graphar-cpp.cmake#L51

no need to install latest cpp, it may make cpp update break the java ci

run: |
mkdir build
pushd build
cmake ../cpp
make -j$(nproc)
sudo make install
popd

- name: Run test
run: |
export JAVA_HOME=${JAVA_HOME_11_X64}
# Temporarily using Java 8, related issue: https://github.com/alibaba/GraphAr/issues/277
export JAVA_HOME=${JAVA_HOME_8_X64}
export LLVM11_HOME=/usr/lib/llvm-11
pushd java
mvn test -Dspotless.check.skip=true
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gar/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ ConstructVerticesCollection(const GraphInfo& graph_info,
* @param edge_label The edge label.
* @param dst_label The destination vertex label.
* @param adj_list_type The adjList type.
* @param vertex_chunk_begin The index of the begin vertex chunk.
* @param vertex_chunk_begin The index of the beginning vertex chunk.
* @param vertex_chunk_end The index of the end vertex chunk (not included).
* @return The constructed collection or error.
*/
Expand Down
26 changes: 16 additions & 10 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
cmake_minimum_required(VERSION 3.6)
project(gar-java)

option(BUILD_GAR_CPP_BY_CMAKE "Build GraphAr C++ library with specific version" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -std=c++17 -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -std=c++17 -Wall")

# set auto-generated JNI code and handwriting JNI code as source files
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target/generated-sources/annotations/*.cc" "${CMAKE_CURRENT_SOURCE_DIR}/target/generated-test-sources/test-annotations/*.cc"
Expand All @@ -19,19 +20,24 @@ find_package(JNI REQUIRED)
include_directories(SYSTEM ${JAVA_INCLUDE_PATH})
include_directories(SYSTEM ${JAVA_INCLUDE_PATH2})

# some JNI code depends on arrow
# some JNI code depends on arrow directly
find_package(Arrow REQUIRED)
# build graphar-cpp in specific version
include(graphar-cpp)
build_graphar_cpp()
find_package(gar REQUIRED)

# build the bridge JNI library
add_library(${LIBNAME} SHARED ${SOURCES})
# include graphar-cpp headers
target_include_directories(${LIBNAME} SYSTEM BEFORE PRIVATE ${GAR_INCLUDE_DIR})
# link graphar-cpp and arrow
target_link_libraries(${LIBNAME} ${CMAKE_JNI_LINKER_FLAGS} gar_shared)
target_link_libraries(${LIBNAME} ${CMAKE_JNI_LINKER_FLAGS} Arrow::arrow_static)
# build GraphAr C++ library or link system installed GraphAr C++ library
if(BUILD_GAR_CPP_BY_CMAKE)
include(graphar-cpp)
build_graphar_cpp()
target_link_libraries(${LIBNAME} ${CMAKE_JNI_LINKER_FLAGS} gar_shared)
# include graphar-cpp headers
target_include_directories(${LIBNAME} SYSTEM BEFORE PRIVATE ${GAR_INCLUDE_DIR})
else()
target_link_libraries(${LIBNAME} ${CMAKE_JNI_LINKER_FLAGS} gar)
endif()
target_link_libraries(${LIBNAME} ${CMAKE_JNI_LINKER_FLAGS} Arrow::arrow_shared)

set_target_properties(${LIBNAME} PROPERTIES LINKER_LANGUAGE CXX)

Expand All @@ -43,4 +49,4 @@ add_custom_command(TARGET ${LIBNAME}
add_custom_command(TARGET ${LIBNAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/target/native/bitcode
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_OBJECTS:${LIBNAME}> ${CMAKE_CURRENT_SOURCE_DIR}/target/native/bitcode COMMAND_EXPAND_LISTS)
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_OBJECTS:${LIBNAME}> ${CMAKE_CURRENT_SOURCE_DIR}/target/native/bitcode COMMAND_EXPAND_LISTS)
99 changes: 17 additions & 82 deletions java/src/main/java/com/alibaba/graphar/edges/EdgesCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,96 +14,29 @@

package com.alibaba.graphar.edges;

import static com.alibaba.graphar.util.CppClassName.GAR_EDGES_COLLECTION;
import static com.alibaba.graphar.util.CppHeaderName.GAR_GRAPH_H;

import com.alibaba.fastffi.CXXHead;
import com.alibaba.fastffi.CXXPointer;
import com.alibaba.fastffi.CXXReference;
import com.alibaba.fastffi.CXXValue;
import com.alibaba.fastffi.FFIGen;
import com.alibaba.fastffi.FFINameAlias;
import com.alibaba.graphar.graphinfo.EdgeInfo;
import com.alibaba.graphar.graphinfo.GraphInfo;
import com.alibaba.graphar.stdcxx.StdString;
import com.alibaba.graphar.types.AdjListType;
import com.alibaba.graphar.util.Result;
import com.alibaba.fastffi.FFITypeAlias;
import java.util.Iterator;

/** EdgesCollection is designed for reading a collection of edges. */
@FFIGen
@FFITypeAlias(GAR_EDGES_COLLECTION)
@CXXHead(GAR_GRAPH_H)
public interface EdgesCollection extends CXXPointer, Iterable<Edge> {
/**
* Construct the collection for a range of edges.
*
* @param graphInfo The GraphInfo for the graph.
* @param srcLabel The source vertex label.
* @param edgeLabel The edge label.
* @param dstLabel The destination vertex label.
* @param adjListType The adjList type.
* @param vertexChunkBegin The index of the beginning vertex chunk.
* @param vertexChunkEnd The index of the end vertex chunk (not included).
* @return The constructed collection or error.
*/
static EdgesCollection create(
final GraphInfo graphInfo,
String srcLabel,
String edgeLabel,
String dstLabel,
AdjListType adjListType,
long vertexChunkBegin,
long vertexChunkEnd) {
Result<EdgeInfo> maybeEdgeInfo =
graphInfo.getEdgeInfo(
StdString.create(srcLabel),
StdString.create(edgeLabel),
StdString.create(dstLabel));
if (maybeEdgeInfo.hasError()) {
throw new RuntimeException(
"graphInfo to create EdgesCollection has error: "
+ maybeEdgeInfo.status().message().toJavaString());
}
EdgeInfo edgeInfo = maybeEdgeInfo.value();
if (!edgeInfo.containAdjList(adjListType)) {
throw new RuntimeException(
"The edge "
+ edgeLabel
+ " of adj list type "
+ adjListType
+ " doesn't exist.");
}
switch (adjListType) {
case ordered_by_source:
return EdgesCollectionOrderedBySource.factory.create(
edgeInfo, graphInfo.getPrefix(), vertexChunkBegin, vertexChunkEnd);
case ordered_by_dest:
return EdgesCollectionOrderedByDest.factory.create(
edgeInfo, graphInfo.getPrefix(), vertexChunkBegin, vertexChunkEnd);
case unordered_by_source:
return EdgesCollectionUnorderedBySource.factory.create(
edgeInfo, graphInfo.getPrefix(), vertexChunkBegin, vertexChunkEnd);
case unordered_by_dest:
return EdgesCollectionUnorderedByDest.factory.create(
edgeInfo, graphInfo.getPrefix(), vertexChunkBegin, vertexChunkEnd);
}
throw new RuntimeException("Unknown adj list type: " + adjListType);
}

/**
* Construct the collection for a range of edges.
*
* @param graphInfo The GraphInfo for the graph.
* @param srcLabel The source vertex label.
* @param edgeLabel The edge label.
* @param dstLabel The destination vertex label.
* @param adjListType The adjList type.
* @return The constructed collection or error.
*/
static EdgesCollection create(
final GraphInfo graphInfo,
String srcLabel,
String edgeLabel,
String dstLabel,
AdjListType adjListType) {
return create(graphInfo, srcLabel, edgeLabel, dstLabel, adjListType, 0, Long.MAX_VALUE);
}

/** The iterator pointing to the first edge. */
@CXXValue
EdgeIter begin();

/** The iterator pointing to the past-the-end element. */
@CXXValue
EdgeIter end();

/**
Expand All @@ -115,7 +48,8 @@ static EdgesCollection create(
* @return The new constructed iterator.
*/
@FFINameAlias("find_src")
EdgeIter findSrc(long id, EdgeIter from);
@CXXValue
EdgeIter findSrc(long id, @CXXReference EdgeIter from);

/**
* Construct and return the iterator pointing to the first incoming edge of the vertex with
Expand All @@ -126,7 +60,8 @@ static EdgesCollection create(
* @return The new constructed iterator.
*/
@FFINameAlias("find_dst")
EdgeIter findDst(long id, EdgeIter from);
@CXXValue
EdgeIter findDst(long id, @CXXReference EdgeIter from);

/** Get the number of edges in the collection. */
long size();
Expand Down

This file was deleted.

Loading