diff --git a/src/Functions/validateNestedArraySizes.cpp b/src/Functions/validateNestedArraySizes.cpp index b589b1e2e5c..a16aed37a1b 100644 --- a/src/Functions/validateNestedArraySizes.cpp +++ b/src/Functions/validateNestedArraySizes.cpp @@ -59,13 +59,25 @@ DataTypePtr FunctionValidateNestedArraySizes::getReturnTypeImpl(const DataTypes ColumnPtr FunctionValidateNestedArraySizes::executeImpl( const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*result_type*/, size_t input_rows_count) const { + bool is_condition_const = false; + bool condition = false; const ColumnUInt8 * condition_column = typeid_cast(arguments[0].column.get()); + if (!condition_column) + { + if (checkAndGetColumnConst(arguments[0].column.get())) + { + is_condition_const = true; + condition = arguments[0].column->getBool(0); + } + } size_t args_num = arguments.size(); for (size_t i = 0; i < input_rows_count; ++i) { - if (!condition_column->getData()[i]) + if (is_condition_const && !condition) + continue; + else if (!is_condition_const && !condition_column->getData()[i]) continue; /// The condition is true, then check the row in subcolumns in Nested Type has the same array size diff --git a/tests/queries/0_stateless/01788_update_nested_type_subcolumn_check.reference b/tests/queries/0_stateless/01788_update_nested_type_subcolumn_check.reference index c6f75cab8b7..48c30f97cd6 100644 --- a/tests/queries/0_stateless/01788_update_nested_type_subcolumn_check.reference +++ b/tests/queries/0_stateless/01788_update_nested_type_subcolumn_check.reference @@ -1,3 +1,4 @@ +********* test 1 ********** 1 [100,200] ['aa','bb'] [1,2] 0 [0,1] ['aa','bb'] [0,0] 1 [100,200] ['aa','bb'] [1,2] @@ -14,6 +15,13 @@ 2 [100,200,300] ['a','b','c'] [100,200,300] 3 [68,72] ['aa','bb'] [68,72] 4 [4,5] ['aa','bb'] [4,8] +********* test 2 ********** +0 [0,1] ['aa','bb'] [0,0] [0,1] ['aa','bb'] +1 [1,2] ['aa','bb'] [1,2] [1,2] ['aa','bb'] +2 [2,3] ['aa','bb'] [2,4] [2,3] ['aa','bb'] +3 [3,4] ['aa','bb'] [3,6] [3,4] ['aa','bb'] +4 [4,5] ['aa','bb'] [4,8] [4,5] ['aa','bb'] +********* test 3 ********** 0 0 aa 0 1 1 bb 2 2 2 aa 4 diff --git a/tests/queries/0_stateless/01788_update_nested_type_subcolumn_check.sql b/tests/queries/0_stateless/01788_update_nested_type_subcolumn_check.sql index 8e850b70c24..accb785ba03 100644 --- a/tests/queries/0_stateless/01788_update_nested_type_subcolumn_check.sql +++ b/tests/queries/0_stateless/01788_update_nested_type_subcolumn_check.sql @@ -11,6 +11,7 @@ ENGINE = MergeTree ORDER BY tuple() SETTINGS min_bytes_for_wide_part = 0; +SELECT '********* test 1 **********'; set mutations_sync = 1; INSERT INTO test_wide_nested SELECT number, [number,number + 1], ['aa','bb'], [number,number * 2] FROM numbers(5); @@ -31,6 +32,7 @@ select * from test_wide_nested; alter table test_wide_nested update `info.id` = [100,200], `info.age` = [10,20,30], `info.name` = ['a','b','c'] where id = 0; -- { serverError 341 } -- Recreate table, because KILL MUTATION is not suitable for parallel tests execution. +SELECT '********* test 2 **********'; DROP TABLE test_wide_nested; CREATE TABLE test_wide_nested @@ -45,11 +47,16 @@ ORDER BY tuple() SETTINGS min_bytes_for_wide_part = 0; INSERT INTO test_wide_nested SELECT number, [number,number + 1], ['aa','bb'], [number,number * 2] FROM numbers(5); +ALTER TABLE test_wide_nested ADD COLUMN `info2.id` Array(Int); +ALTER TABLE test_wide_nested ADD COLUMN `info2.name` Array(String); +ALTER table test_wide_nested update `info2.id` = `info.id`, `info2.name` = `info.name` where 1; +select * from test_wide_nested; alter table test_wide_nested update `info.id` = [100,200,300], `info.age` = [10,20,30] where id = 1; -- { serverError 341 } DROP TABLE test_wide_nested; +SELECT '********* test 3 **********'; DROP TABLE IF EXISTS test_wide_not_nested; CREATE TABLE test_wide_not_nested