From c648c300bf0f793ed69f9f1b7b8c765331759c1d Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 1 May 2020 02:32:50 +0300 Subject: [PATCH] Fix optimize_skip_unused_shards with LowCardinality --- src/Storages/StorageDistributed.cpp | 12 ++++++++---- ...mize_skip_unused_shards_low_cardinality.reference | 0 ...0_optimize_skip_unused_shards_low_cardinality.sql | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/queries/0_stateless/01270_optimize_skip_unused_shards_low_cardinality.reference create mode 100644 tests/queries/0_stateless/01270_optimize_skip_unused_shards_low_cardinality.sql diff --git a/src/Storages/StorageDistributed.cpp b/src/Storages/StorageDistributed.cpp index dcf08aa7d54..8426e5e0ae2 100644 --- a/src/Storages/StorageDistributed.cpp +++ b/src/Storages/StorageDistributed.cpp @@ -163,14 +163,18 @@ UInt64 getMaximumFileNumber(const std::string & dir_path) return res; } -/// the same as DistributedBlockOutputStream::createSelector, should it be static? +/// The same as DistributedBlockOutputStream::createSelector IColumn::Selector createSelector(const ClusterPtr cluster, const ColumnWithTypeAndName & result) { const auto & slot_to_shard = cluster->getSlotToShard(); -#define CREATE_FOR_TYPE(TYPE) \ - if (typeid_cast(result.type.get())) \ - return createBlockSelector(*result.column, slot_to_shard); +// If result.type is DataTypeLowCardinality, do shard according to its dictionaryType +#define CREATE_FOR_TYPE(TYPE) \ + if (typeid_cast(result.type.get())) \ + return createBlockSelector(*result.column, slot_to_shard); \ + else if (auto * type_low_cardinality = typeid_cast(result.type.get())) \ + if (typeid_cast(type_low_cardinality->getDictionaryType().get())) \ + return createBlockSelector(*result.column->convertToFullColumnIfLowCardinality(), slot_to_shard); CREATE_FOR_TYPE(UInt8) CREATE_FOR_TYPE(UInt16) diff --git a/tests/queries/0_stateless/01270_optimize_skip_unused_shards_low_cardinality.reference b/tests/queries/0_stateless/01270_optimize_skip_unused_shards_low_cardinality.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01270_optimize_skip_unused_shards_low_cardinality.sql b/tests/queries/0_stateless/01270_optimize_skip_unused_shards_low_cardinality.sql new file mode 100644 index 00000000000..beffc0464d7 --- /dev/null +++ b/tests/queries/0_stateless/01270_optimize_skip_unused_shards_low_cardinality.sql @@ -0,0 +1,10 @@ +set optimize_skip_unused_shards=1; +set force_optimize_skip_unused_shards=2; +set allow_suspicious_low_cardinality_types=1; + +drop table if exists data_01270; +drop table if exists dist_01270; + +create table data_01270 (key LowCardinality(Int)) Engine=Null(); +create table dist_01270 as data_01270 Engine=Distributed(test_cluster_two_shards, currentDatabase(), data_01270, key); +select * from dist_01270 where key = 1;