From bdb420cdfdb9c591ee0fed42cf86fb51c9f66553 Mon Sep 17 00:00:00 2001 From: qianlixiang Date: Fri, 29 Mar 2019 18:53:50 +0800 Subject: [PATCH] Fixed segment fault of arrayIntersect --- dbms/src/Functions/arrayIntersect.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dbms/src/Functions/arrayIntersect.cpp b/dbms/src/Functions/arrayIntersect.cpp index c6cb02e6caf..51ae95cf707 100644 --- a/dbms/src/Functions/arrayIntersect.cpp +++ b/dbms/src/Functions/arrayIntersect.cpp @@ -277,7 +277,7 @@ void FunctionArrayIntersect::executeImpl(Block & block, const ColumnNumbers & ar const auto & return_type = block.getByPosition(result).type; auto return_type_array = checkAndGetDataType(return_type.get()); - if (!return_type) + if (!return_type_array) throw Exception{"Return type for function " + getName() + " must be array.", ErrorCodes::LOGICAL_ERROR}; const auto & nested_return_type = return_type_array->getNestedType(); @@ -393,6 +393,11 @@ ColumnPtr FunctionArrayIntersect::execute(const UnpackedArrays & arrays, Mutable { bool current_has_nullable = false; size_t off = (*arrays.offsets[arg])[row]; + // const array has only one row + bool const_arg = arrays.is_const[arg]; + if (const_arg) + off = (*arrays.offsets[arg])[0]; + for (auto i : ext::range(prev_off[arg], off)) { if (arrays.null_maps[arg] && (*arrays.null_maps[arg])[i]) @@ -412,6 +417,9 @@ ColumnPtr FunctionArrayIntersect::execute(const UnpackedArrays & arrays, Mutable } prev_off[arg] = off; + if (const_arg) + prev_off[arg] = 0; + if (!current_has_nullable) all_has_nullable = false; }