This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/main by this push:
     new bc26ff840 ORC-1884: [C++] Add a maybe() API to the 
SearchArgumentBuilder
bc26ff840 is described below

commit bc26ff840a702c6f4f7faf1c6e3d3f69be2126b0
Author: luffy-zh <[email protected]>
AuthorDate: Mon Jun 30 08:33:42 2025 -0700

    ORC-1884: [C++] Add a maybe() API to the SearchArgumentBuilder
    
    ### What changes were proposed in this pull request?
    
    Add a maybe() API to the SearchArgumentBuilder to allow the insertion of an 
expression tree that is currently unsupported.
    
    ### Why are the changes needed?
    
    To enhance the SearchArgumentBuilder API with a new method called maybe(), 
we can create a SearchArgument tree for scenarios that may not be adequately 
addressed by existing methods.
    
    ### How was this patch tested?
    
    Uts in TestSearchArgument.cc can cover this patch.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    NO
    
    Closes #2207 from luffy-zh/ORC-1884.
    
    Authored-by: luffy-zh <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 c++/include/orc/sargs/SearchArgument.hh |  6 ++++++
 c++/src/sargs/SearchArgument.cc         |  6 ++++++
 c++/src/sargs/SearchArgument.hh         |  6 ++++++
 c++/test/TestSearchArgument.cc          | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+)

diff --git a/c++/include/orc/sargs/SearchArgument.hh 
b/c++/include/orc/sargs/SearchArgument.hh
index 6493840a9..2fa3ea04c 100644
--- a/c++/include/orc/sargs/SearchArgument.hh
+++ b/c++/include/orc/sargs/SearchArgument.hh
@@ -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;
   };
 
   /**
diff --git a/c++/src/sargs/SearchArgument.cc b/c++/src/sargs/SearchArgument.cc
index 83d4af243..ff0ba1e2d 100644
--- a/c++/src/sargs/SearchArgument.cc
+++ b/c++/src/sargs/SearchArgument.cc
@@ -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.
diff --git a/c++/src/sargs/SearchArgument.hh b/c++/src/sargs/SearchArgument.hh
index 1963c993d..7d663f734 100644
--- a/c++/src/sargs/SearchArgument.hh
+++ b/c++/src/sargs/SearchArgument.hh
@@ -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);
diff --git a/c++/test/TestSearchArgument.cc b/c++/test/TestSearchArgument.cc
index e51ee1e8b..09904139c 100644
--- a/c++/test/TestSearchArgument.cc
+++ b/c++/test/TestSearchArgument.cc
@@ -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

Reply via email to