Skip to content

Commit

Permalink
feat: fields, schemas, and sources binary output for the textplan par…
Browse files Browse the repository at this point in the history
…ser (#66)

* Fields are now emitted in expressions completing expression handling.
    * Schemas and sources are also now implemented.
* Removes projection as a relation detail in favor of expression for
project relations.
  • Loading branch information
EpsilonPrime committed Jun 7, 2023
1 parent d995094 commit 62b4a72
Show file tree
Hide file tree
Showing 13 changed files with 345 additions and 104 deletions.
6 changes: 3 additions & 3 deletions src/substrait/textplan/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ bool std::less<::io::substrait::textplan::Location>::operator()(
const ::io::substrait::textplan::Location& rhs) const noexcept {
if (std::holds_alternative<antlr4::ParserRuleContext*>(lhs.loc_)) {
if (!std::holds_alternative<antlr4::ParserRuleContext*>(rhs.loc_)) {
// This alternative is always less than the remaining choices.
// This alternative is always less than the other location types.
return true;
}
return std::get<antlr4::ParserRuleContext*>(lhs.loc_) <
std::get<antlr4::ParserRuleContext*>(rhs.loc_);
} else if (std::holds_alternative<const google::protobuf::Message*>(
lhs.loc_)) {
if (!std::holds_alternative<const google::protobuf::Message*>(rhs.loc_)) {
// This alternative is always less than the remaining (zero) choices.
return true;
// This alternative is always more than the other location types.
return false;
}
return std::get<const google::protobuf::Message*>(lhs.loc_) <
std::get<const google::protobuf::Message*>(rhs.loc_);
Expand Down
4 changes: 4 additions & 0 deletions src/substrait/textplan/Location.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class Location {
protected:
friend bool operator==(const Location& c1, const Location& c2);

friend bool operator!=(const Location& c1, const Location& c2) {
return !(c1 == c2);
}

private:
friend std::hash<Location>;
friend std::less<Location>;
Expand Down
1 change: 0 additions & 1 deletion src/substrait/textplan/StructuredSymbolData.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <optional>

#include "substrait/proto/algebra.pb.h"
#include "substrait/textplan/Location.h"

namespace io::substrait::textplan {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

#include <gmock/gmock-matchers.h>
#include <gtest/gtest.h>
#include <protobuf-matchers/protocol-buffer-matchers.h>

#include "substrait/textplan/converter/LoadBinary.h"
#include "substrait/textplan/converter/ParseBinary.h"
#include "substrait/textplan/tests/ParseResultMatchers.h"

namespace io::substrait::textplan {

using ::protobuf_matchers::EqualsProto;
using ::protobuf_matchers::Partially;
using ::testing::AllOf;
using ::testing::Eq;

namespace {
Expand Down Expand Up @@ -158,7 +162,13 @@ std::vector<TestCase> getTestCases() {
items = [
{uri_file: "/mock_lineitem.orc" start: 0 length: 3719 orc: {}}
]
})"))),
})")),
AsBinaryPlan(EqualsProto<::substrait::proto::Plan>(
R"(relations { root { input { read {
local_files
{ items { uri_file: "/mock_lineitem.orc" length: 3719 orc { } } }
}
} } })"))),
},
{
"read named table",
Expand Down
1 change: 1 addition & 0 deletions src/substrait/textplan/converter/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_test_case(
substrait_textplan_converter
substrait_common
parse_result_matchers
protobuf-matchers
gmock
gtest
gtest_main)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool continuingPipelineContains(
void SubstraitPlanPipelineVisitor::updateRelationSymbol(
SubstraitPlanParser::PipelineContext* ctx,
const std::string& relationName) {
const auto& symbol = symbolTable_->lookupSymbolByName(relationName);
const auto* symbol = symbolTable_->lookupSymbolByName(relationName);
if (symbol == nullptr) {
// This is a reference to a missing relation so we create a stub for it.
auto relationData = std::make_shared<RelationData>();
Expand Down Expand Up @@ -78,7 +78,7 @@ std::any SubstraitPlanPipelineVisitor::visitPipeline(
}

// Refetch our symbol table entry to make sure we have the latest version.
auto symbol = symbolTable_->lookupSymbolByName(relationName);
auto* symbol = symbolTable_->lookupSymbolByName(relationName);
auto relationData = ANY_CAST(std::shared_ptr<RelationData>, symbol->blob);

// Check for accidental cross-pipeline use.
Expand Down
Loading

0 comments on commit 62b4a72

Please sign in to comment.