-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the plantransformer tool to convert from any plan format to the …
…specified format.
- Loading branch information
1 parent
e3ba635
commit 0acac77
Showing
2 changed files
with
74 additions
and
15 deletions.
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
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,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; | ||
} |