Skip to content
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

fix: support both old and new versions of protobuf #79

Merged
merged 18 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ option(
"Enable substrait-cpp tests. This will enable all other build options automatically."
ON)

find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})

add_subdirectory(third_party)
# Local files come first.
include_directories(include)
include_directories(src)

add_subdirectory(third_party)

find_package(Protobuf QUIET CONFIG)
if(NOT ${Protobuf_FOUND})
find_package(Protobuf REQUIRED)
EpsilonPrime marked this conversation as resolved.
Show resolved Hide resolved
include_directories(${Protobuf_INCLUDE_DIRS})
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
include(BuildUtils)

Expand Down
1 change: 1 addition & 0 deletions scripts/setup-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sudo --preserve-env apt install -y \
libprotobuf-dev \
libprotobuf23 \
protobuf-compiler \
libabsl-dev \
clang-format \
uuid-dev \
default-jre \
Expand Down
2 changes: 0 additions & 2 deletions src/substrait/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

find_package(fmt)

add_library(substrait_common Exceptions.cpp)

target_link_libraries(substrait_common fmt::fmt-header-only)
Expand Down
2 changes: 1 addition & 1 deletion src/substrait/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ add_library(substrait_proto ${PROTO_SRCS} ${PROTO_HDRS} ProtoUtils.cpp
ProtoUtils.h)

# Include the protobuf library as a dependency to use this class.
target_link_libraries(substrait_proto ${PROTOBUF_LIBRARIES})
target_link_libraries(substrait_proto protobuf::libprotobuf)

# Make sure we can see our own generated include files.
target_include_directories(substrait_proto
Expand Down
5 changes: 3 additions & 2 deletions src/substrait/textplan/converter/LoadBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ PlanOrErrors loadFromJson(std::string_view json) {
auto status = google::protobuf::util::JsonStringToMessage(
std::string{usableJson}, &plan);
if (!status.ok()) {
return PlanOrErrors({fmt::format(
"Failed to parse Substrait JSON: {}", status.message().ToString())});
std::string msg{status.message()};
return PlanOrErrors(
{fmt::format("Failed to parse Substrait JSON: {}", msg)});
}
return PlanOrErrors(plan);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,7 @@ std::any SubstraitPlanRelationVisitor::visitExpressionFunctionUse(
expr.mutable_scalar_function()->set_function_reference(funcReference);
for (const auto& exp : ctx->expression()) {
if (endsWith(exp->getText(), "_enum")) {
auto str = exp->getText();
str = absl::StripSuffix(str, "_enum");
std::string str{absl::StripSuffix(exp->getText(), "_enum")};
expr.mutable_scalar_function()->add_arguments()->set_enum_(str);
continue;
}
Expand Down
1 change: 0 additions & 1 deletion src/substrait/textplan/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ if(${SUBSTRAIT_CPP_ROUNDTRIP_TESTING})
parse_result_matchers
protobuf-matchers
fmt::fmt-header-only
absl::strings
gmock
gtest
gtest_main)
Expand Down
8 changes: 4 additions & 4 deletions src/substrait/textplan/tests/RoundtripTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <gtest/gtest.h>
#include <protobuf-matchers/protocol-buffer-matchers.h>

#include "absl/strings/str_split.h"
#include "gmock/gmock.h"
#include "substrait/textplan/SymbolTablePrinter.h"
#include "substrait/textplan/converter/LoadBinary.h"
#include "substrait/textplan/converter/ParseBinary.h"
Expand All @@ -28,10 +26,12 @@ namespace io::substrait::textplan {
namespace {

std::string addLineNumbers(const std::string& text) {
std::stringstream input{text};
std::stringstream result;
int lineNum = 0;
for (absl::string_view sp : absl::StrSplit(text, '\n')) {
result << std::setw(4) << ++lineNum << " " << sp << std::endl;
std::string line;
while (std::getline(input, line, '\n')) {
result << std::setw(4) << ++lineNum << " " << line << std::endl;
}
return result.str();
}
Expand Down
2 changes: 1 addition & 1 deletion third_party/abseil-cpp