mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Shrink totals block to 1 row for JOIN with TOTALS and arrayJoin
This commit is contained in:
parent
f2fc200597
commit
8f5c8f32df
@ -268,6 +268,10 @@ void joinTotals(const Block & totals, const Block & columns_to_add, const TableJ
|
||||
{
|
||||
if (table_join.rightBecomeNullable(col.type))
|
||||
JoinCommon::convertColumnToNullable(col);
|
||||
|
||||
/// In case of arrayJoin it can be not one row
|
||||
if (col.column->size() != 1)
|
||||
col.column = col.column->cloneResized(1);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < totals_without_keys.columns(); ++i)
|
||||
|
@ -38,7 +38,11 @@ void JoiningTransform::transform(Chunk & chunk)
|
||||
if (on_totals)
|
||||
{
|
||||
/// We have to make chunk empty before return
|
||||
block = getInputPort().getHeader().cloneWithColumns(chunk.detachColumns());
|
||||
/// In case of using `arrayJoin` we can get more or less columns than one
|
||||
auto cols = chunk.detachColumns();
|
||||
for (auto & col : cols)
|
||||
col = col->cloneResized(1);
|
||||
block = getInputPort().getHeader().cloneWithColumns(std::move(cols));
|
||||
|
||||
/// Drop totals if both out stream and joined stream doesn't have ones.
|
||||
/// See comment in ExpressionTransform.h
|
||||
|
@ -8,3 +8,13 @@
|
||||
0
|
||||
|
||||
0 0 0
|
||||
|
||||
0 0
|
||||
|
||||
0 0
|
||||
|
||||
0 0
|
||||
|
||||
0 0
|
||||
|
||||
0 0
|
||||
|
@ -35,4 +35,29 @@ FULL JOIN
|
||||
) rr
|
||||
USING (id);
|
||||
|
||||
SELECT id, yago
|
||||
FROM ( SELECT item_id AS id FROM t GROUP BY id ) AS ll
|
||||
FULL OUTER JOIN ( SELECT item_id AS id, arrayJoin([111, 222, 333, 444]), SUM(price_sold) AS yago FROM t GROUP BY id WITH TOTALS ) AS rr
|
||||
USING (id);
|
||||
|
||||
SELECT id, yago
|
||||
FROM ( SELECT item_id AS id, arrayJoin([111, 222, 333]) FROM t GROUP BY id WITH TOTALS ) AS ll
|
||||
FULL OUTER JOIN ( SELECT item_id AS id, SUM(price_sold) AS yago FROM t GROUP BY id ) AS rr
|
||||
USING (id);
|
||||
|
||||
SELECT id, yago
|
||||
FROM ( SELECT item_id AS id, arrayJoin(emptyArrayInt32()) FROM t GROUP BY id WITH TOTALS ) AS ll
|
||||
FULL OUTER JOIN ( SELECT item_id AS id, SUM(price_sold) AS yago FROM t GROUP BY id ) AS rr
|
||||
USING (id);
|
||||
|
||||
SELECT id, yago
|
||||
FROM ( SELECT item_id AS id FROM t GROUP BY id ) AS ll
|
||||
FULL OUTER JOIN ( SELECT item_id AS id, arrayJoin(emptyArrayInt32()), SUM(price_sold) AS yago FROM t GROUP BY id WITH TOTALS ) AS rr
|
||||
USING (id);
|
||||
|
||||
SELECT id, yago
|
||||
FROM ( SELECT item_id AS id, arrayJoin([111, 222, 333]) FROM t GROUP BY id WITH TOTALS ) AS ll
|
||||
FULL OUTER JOIN ( SELECT item_id AS id, arrayJoin([111, 222, 333, 444]), SUM(price_sold) AS yago FROM t GROUP BY id WITH TOTALS ) AS rr
|
||||
USING (id);
|
||||
|
||||
DROP TABLE t;
|
||||
|
Loading…
Reference in New Issue
Block a user