use raw pointer to replace optional reference_wrapper, and fix the bug in DictionaryStorageFetchRequest

This commit is contained in:
jsc0218 2024-02-02 19:41:00 +00:00
parent 4ce770aebf
commit d33b01921c
3 changed files with 8 additions and 10 deletions

View File

@ -156,7 +156,7 @@ Columns CacheDictionary<dictionary_key_type>::getColumns(
DictionaryKeysExtractor<dictionary_key_type> extractor(key_columns, arena_holder.getComplexKeyArena());
auto keys = extractor.extractAllKeys();
DictionaryStorageFetchRequest request(dict_struct, attribute_names, result_types, default_values_columns);
DictionaryStorageFetchRequest request(dict_struct, attribute_names, result_types, &default_values_columns);
FetchResult result_of_fetch_from_storage;

View File

@ -75,15 +75,15 @@ public:
DictionaryStorageFetchRequest(const DictionaryStructure & structure,
const Strings & attributes_to_fetch_names,
const DataTypes & attributes_to_fetch_types,
std::optional<std::reference_wrapper<const Columns>> attributes_to_fetch_default_values_columns = std::nullopt)
const Columns * const attributes_to_fetch_default_values_columns = nullptr)
: 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());
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());
bool has_default = attributes_to_fetch_default_values_columns;
assert(!has_default || attributes_to_fetch_size == attributes_to_fetch_default_values_columns->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);
@ -93,8 +93,7 @@ public:
size_t attributes_size = structure.attributes.size();
dictionary_attributes_names_and_types.reserve(attributes_size);
if (has_default)
attributes_default_value_providers.reserve(attributes_size);
attributes_default_value_providers.reserve(attributes_size);
for (size_t attribute_index = 0; attribute_index < attributes_size; ++attribute_index)
{
@ -104,8 +103,7 @@ 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())
{
if (has_default)
attributes_default_value_providers.emplace_back(dictionary_attribute.null_value);
attributes_default_value_providers.emplace_back(dictionary_attribute.null_value);
continue;
}
@ -124,7 +122,7 @@ public:
if (has_default)
{
const auto & attribute_to_fetch_default_value_column =
(attributes_to_fetch_default_values_columns->get())[attributes_to_fetch_index];
(*attributes_to_fetch_default_values_columns)[attributes_to_fetch_index];
attributes_default_value_providers.emplace_back(dictionary_attribute.null_value,
attribute_to_fetch_default_value_column);
}

View File

@ -54,7 +54,7 @@ Columns DirectDictionary<dictionary_key_type>::getColumns(
DictionaryKeysExtractor<dictionary_key_type> extractor(key_columns, arena_holder.getComplexKeyArena());
const auto requested_keys = extractor.extractAllKeys();
DictionaryStorageFetchRequest request(dict_struct, attribute_names, result_types, default_values_columns);
DictionaryStorageFetchRequest request(dict_struct, attribute_names, result_types, &default_values_columns);
HashMap<KeyType, size_t> key_to_fetched_index;
key_to_fetched_index.reserve(requested_keys.size());