未验证 提交 c762fa2f 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #22129 from vdimir/issue-19303

Shrink totals block to 1 row for JOIN with TOTALS and arrayJoin
...@@ -268,6 +268,10 @@ void joinTotals(const Block & totals, const Block & columns_to_add, const TableJ ...@@ -268,6 +268,10 @@ void joinTotals(const Block & totals, const Block & columns_to_add, const TableJ
{ {
if (table_join.rightBecomeNullable(col.type)) if (table_join.rightBecomeNullable(col.type))
JoinCommon::convertColumnToNullable(col); 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) for (size_t i = 0; i < totals_without_keys.columns(); ++i)
......
...@@ -38,7 +38,11 @@ void JoiningTransform::transform(Chunk & chunk) ...@@ -38,7 +38,11 @@ void JoiningTransform::transform(Chunk & chunk)
if (on_totals) if (on_totals)
{ {
/// We have to make chunk empty before return /// 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 rows 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. /// Drop totals if both out stream and joined stream doesn't have ones.
/// See comment in ExpressionTransform.h /// See comment in ExpressionTransform.h
......
...@@ -8,3 +8,13 @@ ...@@ -8,3 +8,13 @@
0 0
0 0 0 0 0 0
0 0
0 0
0 0
0 0
0 0
...@@ -35,4 +35,29 @@ FULL JOIN ...@@ -35,4 +35,29 @@ FULL JOIN
) rr ) rr
USING (id); 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; DROP TABLE t;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册