diff --git a/src/Interpreters/ExpressionActions.cpp b/src/Interpreters/ExpressionActions.cpp index f5cd0ff409d..025c7d212ab 100644 --- a/src/Interpreters/ExpressionActions.cpp +++ b/src/Interpreters/ExpressionActions.cpp @@ -387,9 +387,6 @@ void ExpressionAction::execute(Block & block, bool dry_run) const source.type = assert_cast(*source.type).getNestedType(); source.name = result_name; - if (source.type->getTypeId() == TypeIndex::Nothing) - throw Exception("ARRAY JOIN of empty array is not allowed", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - block.insert(std::move(source)); break; diff --git a/src/Processors/Transforms/TotalsHavingTransform.cpp b/src/Processors/Transforms/TotalsHavingTransform.cpp index 65043f65e1a..738b0062e6c 100644 --- a/src/Processors/Transforms/TotalsHavingTransform.cpp +++ b/src/Processors/Transforms/TotalsHavingTransform.cpp @@ -13,6 +13,7 @@ namespace DB namespace ErrorCodes { extern const int LOGICAL_ERROR; + extern const int ILLEGAL_COLUMN; } void finalizeChunk(Chunk & chunk) @@ -156,6 +157,13 @@ void TotalsHavingTransform::transform(Chunk & chunk) /// Compute the expression in HAVING. const auto & cur_header = final ? finalized_header : getInputPort().getHeader(); auto finalized_block = cur_header.cloneWithColumns(finalized.detachColumns()); + + for (const ExpressionAction & action : expression->getActions()) + { + if (action.type == ExpressionAction::ARRAY_JOIN) + throw Exception("Having clause cannot contain arrayJoin", ErrorCodes::ILLEGAL_COLUMN); + } + expression->execute(finalized_block); auto columns = finalized_block.getColumns(); @@ -222,6 +230,9 @@ void TotalsHavingTransform::addToTotals(const Chunk & chunk, const IColumn::Filt const ColumnAggregateFunction::Container & vec = column->getData(); size_t size = vec.size(); + if (filter && filter->size() != size) + throw Exception("Filter has size which differs from column size", ErrorCodes::LOGICAL_ERROR); + if (filter) { for (size_t row = 0; row < size; ++row) diff --git a/tests/queries/0_stateless/01472_many_rows_in_totals.reference b/tests/queries/0_stateless/01472_many_rows_in_totals.reference index 6c91bf9f104..28f78731283 100644 --- a/tests/queries/0_stateless/01472_many_rows_in_totals.reference +++ b/tests/queries/0_stateless/01472_many_rows_in_totals.reference @@ -1,20 +1,3 @@ -┏━━━┳━━━━━━━━━━━━━┓ -┃ g ┃ sum(number) ┃ -┡━━━╇━━━━━━━━━━━━━┩ -│ 0 │ 2 │ -├───┼─────────────┤ -│ 0 │ 2 │ -├───┼─────────────┤ -│ 1 │ 4 │ -└───┴─────────────┘ - -Totals: -┏━━━┳━━━━━━━━━━━━━┓ -┃ g ┃ sum(number) ┃ -┡━━━╇━━━━━━━━━━━━━┩ -│ 0 │ 6 │ -└───┴─────────────┘ -- ┏━━━┳━━━┓ ┃ g ┃ s ┃ ┡━━━╇━━━┩ @@ -37,56 +20,10 @@ Totals: 0 2 0 2 1 4 - -0 6 -- -0 2 -0 2 -1 4 1 4 0 6 -- -{ - "meta": - [ - { - "name": "g", - "type": "UInt64" - }, - { - "name": "sum(number)", - "type": "UInt64" - } - ], - - "data": - [ - { - "g": "0", - "sum(number)": "2" - }, - { - "g": "0", - "sum(number)": "2" - }, - { - "g": "1", - "sum(number)": "4" - } - ], - - "totals": - { - "g": "0", - "sum(number)": "6" - }, - - "rows": 3, - - "rows_before_limit_at_least": 4 -} -- { "meta": [ diff --git a/tests/queries/0_stateless/01472_many_rows_in_totals.sql b/tests/queries/0_stateless/01472_many_rows_in_totals.sql index 0be4e2c5c37..4869e264d76 100644 --- a/tests/queries/0_stateless/01472_many_rows_in_totals.sql +++ b/tests/queries/0_stateless/01472_many_rows_in_totals.sql @@ -1,15 +1,9 @@ set output_format_write_statistics = 0; -select g, sum(number) from numbers(4) group by bitAnd(number, 1) as g with totals having sum(number) <= arrayJoin([2, 4]) format Pretty; -select '-'; select g, s from (select g, sum(number) as s from numbers(4) group by bitAnd(number, 1) as g with totals) array join [1, 2] as a format Pretty; select '--'; -select g, sum(number) from numbers(4) group by bitAnd(number, 1) as g with totals having sum(number) <= arrayJoin([2, 4]) format TSV; -select '-'; select g, s from (select g, sum(number) as s from numbers(4) group by bitAnd(number, 1) as g with totals) array join [1, 2] as a format TSV; select '--'; -select g, sum(number) from numbers(4) group by bitAnd(number, 1) as g with totals having sum(number) <= arrayJoin([2, 4]) format JSON; -select '-'; select g, s from (select g, sum(number) as s from numbers(4) group by bitAnd(number, 1) as g with totals) array join [1, 2] as a format JSON; select '--'; diff --git a/tests/queries/0_stateless/01548_with_totals_having.reference b/tests/queries/0_stateless/01548_with_totals_having.reference index c728434f5dd..e69de29bb2d 100644 --- a/tests/queries/0_stateless/01548_with_totals_having.reference +++ b/tests/queries/0_stateless/01548_with_totals_having.reference @@ -1,12 +0,0 @@ -0 -0 -0 -0 -1 -1 -1 -2 -2 -3 - -0 diff --git a/tests/queries/0_stateless/01548_with_totals_having.sql b/tests/queries/0_stateless/01548_with_totals_having.sql index 167d879bbeb..669d989aa5f 100644 --- a/tests/queries/0_stateless/01548_with_totals_having.sql +++ b/tests/queries/0_stateless/01548_with_totals_having.sql @@ -1,2 +1,2 @@ -SELECT * FROM numbers(4) GROUP BY number WITH TOTALS HAVING sum(number) <= arrayJoin([]); -- { serverError 43 } -SELECT * FROM numbers(4) GROUP BY number WITH TOTALS HAVING sum(number) <= arrayJoin([3, 2, 1, 0]) ORDER BY number; +SELECT * FROM numbers(4) GROUP BY number WITH TOTALS HAVING sum(number) <= arrayJoin([]); -- { serverError 44 } +SELECT * FROM numbers(4) GROUP BY number WITH TOTALS HAVING sum(number) <= arrayJoin([3, 2, 1, 0]) ORDER BY number; -- { serverError 44 }