From 5e5b34fb8df404d554cc9b2c3deed2094cfb01e8 Mon Sep 17 00:00:00 2001 From: David Sisson Date: Tue, 6 Feb 2024 16:24:01 -0800 Subject: [PATCH] Removed export stuff (to be added in next PR). --- CMakeLists.txt | 1 - export/CMakeLists.txt | 3 -- export/planloader/CMakeLists.txt | 24 --------- export/planloader/planloader.cpp | 62 ---------------------- export/planloader/planloader.h | 35 ------------ export/planloader/tests/CMakeLists.txt | 35 ------------ export/planloader/tests/PlanLoaderTest.cpp | 32 ----------- 7 files changed, 192 deletions(-) delete mode 100644 export/CMakeLists.txt delete mode 100644 export/planloader/CMakeLists.txt delete mode 100644 export/planloader/planloader.cpp delete mode 100644 export/planloader/planloader.h delete mode 100644 export/planloader/tests/CMakeLists.txt delete mode 100644 export/planloader/tests/PlanLoaderTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 75ab5345..d4f78ef9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,4 +49,3 @@ if(${SUBSTRAIT_CPP_BUILD_TESTING}) endif() add_subdirectory(src/substrait) -add_subdirectory(export) diff --git a/export/CMakeLists.txt b/export/CMakeLists.txt deleted file mode 100644 index 46aa69df..00000000 --- a/export/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -add_subdirectory(planloader) diff --git a/export/planloader/CMakeLists.txt b/export/planloader/CMakeLists.txt deleted file mode 100644 index cb214f4b..00000000 --- a/export/planloader/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# 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." - ) -endif() - -add_library(planloader SHARED planloader.cpp) -add_compile_options(-FPIC) -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}) - -if(${SUBSTRAIT_CPP_BUILD_TESTING}) - add_subdirectory(tests) -endif() diff --git a/export/planloader/planloader.cpp b/export/planloader/planloader.cpp deleted file mode 100644 index 6c53e760..00000000 --- a/export/planloader/planloader.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ - -#include "planloader.h" - -#include - -extern "C" { - -// Load a Substrait plan (in any format) from disk. -// Stores the Substrait plan in planBuffer in serialized form. -// Returns a SerializedPlan structure containing either the serialized plan or -// an error message. errorMessage is nullptr upon success. -SerializedPlan* load_substrait_plan(const char* filename) { - auto newPlan = new SerializedPlan(); - newPlan->buffer = nullptr; - newPlan->size = 0; - newPlan->errorMessage = nullptr; - - auto planOrError = io::substrait::loadPlan(filename); - if (!planOrError.ok()) { - auto errMsg = planOrError.status().message(); - newPlan->errorMessage = new char[errMsg.length()+1]; - strncpy(newPlan->errorMessage, errMsg.data(), errMsg.length()+1); - return newPlan; - } - ::substrait::proto::Plan plan = *planOrError; - std::string text = plan.SerializeAsString(); - newPlan->buffer = new char[text.length()+1]; - memcpy(newPlan->buffer, text.data(), text.length()+1); - newPlan->size = text.length(); - return newPlan; -} - -void free_substrait_plan(SerializedPlan* plan) { - if (plan->buffer) { - free(plan->buffer); - } - if (plan->errorMessage) { - free(plan->errorMessage); - } - free(plan); -} - -// Write a serialized Substrait plan to disk in the specified format. -// On error returns a non-empty error message. -// On success a nullptr is returned. -const char* save_substrait_plan( - const char* planData, - uint32_t planDataLength, - const char* filename, - io::substrait::PlanFileFormat format) { - ::substrait::proto::Plan plan; - std::string data(planData, planDataLength); - plan.ParseFromString(data); - auto result = io::substrait::savePlan(plan, filename, format); - if (!result.ok()) { - return result.message().data(); - } - return nullptr; -} - -} // extern "C" diff --git a/export/planloader/planloader.h b/export/planloader/planloader.h deleted file mode 100644 index d429d8c4..00000000 --- a/export/planloader/planloader.h +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ - -#include - -extern "C" { - -using SerializedPlan = struct { - char *buffer; - uint32_t size; - char *errorMessage; -}; - -// Since this is actually C code, stick to C style names for exporting. -// NOLINTBEGIN(readability-identifier-naming) - -// Load a Substrait plan (in any format) from disk. -// Stores the Substrait plan in planBuffer in serialized form. -// Returns a SerializedPlan structure containing either the serialized plan or -// an error message. -SerializedPlan* load_substrait_plan(const char* filename); - -void free_substrait_plan(SerializedPlan* plan); - -// Write a serialized Substrait plan to disk in the specified format. -// On error returns a non-empty error message. -// On success an empty string is returned. -const char* save_substrait_plan( - const char* planData, - uint32_t planDataLength, - const char* filename, - io::substrait::PlanFileFormat format); - -// NOLINTEND(readability-identifier-naming) - -} // extern "C" diff --git a/export/planloader/tests/CMakeLists.txt b/export/planloader/tests/CMakeLists.txt deleted file mode 100644 index 13c1c175..00000000 --- a/export/planloader/tests/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_path(GET CMAKE_CURRENT_BINARY_DIR PARENT_PATH - CMAKE_CURRENT_BINARY_PARENT_DIR) -cmake_path(GET CMAKE_CURRENT_BINARY_PARENT_DIR PARENT_PATH - CMAKE_CURRENT_BINARY_TOPLEVEL_DIR) - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY - "${CMAKE_CURRENT_BINARY_TOPLEVEL_DIR}/${BUILD_SUBDIR_NAME}") - -add_test_case( - 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") - -message( - STATUS "test data will be here: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/data" -) diff --git a/export/planloader/tests/PlanLoaderTest.cpp b/export/planloader/tests/PlanLoaderTest.cpp deleted file mode 100644 index 4216bf10..00000000 --- a/export/planloader/tests/PlanLoaderTest.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ - -#include -#include - -#include "../planloader.h" -#include "substrait/proto/plan.pb.h" - -namespace io::substrait::textplan { -namespace { - -TEST(PlanLoaderTest, LoadAndSave) { - auto serializedPlan = load_substrait_plan("data/q6_first_stage.json"); - ASSERT_EQ(serializedPlan->errorMessage, nullptr); - - ::substrait::proto::Plan plan; - bool parseStatus = - plan.ParseFromArray(serializedPlan->buffer, serializedPlan->size); - ASSERT_TRUE(parseStatus) << "Failed to parse the plan."; - - const char* saveStatus = save_substrait_plan( - serializedPlan->buffer, - serializedPlan->size, - "outfile.splan", - PlanFileFormat::kText); - ASSERT_EQ(saveStatus, nullptr); - - free_substrait_plan(serializedPlan); -} - -} // namespace -} // namespace io::substrait::textplan