eldenmoon commented on code in PR #20556:
URL: https://github.com/apache/doris/pull/20556#discussion_r1222981644


##########
be/src/vec/data_types/data_type_array.cpp:
##########
@@ -188,77 +188,49 @@ std::string DataTypeArray::to_string(const IColumn& 
column, size_t row_num) cons
     return str;
 }
 
-bool next_element_from_string(ReadBuffer& rb, StringRef& output, bool& 
has_quota) {
-    StringRef element(rb.position(), 0);
-    has_quota = false;
-    if (rb.eof()) {
-        return false;
-    }
-
-    // ltrim
-    while (!rb.eof() && isspace(*rb.position())) {
-        ++rb.position();
-        element.data = rb.position();
-    }
-
-    // parse string
-    if (*rb.position() == '"' || *rb.position() == '\'') {
-        const char str_sep = *rb.position();
-        size_t str_len = 1;
-        // search until next '"' or '\''
-        while (str_len < rb.count() && *(rb.position() + str_len) != str_sep) {
-            ++str_len;
-        }
-        // invalid string
-        if (str_len >= rb.count()) {
-            rb.position() = rb.end();
-            return false;
-        }
-        has_quota = true;
-        rb.position() += str_len + 1;
-        element.size += str_len + 1;
-    }
+Status DataTypeArray::from_json(simdjson::ondemand::value& json_value, 
IColumn* column) const {
+    CHECK(json_value.type() == simdjson::ondemand::json_type::array);
+    simdjson::ondemand::array outer_array = json_value.get_array();
+    auto* array_column = assert_cast<ColumnArray*>(column);
+    auto& offsets = array_column->get_offsets();
+    IColumn& nested_column = array_column->get_data();
+    DCHECK(nested_column.is_nullable());
+    auto& nested_null_col = reinterpret_cast<ColumnNullable&>(nested_column);
 
-    // parse array element until array separator ',' or end ']'
-    while (!rb.eof() && (*rb.position() != ',') && (rb.count() != 1 || 
*rb.position() != ']')) {
-        // invalid elements such as ["123" 456,"789" 777]
-        // correct elements such as ["123"    ,"789"    ]
-        if (has_quota && !isspace(*rb.position())) {
-            return false;
+    size_t element_num = 0;
+    for (auto it = outer_array.begin(); it != outer_array.end(); ++it) {
+        Status st;
+        try {
+            if (is_complex_type(remove_nullable(nested))) {
+                simdjson::ondemand::value val;
+                (*it).get(val);
+                st = nested->from_json(val, &nested_null_col);
+            } else {
+                std::string_view sv = (*it).raw_json_token().value();
+                ReadBuffer nested_rb(const_cast<char*>(sv.data()), sv.size());

Review Comment:
   it seems little confusing for me that some use `from_json` while others use 
`from_string`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to