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

yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.2 by this push:
     new 35f2462761b branch-4.2: [improvement](be) Iterate JSONB arrays 
linearly in json functions #69059 (#69098)
35f2462761b is described below

commit 35f2462761b151b1611706217fd2989163cd5c36
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Oct 15 19:04:00 2026 +0800

    branch-4.2: [improvement](be) Iterate JSONB arrays linearly in json 
functions #69059 (#69098)
    
    Cherry-picked from #69059
    
    Co-authored-by: Hail <[email protected]>
---
 be/src/exprs/function/function_jsonb.cpp | 15 ++++++++-------
 be/src/util/jsonb_document.h             | 10 ++++------
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/be/src/exprs/function/function_jsonb.cpp 
b/be/src/exprs/function/function_jsonb.cpp
index bfee90dc1a9..3b5b9d4417e 100644
--- a/be/src/exprs/function/function_jsonb.cpp
+++ b/be/src/exprs/function/function_jsonb.cpp
@@ -2186,8 +2186,9 @@ public:
         if (root->isArray()) {
             writer.writeStartArray();
             const auto* array_val = root->unpack<ArrayVal>();
-            for (int i = 0; i != array_val->numElem(); ++i) {
-                auto* it = array_val->get(i);
+            int i = 0;
+            for (auto iter = array_val->begin(); iter < array_val->end(); 
++iter, ++i) {
+                const auto* it = &*iter;
 
                 if (is_last_parent && last_leg->array_index == i) {
                     value_written = true;
@@ -2412,12 +2413,12 @@ private:
         } else if (element->isArray()) {
             const auto* array = element->unpack<ArrayVal>();
             bool find = false;
-            for (int i = 0; i < array->numElem(); ++i) {
-                auto leg = std::make_unique<leg_info>(nullptr, 0, i, 
ARRAY_CODE);
-                cur_path->add_leg_to_leg_vector(std::move(leg));
-                const auto* child_element = array->get(i);
+            int index = 0;
+            for (auto it = array->begin(); it < array->end(); ++it, ++index) {
                 // construct an array cell path leg.
-                find |= find_matches(child_element, one_match, state, 
cur_path, matches);
+                auto leg = std::make_unique<leg_info>(nullptr, 0, index, 
ARRAY_CODE);
+                cur_path->add_leg_to_leg_vector(std::move(leg));
+                find |= find_matches(&*it, one_match, state, cur_path, 
matches);
                 cur_path->pop_leg_from_leg_vector();
                 if (one_match && find) {
                     return true;
diff --git a/be/src/util/jsonb_document.h b/be/src/util/jsonb_document.h
index 0ac046ef78f..62d013bd0cb 100644
--- a/be/src/util/jsonb_document.h
+++ b/be/src/util/jsonb_document.h
@@ -1286,9 +1286,8 @@ inline bool numeric_equal(const JsonbValue* lhs, const 
JsonbValue* rhs) {
 }
 
 inline bool array_contains_value(const ArrayVal* target_array, const 
JsonbValue* candidate) {
-    const int target_num = target_array->numElem();
-    for (int i = 0; i < target_num; ++i) {
-        if (target_array->get(i)->contains(candidate)) {
+    for (auto it = target_array->begin(); it < target_array->end(); ++it) {
+        if (it->contains(candidate)) {
             return true;
         }
     }
@@ -1296,9 +1295,8 @@ inline bool array_contains_value(const ArrayVal* 
target_array, const JsonbValue*
 }
 
 inline bool array_contains_array(const ArrayVal* target_array, const ArrayVal* 
candidate_array) {
-    const int candidate_num = candidate_array->numElem();
-    for (int i = 0; i < candidate_num; ++i) {
-        if (!array_contains_value(target_array, candidate_array->get(i))) {
+    for (auto it = candidate_array->begin(); it < candidate_array->end(); 
++it) {
+        if (!array_contains_value(target_array, &*it)) {
             return false;
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to