From b7784b91b7e9fd06f6b22bbd1ecf8cbc390885bd Mon Sep 17 00:00:00 2001 From: cambyzju Date: Mon, 5 Dec 2022 23:11:06 +0800 Subject: [PATCH] bug fix for ColumnVector::insert_date_column --- be/src/vec/columns/column_vector.h | 2 ++ be/test/CMakeLists.txt | 1 + be/test/vec/core/column_vector_test.cpp | 41 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 be/test/vec/core/column_vector_test.cpp diff --git a/be/src/vec/columns/column_vector.h b/be/src/vec/columns/column_vector.h index 211e225e0797ba..c944827fbc832a 100644 --- a/be/src/vec/columns/column_vector.h +++ b/be/src/vec/columns/column_vector.h @@ -166,6 +166,7 @@ class ColumnVector final : public COWHelper> } void insert_date_column(const char* data_ptr, size_t num) { + data.reserve(data.size() + num); size_t input_value_size = sizeof(uint24_t); for (int i = 0; i < num; i++) { @@ -180,6 +181,7 @@ class ColumnVector final : public COWHelper> } void insert_datetime_column(const char* data_ptr, size_t num) { + data.reserve(data.size() + num); size_t value_size = sizeof(uint64_t); for (int i = 0; i < num; i++) { const char* cur_ptr = data_ptr + value_size * i; diff --git a/be/test/CMakeLists.txt b/be/test/CMakeLists.txt index 0d6a6e633277d5..da1b5dc86c2e82 100644 --- a/be/test/CMakeLists.txt +++ b/be/test/CMakeLists.txt @@ -342,6 +342,7 @@ set(VEC_TEST_FILES vec/core/column_array_test.cpp vec/core/column_complex_test.cpp vec/core/column_nullable_test.cpp + vec/core/column_vector_test.cpp vec/exec/vgeneric_iterators_test.cpp vec/exec/vbroker_scan_node_test.cpp vec/exec/vbroker_scanner_test.cpp diff --git a/be/test/vec/core/column_vector_test.cpp b/be/test/vec/core/column_vector_test.cpp new file mode 100644 index 00000000000000..d310e8a7e775f9 --- /dev/null +++ b/be/test/vec/core/column_vector_test.cpp @@ -0,0 +1,41 @@ + +// 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 "vec/columns/column_vector.h" + +#include + +#include +#include + +#include "vec/data_types/data_type_date.h" + +namespace doris::vectorized { + +TEST(VColumnVectorTest, insert_date_column) { + auto column = ColumnVector::create(); + + size_t rows = 4096; + int64_t val = 0; + for (size_t i = 0; i < rows; ++i) { + column->insert_date_column(reinterpret_cast(&val), 1); + } + ASSERT_EQ(column->size(), rows); +} + +} // namespace doris::vectorized