fixed problem with dictGetString and Float32

This commit is contained in:
Артем Стрельцов 2020-05-02 20:58:24 +03:00
parent 2a4ce4f41c
commit 5ba6572210
3 changed files with 61 additions and 20 deletions

View File

@ -40,7 +40,6 @@ DirectDictionary::DirectDictionary(
void DirectDictionary::toParent(const PaddedPODArray<Key> & ids, PaddedPODArray<Key> & out) const void DirectDictionary::toParent(const PaddedPODArray<Key> & ids, PaddedPODArray<Key> & out) const
{ {
const auto null_value = std::get<UInt64>(hierarchical_attribute->null_values); const auto null_value = std::get<UInt64>(hierarchical_attribute->null_values);
std::cerr << "HERE\n" << std::endl;
getItemsImpl<UInt64, UInt64>( getItemsImpl<UInt64, UInt64>(
*hierarchical_attribute, *hierarchical_attribute,
ids, ids,
@ -238,7 +237,7 @@ void DirectDictionary::getString(
const auto & attribute = getAttribute(attribute_name); const auto & attribute = getAttribute(attribute_name);
checkAttributeType(full_name, attribute_name, attribute.type, AttributeUnderlyingType::utString); checkAttributeType(full_name, attribute_name, attribute.type, AttributeUnderlyingType::utString);
DirectDictionary::getItemsImpl<StringRef, StringRef>( DirectDictionary::getItemsStringImpl<StringRef, StringRef>(
attribute, attribute,
ids, ids,
[&](const size_t, const StringRef value) { out->insertData(value.data, value.size); }, [&](const size_t, const StringRef value) { out->insertData(value.data, value.size); },
@ -438,20 +437,27 @@ void DirectDictionary::getItemsImpl(
if (key == ids[row] && attribute.name == attribute_name_by_index.at(attribute_idx)) if (key == ids[row] && attribute.name == attribute_name_by_index.at(attribute_idx))
{ {
is_found[row] = true; is_found[row] = true;
// std::cerr << "FOUND: " << key << " " << static_cast<Float32>(attribute_column[row_idx].get<Float64>()) << "\n";
if (attribute.type == AttributeUnderlyingType::utFloat32)
{
set_value(row, static_cast<Float32>(attribute_column[row_idx].get<Float64>()));
}
else
{
set_value(row, static_cast<OutputType>(attribute_column[row_idx].get<AttributeType>())); set_value(row, static_cast<OutputType>(attribute_column[row_idx].get<AttributeType>()));
} }
}
} }
} }
} }
} }
stream->readSuffix(); stream->readSuffix();
for (const auto row : ext::range(0, rows)) for (const auto row : ext::range(0, rows))
if (!is_found[row]) if (!is_found[row])
set_value(row, get_default(row)); set_value(row, get_default(row));
query_count.fetch_add(rows, std::memory_order_relaxed); 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)) if (key == ids[row] && attribute.name == attribute_name_by_index.at(attribute_idx))
{ {
is_found[row] = true; is_found[row] = true;
const String from_source = attribute_column[row_idx].get<String>(); const String from_source = attribute_column[row_idx].get<String>();
const auto * string_in_arena = temp_arena->insert(from_source.data(), from_source.size()); const auto * string_in_arena = temp_arena->insert(from_source.data(), from_source.size());
const auto reference = StringRef{string_in_arena, from_source.size()}; const auto reference = StringRef{string_in_arena, from_source.size()};

View File

@ -6,17 +6,20 @@ INITIALIZING DICTIONARY
0 0
2 2
0 0
2
1
0
London London
Great Britain Great Britain
NONE
0 Great Britain 0 Moscow
1 Moscow 1 Great Britain
2 Russia 2 London
3 London 3 Russia
4 Center 4 Center
5 5 NONE
6 6 NONE
7 7 NONE
8 8 NONE
9 9 NONE
END END

View File

@ -3,8 +3,8 @@ DROP DATABASE IF EXISTS database_for_dict;
CREATE DATABASE database_for_dict Engine = Ordinary; 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_dict1;
DROP TABLE IF EXISTS database_for_dict.table_for_dict2; 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 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 (4, 0, 'Great Britain');
INSERT INTO database_for_dict.table_for_dict2 VALUES (5, 4, 'London'); 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; DROP DATABASE IF EXISTS ordinary_db;
CREATE DATABASE ordinary_db ENGINE = Ordinary; CREATE DATABASE ordinary_db ENGINE = Ordinary;
DROP DICTIONARY IF EXISTS ordinary_db.dict1; 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 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) LIFETIME(MIN 600 MAX 600)
LAYOUT(DIRECT()); 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 'INITIALIZING DICTIONARY';
SELECT dictGetHierarchy('ordinary_db.dict2', toUInt64(3)); 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 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(3));
SELECT dictGetUInt64('ordinary_db.dict2', 'parent_region', toUInt64(99)); 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(5));
SELECT dictGetString('ordinary_db.dict2', 'region_name', toUInt64(4)); 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 } 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.dict1;
DROP DICTIONARY IF EXISTS ordinary_db.dict2; DROP DICTIONARY IF EXISTS ordinary_db.dict2;
DROP DICTIONARY IF EXISTS ordinary_db.dict3;
DROP DATABASE IF EXISTS ordinary_db; 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_dict1;
DROP TABLE IF EXISTS database_for_dict.table_for_dict2; 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; DROP DATABASE IF EXISTS database_for_dict;