@@ -163,29 +163,6 @@ UInt64 getMaximumFileNumber(const std::string & dir_path)
163163 return res;
164164}
165165
166- // / the same as DistributedBlockOutputStream::createSelector, should it be static?
167- IColumn::Selector createSelector (const ClusterPtr cluster, const ColumnWithTypeAndName & result)
168- {
169- const auto & slot_to_shard = cluster->getSlotToShard ();
170-
171- #define CREATE_FOR_TYPE (TYPE ) \
172- if (typeid_cast<const DataType##TYPE *>(result.type .get ())) \
173- return createBlockSelector<TYPE>(*result.column , slot_to_shard);
174-
175- CREATE_FOR_TYPE (UInt8)
176- CREATE_FOR_TYPE (UInt16)
177- CREATE_FOR_TYPE (UInt32)
178- CREATE_FOR_TYPE (UInt64)
179- CREATE_FOR_TYPE (Int8)
180- CREATE_FOR_TYPE (Int16)
181- CREATE_FOR_TYPE (Int32)
182- CREATE_FOR_TYPE (Int64)
183-
184- #undef CREATE_FOR_TYPE
185-
186- throw Exception{" Sharding key expression does not evaluate to an integer type" , ErrorCodes::TYPE_MISMATCH};
187- }
188-
189166std::string makeFormattedListOfShards (const ClusterPtr & cluster)
190167{
191168 std::ostringstream os;
@@ -730,6 +707,32 @@ void StorageDistributed::ClusterNodeData::shutdownAndDropAllData() const
730707 directory_monitor->shutdownAndDropAllData ();
731708}
732709
710+ IColumn::Selector StorageDistributed::createSelector (const ClusterPtr cluster, const ColumnWithTypeAndName & result)
711+ {
712+ const auto & slot_to_shard = cluster->getSlotToShard ();
713+
714+ // If result.type is DataTypeLowCardinality, do shard according to its dictionaryType
715+ #define CREATE_FOR_TYPE (TYPE ) \
716+ if (typeid_cast<const DataType##TYPE *>(result.type .get ())) \
717+ return createBlockSelector<TYPE>(*result.column , slot_to_shard); \
718+ else if (auto * type_low_cardinality = typeid_cast<const DataTypeLowCardinality *>(result.type .get ())) \
719+ if (typeid_cast<const DataType ## TYPE *>(type_low_cardinality->getDictionaryType ().get ())) \
720+ return createBlockSelector<TYPE>(*result.column ->convertToFullColumnIfLowCardinality (), slot_to_shard);
721+
722+ CREATE_FOR_TYPE (UInt8)
723+ CREATE_FOR_TYPE (UInt16)
724+ CREATE_FOR_TYPE (UInt32)
725+ CREATE_FOR_TYPE (UInt64)
726+ CREATE_FOR_TYPE (Int8)
727+ CREATE_FOR_TYPE (Int16)
728+ CREATE_FOR_TYPE (Int32)
729+ CREATE_FOR_TYPE (Int64)
730+
731+ #undef CREATE_FOR_TYPE
732+
733+ throw Exception{" Sharding key expression does not evaluate to an integer type" , ErrorCodes::TYPE_MISMATCH};
734+ }
735+
733736// / Returns a new cluster with fewer shards if constant folding for `sharding_key_expr` is possible
734737// / using constraints from "PREWHERE" and "WHERE" conditions, otherwise returns `nullptr`
735738ClusterPtr StorageDistributed::skipUnusedShards (ClusterPtr cluster, const ASTPtr & query_ptr, const Context & context) const
0 commit comments