Skip to content

Commit

Permalink
Switched back to string from string_view to make it easier to use Goo…
Browse files Browse the repository at this point in the history
…gle's zero copy stream.
  • Loading branch information
EpsilonPrime committed Jul 27, 2023
1 parent 4526df7 commit f6ed071
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/substrait/common/Io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PlanFileEncoding detectEncoding(std::string_view content) {

absl::StatusOr<::substrait::proto::Plan> loadPlanWithUnknownEncoding(
std::string_view input_filename) {
auto contentOrError = textplan::readFromFile(input_filename);
auto contentOrError = textplan::readFromFile(input_filename.data());
if (!contentOrError.ok()) {
return contentOrError.status();
}
Expand Down
1 change: 1 addition & 0 deletions src/substrait/common/tests/IoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ constexpr const char* planFileEncodingToString(PlanFileEncoding e) noexcept {
case PlanFileEncoding::kText:
return "kText";
}
return "IMPOSSIBLE";
}

} // namespace
Expand Down
6 changes: 3 additions & 3 deletions src/substrait/textplan/converter/LoadBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ absl::StatusOr<std::string> readFromFile(std::string_view msgPath) {
return buffer.str();
}

absl::StatusOr<::substrait::proto::Plan> loadFromJson(std::string_view json) {
absl::StatusOr<::substrait::proto::Plan> loadFromJson(const std::string& json) {
if (json.empty()) {
return absl::InternalError("Provided JSON string was empty.");
}
Expand All @@ -76,7 +76,7 @@ absl::StatusOr<::substrait::proto::Plan> loadFromJson(std::string_view json) {
}

absl::StatusOr<::substrait::proto::Plan> loadFromProtoText(
std::string_view text) {
const std::string& text) {
::substrait::proto::Plan plan;
::google::protobuf::TextFormat::Parser parser;
StringErrorCollector collector;
Expand All @@ -89,7 +89,7 @@ absl::StatusOr<::substrait::proto::Plan> loadFromProtoText(
}

absl::StatusOr<::substrait::proto::Plan> loadFromBinary(
std::string_view bytes) {
const std::string& bytes) {
::substrait::proto::Plan plan;
if (!plan.ParseFromString(bytes)) {
return absl::InternalError("Failed to parse as a binary Substrait plan.");
Expand Down
7 changes: 4 additions & 3 deletions src/substrait/textplan/converter/LoadBinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ absl::StatusOr<std::string> readFromFile(std::string_view msgPath);

// Reads a plan from a json-encoded text proto.
// Returns a list of errors if the file cannot be parsed.
absl::StatusOr<::substrait::proto::Plan> loadFromJson(std::string_view json);
absl::StatusOr<::substrait::proto::Plan> loadFromJson(const std::string& json);

// Reads a plan encoded as a text protobuf.
// Returns a list of errors if the file cannot be parsed.
absl::StatusOr<::substrait::proto::Plan> loadFromProtoText(
std::string_view text);
const std::string& text);

// Reads a plan serialized as a binary protobuf.
// Returns a list of errors if the file cannot be parsed.
absl::StatusOr<::substrait::proto::Plan> loadFromBinary(std::string_view bytes);
absl::StatusOr<::substrait::proto::Plan> loadFromBinary(
const std::string& bytes);

} // namespace io::substrait::textplan
2 changes: 1 addition & 1 deletion src/substrait/textplan/parser/LoadText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace io::substrait::textplan {

absl::StatusOr<::substrait::proto::Plan> loadFromText(std::string_view text) {
absl::StatusOr<::substrait::proto::Plan> loadFromText(const std::string& text) {
auto stream = loadTextString(text);
auto parseResult = io::substrait::textplan::parseStream(stream);
if (!parseResult.successful()) {
Expand Down
3 changes: 1 addition & 2 deletions src/substrait/textplan/parser/LoadText.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#pragma once

#include <absl/status/statusor.h>
#include <string_view>

namespace substrait::proto {
class Plan;
Expand All @@ -13,6 +12,6 @@ namespace io::substrait::textplan {

// Reads a plan encoded as a text protobuf.
// Returns a list of errors if the text cannot be parsed.
absl::StatusOr<::substrait::proto::Plan> loadFromText(std::string_view text);
absl::StatusOr<::substrait::proto::Plan> loadFromText(const std::string& text);

} // namespace io::substrait::textplan

0 comments on commit f6ed071

Please sign in to comment.