diff --git a/dbms/src/DataStreams/CubeBlockInputStream.cpp b/dbms/src/DataStreams/CubeBlockInputStream.cpp index ee9b3f66036..2253524c638 100644 --- a/dbms/src/DataStreams/CubeBlockInputStream.cpp +++ b/dbms/src/DataStreams/CubeBlockInputStream.cpp @@ -49,8 +49,9 @@ Block CubeBlockInputStream::readImpl() { if (!((mask >> i) & 1)) { - auto & current = cube_block.getByPosition(keys[keys.size() - i - 1]); - current.column = current.column->cloneEmpty()->cloneResized(cube_block.rows()); + size_t pos = keys.size() - i - 1; + auto & current = cube_block.getByPosition(keys[pos]); + current.column = empty_block.getByPosition(pos).column->cloneResized(cube_block.rows()); } } @@ -60,6 +61,7 @@ Block CubeBlockInputStream::readImpl() } source_block = children[0]->read(); + empty_block = source_block.cloneEmpty(); Block finalized = source_block; finalizeBlock(finalized); mask = (1 << keys.size()) - 1; diff --git a/dbms/src/DataStreams/CubeBlockInputStream.h b/dbms/src/DataStreams/CubeBlockInputStream.h index ca2de5367bb..d399e44b6d5 100644 --- a/dbms/src/DataStreams/CubeBlockInputStream.h +++ b/dbms/src/DataStreams/CubeBlockInputStream.h @@ -36,6 +36,7 @@ private: ColumnNumbers keys; UInt32 mask = 0; Block source_block; + Block empty_block; }; }