-
Notifications
You must be signed in to change notification settings - Fork 12
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: create an exportable version of plan loading #91
Merged
Merged
Changes from 15 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
0ea3c42
feat: add support for all subquery types
EpsilonPrime 6758f3f
Ran clang tidy.
EpsilonPrime af4fb1e
Tidy fixes.
EpsilonPrime bfe2ff6
Fix for some errors occuring too often.
EpsilonPrime 44188b6
Fixed problem with falling through to the wrong case.
EpsilonPrime 20acf0b
Created initial external library
EpsilonPrime 77fcd30
Now the library is in a usable state.
EpsilonPrime df1b42c
Switch to returning a structure instead of modifying passed in argume…
EpsilonPrime 58bed47
Make the planloader library installable.
EpsilonPrime 73bec1f
Remove extraneous Makefile.
EpsilonPrime 74bf673
Added a planloader test.
EpsilonPrime 80b2c3e
Ran clang tidy.
EpsilonPrime 347fbe2
Remove accidentally added java library still in progress.
EpsilonPrime e4485db
Fixed SetComparison to require only a single relation.
EpsilonPrime a72a827
Handled the rest of the review notes.
EpsilonPrime d0c187d
Clean version
EpsilonPrime 320053c
Cleaned merge.
EpsilonPrime 125a8cb
Updated based on review.
EpsilonPrime db12b3d
Use int32 instead of uint32 for the buffer length for increased porta…
EpsilonPrime 12b54fe
More tidyness.
EpsilonPrime 3d1e40e
Try making everything position independent.
EpsilonPrime e49c11a
Be more explicit about what needs position independent code.
EpsilonPrime 00de8bc
Try another way to force PIC.
EpsilonPrime e754a1c
Handle an impossible error to make a warning go away.
EpsilonPrime 1b191ea
Overly force -fPIC everywhere for now.
EpsilonPrime f5ce243
Fix new/free mismatch.
EpsilonPrime 755c4ef
Fix delete.
EpsilonPrime c28f6f0
Apparently delete doesn't need to worry about nullptr so removing thi…
EpsilonPrime dac8ea9
Removed one unnecessary fPIC setting.
EpsilonPrime 5c3d5f2
Removed some more unnecessary fPIC settings.
EpsilonPrime dd6b5c3
and one more
EpsilonPrime 8fc79fb
One last cleanup.
EpsilonPrime 7f8a7da
Update export/planloader/planloader.h
EpsilonPrime fbe9231
Various review changes.
EpsilonPrime e487313
Added error test case.
EpsilonPrime 8ea2556
fix tidy warning
EpsilonPrime 0d0246d
Added error test case.
EpsilonPrime 06cd5c9
Switch save_plan to also use int32_t.
EpsilonPrime 9be359b
Fix path used for output files.
EpsilonPrime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -49,3 +49,4 @@ if(${SUBSTRAIT_CPP_BUILD_TESTING}) | |
endif() | ||
|
||
add_subdirectory(src/substrait) | ||
add_subdirectory(export) |
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,3 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory(planloader) |
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,24 @@ | ||
# 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) | ||
EpsilonPrime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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() |
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,62 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
#include "planloader.h" | ||
|
||
#include <substrait/common/Io.h> | ||
|
||
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" |
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,35 @@ | ||||||
/* SPDX-License-Identifier: Apache-2.0 */ | ||||||
|
||||||
#include <substrait/common/Io.h> | ||||||
|
||||||
extern "C" { | ||||||
|
||||||
using SerializedPlan = struct { | ||||||
char *buffer; | ||||||
uint32_t size; | ||||||
char *errorMessage; | ||||||
EpsilonPrime marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}; | ||||||
|
||||||
// Since this is actually C code, stick to C style names for exporting. | ||||||
// NOLINTBEGIN(readability-identifier-naming) | ||||||
EpsilonPrime marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
// Load a Substrait plan (in any format) from disk. | ||||||
// Stores the Substrait plan in planBuffer in serialized form. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// Returns a SerializedPlan structure containing either the serialized plan or | ||||||
// an error message. | ||||||
SerializedPlan* load_substrait_plan(const char* filename); | ||||||
EpsilonPrime marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
void free_substrait_plan(SerializedPlan* plan); | ||||||
EpsilonPrime marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
// 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, | ||||||
EpsilonPrime marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
uint32_t planDataLength, | ||||||
const char* filename, | ||||||
io::substrait::PlanFileFormat format); | ||||||
|
||||||
// NOLINTEND(readability-identifier-naming) | ||||||
|
||||||
} // 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,35 @@ | ||
# 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); | ||
} | ||
EpsilonPrime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} // namespace | ||
} // namespace io::substrait::textplan |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? Does this mean you can't build the planloader in debug mode (annoying but ok)? Or does this mean that someone linking to the planloader cannot build in debug (probably an issue)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is all of the sanitization stuff that we're including in debug mode. An unfettered debug mode would be fine.