From 6089b26ef04fd46f378ed2fc06b7be01409a2eba Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Tue, 4 Dec 2018 15:49:21 +0300 Subject: [PATCH] Fix |RangeHashedDictionary| getter against |ColumnConst| --- dbms/src/Columns/IColumn.h | 2 +- .../Dictionaries/RangeHashedDictionary.cpp | 2 ++ .../Functions/FunctionsExternalDictionaries.h | 19 ++++++++++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dbms/src/Columns/IColumn.h b/dbms/src/Columns/IColumn.h index 088be128e8d..d9eaf13633c 100644 --- a/dbms/src/Columns/IColumn.h +++ b/dbms/src/Columns/IColumn.h @@ -84,7 +84,7 @@ public: } /// If column stores integers, it returns n-th element transformed to UInt64 using static_cast. - /// If column stores floting point numbers, bits of n-th elements are copied to lower bits of UInt64, the remaining bits are zeros. + /// If column stores floating point numbers, bits of n-th elements are copied to lower bits of UInt64, the remaining bits are zeros. /// Is used to optimize some computations (in aggregation, for example). virtual UInt64 get64(size_t /*n*/) const { diff --git a/dbms/src/Dictionaries/RangeHashedDictionary.cpp b/dbms/src/Dictionaries/RangeHashedDictionary.cpp index 5db404b793d..b139526712d 100644 --- a/dbms/src/Dictionaries/RangeHashedDictionary.cpp +++ b/dbms/src/Dictionaries/RangeHashedDictionary.cpp @@ -354,7 +354,9 @@ void RangeHashedDictionary::getItemsImpl( out[i] = static_cast(val_it != std::end(ranges_and_values) ? val_it->value : null_value); } else + { out[i] = static_cast(null_value); + } } query_count.fetch_add(ids.size(), std::memory_order_relaxed); diff --git a/dbms/src/Functions/FunctionsExternalDictionaries.h b/dbms/src/Functions/FunctionsExternalDictionaries.h index b99ec11bf6b..a8116f44fbb 100644 --- a/dbms/src/Functions/FunctionsExternalDictionaries.h +++ b/dbms/src/Functions/FunctionsExternalDictionaries.h @@ -1683,20 +1683,21 @@ private: template static const PaddedPODArray & getColumnDataAsPaddedPODArray(const IColumn & column, PaddedPODArray & backup_storage) { - if (const auto vector_col = checkAndGetColumn>(&column)) + if (!column.isColumnConst()) { - return vector_col->getData(); - } - if (const auto const_col = checkAndGetColumnConstData>(&column)) - { - return const_col->getData(); + if (const auto vector_col = checkAndGetColumn>(&column)) + { + return vector_col->getData(); + } } - // With type conversion, need to use backup storage here - const auto size = column.size(); + const auto full_column = column.isColumnConst() ? column.convertToFullColumnIfConst() : column.getPtr(); + + // With type conversion and const columns we need to use backup storage here + const auto size = full_column->size(); backup_storage.resize(size); for (size_t i = 0; i < size; ++i) - backup_storage[i] = column.getUInt(i); + backup_storage[i] = full_column->getUInt(i); return backup_storage; }