-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73bec1f
commit 74bf673
Showing
5 changed files
with
110 additions
and
13 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# MEGAHACK -- Given that the compiler options include lots of undesirable stuff in Debug mode, either cleanse it or refuse to build unless we're in release mode. | ||
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 textplan.cpp) | ||
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}) | ||
install(TARGETS planloader LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCDIR}) | ||
|
||
if(${SUBSTRAIT_CPP_BUILD_TESTING}) | ||
add_subdirectory(tests) | ||
endif() |
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,30 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
#include <substrait/common/Io.h> | ||
|
||
extern "C" { | ||
|
||
typedef struct { | ||
char *buffer; | ||
uint32_t size; | ||
char *errorMessage; | ||
} SerializedPlan; | ||
|
||
// 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); | ||
|
||
} // extern "C" |
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,34 @@ | ||
# 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") |
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,32 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
#include <gtest/gtest.h> | ||
#include <functional> | ||
|
||
#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 |