From 04e3e3179cd7fb6ea329b252a218333536ebec4a Mon Sep 17 00:00:00 2001 From: alesapin Date: Mon, 6 Apr 2020 22:09:39 +0300 Subject: [PATCH] Add converting stream to localhost clickhouse dict --- .../ClickHouseDictionarySource.cpp | 15 +++++++++-- ...local_dictionary_type_conversion.reference | 2 ++ ...01113_local_dictionary_type_conversion.sql | 27 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/01113_local_dictionary_type_conversion.reference create mode 100644 tests/queries/0_stateless/01113_local_dictionary_type_conversion.sql diff --git a/src/Dictionaries/ClickHouseDictionarySource.cpp b/src/Dictionaries/ClickHouseDictionarySource.cpp index 0894a655724..015d3f499ee 100644 --- a/src/Dictionaries/ClickHouseDictionarySource.cpp +++ b/src/Dictionaries/ClickHouseDictionarySource.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -131,6 +132,7 @@ BlockInputStreamPtr ClickHouseDictionarySource::loadAll() { BlockIO res = executeQuery(load_all_query, context, true); /// FIXME res.in may implicitly use some objects owned be res, but them will be destructed after return + res.in = std::make_shared(context, res.in, sample_block, ConvertingBlockInputStream::MatchColumnsMode::Position); return res.in; } return std::make_shared(pool, load_all_query, sample_block, context); @@ -140,7 +142,11 @@ BlockInputStreamPtr ClickHouseDictionarySource::loadUpdatedAll() { std::string load_update_query = getUpdateFieldAndDate(); if (is_local) - return executeQuery(load_update_query, context, true).in; + { + auto res = executeQuery(load_update_query, context, true); + res.in = std::make_shared(context, res.in, sample_block, ConvertingBlockInputStream::MatchColumnsMode::Position); + return res.in; + } return std::make_shared(pool, load_update_query, sample_block, context); } @@ -183,7 +189,12 @@ std::string ClickHouseDictionarySource::toString() const BlockInputStreamPtr ClickHouseDictionarySource::createStreamForSelectiveLoad(const std::string & query) { if (is_local) - return executeQuery(query, context, true).in; + { + auto res = executeQuery(query, context, true); + res.in = std::make_shared( + context, res.in, sample_block, ConvertingBlockInputStream::MatchColumnsMode::Position); + return res.in; + } return std::make_shared(pool, query, sample_block, context); } diff --git a/tests/queries/0_stateless/01113_local_dictionary_type_conversion.reference b/tests/queries/0_stateless/01113_local_dictionary_type_conversion.reference new file mode 100644 index 00000000000..ac390663059 --- /dev/null +++ b/tests/queries/0_stateless/01113_local_dictionary_type_conversion.reference @@ -0,0 +1,2 @@ +First WINDOWS 1 +Second LINUX 2 diff --git a/tests/queries/0_stateless/01113_local_dictionary_type_conversion.sql b/tests/queries/0_stateless/01113_local_dictionary_type_conversion.sql new file mode 100644 index 00000000000..df1f405e286 --- /dev/null +++ b/tests/queries/0_stateless/01113_local_dictionary_type_conversion.sql @@ -0,0 +1,27 @@ +DROP DATABASE IF EXISTS database_for_dict; + +CREATE DATABASE database_for_dict; + +CREATE TABLE database_for_dict.table_for_dict ( + CompanyID String, + OSType Enum('UNKNOWN' = 0, 'WINDOWS' = 1, 'LINUX' = 2, 'ANDROID' = 3, 'MAC' = 4), + SomeID Int32 +) +ENGINE = Memory(); + +INSERT INTO database_for_dict.table_for_dict VALUES ('First', 'WINDOWS', 1), ('Second', 'LINUX', 2); + +CREATE DICTIONARY database_for_dict.dict_with_conversion +( + CompanyID String DEFAULT '', + OSType String DEFAULT '', + SomeID Int32 DEFAULT 0 +) +PRIMARY KEY CompanyID +SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' DB 'database_for_dict')) +LIFETIME(MIN 1 MAX 20) +LAYOUT(COMPLEX_KEY_HASHED()); + +SELECT * FROM database_for_dict.dict_with_conversion ORDER BY CompanyID; + +DROP DATABASE IF EXISTS database_for_dict;