Fixed totally wrong code in SummingMergeTree in the case of complex maps [#CLICKHOUSE-2]

This commit is contained in:
Alexey Milovidov 2018-04-06 21:09:20 +03:00 committed by proller
parent 1e4544e05b
commit 1beab90244
3 changed files with 16 additions and 10 deletions

2
contrib/poco vendored

@ -1 +1 @@
Subproject commit 930a7ec1154f4f9711edfb4b4a39f9fff2a5bbb5 Subproject commit a107b0c9cee109fe0abfbf509df3c78a1e0c05fa

View File

@ -330,7 +330,20 @@ void SummingSortedBlockInputStream::merge(MutableColumns & merged_columns, std::
// Start aggregations with current row // Start aggregations with current row
addRow(current); addRow(current);
current_row_is_zero = true;
if (maps_to_sum.empty())
{
/// We have only columns_to_aggregate. The status of current row will be determined
/// in 'insertCurrentRowIfNeeded' method on the values of aggregate functions.
current_row_is_zero = true;
}
else
{
/// We have complex maps that will be summed with 'mergeMap' method.
/// The single row is considered non zero, and the status after merging with other rows
/// will be determined in the branch below (when key_differs == false).
current_row_is_zero = false;
}
} }
else else
{ {
@ -338,10 +351,8 @@ void SummingSortedBlockInputStream::merge(MutableColumns & merged_columns, std::
// Merge maps only for same rows // Merge maps only for same rows
for (const auto & desc : maps_to_sum) for (const auto & desc : maps_to_sum)
{
if (mergeMap(desc, current_row, current)) if (mergeMap(desc, current_row, current))
current_row_is_zero = false; current_row_is_zero = false;
}
} }
if (!current->isLast()) if (!current->isLast())

View File

@ -1,12 +1,7 @@
DROP TABLE IF EXISTS test.summing_composite_key; DROP TABLE IF EXISTS test.summing_composite_key;
CREATE TABLE test.summing_composite_key (d Date, k UInt64, FirstMap Nested(k1 UInt32, k2ID Int8, s Float64), SecondMap Nested(k1ID UInt64, k2Key UInt32, k3Type Int32, s Int64)) ENGINE = SummingMergeTree(d, k, 1); CREATE TABLE test.summing_composite_key (d Date, k UInt64, FirstMap Nested(k1 UInt32, k2ID Int8, s Float64), SecondMap Nested(k1ID UInt64, k2Key UInt32, k3Type Int32, s Int64)) ENGINE = SummingMergeTree(d, k, 1);
INSERT INTO test.summing_composite_key VALUES ('2000-01-01', 1, [1,2], [3,4], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]); INSERT INTO test.summing_composite_key VALUES ('2000-01-01', 1, [1,2], [3,4], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]), ('2000-01-01', 1, [2,1], [4,3], [20,22], [2,2,1], [5,5,0], [-3,-3,-33], [10,100,1000]), ('2000-01-01', 2, [1,2], [3,4], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]), ('2000-01-01', 2, [2,1,1], [4,3,3], [20,22,33], [2,2], [5,5], [-3,-3], [10,100]), ('2000-01-01', 2, [1,2], [3,4], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]);
INSERT INTO test.summing_composite_key VALUES ('2000-01-01', 1, [2,1], [4,3], [20,22], [2,2,1], [5,5,0], [-3,-3,-33], [10,100,1000]);
INSERT INTO test.summing_composite_key VALUES ('2000-01-01', 2, [1,2], [3,4], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]);
INSERT INTO test.summing_composite_key VALUES ('2000-01-01', 2, [2,1,1], [4,3,3], [20,22,33], [2,2], [5,5], [-3,-3], [10,100]);
INSERT INTO test.summing_composite_key VALUES ('2000-01-01', 2, [1,2], [3,4], [10,11], [0,1,2], [3,4,5], [-1,-2,-3], [1,10,100]);
SELECT * FROM test.summing_composite_key ORDER BY d, k, _part_index; SELECT * FROM test.summing_composite_key ORDER BY d, k, _part_index;