diff --git a/export/java/TextPlan.java b/export/java/TextPlan.java new file mode 100644 index 00000000..0e846663 --- /dev/null +++ b/export/java/TextPlan.java @@ -0,0 +1,29 @@ +package io.substrait; + +public class SubstraitPlanLoader { + enum PlanFileFormat { + kBinary = 0, + kJson = 1, + kProtoText = 2, + kText = 3, + }; + + // Load a Substrait plan (in any format) from disk. + // Returns error message on failure, otherwise returns nullptr and + // updates the provided buffer. + public native String loadSubstraitPlan(String filename); + + // Write a Substrait plan to disk in the specified format. + public native String saveSubstraitPlan(Plan plan, String filename, PlanFileFormat format); + + static { + System.load("/path/to/libMYSTUFF.so"); + } + + public static void main(String [] args) { + SubstraitPlanLoader loader = new SubstraitPlanLoader(); + + String result = loader.loadSubstraitPlan("filename.plan"); + System.out.println("Result: " + result); + } +} diff --git a/export/planloader/CMakeLists.txt b/export/planloader/CMakeLists.txt index 7d9547b9..cb214f4b 100644 --- a/export/planloader/CMakeLists.txt +++ b/export/planloader/CMakeLists.txt @@ -1,7 +1,10 @@ # SPDX-License-Identifier: Apache-2.0 if(NOT BUILD_SUBDIR_NAME EQUAL "release") - message(SEND_ERROR, "The planloader library does not work in Debug mode due to its dependencies.") + message( + SEND_ERROR, + "The planloader library does not work in Debug mode due to its dependencies." + ) endif() add_library(planloader SHARED planloader.cpp) @@ -11,7 +14,10 @@ set_target_properties(planloader PROPERTIES SUBVERSION 1) add_dependencies(planloader substrait_io) target_link_libraries(planloader substrait_io) -install(TARGETS planloader LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCDIR}) +install( + TARGETS planloader + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCDIR}) if(${SUBSTRAIT_CPP_BUILD_TESTING}) add_subdirectory(tests) diff --git a/export/planloader/tests/CMakeLists.txt b/export/planloader/tests/CMakeLists.txt index 1989bf4e..13c1c175 100644 --- a/export/planloader/tests/CMakeLists.txt +++ b/export/planloader/tests/CMakeLists.txt @@ -1,34 +1,35 @@ # SPDX-License-Identifier: Apache-2.0 cmake_path(GET CMAKE_CURRENT_BINARY_DIR PARENT_PATH - CMAKE_CURRENT_BINARY_PARENT_DIR) + CMAKE_CURRENT_BINARY_PARENT_DIR) cmake_path(GET CMAKE_CURRENT_BINARY_PARENT_DIR PARENT_PATH - CMAKE_CURRENT_BINARY_TOPLEVEL_DIR) + CMAKE_CURRENT_BINARY_TOPLEVEL_DIR) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY - "${CMAKE_CURRENT_BINARY_TOPLEVEL_DIR}/${BUILD_SUBDIR_NAME}") + "${CMAKE_CURRENT_BINARY_TOPLEVEL_DIR}/${BUILD_SUBDIR_NAME}") add_test_case( - planloader_test - SOURCES - PlanLoaderTest.cpp - EXTRA_LINK_LIBS - planloader - gtest - gtest_main) + planloader_test + SOURCES + PlanLoaderTest.cpp + EXTRA_LINK_LIBS + planloader + gtest + gtest_main) set(TEXTPLAN_SOURCE_DIR "${CMAKE_SOURCE_DIR}/src/substrait/textplan") add_custom_command( - TARGET planloader_test - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E echo "Copying unit test data.." - COMMAND ${CMAKE_COMMAND} -E make_directory - "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data" - COMMAND - ${CMAKE_COMMAND} -E copy - "${TEXTPLAN_SOURCE_DIR}/converter/data/q6_first_stage.json" - "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data/q6_first_stage.json") + TARGET planloader_test + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Copying unit test data.." + COMMAND ${CMAKE_COMMAND} -E make_directory + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data" + COMMAND + ${CMAKE_COMMAND} -E copy + "${TEXTPLAN_SOURCE_DIR}/converter/data/q6_first_stage.json" + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data/q6_first_stage.json") message( - STATUS "test data will be here: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data") + STATUS "test data will be here: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data" +)