decster commented on a change in pull request #3580:
URL: https://github.com/apache/incubator-doris/pull/3580#discussion_r426438772



##########
File path: be/src/olap/memory/typed_column_writer.h
##########
@@ -0,0 +1,305 @@
+// 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 "olap/memory/column.h"
+#include "olap/memory/column_writer.h"
+#include "olap/memory/typed_column_reader.h"
+
+namespace doris {
+namespace memory {
+
+// Used to hold temporary nullable update cells in ColumnWriter
+template <class T>
+class NullableUpdateType {
+public:
+    bool& isnull() { return _isnull; }
+    T& value() { return _value; }
+
+private:
+    bool _isnull;
+    T _value;
+};
+
+// Used to hold temporary update cells in ColumnWriter
+template <class T>
+class UpdateType {
+public:
+    bool& isnull() { return *static_cast<bool*>(0); /*unused*/ }
+    T& value() { return _value; }
+
+private:
+    T _value;
+};
+
+// ColumnWriter typed implementations
+// currently only works for int8/int16/int32/int64/int128/float/double
+// TODO: add string and other varlen type support
+template <class T, bool Nullable = false, class ST = T, class UT = T>
+class TypedColumnWriter : public ColumnWriter {
+public:
+    TypedColumnWriter(Column* column, uint64_t version, uint64_t real_version,
+                      vector<ColumnDelta*>&& deltas)
+            : _column(column),
+              _base(&_column->_base),
+              _version(version),
+              _real_version(real_version),
+              _deltas(std::move(deltas)) {}
+
+    const void* get(const uint32_t rid) const {
+        return TypedColumnGet<TypedColumnWriter<T, Nullable, ST, UT>, T, 
Nullable, ST>(*this, rid);
+    }
+
+    uint64_t hashcode(const void* rhs, size_t rhs_idx) const {
+        return TypedColumnHashcode<T, ST>(rhs, rhs_idx);
+    }
+
+    bool equals(const uint32_t rid, const void* rhs, size_t rhs_idx) const {
+        return TypedColumnEquals<TypedColumnWriter<T, Nullable, ST, UT>, T, 
Nullable, ST>(
+                *this, rid, rhs, rhs_idx);
+    }
+
+    string debug_string() const {
+        return StringPrintf("%s version=%zu(real=%zu) ndelta=%zu insert:%zu 
update:%zu",
+                            _column->debug_string().c_str(), _version, 
_real_version,
+                            _deltas.size(), _num_insert, _num_update);
+    }
+
+    Status insert(uint32_t rid, const void* value) {
+        uint32_t bid = rid >> 16;
+        if (bid >= _base->size()) {
+            RETURN_IF_ERROR(add_block());
+            // add one block should be enough
+            CHECK(bid < _base->size());
+        }
+        auto& block = (*_base)[bid];
+        uint32_t idx = rid & 0xffff;
+        DCHECK(idx * sizeof(T) < block->data().bsize());
+        if (Nullable) {
+            if (value) {
+                if (std::is_same<T, ST>::value) {
+                    block->set_not_null(idx);
+                    block->data().as<ST>()[idx] = *static_cast<const 
ST*>(value);
+                } else {
+                    // TODO: string support
+                }
+            } else {
+                block->set_null(idx);
+            }
+        } else {
+            DCHECK(value);
+            if (std::is_same<T, ST>::value) {
+                block->data().as<ST>()[idx] = *static_cast<const ST*>(value);
+            } else {
+                // TODO: string support

Review comment:
       fixed




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

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