Skip to content

Commit

Permalink
Merge branch 'substrait-io:main' into fix_cmake_targets
Browse files Browse the repository at this point in the history
  • Loading branch information
EpsilonPrime committed Mar 15, 2024
2 parents fd893da + 3f84014 commit 5f7b386
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ jobs:
with:
submodules: recursive
- name: Setup Ubuntu
run: ./scripts/setup-ubuntu.sh
- run: mkdir build
run: |
./scripts/setup-ubuntu.sh
mkdir build
- name: Run cmake
run: cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TZ_LIB=ON
run: |
cmake --version
cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TZ_LIB=ON
- name: Build
run: ninja -C build
- name: Test
run: ctest --test-dir build --output-on-failure
run: ctest --test-dir build --output-on-failure --timeout 30

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

option(SUBSTRAIT_CPP_SANITIZE_DEBUG_BUILD
"Turns on address and undefined memory sanitization runtime checking."
ON)
OFF)

if(${SUBSTRAIT_CPP_SANITIZE_DEBUG_BUILD})
add_compile_options($<$<CONFIG:Debug>:-fsanitize=undefined>)
Expand Down
7 changes: 0 additions & 7 deletions export/planloader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

if(CMAKE_BUILD_TYPE MATCHES Debug)
message(
WARNING
"The planloader library does not work well in Debug mode due to bundled heap checking."
)
endif()

add_library(planloader SHARED planloader.cpp)

add_dependencies(planloader substrait_io)
Expand Down
4 changes: 4 additions & 0 deletions src/substrait/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ endif()
install(TARGETS substrait_io LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ../../../include/substrait/common/Io.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/substrait/common")

add_executable(plantransformer PlanTransformerTool.cpp)

target_link_libraries(plantransformer substrait_io)
54 changes: 54 additions & 0 deletions src/substrait/common/PlanTransformerTool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <iostream>

#include "substrait/common/Io.h"

namespace io::substrait {
namespace {

PlanFileFormat planFileFormatFromText(std::string_view str) {
std::string foo;
foo.resize(str.size());
std::transform(str.begin(), str.end(), foo.begin(), [](unsigned char c) {
return std::tolower(c);
});
if (foo == "binary") {
return PlanFileFormat::kBinary;
} else if (foo == "json") {
return PlanFileFormat::kJson;
} else if (foo == "prototext") {
return PlanFileFormat::kProtoText;
} else if (foo == "text") {
return PlanFileFormat::kText;
}
// If the format can't be understood, default to text.
return PlanFileFormat::kText;
}

} // namespace
} // namespace io::substrait

int main(int argc, char* argv[]) {
if (argc <= 3) {
printf(
"Usage: plantransformer <inputfilename> <outputfilename> [BINARY|JSON|PROTOTEXT|TEXT]\n");
return EXIT_FAILURE;
}

auto planOrError = io::substrait::loadPlan(argv[1]);
if (!planOrError.ok()) {
std::cerr << planOrError.status() << std::endl;
return EXIT_FAILURE;
}

auto format = io::substrait::planFileFormatFromText(argv[3]);

auto result = io::substrait::savePlan(*planOrError, argv[2], format);
if (!result.ok()) {
std::cerr << result << std::endl;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

0 comments on commit 5f7b386

Please sign in to comment.