mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Fixed mismatched header of prewhere with sample column
This commit is contained in:
parent
c3f82f0b8c
commit
64d65c0123
@ -666,6 +666,21 @@ void InterpreterSelectQuery::executeImpl(TPipeline & pipeline, const BlockInputS
|
||||
pipeline.streams.back() = std::make_shared<FilterBlockInputStream>(
|
||||
pipeline.streams.back(), expressions.prewhere_info->prewhere_actions,
|
||||
expressions.prewhere_info->prewhere_column_name, expressions.prewhere_info->remove_prewhere_column);
|
||||
|
||||
// To remove additional columns in dry run
|
||||
// For example, sample column which can be removed in this stage
|
||||
if (expressions.prewhere_info->remove_columns_actions)
|
||||
{
|
||||
if constexpr (pipeline_with_processors)
|
||||
{
|
||||
pipeline.addSimpleTransform([&](const Block & header)
|
||||
{
|
||||
return std::make_shared<ExpressionTransform>(header, expressions.prewhere_info->remove_columns_actions);
|
||||
});
|
||||
}
|
||||
else
|
||||
pipeline.streams.back() = std::make_shared<ExpressionBlockInputStream>(pipeline.streams.back(), expressions.prewhere_info->remove_columns_actions);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1269,12 +1284,23 @@ void InterpreterSelectQuery::executeFetchColumns(
|
||||
streams = {std::make_shared<NullBlockInputStream>(storage->getSampleBlockForColumns(required_columns))};
|
||||
|
||||
if (query_info.prewhere_info)
|
||||
{
|
||||
streams.back() = std::make_shared<FilterBlockInputStream>(
|
||||
streams.back(),
|
||||
prewhere_info->prewhere_actions,
|
||||
prewhere_info->prewhere_column_name,
|
||||
prewhere_info->remove_prewhere_column);
|
||||
|
||||
// To remove additional columns
|
||||
// In some cases, we did not read any marks so that the pipeline.streams is empty
|
||||
// Thus, some columns in prewhere are not removed as expected
|
||||
// This leads to mismatched header in distributed table
|
||||
if (query_info.prewhere_info->remove_columns_actions)
|
||||
{
|
||||
streams.back() = std::make_shared<ExpressionBlockInputStream>(streams.back(), query_info.prewhere_info->remove_columns_actions);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (auto & stream : streams)
|
||||
|
@ -0,0 +1,2 @@
|
||||
3
|
||||
6
|
17
dbms/tests/queries/0_stateless/00975_sample_prewhere.sql
Normal file
17
dbms/tests/queries/0_stateless/00975_sample_prewhere.sql
Normal file
@ -0,0 +1,17 @@
|
||||
drop table if exists test.sample_prewhere;
|
||||
drop table if exists test.sample_prewhere_all;
|
||||
|
||||
create table if not exists test.sample_prewhere (date Date, id Int32, time Int64) engine = MergeTree partition by date order by (id, time, intHash64(time)) sample by intHash64(time);
|
||||
insert into test.sample_prewhere values ('2019-01-01', 2, 1564028096);
|
||||
insert into test.sample_prewhere values ('2019-01-01', 1, 1564028096);
|
||||
insert into test.sample_prewhere values ('2019-01-02', 3, 1564028096);
|
||||
|
||||
create table if not exists test.sample_prewhere_all as test.sample_prewhere engine = Distributed('test_cluster_two_shards_localhost', 'test', 'sample_prewhere');
|
||||
|
||||
select id from test.sample_prewhere_all SAMPLE 1 where toDateTime(time) = '2019-07-20 00:00:00' limit 0, 1;
|
||||
select id from test.sample_prewhere_all SAMPLE 1 where toDateTime(time) > '2019-07-20 00:00:00' limit 0, 1;
|
||||
select id from test.sample_prewhere_all SAMPLE 1 where toDateTime(time) = '2019-07-20 00:00:00';
|
||||
select count() from test.sample_prewhere_all SAMPLE 1 where toDateTime(time) > '2019-07-20 00:00:00' limit 0, 1;
|
||||
|
||||
drop table if exists test.sample_prewhere;
|
||||
drop table if exists test.sample_prewhere_all;
|
Loading…
Reference in New Issue
Block a user