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


##########
be/src/vec/columns/column_json.h:
##########
@@ -0,0 +1,299 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <cassert>
+#include <cstring>
+
+#include "vec/columns/column.h"
+#include "vec/columns/column_impl.h"
+#include "vec/common/assert_cast.h"
+#include "vec/common/memcmp_small.h"
+#include "vec/common/memcpy_small.h"
+#include "vec/common/pod_array.h"
+#include "vec/common/sip_hash.h"
+#include "vec/core/field.h"
+
+namespace doris::vectorized {
+class ColumnJson final : public COWHelper<IColumn, ColumnJson> {
+public:
+    using Char = UInt8;
+    using Chars = PaddedPODArray<UInt8>;
+
+private:
+    friend class COWHelper<IColumn, ColumnJson>;
+
+    Offsets offsets;
+
+    Chars chars;
+
+    size_t ALWAYS_INLINE offset_at(ssize_t i) const { return offsets[i - 1]; }
+
+    size_t ALWAYS_INLINE size_at(ssize_t i) const { return offsets[i] - 
offsets[i - 1]; }
+
+    template <bool positive>
+    struct less;
+
+    template <bool positive>
+    struct lessWithCollation;
+
+    ColumnJson() = default;
+
+    ColumnJson(const ColumnJson& src)
+            : offsets(src.offsets.begin(), src.offsets.end()),
+              chars(src.chars.begin(), src.chars.end()) {}
+
+public:
+    const char* get_family_name() const override { return "JSON"; }
+
+    size_t size() const override { return offsets.size(); }
+
+    size_t byte_size() const override { return chars.size() + offsets.size() * 
sizeof(offsets[0]); }
+
+    size_t allocated_bytes() const override {
+        return chars.allocated_bytes() + offsets.allocated_bytes();
+    }
+
+    void protect() override;
+
+    MutableColumnPtr clone_resized(size_t to_size) const override;
+
+    Field operator[](size_t n) const override {
+        assert(n < size());
+        return Field(&chars[offset_at(n)], size_at(n) - 1);
+    }
+
+    void get(size_t n, Field& res) const override {
+        assert(n < size());
+        res.assign_json(&chars[offset_at(n)], size_at(n) - 1);
+    }
+
+    StringRef get_data_at(size_t n) const override {
+        assert(n < size());
+        return StringRef(&chars[offset_at(n)], size_at(n) - 1);
+    }
+
+/// Suppress gcc 7.3.1 warning: '*((void*)&<anonymous> +8)' may be used 
uninitialized in this function
+#if !__clang__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+
+    void insert(const Field& x) override {
+        const JsonField& s = doris::vectorized::get<const JsonField&>(x);
+
+        const size_t old_size = chars.size();
+        const size_t size_to_append = s.get_size() + 1;

Review Comment:
   is extra 1 byte necessary for ColumnJSON?



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