dbms: fixed error with StorageSet and StorageJoin [#METR-2944].

This commit is contained in:
Alexey Milovidov 2015-01-30 21:57:44 +03:00
parent 79dbfaa659
commit da2ba1f7f7
3 changed files with 35 additions and 2 deletions

View File

@ -22,8 +22,23 @@ SetOrJoinBlockOutputStream::SetOrJoinBlockOutputStream(StorageSetOrJoinBase & ta
void SetOrJoinBlockOutputStream::write(const Block & block)
{
table.insertBlock(block);
backup_stream.write(block);
/// Сортируем столбцы в блоке. Это нужно, так как Set и Join рассчитывают на одинаковый порядок столбцов в разных блоках.
size_t columns = block.columns();
std::vector<std::string> names(columns);
for (size_t i = 0; i < columns; ++i)
names[i] = block.unsafeGetByPosition(i).name;
std::sort(names.begin(), names.end());
Block sorted_block;
for (const auto & name : names)
sorted_block.insert(block.getByName(name)); /// NOTE Можно чуть-чуть оптимальнее.
table.insertBlock(sorted_block);
backup_stream.write(sorted_block);
}
void SetOrJoinBlockOutputStream::writeSuffix()

View File

@ -0,0 +1,18 @@
DROP TABLE IF EXISTS test.join;
CREATE TABLE test.join (s String, x Array(UInt8), k UInt8) ENGINE = Join(ANY, LEFT, k);
USE test;
INSERT INTO test.join VALUES ('abc', [0], 1), ('def', [1, 2], 2);
INSERT INTO test.join (k, s) VALUES (3, 'ghi');
INSERT INTO test.join (x, k) VALUES ([3, 4, 5], 4);
SELECT k, s FROM (SELECT number AS k FROM system.numbers LIMIT 10) ANY LEFT JOIN join USING k;
SELECT s, x FROM (SELECT number AS k FROM system.numbers LIMIT 10) ANY LEFT JOIN join USING k;
SELECT x, s, k FROM (SELECT number AS k FROM system.numbers LIMIT 10) ANY LEFT JOIN join USING k;
SELECT 1, x, 2, s, 3, k, 4 FROM (SELECT number AS k FROM system.numbers LIMIT 10) ANY LEFT JOIN join USING k;
USE default;
DROP TABLE test.join;