You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by do...@apache.org on 2021/08/29 02:46:26 UTC
[orc] branch branch-1.7 updated: ORC-973: [C++] Support providing
IN-predicate literals using vector (#884)
This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch branch-1.7
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/branch-1.7 by this push:
new 2667f29 ORC-973: [C++] Support providing IN-predicate literals using vector (#884)
2667f29 is described below
commit 2667f2996b75e879e52365edfd06b05da4eda941
Author: Quanlong Huang <hu...@gmail.com>
AuthorDate: Sun Aug 29 10:45:53 2021 +0800
ORC-973: [C++] Support providing IN-predicate literals using vector (#884)
### What changes were proposed in this pull request?
Add two more interfaces for creating IN-predicate literals using vector. This provide more flexibility that doesn't requires callers know the list size at compilation time.
### Why are the changes needed?
Described as above.
### How was this patch tested?
Add unit test in c++/test/TestPredicateLeaf.cc
(cherry picked from commit d108f774f59642d4829d0a0a853be65236cc0d09)
Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
c++/include/orc/sargs/SearchArgument.hh | 22 ++++++++++++++++++++++
c++/src/sargs/PredicateLeaf.cc | 26 ++++++++++++++++++++++++++
c++/src/sargs/PredicateLeaf.hh | 10 ++++++++++
c++/src/sargs/SearchArgument.cc | 16 ++++++++++++++--
c++/src/sargs/SearchArgument.hh | 26 ++++++++++++++++++++++++--
c++/test/TestPredicateLeaf.cc | 19 +++++++++++++++++++
6 files changed, 115 insertions(+), 4 deletions(-)
diff --git a/c++/include/orc/sargs/SearchArgument.hh b/c++/include/orc/sargs/SearchArgument.hh
index 48796cb..44fde8f 100644
--- a/c++/include/orc/sargs/SearchArgument.hh
+++ b/c++/include/orc/sargs/SearchArgument.hh
@@ -191,6 +191,28 @@ namespace orc {
const std::initializer_list<Literal>& literals) = 0;
/**
+ * Add an in leaf to the current item on the stack.
+ * @param column the field name of the column
+ * @param type the type of the expression
+ * @param literals the literals
+ * @return this
+ */
+ virtual SearchArgumentBuilder& in(const std::string& column,
+ PredicateDataType type,
+ const std::vector<Literal>& literals) = 0;
+
+ /**
+ * Add an in leaf to the current item on the stack.
+ * @param columnId the column id of the column
+ * @param type the type of the expression
+ * @param literals the literals
+ * @return this
+ */
+ virtual SearchArgumentBuilder& in(uint64_t columnId,
+ PredicateDataType type,
+ const std::vector<Literal>& literals) = 0;
+
+ /**
* Add an is null leaf to the current item on the stack.
* @param column the field name of the column
* @param type the type of the expression
diff --git a/c++/src/sargs/PredicateLeaf.cc b/c++/src/sargs/PredicateLeaf.cc
index 7260c9d..5854118 100644
--- a/c++/src/sargs/PredicateLeaf.cc
+++ b/c++/src/sargs/PredicateLeaf.cc
@@ -81,6 +81,32 @@ namespace orc {
validate();
}
+ PredicateLeaf::PredicateLeaf(Operator op,
+ PredicateDataType type,
+ const std::string& colName,
+ const std::vector<Literal>& literals)
+ : mOperator(op)
+ , mType(type)
+ , mColumnName(colName)
+ , mHasColumnName(true)
+ , mLiterals(literals.begin(), literals.end()) {
+ mHashCode = hashCode();
+ validate();
+ }
+
+ PredicateLeaf::PredicateLeaf(Operator op,
+ PredicateDataType type,
+ uint64_t columnId,
+ const std::vector<Literal>& literals)
+ : mOperator(op)
+ , mType(type)
+ , mHasColumnName(false)
+ , mColumnId(columnId)
+ , mLiterals(literals.begin(), literals.end()) {
+ mHashCode = hashCode();
+ validate();
+ }
+
void PredicateLeaf::validateColumn() const {
if (mHasColumnName && mColumnName.empty()) {
throw std::invalid_argument("column name should not be empty");
diff --git a/c++/src/sargs/PredicateLeaf.hh b/c++/src/sargs/PredicateLeaf.hh
index 298470b..99791cf 100644
--- a/c++/src/sargs/PredicateLeaf.hh
+++ b/c++/src/sargs/PredicateLeaf.hh
@@ -86,6 +86,16 @@ namespace orc {
uint64_t columnId,
const std::initializer_list<Literal>& literalList);
+ PredicateLeaf(Operator op,
+ PredicateDataType type,
+ const std::string& colName,
+ const std::vector<Literal>& literalList);
+
+ PredicateLeaf(Operator op,
+ PredicateDataType type,
+ uint64_t columnId,
+ const std::vector<Literal>& literalList);
+
/**
* Get the operator for the leaf.
*/
diff --git a/c++/src/sargs/SearchArgument.cc b/c++/src/sargs/SearchArgument.cc
index 400b40f..ceb56be 100644
--- a/c++/src/sargs/SearchArgument.cc
+++ b/c++/src/sargs/SearchArgument.cc
@@ -191,10 +191,10 @@ namespace orc {
PredicateLeaf::Operator::NULL_SAFE_EQUALS, columnId, type, literal);
}
- template<typename T>
+ template<typename T, typename CONTAINER>
SearchArgumentBuilder& SearchArgumentBuilderImpl::addChildForIn(T column,
PredicateDataType type,
- const std::initializer_list<Literal>& literals) {
+ const CONTAINER& literals) {
TreeNode &parent = mCurrTree.front();
if (isInvalidColumn(column)) {
parent->addChild(
@@ -223,6 +223,18 @@ namespace orc {
return addChildForIn(columnId, type, literals);
}
+ SearchArgumentBuilder& SearchArgumentBuilderImpl::in(const std::string& column,
+ PredicateDataType type,
+ const std::vector<Literal>& literals) {
+ return addChildForIn(column, type, literals);
+ }
+
+ SearchArgumentBuilder& SearchArgumentBuilderImpl::in(uint64_t columnId,
+ PredicateDataType type,
+ const std::vector<Literal>& literals) {
+ return addChildForIn(columnId, type, literals);
+ }
+
template<typename T>
SearchArgumentBuilder& SearchArgumentBuilderImpl::addChildForIsNull(T column, PredicateDataType type) {
TreeNode& parent = mCurrTree.front();
diff --git a/c++/src/sargs/SearchArgument.hh b/c++/src/sargs/SearchArgument.hh
index b2426f3..57d765e 100644
--- a/c++/src/sargs/SearchArgument.hh
+++ b/c++/src/sargs/SearchArgument.hh
@@ -214,6 +214,28 @@ namespace orc {
const std::initializer_list<Literal>& literals) override;
/**
+ * Add an in leaf to the current item on the stack.
+ * @param column the field name of the column
+ * @param type the type of the expression
+ * @param literals the literals
+ * @return this
+ */
+ SearchArgumentBuilder& in(const std::string& column,
+ PredicateDataType type,
+ const std::vector<Literal>& literals) override;
+
+ /**
+ * Add an in leaf to the current item on the stack.
+ * @param columnId the column id of the column
+ * @param type the type of the expression
+ * @param literals the literals
+ * @return this
+ */
+ SearchArgumentBuilder& in(uint64_t columnId,
+ PredicateDataType type,
+ const std::vector<Literal>& literals) override;
+
+ /**
* Add an is null leaf to the current item on the stack.
* @param column the field name of the column
* @param type the type of the expression
@@ -284,10 +306,10 @@ namespace orc {
PredicateDataType type,
Literal literal);
- template<typename T>
+ template<typename T, typename CONTAINER>
SearchArgumentBuilder& addChildForIn(T column,
PredicateDataType type,
- const std::initializer_list<Literal>& literals);
+ const CONTAINER& literals);
template<typename T>
SearchArgumentBuilder& addChildForIsNull(T column,
diff --git a/c++/test/TestPredicateLeaf.cc b/c++/test/TestPredicateLeaf.cc
index deb7eef..7ab21a3 100644
--- a/c++/test/TestPredicateLeaf.cc
+++ b/c++/test/TestPredicateLeaf.cc
@@ -400,6 +400,25 @@ namespace orc {
evaluate(pred, createIntStats(10L, 30L, true)));
EXPECT_EQ(TruthValue::NO_NULL,
evaluate(pred, createIntStats(12L, 18L, true)));
+
+ std::vector<Literal> inList{
+ static_cast<int64_t>(10),
+ static_cast<int64_t>(15),
+ static_cast<int64_t>(20)
+ };
+ PredicateLeaf pred2(
+ PredicateLeaf::Operator::IN,
+ PredicateDataType::LONG,
+ "y",
+ inList);
+ EXPECT_EQ(TruthValue::YES_NULL,
+ evaluate(pred2, createIntStats(20L, 20L, true)));
+ EXPECT_EQ(TruthValue::NO_NULL,
+ evaluate(pred2, createIntStats(12L, 14L, true)));
+ EXPECT_EQ(TruthValue::NO_NULL,
+ evaluate(pred2, createIntStats(16L, 19L, true)));
+ EXPECT_EQ(TruthValue::YES_NO_NULL,
+ evaluate(pred2, createIntStats(12L, 18L, true)));
}
TEST(TestPredicateLeaf, testBetween) {