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
{
const auto null_value = std::get<UInt64>(hierarchical_attribute->null_values);
std::cerr << "HERE\n" << std::endl;
getItemsImpl<UInt64, UInt64>(
*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<StringRef, StringRef>(
DirectDictionary::getItemsStringImpl<StringRef, StringRef>(
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<OutputType>(attribute_column[row_idx].get<AttributeType>()));
// 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>()));
}
}
}
}
@ -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<String>();
const auto * string_in_arena = temp_arena->insert(from_source.data(), from_source.size());
const auto reference = StringRef{string_in_arena, from_source.size()};

View File

@ -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
5 NONE
6 NONE
7 NONE
8 NONE
9 NONE
END

View File

@ -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;