This commit is contained in:
nikitamikhaylov 2020-11-05 19:00:05 +03:00
parent 08b63fde77
commit aceb82ae6a
6 changed files with 13 additions and 86 deletions

View File

@ -387,9 +387,6 @@ void ExpressionAction::execute(Block & block, bool dry_run) const
source.type = assert_cast<const DataTypeArray &>(*source.type).getNestedType(); source.type = assert_cast<const DataTypeArray &>(*source.type).getNestedType();
source.name = result_name; 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)); block.insert(std::move(source));
break; break;

View File

@ -13,6 +13,7 @@ namespace DB
namespace ErrorCodes namespace ErrorCodes
{ {
extern const int LOGICAL_ERROR; extern const int LOGICAL_ERROR;
extern const int ILLEGAL_COLUMN;
} }
void finalizeChunk(Chunk & chunk) void finalizeChunk(Chunk & chunk)
@ -156,6 +157,13 @@ void TotalsHavingTransform::transform(Chunk & chunk)
/// Compute the expression in HAVING. /// Compute the expression in HAVING.
const auto & cur_header = final ? finalized_header : getInputPort().getHeader(); const auto & cur_header = final ? finalized_header : getInputPort().getHeader();
auto finalized_block = cur_header.cloneWithColumns(finalized.detachColumns()); 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); expression->execute(finalized_block);
auto columns = finalized_block.getColumns(); auto columns = finalized_block.getColumns();
@ -222,6 +230,9 @@ void TotalsHavingTransform::addToTotals(const Chunk & chunk, const IColumn::Filt
const ColumnAggregateFunction::Container & vec = column->getData(); const ColumnAggregateFunction::Container & vec = column->getData();
size_t size = vec.size(); 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) if (filter)
{ {
for (size_t row = 0; row < size; ++row) for (size_t row = 0; row < size; ++row)

View File

@ -1,20 +1,3 @@
┏━━━┳━━━━━━━━━━━━━┓
g ┃ sum(number) ┃
┡━━━╇━━━━━━━━━━━━━┩
│ 0 │ 2 │
├───┼─────────────┤
│ 0 │ 2 │
├───┼─────────────┤
│ 1 │ 4 │
└───┴─────────────┘
Totals:
┏━━━┳━━━━━━━━━━━━━┓
g ┃ sum(number) ┃
┡━━━╇━━━━━━━━━━━━━┩
│ 0 │ 6 │
└───┴─────────────┘
-
┏━━━┳━━━┓ ┏━━━┳━━━┓
g ┃ s ┃ g ┃ s ┃
┡━━━╇━━━┩ ┡━━━╇━━━┩
@ -37,56 +20,10 @@ Totals:
0 2 0 2
0 2 0 2
1 4 1 4
0 6
-
0 2
0 2
1 4
1 4 1 4
0 6 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": "meta":
[ [

View File

@ -1,15 +1,9 @@
set output_format_write_statistics = 0; 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 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 '--';
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 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 '--';
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 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 '--'; select '--';

View File

@ -1,12 +0,0 @@
0
0
0
0
1
1
1
2
2
3
0

View File

@ -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([]); -- { serverError 44 }
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([3, 2, 1, 0]) ORDER BY number; -- { serverError 44 }