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



##########
File path: be/src/olap/memory/typed_column_reader.h
##########
@@ -0,0 +1,208 @@
+// 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_reader.h"
+#include "util/hash_util.hpp"
+
+namespace doris {
+namespace memory {
+
+// This method needs to be shared by reader/writer, so extract it as template 
function
+template <class Reader, class T, bool Nullable, class ST>
+inline const void* TypedColumnGet(const Reader& reader, const uint32_t rid) {
+    for (ssize_t i = reader._deltas.size() - 1; i >= 0; i--) {
+        ColumnDelta* pdelta = reader._deltas[i];
+        uint32_t pos = pdelta->find_idx(rid);
+        if (pos != DeltaIndex::npos) {
+            if (Nullable) {
+                bool isnull = pdelta->nulls() && 
pdelta->nulls().as<bool>()[pos];
+                if (isnull) {
+                    return nullptr;
+                } else {
+                    return &(pdelta->data().template as<ST>()[pos]);
+                }
+            } else {
+                return &(pdelta->data().template as<ST>()[pos]);
+            }
+        }
+    }
+    uint32_t bid = rid >> 16;
+    DCHECK(bid < reader._base->size());
+    uint32_t idx = rid & 0xffff;
+    DCHECK(idx * sizeof(ST) < (*reader._base)[bid]->data().bsize());
+    if (Nullable) {
+        bool isnull = (*reader._base)[bid]->is_null(idx);
+        if (isnull) {
+            return nullptr;
+        } else {
+            return &((*reader._base)[bid]->data().template as<ST>()[idx]);
+        }
+    } else {
+        return &((*reader._base)[bid]->data().template as<ST>()[idx]);
+    }
+}
+
+template <class T, class ST>
+inline uint64_t TypedColumnHashcode(const void* rhs, size_t rhs_idx) {
+    if (std::is_same<T, ST>::value) {
+        const T* prhs = ((const T*)rhs) + rhs_idx;
+        return HashUtil::fnv_hash64(prhs, sizeof(T), 0);
+    } else {
+        // TODO: support other type's hash
+        return 0;
+    }
+}
+
+template <class Reader, class T, bool Nullable, class ST>
+bool TypedColumnEquals(const Reader& reader, const uint32_t rid, const void* 
rhs, size_t rhs_idx) {
+    const T& rhs_value = ((const T*)rhs)[rhs_idx];
+    for (ssize_t i = reader._deltas.size() - 1; i >= 0; i--) {
+        ColumnDelta* pdelta = reader._deltas[i];
+        uint32_t pos = pdelta->find_idx(rid);
+        if (pos != DeltaIndex::npos) {
+            if (Nullable) {
+                CHECK(false) << "only used for key column";
+                return false;
+            } else {
+                return (pdelta->data().template as<T>()[pos]) == rhs_value;
+            }
+        }
+    }
+    uint32_t bid = rid >> 16;
+    DCHECK(bid < reader._base->size());
+    uint32_t idx = rid & 0xffff;
+    DCHECK(idx * sizeof(ST) < (*reader._base)[bid]->data().bsize());
+    if (Nullable) {
+        CHECK(false) << "only used for key column";
+        return false;
+    } else {
+        DCHECK(rhs);
+        return ((*reader._base)[bid]->data().template as<T>()[idx]) == 
rhs_value;
+    }
+}
+
+// ColumnReader 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 TypedColumnReader : public ColumnReader {
+public:
+    TypedColumnReader(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<TypedColumnReader<T, Nullable, ST>, T, Nullable, 
ST>(*this, rid);
+    }
+
+    Status get_block(size_t nrows, size_t block, ColumnBlockHolder* cbh) const 
{

Review comment:
       fixed, all renamed to block




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