mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
dbms: fixed error with StorageSet and StorageJoin [#METR-2944].
This commit is contained in:
parent
79dbfaa659
commit
da2ba1f7f7
@ -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()
|
||||
|
18
dbms/tests/queries/0_stateless/00119_storage_join.sql
Normal file
18
dbms/tests/queries/0_stateless/00119_storage_join.sql
Normal 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;
|
Loading…
Reference in New Issue
Block a user