Skip to content

ORC-1884: [C++] Add a maybe() API to the SearchArgumentBuilder #2207

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions c++/include/orc/sargs/SearchArgument.hh
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ namespace orc {
* @return the new SearchArgument
*/
virtual std::unique_ptr<SearchArgument> build() = 0;

/**
* Add a maybe leaf to the current item on the stack.
* @return this
*/
virtual SearchArgumentBuilder& maybe() = 0;
};

/**
Expand Down
6 changes: 6 additions & 0 deletions c++/src/sargs/SearchArgument.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ namespace orc {
return *this;
}

SearchArgumentBuilder& SearchArgumentBuilderImpl::maybe() {
TreeNode& parent = currTree_.front();
parent->addChild(std::make_shared<ExpressionTree>(TruthValue::YES_NO_NULL));
return *this;
}

/**
* Recursively explore the tree to find the leaves that are still reachable
* after optimizations.
Expand Down
6 changes: 6 additions & 0 deletions c++/src/sargs/SearchArgument.hh
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ namespace orc {
*/
std::unique_ptr<SearchArgument> build() override;

/**
* Add a maybe leaf to the current item on the stack.
* @return this
*/
SearchArgumentBuilder& maybe() override;

private:
SearchArgumentBuilder& start(ExpressionTree::Operator op);
size_t addLeaf(PredicateLeaf leaf);
Expand Down
32 changes: 32 additions & 0 deletions c++/test/TestSearchArgument.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,36 @@ namespace orc {
EXPECT_THROW(invalidNode->evaluate(leaves), std::invalid_argument);
}

TEST(TestSearchArgument, testMaybe) {
auto expectedSarg =
SearchArgumentFactory::newBuilder()
->startNot()
.startOr()
.isNull("x", PredicateDataType::LONG)
.between("y", PredicateDataType::DECIMAL, Literal(10, 3, 0), Literal(200, 3, 1))
.in("z", PredicateDataType::LONG,
{Literal(static_cast<int64_t>(1)), Literal(static_cast<int64_t>(2)),
Literal(static_cast<int64_t>(3))})
.nullSafeEquals("a", PredicateDataType::STRING, Literal("stinger", 7))
.end()
.end()
.build();

auto sargWithMaybe =
SearchArgumentFactory::newBuilder()
->startNot()
.startOr()
.isNull("x", PredicateDataType::LONG)
.between("y", PredicateDataType::DECIMAL, Literal(10, 3, 0), Literal(200, 3, 1))
.in("z", PredicateDataType::LONG,
{Literal(static_cast<int64_t>(1)), Literal(static_cast<int64_t>(2)),
Literal(static_cast<int64_t>(3))})
.maybe()
.nullSafeEquals("a", PredicateDataType::STRING, Literal("stinger", 7))
.end()
.end()
.build();
EXPECT_EQ(expectedSarg->toString(), sargWithMaybe->toString());
}

} // namespace orc
Loading