From 97fbd37cb099cd244ee811f3d1b9b8b246011bed Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Thu, 3 May 2018 15:47:14 +0300 Subject: [PATCH] added IColumn::select --- dbms/src/Columns/ColumnWithDictionary.h | 2 ++ dbms/src/Functions/IFunction.cpp | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/dbms/src/Columns/ColumnWithDictionary.h b/dbms/src/Columns/ColumnWithDictionary.h index e38010e22a5..f0bd2230480 100644 --- a/dbms/src/Columns/ColumnWithDictionary.h +++ b/dbms/src/Columns/ColumnWithDictionary.h @@ -212,6 +212,8 @@ public: const IColumn * getIndexes() const { return indexes.get(); } const ColumnPtr & getIndexesPtr() const { return indexes; } + void setIndexes(MutableColumnPtr && indexes_) { indexes = indexes_; } + bool withDictionary() const override { return true; } private: diff --git a/dbms/src/Functions/IFunction.cpp b/dbms/src/Functions/IFunction.cpp index 30e7a8f369b..061147d3065 100644 --- a/dbms/src/Functions/IFunction.cpp +++ b/dbms/src/Functions/IFunction.cpp @@ -305,19 +305,23 @@ void PreparedFunctionImpl::execute(Block & block, const ColumnNumbers & args, si executeWithoutColumnsWithDictionary(temp_block, temp_numbers, 0); auto & temp_res_col = temp_block.getByPosition(0).column; auto & res_col = block.getByPosition(result); + res_col.column = res_col.type->createColumn(); + + auto * col_with_dict = checkAndGetColumn(res_col.column.get()); + if (!col_with_dict) + throw Exception("Expected ColumnWithDictionary, got" + res_col.column->getName(), + ErrorCodes::LOGICAL_ERROR); + + ColumnWithDictionary & mut_col_with_dict = col_with_dict->assumeMutableRef(); + if (indexes) - res_col.column = ColumnWithDictionary::create(ColumnUnique::create((*std::move(temp_res_col)).mutate(), - (*std::move(indexes)).mutate())); + { + auto new_ind = mut_col_with_dict.getUnique()->uniqueInsertRangeFrom(*temp_res_col, 0, temp_res_col->size()); + mut_col_with_dict.setIndexes(new_ind->index(indexes, 0)->assumeMutable()); + } else { - res_col.column = res_col.type->createColumn(); - - auto * col_with_dict = checkAndGetColumn(res_col.column.get()); - if (!col_with_dict) - throw Exception("Expected ColumnWithDictionary, got" + res_col.column->getName(), - ErrorCodes::LOGICAL_ERROR); - - col_with_dict->assumeMutableRef().insertRangeFrom(*temp_res_col, 0, temp_res_col->size()); + mut_col_with_dict.insertRangeFrom(*temp_res_col, 0, temp_res_col->size()); } return; }