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

eldenmoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 473ab508453 [improvement](be) Iterate JSONB arrays linearly in json 
functions (#69059)
473ab508453 is described below

commit 473ab50845384af04b5db071bbdcb2c84cf18d12
Author: Hail <[email protected]>
AuthorDate: Thu Oct 15 09:14:46 2026 +0530

    [improvement](be) Iterate JSONB arrays linearly in json functions (#69059)
---
 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 2070109c409..a649fb0263c 100644
--- a/be/src/exprs/function/function_jsonb.cpp
+++ b/be/src/exprs/function/function_jsonb.cpp
@@ -2157,8 +2157,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;
@@ -2383,12 +2384,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 40c1e9792a4..ba4ccb8fe00 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