Fix optimize_skip_unused_shards with LowCardinality

This commit is contained in:
Azat Khuzhin 2020-05-01 02:32:50 +03:00
parent fc28416b81
commit c648c300bf
3 changed files with 18 additions and 4 deletions

View File

@ -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<const DataType##TYPE *>(result.type.get())) \
return createBlockSelector<TYPE>(*result.column, slot_to_shard);
// If result.type is DataTypeLowCardinality, do shard according to its dictionaryType
#define CREATE_FOR_TYPE(TYPE) \
if (typeid_cast<const DataType##TYPE *>(result.type.get())) \
return createBlockSelector<TYPE>(*result.column, slot_to_shard); \
else if (auto * type_low_cardinality = typeid_cast<const DataTypeLowCardinality *>(result.type.get())) \
if (typeid_cast<const DataType ## TYPE *>(type_low_cardinality->getDictionaryType().get())) \
return createBlockSelector<TYPE>(*result.column->convertToFullColumnIfLowCardinality(), slot_to_shard);
CREATE_FOR_TYPE(UInt8)
CREATE_FOR_TYPE(UInt16)

View File

@ -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;