yiguolei commented on code in PR #51766:
URL: https://github.com/apache/doris/pull/51766#discussion_r2159820211


##########
be/src/util/jsonb_document.h:
##########
@@ -587,315 +611,204 @@ class JsonbValue {
     //Whether to include the jsonbvalue rhs
     bool contains(JsonbValue* rhs) const;
 
-    // get the raw byte array of the value
-    const char* getValuePtr() const;
-
     // find the JSONB value by JsonbPath
     JsonbValue* findValue(JsonbPath& path, hDictFind handler);
     friend class JsonbDocument;
 
-protected:
-    JsonbType type_; // type info
+    JsonbType type; // type info
+
+    char payload[0]; // payload, which is the packed bytes of the value
+
+    template <typename T>
+    const T* unpack() const {
+        return reinterpret_cast<const T*>(payload);
+    }
+
+    template <typename T>
+    T* unpack() {
+        return reinterpret_cast<T*>(payload);
+    }
 
-    JsonbValue();
+    JsonbValue() = delete;
 };
 
 /*
  * NumerValT is the template class (derived from JsonbValue) of all number
  * types (integers and double).
  */
-template <class T>
-class NumberValT : public JsonbValue {
+template <typename T>
+struct NumberValT {
 public:
-    T val() const { return num_; }
-
-    unsigned int numPackedBytes() const { return sizeof(JsonbValue) + 
sizeof(T); }
+    NumberValT() = delete;
+    T val() const { return num; }
 
-    // catch all unknow specialization of the template class
-    bool setVal(T value) { return false; }
-
-private:
-    T num_;
+    static constexpr unsigned int numPackedBytes() { return sizeof(JsonbValue) 
+ sizeof(T); }
 
-    NumberValT();
+    T num;
 };
 
-typedef NumberValT<int8_t> JsonbInt8Val;
-
-// override setVal for Int8Val
-template <>
-inline bool JsonbInt8Val::setVal(int8_t value) {
-    if (!isInt8()) {
-        return false;
-    }
-
-    num_ = value;
-    return true;
-}
-
-typedef NumberValT<int16_t> JsonbInt16Val;
-
-// override setVal for Int16Val
-template <>
-inline bool JsonbInt16Val::setVal(int16_t value) {
-    if (!isInt16()) {
-        return false;
-    }
-
-    num_ = value;
-    return true;
-}
-typedef NumberValT<int32_t> JsonbInt32Val;
-
-// override setVal for Int32Val
-template <>
-inline bool JsonbInt32Val::setVal(int32_t value) {
-    if (!isInt32()) {
-        return false;
-    }
-
-    num_ = value;
-    return true;
-}
-
-typedef NumberValT<int64_t> JsonbInt64Val;
-
-// override setVal for Int64Val
-template <>
-inline bool JsonbInt64Val::setVal(int64_t value) {
-    if (!isInt64()) {
-        return false;
-    }
-
-    num_ = value;
-    return true;
-}
-
-typedef NumberValT<int128_t> JsonbInt128Val;
-
-// override setVal for Int128Val
-template <>
-inline bool JsonbInt128Val::setVal(int128_t value) {
-    if (!isInt128()) {
-        return false;
-    }
-
-    num_ = value;
-    return true;
-}
-
-typedef NumberValT<double> JsonbDoubleVal;
-
-// override setVal for DoubleVal
-template <>
-inline bool JsonbDoubleVal::setVal(double value) {
-    if (!isDouble()) {
-        return false;
-    }
-
-    num_ = value;
-    return true;
+inline ObjectVal* JsonbDocument::operator->() {
+    return (((JsonbValue*)payload_)->unpack<ObjectVal>());
 }
 
-typedef NumberValT<float> JsonbFloatVal;
-
-// override setVal for DoubleVal
-template <>
-inline bool JsonbFloatVal::setVal(float value) {
-    if (!isFloat()) {
-        return false;
-    }
-
-    num_ = value;
-    return true;
+inline const ObjectVal* JsonbDocument::operator->() const {
+    return (((JsonbValue*)payload_)->unpack<ObjectVal>());
 }
 
+using JsonbInt8Val = NumberValT<int8_t>;
+using JsonbInt16Val = NumberValT<int16_t>;
+using JsonbInt32Val = NumberValT<int32_t>;
+using JsonbInt64Val = NumberValT<int64_t>;
+using JsonbInt128Val = NumberValT<int128_t>;
+using JsonbDoubleVal = NumberValT<double>;
+using JsonbFloatVal = NumberValT<float>;
 // A class to get an integer
-class JsonbIntVal : public JsonbValue {
-public:
+struct JsonbIntVal : public JsonbValue {

Review Comment:
   为什么只有这个继承了 jsonbvalue,而其他类没有?



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