From a4e8c477022a37a3814e707cfd298e807aad2fc8 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 2 Aug 2020 04:07:08 +0300 Subject: [PATCH] Fix assert in arrayElement --- src/Functions/array/arrayElement.cpp | 6 ++++-- .../01421_array_nullable_element_nullable_index.reference | 4 ++++ .../01421_array_nullable_element_nullable_index.sql | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/01421_array_nullable_element_nullable_index.reference create mode 100644 tests/queries/0_stateless/01421_array_nullable_element_nullable_index.sql diff --git a/src/Functions/array/arrayElement.cpp b/src/Functions/array/arrayElement.cpp index 2836c5ea4d7..9a60ac4a39d 100644 --- a/src/Functions/array/arrayElement.cpp +++ b/src/Functions/array/arrayElement.cpp @@ -780,8 +780,10 @@ void FunctionArrayElement::executeImpl(Block & block, const ColumnNumbers & argu ArrayImpl::NullMapBuilder builder; Block source_block; - const auto & input_type = typeid_cast(*typeid_cast(*block.getByPosition(arguments[0]).type).getNestedType()).getNestedType(); - const auto & tmp_ret_type = typeid_cast(*block.getByPosition(result).type).getNestedType(); + const DataTypePtr & input_type = typeid_cast( + *typeid_cast(*block.getByPosition(arguments[0]).type).getNestedType()).getNestedType(); + + DataTypePtr tmp_ret_type = removeNullable(block.getByPosition(result).type); if (col_array) { diff --git a/tests/queries/0_stateless/01421_array_nullable_element_nullable_index.reference b/tests/queries/0_stateless/01421_array_nullable_element_nullable_index.reference new file mode 100644 index 00000000000..070f5e44a15 --- /dev/null +++ b/tests/queries/0_stateless/01421_array_nullable_element_nullable_index.reference @@ -0,0 +1,4 @@ +[1] 1 +[1] 1 +[1] 1 +[1] 1 diff --git a/tests/queries/0_stateless/01421_array_nullable_element_nullable_index.sql b/tests/queries/0_stateless/01421_array_nullable_element_nullable_index.sql new file mode 100644 index 00000000000..5cf8bc8fe00 --- /dev/null +++ b/tests/queries/0_stateless/01421_array_nullable_element_nullable_index.sql @@ -0,0 +1,4 @@ +SELECT [toNullable(1)] AS x, x[toNullable(1)] AS y; +SELECT materialize([toNullable(1)]) AS x, x[toNullable(1)] AS y; +SELECT [toNullable(1)] AS x, x[materialize(toNullable(1))] AS y; +SELECT materialize([toNullable(1)]) AS x, x[materialize(toNullable(1))] AS y;