You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/03/16 16:56:33 UTC

[GitHub] [incubator-doris] kangpinghuang commented on a change in pull request #3025: Restructure storage type to support complex types expending

kangpinghuang commented on a change in pull request #3025: Restructure storage type to support complex types expending
URL: https://github.com/apache/incubator-doris/pull/3025#discussion_r393147724
 
 

 ##########
 File path: be/src/olap/column_vector.cpp
 ##########
 @@ -0,0 +1,150 @@
+// 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.
+
+#include "column_vector.h"
+
+namespace doris {
+
+ColumnVectorBatch::~ColumnVectorBatch() {
+    SAFE_DELETE_ARRAY(_null_signs);
+}
+
+Status ColumnVectorBatch::resize(size_t new_cap) {
+    if (_nullable) {
+        resize_buff(_capacity, new_cap, reinterpret_cast<uint8_t**>(&_null_signs));
+    }
+    _capacity = new_cap;
+    return Status::OK();
+}
+
+Status ColumnVectorBatch::resize_buff(size_t copy_bytes, size_t new_cap, uint8_t** _buf_ptr) {
+    const uint8_t* old_buf = *_buf_ptr;
+    if (old_buf) {
+        *_buf_ptr = new uint8_t[new_cap];
+        memcpy(*_buf_ptr, old_buf, copy_bytes);
+        delete[] old_buf;
+    } else {
+        *_buf_ptr = new uint8_t[new_cap];
+    }
+    return Status::OK();
+}
+
+Status ColumnVectorBatch::create(size_t init_capacity,
+        bool is_nullable,
+        const TypeInfo* type_info,
+        std::unique_ptr<ColumnVectorBatch>* column_vector_batch) {
+    if (is_scalar_type(type_info->type())) {
+        std::unique_ptr<ColumnVectorBatch> local(
+                new ScalarColumnVectorBatch(type_info, is_nullable, init_capacity));
+        *column_vector_batch = std::move(local);
+        return Status::OK();
+    } else {
+        switch (type_info->type()) {
+        case FieldType::OLAP_FIELD_TYPE_LIST: {
+            std::unique_ptr<ColumnVectorBatch> local(new ListColumnVectorBatch(type_info, is_nullable, init_capacity));
+            *column_vector_batch = std::move(local);
+            return Status::OK();
+        }
+        default:
+            return Status::NotSupported("unsupported type for ColumnVectorBatch: " + std::to_string(type_info->type()));
+        }
+    }
+}
+
+ScalarColumnVectorBatch::ScalarColumnVectorBatch(const TypeInfo* type_info, bool is_nullable, size_t init_capacity)
+: ColumnVectorBatch(type_info, is_nullable) {
+    resize(init_capacity);
+}
+ScalarColumnVectorBatch::~ScalarColumnVectorBatch() {
+    SAFE_DELETE_ARRAY(_data);
+}
+
+Status ScalarColumnVectorBatch::resize(size_t new_cap) {
+    if (get_capacity() < new_cap) { // before first init, _capacity is 0.
+        size_t type_size = type_info()->size();
+        auto copy_bytes = get_capacity() * type_size;
+        size_t new_data_size = new_cap * type_size;
+        resize_buff(copy_bytes, new_data_size, &_data);
+        return ColumnVectorBatch::resize(new_cap);
+    }
+    return Status::OK();
+}
+
+uint8_t* ScalarColumnVectorBatch::data() const { return _data; };
+
+const uint8_t* ScalarColumnVectorBatch::cell_ptr(size_t idx) const { return _data + idx * type_info()->size(); };
+
+uint8_t* ScalarColumnVectorBatch::mutable_cell_ptr(size_t idx) const { return _data + idx * type_info()->size(); };
+
 
 Review comment:
   additional line

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org