mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-12 01:12:12 +00:00
remove some duplication
This commit is contained in:
parent
237776c4d4
commit
3a8cfe5a0b
@ -75,13 +75,15 @@ public:
|
||||
DictionaryStorageFetchRequest(const DictionaryStructure & structure,
|
||||
const Strings & attributes_to_fetch_names,
|
||||
const DataTypes & attributes_to_fetch_types,
|
||||
const Columns & attributes_to_fetch_default_values_columns)
|
||||
std::optional<std::reference_wrapper<const Columns>> attributes_to_fetch_default_values_columns = std::nullopt)
|
||||
: attributes_to_fetch_filter(structure.attributes.size(), false)
|
||||
{
|
||||
size_t attributes_to_fetch_size = attributes_to_fetch_names.size();
|
||||
|
||||
assert(attributes_to_fetch_size == attributes_to_fetch_types.size());
|
||||
assert(attributes_to_fetch_size == attributes_to_fetch_default_values_columns.size());
|
||||
|
||||
bool has_default = attributes_to_fetch_default_values_columns.has_value();
|
||||
assert(!has_default || attributes_to_fetch_size == attributes_to_fetch_default_values_columns->get().size());
|
||||
|
||||
for (size_t i = 0; i < attributes_to_fetch_size; ++i)
|
||||
attributes_to_fetch_name_to_index.emplace(attributes_to_fetch_names[i], i);
|
||||
@ -91,7 +93,8 @@ public:
|
||||
|
||||
size_t attributes_size = structure.attributes.size();
|
||||
dictionary_attributes_names_and_types.reserve(attributes_size);
|
||||
attributes_default_value_providers.reserve(attributes_size);
|
||||
if (has_default)
|
||||
attributes_default_value_providers.reserve(attributes_size);
|
||||
|
||||
for (size_t attribute_index = 0; attribute_index < attributes_size; ++attribute_index)
|
||||
{
|
||||
@ -101,7 +104,8 @@ public:
|
||||
auto attribute_to_fetch_index_it = attributes_to_fetch_name_to_index.find(dictionary_attribute.name);
|
||||
if (attribute_to_fetch_index_it == attributes_to_fetch_name_to_index.end())
|
||||
{
|
||||
attributes_default_value_providers.emplace_back(dictionary_attribute.null_value);
|
||||
if (has_default)
|
||||
attributes_default_value_providers.emplace_back(dictionary_attribute.null_value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -109,7 +113,6 @@ public:
|
||||
|
||||
size_t attributes_to_fetch_index = attribute_to_fetch_index_it->second;
|
||||
const auto & attribute_to_fetch_result_type = attributes_to_fetch_types[attributes_to_fetch_index];
|
||||
const auto & attribute_to_fetch_default_value_column = attributes_to_fetch_default_values_columns[attributes_to_fetch_index];
|
||||
|
||||
if (!attribute_to_fetch_result_type->equals(*dictionary_attribute.type))
|
||||
throw Exception(ErrorCodes::TYPE_MISMATCH,
|
||||
@ -118,48 +121,13 @@ public:
|
||||
attribute_to_fetch_result_type->getName(),
|
||||
dictionary_attribute.type->getName());
|
||||
|
||||
attributes_default_value_providers.emplace_back(dictionary_attribute.null_value, attribute_to_fetch_default_value_column);
|
||||
}
|
||||
}
|
||||
|
||||
DictionaryStorageFetchRequest(const DictionaryStructure & structure,
|
||||
const Strings & attributes_to_fetch_names,
|
||||
const DataTypes & attributes_to_fetch_types)
|
||||
: attributes_to_fetch_filter(structure.attributes.size(), false)
|
||||
{
|
||||
size_t attributes_to_fetch_size = attributes_to_fetch_names.size();
|
||||
|
||||
assert(attributes_to_fetch_size == attributes_to_fetch_types.size());
|
||||
|
||||
for (size_t i = 0; i < attributes_to_fetch_size; ++i)
|
||||
attributes_to_fetch_name_to_index.emplace(attributes_to_fetch_names[i], i);
|
||||
|
||||
if (attributes_to_fetch_name_to_index.size() != attributes_to_fetch_name_to_index.size())
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Attribute names to fetch should be unique");
|
||||
|
||||
size_t attributes_size = structure.attributes.size();
|
||||
dictionary_attributes_names_and_types.reserve(attributes_size);
|
||||
|
||||
for (size_t attribute_index = 0; attribute_index < attributes_size; ++attribute_index)
|
||||
{
|
||||
const auto & dictionary_attribute = structure.attributes[attribute_index];
|
||||
dictionary_attributes_names_and_types.emplace_back(dictionary_attribute.name, dictionary_attribute.type);
|
||||
|
||||
auto attribute_to_fetch_index_it = attributes_to_fetch_name_to_index.find(dictionary_attribute.name);
|
||||
if (attribute_to_fetch_index_it == attributes_to_fetch_name_to_index.end())
|
||||
continue;
|
||||
|
||||
attributes_to_fetch_filter[attribute_index] = true;
|
||||
|
||||
size_t attributes_to_fetch_index = attribute_to_fetch_index_it->second;
|
||||
const auto & attribute_to_fetch_result_type = attributes_to_fetch_types[attributes_to_fetch_index];
|
||||
|
||||
if (!attribute_to_fetch_result_type->equals(*dictionary_attribute.type))
|
||||
throw Exception(ErrorCodes::TYPE_MISMATCH,
|
||||
"Attribute {} type does not match, expected {}, found {}",
|
||||
dictionary_attribute.name,
|
||||
attribute_to_fetch_result_type->getName(),
|
||||
dictionary_attribute.type->getName());
|
||||
if (has_default)
|
||||
{
|
||||
const auto & attribute_to_fetch_default_value_column =
|
||||
(attributes_to_fetch_default_values_columns->get())[attributes_to_fetch_index];
|
||||
attributes_default_value_providers.emplace_back(dictionary_attribute.null_value,
|
||||
attribute_to_fetch_default_value_column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user