liutang123 commented on a change in pull request #3025: URL: https://github.com/apache/incubator-doris/pull/3025#discussion_r521096363
########## File path: be/src/olap/column_vector.cpp ########## @@ -0,0 +1,212 @@ +// 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" +#include "olap/field.h" + +namespace doris { + +ColumnVectorBatch::~ColumnVectorBatch() = default; + +Status ColumnVectorBatch::resize(size_t new_cap) { + if (_nullable) { + _null_signs.resize(new_cap); + } + _capacity = new_cap; + return Status::OK(); +} + +Status ColumnVectorBatch::create(size_t init_capacity, + bool is_nullable, + const TypeInfo* type_info, + Field* field, + std::unique_ptr<ColumnVectorBatch>* column_vector_batch) { + if (is_scalar_type(type_info->type())) { + std::unique_ptr<ColumnVectorBatch> local; + switch (type_info->type()) { + case OLAP_FIELD_TYPE_BOOL: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_BOOL>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_TINYINT: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_TINYINT>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_SMALLINT: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_SMALLINT>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_INT: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_INT>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_UNSIGNED_INT: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_UNSIGNED_INT>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_BIGINT: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_BIGINT>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_UNSIGNED_BIGINT: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_UNSIGNED_BIGINT>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_LARGEINT: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_LARGEINT>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_FLOAT: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_FLOAT>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_DOUBLE: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_DOUBLE>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_DECIMAL: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_DECIMAL>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_DATE: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_DATE>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_DATETIME: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_DATETIME>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_CHAR: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_CHAR>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_VARCHAR: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_VARCHAR>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_HLL: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_HLL>::CppType>(type_info, is_nullable)); + break; + case OLAP_FIELD_TYPE_OBJECT: + local.reset(new ScalarColumnVectorBatch<CppTypeTraits<OLAP_FIELD_TYPE_OBJECT>::CppType>(type_info, is_nullable)); + break; + default: + return Status::NotSupported("unsupported type for ColumnVectorBatch: " + std::to_string(type_info->type())); + } + RETURN_IF_ERROR(local->resize(init_capacity)); + *column_vector_batch = std::move(local); + return Status::OK(); + } else { + switch (type_info->type()) { + case FieldType::OLAP_FIELD_TYPE_ARRAY: { + if (field == nullptr) { + return Status::NotSupported("When create ArrayColumnVectorBatch, `Field` is indispensable"); + } + std::unique_ptr<ColumnVectorBatch> local(new ArrayColumnVectorBatch(type_info, is_nullable, init_capacity, field)); + RETURN_IF_ERROR(local->resize(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())); + } + } +} + +template <class ScalarType> +ScalarColumnVectorBatch<ScalarType>::ScalarColumnVectorBatch(const TypeInfo* type_info, bool is_nullable) +: ColumnVectorBatch(type_info, is_nullable), _data(0) { +} + +template <class ScalarType> +ScalarColumnVectorBatch<ScalarType>::~ScalarColumnVectorBatch() = default; + +template <class ScalarType> +Status ScalarColumnVectorBatch<ScalarType>::resize(size_t new_cap) { + if (capacity() < new_cap) { // before first init, _capacity is 0. + RETURN_IF_ERROR(ColumnVectorBatch::resize(new_cap)); + _data.resize(new_cap); + } + return Status::OK(); +} + +ArrayColumnVectorBatch::ArrayColumnVectorBatch( + const TypeInfo* type_info, + bool is_nullable, + size_t init_capacity, + Field* field) : ColumnVectorBatch(type_info, is_nullable), _data(0), _item_offsets(1) { + auto array_type_info = reinterpret_cast<const ArrayTypeInfo*>(type_info); + _item_offsets[0] = 0; + ColumnVectorBatch::create( + init_capacity * 2, Review comment: This is based on item's number is usually bigger than array's. ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org