fixed (hope) test flapping

This commit is contained in:
Артем Стрельцов 2020-05-02 23:26:22 +03:00
parent 5ba6572210
commit c82b1fc0fe
3 changed files with 45 additions and 35 deletions

View File

@ -159,8 +159,8 @@ void DirectDictionary::getString(const std::string & attribute_name, const Padde
getItemsStringImpl<StringRef, StringRef>(
attribute,
ids,
[&](const size_t, const StringRef value) { out->insertData(value.data, value.size); },
[&](const size_t) { return null_value; });
[&](const size_t, const String value) { const auto ref = StringRef{value}; out->insertData(ref.data, ref.size); },
[&](const size_t) { return String(null_value.data, null_value.size); });
}
#define DECLARE(TYPE) \
@ -201,8 +201,8 @@ void DirectDictionary::getString(
getItemsStringImpl<StringRef, StringRef>(
attribute,
ids,
[&](const size_t, const StringRef value) { out->insertData(value.data, value.size); },
[&](const size_t row) { return def->getDataAt(row); });
[&](const size_t, const String value) { const auto ref = StringRef{value}; out->insertData(ref.data, ref.size); },
[&](const size_t row) { const auto ref = def->getDataAt(row); return String(ref.data, ref.size); });
}
#define DECLARE(TYPE) \
@ -240,8 +240,8 @@ void DirectDictionary::getString(
DirectDictionary::getItemsStringImpl<StringRef, StringRef>(
attribute,
ids,
[&](const size_t, const StringRef value) { out->insertData(value.data, value.size); },
[&](const size_t) { return StringRef{def}; });
[&](const size_t, const String value) { const auto ref = StringRef{value}; out->insertData(ref.data, ref.size); },
[&](const size_t) { return def; });
}
@ -437,7 +437,6 @@ void DirectDictionary::getItemsImpl(
if (key == ids[row] && attribute.name == attribute_name_by_index.at(attribute_idx))
{
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>()));
@ -469,36 +468,37 @@ void DirectDictionary::getItemsStringImpl(
std::vector<bool> is_found(rows, false);
auto stream = source_ptr->loadAll();
stream->readPrefix();
while (const auto block = stream->read())
for (const auto row : ext::range(0, rows))
{
const IColumn & id_column = *block.safeGetByPosition(0).column;
for (const size_t attribute_idx : ext::range(0, attributes.size()))
auto stream = source_ptr->loadAll();
stream->readPrefix();
while (const auto block = stream->read())
{
const IColumn & attribute_column = *block.safeGetByPosition(attribute_idx + 1).column;
const IColumn & id_column = *block.safeGetByPosition(0).column;
for (const auto row_idx : ext::range(0, id_column.size()))
for (const size_t attribute_idx : ext::range(0, attributes.size()))
{
const auto key = id_column[row_idx].get<UInt64>();
for (const auto row : ext::range(0, rows))
const IColumn & attribute_column = *block.safeGetByPosition(attribute_idx + 1).column;
for (const auto row_idx : ext::range(0, id_column.size()))
{
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()};
set_value(row, reference);
}
const auto key = id_column[row_idx].get<UInt64>();
// for (const auto row : ext::range(0, rows))
// {
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>();
set_value(row, from_source);
}
// }
}
}
}
stream->readSuffix();
}
stream->readSuffix();
for (const auto row : ext::range(0, rows))
if (!is_found[row])

View File

@ -12,8 +12,8 @@ INITIALIZING DICTIONARY
London
Great Britain
NONE
0 Moscow
1 Great Britain
0 Great Britain
1 Moscow
2 London
3 Russia
4 Center

View File

@ -63,7 +63,7 @@ CREATE DICTIONARY ordinary_db.dict1
)
PRIMARY KEY key_column
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict1' PASSWORD '' DB 'database_for_dict'))
LIFETIME(MIN 600 MAX 600)
LIFETIME(MIN 1 MAX 600)
LAYOUT(DIRECT()) SETTINGS(max_result_bytes=1);
CREATE DICTIONARY ordinary_db.dict2
@ -74,7 +74,7 @@ CREATE DICTIONARY ordinary_db.dict2
)
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)
LIFETIME(MIN 1 MAX 600)
LAYOUT(DIRECT());
CREATE DICTIONARY ordinary_db.dict3
@ -84,8 +84,8 @@ CREATE DICTIONARY ordinary_db.dict3
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)
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict3' PASSWORD '' DB 'database_for_dict'))
LIFETIME(MIN 1 MAX 600)
LAYOUT(DIRECT());
SELECT 'INITIALIZING DICTIONARY';
@ -104,8 +104,18 @@ SELECT dictGetString('ordinary_db.dict2', 'region_name', toUInt64(5));
SELECT dictGetString('ordinary_db.dict2', 'region_name', toUInt64(4));
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(100), 'NONE');
SELECT number, dictGetStringOrDefault('ordinary_db.dict2', 'region_name', number, 'NONE') chars FROM numbers(10);
SELECT number + 1, dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(number + 1), 'NONE') chars FROM numbers(10);
SELECT number + 1, dictGetFloat32OrDefault('ordinary_db.dict3', 'parent_region', toUInt64(number + 1), toFloat32(0)) chars FROM numbers(10);
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(1), 'NONE');
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(2), 'NONE');
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(3), 'NONE');
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(4), 'NONE');
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(5), 'NONE');
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(6), 'NONE');
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(7), 'NONE');
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(8), 'NONE');
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(9), 'NONE');
SELECT dictGetStringOrDefault('ordinary_db.dict2', 'region_name', toUInt64(10), 'NONE');
SELECT dictGetUInt64('ordinary_db.dict1', 'second_column', toUInt64(100500)); -- { serverError 396 }