From c7d31c3a90e395b3245d0fad8dfc991fbb99abbe Mon Sep 17 00:00:00 2001 From: FArthur-cmd <613623@mail.ru> Date: Tue, 30 Aug 2022 15:32:05 +0000 Subject: [PATCH] fix indexes for ColumnArray --- contrib/annoy-cmake/CMakeLists.txt | 2 +- src/Storages/MergeTree/MergeTreeIndexAnnoy.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/annoy-cmake/CMakeLists.txt b/contrib/annoy-cmake/CMakeLists.txt index f2535ba7fde..4c2c2bf565f 100644 --- a/contrib/annoy-cmake/CMakeLists.txt +++ b/contrib/annoy-cmake/CMakeLists.txt @@ -1,6 +1,6 @@ option(ENABLE_ANNOY "Enable Annoy index support" ${ENABLE_LIBRARIES}) -if ((NOT ENABLE_ANNOY) OR (SANITIZE STREQUAL "undefined")) +if (NOT ENABLE_ANNOY) message (STATUS "Not using annoy") return() endif() diff --git a/src/Storages/MergeTree/MergeTreeIndexAnnoy.cpp b/src/Storages/MergeTree/MergeTreeIndexAnnoy.cpp index a8b825d832d..b7b8da625e4 100644 --- a/src/Storages/MergeTree/MergeTreeIndexAnnoy.cpp +++ b/src/Storages/MergeTree/MergeTreeIndexAnnoy.cpp @@ -128,6 +128,8 @@ void MergeTreeIndexAggregatorAnnoy::update(const Block & block, size_t * pos, si toString(*pos), toString(block.rows())); size_t rows_read = std::min(limit, block.rows() - *pos); + if (rows_read == 0) + return; if (index_sample_block.columns() > 1) { @@ -142,7 +144,7 @@ void MergeTreeIndexAggregatorAnnoy::update(const Block & block, size_t * pos, si const auto & data = column_array->getData(); const auto & array = typeid_cast(data).getData(); const auto & offsets = column_array->getOffsets(); - size_t num_rows = column_array->size(); + size_t num_rows = offsets->size(); /// All sizes are the same size_t size = offsets[0]; @@ -155,6 +157,8 @@ void MergeTreeIndexAggregatorAnnoy::update(const Block & block, size_t * pos, si } index = std::make_shared(size); + index->add_item(index->get_n_items(), &array[0]); + /// add all rows from 1 to num_rows - 1 (this is the same as the beginning of the last element) for (size_t current_row = 0; current_row < num_rows; ++current_row) { index->add_item(index->get_n_items(), &array[offsets[current_row]]);