Merge pull request #11602 from ClickHouse/fix-buffer-sample

Fix buffer sample
This commit is contained in:
Nikita Mikhaylov 2020-06-17 14:44:48 +04:00 committed by GitHub
commit d2be6c036b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 0 deletions

View File

@ -229,6 +229,17 @@ Pipes StorageBuffer::read(
for (auto & buf : buffers)
pipes_from_buffers.emplace_back(std::make_shared<BufferSource>(column_names, buf, *this));
/// Convert pipes from table to structure from buffer.
if (!pipes_from_buffers.empty() && !pipes_from_dst.empty()
&& !blocksHaveEqualStructure(pipes_from_buffers.front().getHeader(), pipes_from_dst.front().getHeader()))
{
for (auto & pipe : pipes_from_dst)
pipe.addSimpleTransform(std::make_shared<ConvertingTransform>(
pipe.getHeader(),
pipes_from_buffers.front().getHeader(),
ConvertingTransform::MatchColumnsMode::Name));
}
/** If the sources from the table were processed before some non-initial stage of query execution,
* then sources from the buffers must also be wrapped in the processing pipeline before the same stage.
*/

View File

@ -0,0 +1,11 @@
drop table if exists t;
drop table if exists t_buf;
create table t (x UInt64) engine = MergeTree order by (x, intHash64(x)) sample by intHash64(x);
insert into t select number from numbers(10000);
create table t_buf as t engine = Buffer(currentDatabase(), 't', 16, 20, 100, 100000, 10000000, 50000000, 250000000);
insert into t_buf values (1);
select count() from t_buf sample 1/2 format Null;
drop table if exists t_buf;
drop table if exists t;