From 551e99526540dfd8ef5b9584cbc28ed384b0e44a Mon Sep 17 00:00:00 2001 From: Shichao Jin Date: Wed, 20 Nov 2024 19:56:27 +0000 Subject: [PATCH] Merge pull request #71894 from udiz/fix-arrayWithConstant-size-estimation Fix: arrayWithConstant size estimation using row's element size --- src/Functions/array/arrayWithConstant.cpp | 7 ++++--- .../queries/0_stateless/03216_arrayWithConstant_limits.sql | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Functions/array/arrayWithConstant.cpp b/src/Functions/array/arrayWithConstant.cpp index 4cbc6404b9bc..70d5080d1f97 100644 --- a/src/Functions/array/arrayWithConstant.cpp +++ b/src/Functions/array/arrayWithConstant.cpp @@ -62,16 +62,17 @@ class FunctionArrayWithConstant : public IFunction for (size_t i = 0; i < num_rows; ++i) { auto array_size = col_num->getInt(i); + auto element_size = col_value->byteSizeAt(i); if (unlikely(array_size < 0)) throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Array size {} cannot be negative: while executing function {}", array_size, getName()); Int64 estimated_size = 0; - if (unlikely(common::mulOverflow(array_size, col_value->byteSize(), estimated_size))) - throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Array size {} with element size {} bytes is too large: while executing function {}", array_size, col_value->byteSize(), getName()); + if (unlikely(common::mulOverflow(array_size, element_size, estimated_size))) + throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Array size {} with element size {} bytes is too large: while executing function {}", array_size, element_size, getName()); if (unlikely(estimated_size > max_array_size_in_columns_bytes)) - throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Array size {} with element size {} bytes is too large: while executing function {}", array_size, col_value->byteSize(), getName()); + throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Array size {} with element size {} bytes is too large: while executing function {}", array_size, element_size, getName()); offset += array_size; diff --git a/tests/queries/0_stateless/03216_arrayWithConstant_limits.sql b/tests/queries/0_stateless/03216_arrayWithConstant_limits.sql index c46524c50e6d..b9577e2ca53f 100644 --- a/tests/queries/0_stateless/03216_arrayWithConstant_limits.sql +++ b/tests/queries/0_stateless/03216_arrayWithConstant_limits.sql @@ -1,3 +1,6 @@ SELECT arrayWithConstant(96142475, ['qMUF']); -- { serverError TOO_LARGE_ARRAY_SIZE } SELECT arrayWithConstant(100000000, materialize([[[[[[[[[['Hello, world!']]]]]]]]]])); -- { serverError TOO_LARGE_ARRAY_SIZE } SELECT length(arrayWithConstant(10000000, materialize([[[[[[[[[['Hello world']]]]]]]]]]))); + +CREATE TEMPORARY TABLE args (value Array(Int)) ENGINE=Memory AS SELECT [1, 1, 1, 1] as value FROM numbers(1, 100); +SELECT length(arrayWithConstant(1000000, value)) FROM args FORMAT NULL;