From abf26d4935a831ba663554377f3ac5967ec68795 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Wed, 24 Feb 2021 14:45:14 +0800 Subject: [PATCH] disable null_as_default when type is Nullable --- .../Formats/Impl/ValuesBlockInputFormat.cpp | 12 +++++++++--- .../0_stateless/01736_null_as_default.reference | 2 ++ tests/queries/0_stateless/01736_null_as_default.sql | 5 +++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 tests/queries/0_stateless/01736_null_as_default.reference create mode 100644 tests/queries/0_stateless/01736_null_as_default.sql diff --git a/src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp b/src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp index 34a4a98f16b..7860498e4ff 100644 --- a/src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp +++ b/src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp @@ -255,9 +255,15 @@ bool ValuesBlockInputFormat::parseExpression(IColumn & column, size_t column_idx bool found_in_cache = false; const auto & result_type = header.getByPosition(column_idx).type; const char * delimiter = (column_idx + 1 == num_columns) ? ")" : ","; - auto structure = templates_cache.getFromCacheOrConstruct(result_type, format_settings.null_as_default, - TokenIterator(tokens), token_iterator, - ast, *context, &found_in_cache, delimiter); + auto structure = templates_cache.getFromCacheOrConstruct( + result_type, + !result_type->isNullable() && format_settings.null_as_default, + TokenIterator(tokens), + token_iterator, + ast, + *context, + &found_in_cache, + delimiter); templates[column_idx].emplace(structure); if (found_in_cache) ++attempts_to_deduce_template_cached[column_idx]; diff --git a/tests/queries/0_stateless/01736_null_as_default.reference b/tests/queries/0_stateless/01736_null_as_default.reference new file mode 100644 index 00000000000..baf83eb21d7 --- /dev/null +++ b/tests/queries/0_stateless/01736_null_as_default.reference @@ -0,0 +1,2 @@ +A +\N diff --git a/tests/queries/0_stateless/01736_null_as_default.sql b/tests/queries/0_stateless/01736_null_as_default.sql new file mode 100644 index 00000000000..f9a4bc69acf --- /dev/null +++ b/tests/queries/0_stateless/01736_null_as_default.sql @@ -0,0 +1,5 @@ +drop table if exists test_num; +create table test_enum (c Nullable(Enum16('A' = 1, 'B' = 2))) engine Log; +insert into test_enum values (1), (NULL); +select * from test_enum; +drop table if exists test_num;