Skip to content

Commit

Permalink
Merge pull request #3330 from CurtizJ/CLICKHOUSE-4005
Browse files Browse the repository at this point in the history
Interpret empty null_value in external dictionaries as type default value [ClLICKHOUSE-4005]
  • Loading branch information
alexey-milovidov committed Oct 9, 2018
2 parents caaa7ff + 33b4a50 commit b776633
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
13 changes: 9 additions & 4 deletions dbms/src/Dictionaries/DictionaryStructure.cpp
Expand Up @@ -316,10 +316,15 @@ std::vector<DictionaryAttribute> DictionaryStructure::getAttributes(
const auto null_value_string = config.getString(prefix + "null_value");
try
{
ReadBufferFromString null_value_buffer{null_value_string};
auto column_with_null_value = type->createColumn();
type->deserializeTextEscaped(*column_with_null_value, null_value_buffer, format_settings);
null_value = (*column_with_null_value)[0];
if (null_value_string.empty())
null_value = type->getDefault();
else
{
ReadBufferFromString null_value_buffer{null_value_string};
auto column_with_null_value = type->createColumn();
type->deserializeTextEscaped(*column_with_null_value, null_value_buffer, format_settings);
null_value = (*column_with_null_value)[0];
}
}
catch (Exception & e)
{
Expand Down
Expand Up @@ -20,11 +20,11 @@
]

implicit_defaults = [
'1', '1', '1', '1',
'1', '1', '1', '',
'-1', '-1', '-1', '-1',
'2.71828', '2.71828',
'implicit-default',
'2015-11-25', '2015-11-25 00:00:00'
'2015-11-25', ''
]


Expand Down
11 changes: 11 additions & 0 deletions dbms/tests/integration/test_dictionaries/test.py
Expand Up @@ -121,3 +121,14 @@ def test_select_all_from_cached(cached_dictionary_structure):
diff = test_table.compare_by_keys(keys, result.lines, use_parent, add_not_found_rows=True)
print test_table.process_diff(diff)
assert not diff

def test_null_value(started_cluster):
query = instance.query

assert TSV(query("select dictGetUInt8('clickhouse_cache', 'UInt8_', toUInt64(12121212))")) == TSV("1")
assert TSV(query("select dictGetString('clickhouse_cache', 'String_', toUInt64(12121212))")) == TSV("implicit-default")
assert TSV(query("select dictGetDate('clickhouse_cache', 'Date_', toUInt64(12121212))")) == TSV("2015-11-25")

# Check, that empty null_value interprets as default value
assert TSV(query("select dictGetUInt64('clickhouse_cache', 'UInt64_', toUInt64(12121212))")) == TSV("0")
assert TSV(query("select dictGetDateTime('clickhouse_cache', 'DateTime_', toUInt64(12121212))")) == TSV("0000-00-00 00:00:00")

0 comments on commit b776633

Please sign in to comment.