Merge pull request #2005 from yandex/fix-dictionary-block-input-stream-for-empty-dicts

fix DictionaryBlockInputStream::getBlock for empty dictionary
This commit is contained in:
KochetovNicolai 2018-03-07 18:20:19 +03:00 committed by GitHub
commit 3d0f298ace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,6 +114,15 @@ private:
Columns data_columns;
GetColumnsFunction get_key_columns_function;
GetColumnsFunction get_view_columns_function;
enum class DictionaryKeyType
{
Id,
ComplexKey,
Callback
};
DictionaryKeyType key_type;
};
template <typename DictionaryType, typename Key>
@ -124,7 +133,8 @@ DictionaryBlockInputStream<DictionaryType, Key>::DictionaryBlockInputStream(
dictionary(std::static_pointer_cast<const DictionaryType>(dictionary)),
column_names(column_names), ids(std::move(ids)),
logger(&Poco::Logger::get("DictionaryBlockInputStream")),
fillBlockFunction(&DictionaryBlockInputStream<DictionaryType, Key>::fillBlock<DictionaryGetter, DictionaryStringGetter>)
fillBlockFunction(&DictionaryBlockInputStream<DictionaryType, Key>::fillBlock<DictionaryGetter, DictionaryStringGetter>),
key_type(DictionaryKeyType::Id)
{
}
@ -135,7 +145,8 @@ DictionaryBlockInputStream<DictionaryType, Key>::DictionaryBlockInputStream(
: DictionaryBlockInputStreamBase(keys.size(), max_block_size),
dictionary(std::static_pointer_cast<const DictionaryType>(dictionary)), column_names(column_names),
logger(&Poco::Logger::get("DictionaryBlockInputStream")),
fillBlockFunction(&DictionaryBlockInputStream<DictionaryType, Key>::fillBlock<GetterByKey, StringGetterByKey>)
fillBlockFunction(&DictionaryBlockInputStream<DictionaryType, Key>::fillBlock<GetterByKey, StringGetterByKey>),
key_type(DictionaryKeyType::ComplexKey)
{
const DictionaryStructure & dictionaty_structure = dictionary->getStructure();
fillKeyColumns(keys, 0, keys.size(), dictionaty_structure, key_columns);
@ -152,14 +163,17 @@ DictionaryBlockInputStream<DictionaryType, Key>::DictionaryBlockInputStream(
logger(&Poco::Logger::get("DictionaryBlockInputStream")),
fillBlockFunction(&DictionaryBlockInputStream<DictionaryType, Key>::fillBlock<GetterByKey, StringGetterByKey>),
data_columns(data_columns),
get_key_columns_function(get_key_columns_function), get_view_columns_function(get_view_columns_function)
get_key_columns_function(get_key_columns_function), get_view_columns_function(get_view_columns_function),
key_type(DictionaryKeyType::Callback)
{
}
template <typename DictionaryType, typename Key>
Block DictionaryBlockInputStream<DictionaryType, Key>::getBlock(size_t start, size_t length) const
{
if (!key_columns.empty())
switch (key_type)
{
case DictionaryKeyType::ComplexKey:
{
Columns columns;
ColumnsWithTypeAndName view_columns;
@ -172,12 +186,12 @@ Block DictionaryBlockInputStream<DictionaryType, Key>::getBlock(size_t start, si
}
return (this->*fillBlockFunction)({}, columns, {}, std::move(view_columns));
}
else if (!ids.empty())
case DictionaryKeyType::Id:
{
PaddedPODArray<Key> block_ids(ids.begin() + start, ids.begin() + start + length);
return (this->*fillBlockFunction)(block_ids, {}, {}, {});
}
else
case DictionaryKeyType::Callback:
{
Columns columns;
columns.reserve(data_columns.size());
@ -196,6 +210,8 @@ Block DictionaryBlockInputStream<DictionaryType, Key>::getBlock(size_t start, si
}
return (this->*fillBlockFunction)({}, columns, types, std::move(view_with_type_and_name));
}
}
throw Exception("Unexpected DictionaryKeyType.", ErrorCodes::LOGICAL_ERROR);
}
template <typename DictionaryType, typename Key>