xiaokang commented on code in PR #10322:
URL: https://github.com/apache/doris/pull/10322#discussion_r928256518


##########
be/src/olap/types.h:
##########
@@ -1454,6 +1460,66 @@ struct FieldTypeTraits<OLAP_FIELD_TYPE_STRING> : public 
FieldTypeTraits<OLAP_FIE
     }
 };
 
+template <>
+struct FieldTypeTraits<OLAP_FIELD_TYPE_JSON> : public 
FieldTypeTraits<OLAP_FIELD_TYPE_VARCHAR> {
+    static int cmp(const void* left, const void* right) {
+        LOG(WARNING) << "can not compare JSON values";
+        return -1; // always update ?
+    }
+
+    static Status from_string(void* buf, const std::string& scan_key, const 
int precision,
+                              const int scale) {
+        auto jdoc = JsonbDocument::createDocument(scan_key.c_str(), 
scan_key.size());
+        size_t value_len = jdoc->numPackedBytes();
+        if (value_len > config::json_type_length_soft_limit_bytes) {
+            LOG(WARNING) << "the len of value json is too long, len=" << 
value_len
+                         << ", max_len=" << 
config::json_type_length_soft_limit_bytes;
+            return Status::OLAPInternalError(OLAP_ERR_INPUT_PARAMETER_ERROR);
+        }
+
+        auto slice = reinterpret_cast<Slice*>(buf);
+        memory_copy(slice->data, reinterpret_cast<const 
char*>(jdoc->getValue()), value_len);
+        slice->size = value_len;
+        return Status::OK();
+    }
+
+    static Status convert_from(void* dest, const void* src, const TypeInfo* 
src_type,
+                               MemPool* mem_pool, size_t variable_len = 0) {
+        JsonbToJson toStr;
+        switch (src_type->type()) {
+        case OLAP_FIELD_TYPE_TINYINT:
+        case OLAP_FIELD_TYPE_SMALLINT:
+        case OLAP_FIELD_TYPE_INT:
+        case OLAP_FIELD_TYPE_BIGINT:
+        case OLAP_FIELD_TYPE_LARGEINT:
+        case OLAP_FIELD_TYPE_FLOAT:
+        case OLAP_FIELD_TYPE_DOUBLE:
+        case OLAP_FIELD_TYPE_DECIMAL: {
+            auto s = src_type->to_string(src);
+            std::string result =
+                    toStr.json(JsonbDocument::createDocument(s.c_str(), 
s.size())->getValue());

Review Comment:
   can int string be parsed?



-- 
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