From 0903f747a5ceeea671dea8f3d6af02f9ed2e3f97 Mon Sep 17 00:00:00 2001 From: David Sisson Date: Wed, 26 Jul 2023 17:18:10 -0700 Subject: [PATCH] Updated Google save methods to use creat. --- src/substrait/common/Io.cpp | 4 +++- src/substrait/common/tests/IoTest.cpp | 1 + .../textplan/converter/CMakeLists.txt | 3 ++- .../textplan/converter/SaveBinary.cpp | 21 +++++++++++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/substrait/common/Io.cpp b/src/substrait/common/Io.cpp index 7055160c..69d61cf8 100644 --- a/src/substrait/common/Io.cpp +++ b/src/substrait/common/Io.cpp @@ -13,8 +13,10 @@ namespace io::substrait { namespace { +// TODO - Avoid capturing. const std::regex kIsJson(R"(("extensionUris"|"extensions"|"relations"))"); -const std::regex kIsProtoText(R"(potatoes)"); +const std::regex kIsProtoText( + R"((^|\n)((relations|extensions|extension_uris|expected_type_urls) \{))"); const std::regex kIsText( R"((^|\n) *(pipelines|[a-z]+ *relation|schema|source|extension_space) *)"); diff --git a/src/substrait/common/tests/IoTest.cpp b/src/substrait/common/tests/IoTest.cpp index eec65562..157cc5cf 100644 --- a/src/substrait/common/tests/IoTest.cpp +++ b/src/substrait/common/tests/IoTest.cpp @@ -65,6 +65,7 @@ TEST_P(SaveAndLoadTestFixture, SaveAndLoad) { ::substrait::proto::Plan plan; auto root = plan.add_relations()->mutable_root(); auto read = root->mutable_input()->mutable_read(); + read->mutable_common()->mutable_direct(); read->mutable_named_table()->add_names("table_name"); auto status = ::io::substrait::savePlan(plan, tempFilename, encoding); ASSERT_TRUE(status.ok()) << "Save failed.\n" << status; diff --git a/src/substrait/textplan/converter/CMakeLists.txt b/src/substrait/textplan/converter/CMakeLists.txt index 72a28966..5c7ae9ac 100644 --- a/src/substrait/textplan/converter/CMakeLists.txt +++ b/src/substrait/textplan/converter/CMakeLists.txt @@ -26,7 +26,8 @@ target_link_libraries( substrait_proto symbol_table error_listener - date::date) + date::date + fmt::fmt-header-only) if(${SUBSTRAIT_CPP_BUILD_TESTING}) add_subdirectory(tests) diff --git a/src/substrait/textplan/converter/SaveBinary.cpp b/src/substrait/textplan/converter/SaveBinary.cpp index 656ad3bf..dc7a9ff9 100644 --- a/src/substrait/textplan/converter/SaveBinary.cpp +++ b/src/substrait/textplan/converter/SaveBinary.cpp @@ -2,6 +2,7 @@ #include "substrait/textplan/converter/SaveBinary.h" +#include #include #include #include @@ -17,9 +18,11 @@ absl::Status savePlanToBinary( const ::substrait::proto::Plan& plan, const std::string_view& output_filename) { int outputFileDescriptor = - open(std::string{output_filename}.c_str(), O_WRONLY); + creat(std::string{output_filename}.c_str(), S_IREAD | S_IWRITE); if (outputFileDescriptor == -1) { - return absl::ErrnoToStatus(errno, "Failed to open file for writing"); + return absl::ErrnoToStatus( + errno, + fmt::format("Failed to open file {} for writing", output_filename)); } auto stream = new google::protobuf::io::FileOutputStream(outputFileDescriptor); @@ -37,7 +40,12 @@ absl::Status savePlanToJson( const ::substrait::proto::Plan& plan, const std::string_view& output_filename) { int outputFileDescriptor = - open(std::string{output_filename}.c_str(), O_WRONLY); + creat(std::string{output_filename}.c_str(), S_IREAD | S_IWRITE); + if (outputFileDescriptor == -1) { + return absl::ErrnoToStatus( + errno, + fmt::format("Failed to open file {} for writing", output_filename)); + } auto stream = new google::protobuf::io::FileOutputStream(outputFileDescriptor); @@ -76,7 +84,12 @@ absl::Status savePlanToProtoText( const ::substrait::proto::Plan& plan, const std::string_view& output_filename) { int outputFileDescriptor = - open(std::string{output_filename}.c_str(), O_WRONLY); + creat(std::string{output_filename}.c_str(), S_IREAD | S_IWRITE); + if (outputFileDescriptor == -1) { + return absl::ErrnoToStatus( + errno, + fmt::format("Failed to open file {} for writing", output_filename)); + } auto stream = new google::protobuf::io::FileOutputStream(outputFileDescriptor);