diff --git a/src/Dictionaries/DirectDictionary.cpp b/src/Dictionaries/DirectDictionary.cpp index fa632bfd0c9..a3d73f442c0 100644 --- a/src/Dictionaries/DirectDictionary.cpp +++ b/src/Dictionaries/DirectDictionary.cpp @@ -40,7 +40,6 @@ DirectDictionary::DirectDictionary( void DirectDictionary::toParent(const PaddedPODArray & ids, PaddedPODArray & out) const { const auto null_value = std::get(hierarchical_attribute->null_values); - std::cerr << "HERE\n" << std::endl; getItemsImpl( *hierarchical_attribute, ids, @@ -238,7 +237,7 @@ void DirectDictionary::getString( const auto & attribute = getAttribute(attribute_name); checkAttributeType(full_name, attribute_name, attribute.type, AttributeUnderlyingType::utString); - DirectDictionary::getItemsImpl( + DirectDictionary::getItemsStringImpl( attribute, ids, [&](const size_t, const StringRef value) { out->insertData(value.data, value.size); }, @@ -438,7 +437,16 @@ void DirectDictionary::getItemsImpl( if (key == ids[row] && attribute.name == attribute_name_by_index.at(attribute_idx)) { is_found[row] = true; - set_value(row, static_cast(attribute_column[row_idx].get())); + // std::cerr << "FOUND: " << key << " " << static_cast(attribute_column[row_idx].get()) << "\n"; + if (attribute.type == AttributeUnderlyingType::utFloat32) + { + set_value(row, static_cast(attribute_column[row_idx].get())); + } + else + { + set_value(row, static_cast(attribute_column[row_idx].get())); + } + } } } @@ -446,12 +454,10 @@ void DirectDictionary::getItemsImpl( } stream->readSuffix(); - for (const auto row : ext::range(0, rows)) if (!is_found[row]) set_value(row, get_default(row)); - query_count.fetch_add(rows, std::memory_order_relaxed); } @@ -482,7 +488,6 @@ void DirectDictionary::getItemsStringImpl( if (key == ids[row] && attribute.name == attribute_name_by_index.at(attribute_idx)) { is_found[row] = true; - const String from_source = attribute_column[row_idx].get(); const auto * string_in_arena = temp_arena->insert(from_source.data(), from_source.size()); const auto reference = StringRef{string_in_arena, from_source.size()}; diff --git a/tests/queries/0_stateless/01268_dictionary_direct_layout.reference b/tests/queries/0_stateless/01268_dictionary_direct_layout.reference index 60be4951cb2..bc480542f2e 100644 --- a/tests/queries/0_stateless/01268_dictionary_direct_layout.reference +++ b/tests/queries/0_stateless/01268_dictionary_direct_layout.reference @@ -6,17 +6,20 @@ INITIALIZING DICTIONARY 0 2 0 +2 +1 +0 London Great Britain - -0 Great Britain -1 Moscow -2 Russia -3 London +NONE +0 Moscow +1 Great Britain +2 London +3 Russia 4 Center -5 -6 -7 -8 -9 -END \ No newline at end of file +5 NONE +6 NONE +7 NONE +8 NONE +9 NONE +END diff --git a/tests/queries/0_stateless/01268_dictionary_direct_layout.sql b/tests/queries/0_stateless/01268_dictionary_direct_layout.sql index 72c61d44575..7f450fc8c62 100644 --- a/tests/queries/0_stateless/01268_dictionary_direct_layout.sql +++ b/tests/queries/0_stateless/01268_dictionary_direct_layout.sql @@ -3,8 +3,8 @@ DROP DATABASE IF EXISTS database_for_dict; CREATE DATABASE database_for_dict Engine = Ordinary; DROP TABLE IF EXISTS database_for_dict.table_for_dict1; - DROP TABLE IF EXISTS database_for_dict.table_for_dict2; +DROP TABLE IF EXISTS database_for_dict.table_for_dict3; CREATE TABLE database_for_dict.table_for_dict1 ( @@ -32,11 +32,28 @@ INSERT INTO database_for_dict.table_for_dict2 VALUES (3, 2, 'Center'); INSERT INTO database_for_dict.table_for_dict2 VALUES (4, 0, 'Great Britain'); INSERT INTO database_for_dict.table_for_dict2 VALUES (5, 4, 'London'); +CREATE TABLE database_for_dict.table_for_dict3 +( + region_id UInt64, + parent_region Float32, + region_name String +) +ENGINE = MergeTree() +ORDER BY region_id; + +INSERT INTO database_for_dict.table_for_dict3 VALUES (1, 0.5, 'Russia'); +INSERT INTO database_for_dict.table_for_dict3 VALUES (2, 1.6, 'Moscow'); +INSERT INTO database_for_dict.table_for_dict3 VALUES (3, 2.3, 'Center'); +INSERT INTO database_for_dict.table_for_dict3 VALUES (4, 0.2, 'Great Britain'); +INSERT INTO database_for_dict.table_for_dict3 VALUES (5, 4.9, 'London'); + DROP DATABASE IF EXISTS ordinary_db; CREATE DATABASE ordinary_db ENGINE = Ordinary; DROP DICTIONARY IF EXISTS ordinary_db.dict1; +DROP DICTIONARY IF EXISTS ordinary_db.dict2; +DROP DICTIONARY IF EXISTS ordinary_db.dict3; CREATE DICTIONARY ordinary_db.dict1 ( @@ -60,6 +77,17 @@ SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dic LIFETIME(MIN 600 MAX 600) LAYOUT(DIRECT()); +CREATE DICTIONARY ordinary_db.dict3 +( + region_id UInt64 DEFAULT 0, + parent_region Float32 DEFAULT 0, + region_name String DEFAULT '' +) +PRIMARY KEY region_id +SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict2' PASSWORD '' DB 'database_for_dict')) +LIFETIME(MIN 600 MAX 600) +LAYOUT(DIRECT()); + SELECT 'INITIALIZING DICTIONARY'; SELECT dictGetHierarchy('ordinary_db.dict2', toUInt64(3)); @@ -69,11 +97,14 @@ SELECT dictIsIn('ordinary_db.dict2', toUInt64(3), toUInt64(1)); SELECT dictIsIn('ordinary_db.dict2', toUInt64(1), toUInt64(3)); SELECT dictGetUInt64('ordinary_db.dict2', 'parent_region', toUInt64(3)); SELECT dictGetUInt64('ordinary_db.dict2', 'parent_region', toUInt64(99)); +SELECT dictGetFloat32('ordinary_db.dict3', 'parent_region', toUInt64(3)); +SELECT dictGetFloat32('ordinary_db.dict3', 'parent_region', toUInt64(2)); +SELECT dictGetFloat32('ordinary_db.dict3', 'parent_region', toUInt64(1)); SELECT dictGetString('ordinary_db.dict2', 'region_name', toUInt64(5)); SELECT dictGetString('ordinary_db.dict2', 'region_name', toUInt64(4)); -SELECT dictGetString('ordinary_db.dict2', 'region_name', toUInt64(100)); +SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(100), 'NONE'); -SELECT number, dictGetString('ordinary_db.dict2', 'region_name', number) chars FROM numbers(10); +SELECT number, dictGetStringOrDefault('ordinary_db.dict2', 'region_name', number, 'NONE') chars FROM numbers(10); SELECT dictGetUInt64('ordinary_db.dict1', 'second_column', toUInt64(100500)); -- { serverError 396 } @@ -82,10 +113,12 @@ SELECT 'END'; DROP DICTIONARY IF EXISTS ordinary_db.dict1; DROP DICTIONARY IF EXISTS ordinary_db.dict2; +DROP DICTIONARY IF EXISTS ordinary_db.dict3; DROP DATABASE IF EXISTS ordinary_db; DROP TABLE IF EXISTS database_for_dict.table_for_dict1; DROP TABLE IF EXISTS database_for_dict.table_for_dict2; +DROP TABLE IF EXISTS database_for_dict.table_for_dict3; DROP DATABASE IF EXISTS database_for_dict;