HappenLee commented on code in PR #33904:
URL: https://github.com/apache/doris/pull/33904#discussion_r1576181650


##########
be/src/vec/exprs/table_function/vexplode_json_array.h:
##########
@@ -19,85 +19,231 @@
 
 #include <glog/logging.h>
 #include <rapidjson/document.h>
-#include <stddef.h>
-#include <stdint.h>
 
 #include <ostream>
 #include <string>
 #include <vector>
 
 #include "common/status.h"
 #include "gutil/integral_types.h"
+#include "rapidjson/stringbuffer.h"
+#include "rapidjson/writer.h"
 #include "vec/common/string_ref.h"
+#include "vec/core/types.h"
 #include "vec/data_types/data_type.h"
 #include "vec/exprs/table_function/table_function.h"
 
-namespace doris {
-namespace vectorized {
-class Block;
-} // namespace vectorized
-} // namespace doris
-
 namespace doris::vectorized {
 
-enum ExplodeJsonArrayType { INT = 0, DOUBLE, STRING, JSON };
-
+template <typename T>
 struct ParsedData {
-    static std::string true_value;
-    static std::string false_value;
+    ParsedData() = default;
+    virtual ~ParsedData() = default;
+    virtual void reset() = 0;
+    virtual int set_output(rapidjson::Document& document, int value_size) = 0;
+    virtual void insert_result_from_parsed_data(MutableColumnPtr& column, int 
max_step,
+                                                int64_t cur_offset) = 0;
+    const char* get_null_flag_address(int cur_offset) {
+        return reinterpret_cast<const char*>(_values_null_flag.data() + 
cur_offset);
+    }
+    std::vector<UInt8> _values_null_flag;
+};
 
-    // The number parsed from json array
-    // the `_backup` saved the real number entity.
-    std::vector<void*> _data;
-    std::vector<StringRef> _data_string;
+struct ParsedDataInt : public ParsedData<int64_t> {
+    static auto constexpr max_value = std::numeric_limits<int64_t>::max(); 
//9223372036854775807
+    static auto constexpr min_value = std::numeric_limits<int64_t>::min(); 
//-9223372036854775808
+
+    int set_output(rapidjson::Document& document, int value_size) override {
+        _values_null_flag.resize(value_size, 0);
+        _backup_int.resize(value_size);
+        int i = 0;
+        for (auto& v : document.GetArray()) {
+            if (v.IsInt64()) {
+                _backup_int[i] = v.GetInt64();
+            } else if (v.IsUint64()) {
+                auto value = v.GetUint64();
+                if (value > max_value) {
+                    _backup_int[i] = max_value;
+                } else {
+                    _backup_int[i] = value;
+                }
+            } else if (v.IsDouble()) {
+                auto value = v.GetDouble();
+                if (value > max_value) {
+                    _backup_int[i] = max_value;
+                } else if (value < min_value) {
+                    _backup_int[i] = min_value;
+                } else {
+                    _backup_int[i] = long(value);
+                }
+            } else {
+                _values_null_flag[i] = 1;
+                _backup_int[i] = 0;
+            }
+            ++i;
+        }
+        return value_size;
+    }
+    void insert_result_from_parsed_data(MutableColumnPtr& column, int max_step,
+                                        int64_t cur_offset) override {
+        assert_cast<ColumnInt64*>(column.get())
+                ->insert_many_raw_data(
+                        reinterpret_cast<const char*>(_backup_int.data() + 
cur_offset), max_step);
+    }
+    void reset() override { _backup_int.clear(); }
     std::vector<int64_t> _backup_int;
+};
+
+struct ParsedDataDouble : public ParsedData<double> {
+    int set_output(rapidjson::Document& document, int value_size) override {
+        _values_null_flag.resize(value_size, 0);
+        _backup_double.resize(value_size);
+        int i = 0;
+        for (auto& v : document.GetArray()) {
+            if (v.IsDouble()) {
+                _backup_double[i] = v.GetDouble();
+            } else {
+                _backup_double[i] = 0;
+                _values_null_flag[i] = 1;
+            }
+            ++i;
+        }
+        return value_size;
+    }
+    void insert_result_from_parsed_data(MutableColumnPtr& column, int max_step,
+                                        int64_t cur_offset) override {
+        assert_cast<ColumnFloat64*>(column.get())
+                ->insert_many_raw_data(
+                        reinterpret_cast<const char*>(_backup_double.data() + 
cur_offset),
+                        max_step);
+    }
+    void reset() override { _backup_double.clear(); }
     std::vector<double> _backup_double;
+};
+
+struct ParsedDataStringBase : public ParsedData<std::string> {
+    void insert_result_from_parsed_data(MutableColumnPtr& column, int max_step,
+                                        int64_t cur_offset) override {
+        assert_cast<ColumnString*>(column.get())
+                ->insert_many_strings(_data_string_ref.data() + cur_offset, 
max_step);
+    }
+    void reset() override {
+        _data_string_ref.clear();
+        _backup_string.clear();
+    }
+
+    static std::string true_value;
+    static std::string false_value;

Review Comment:
   constexpr char* =  UPPER



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to