From fbcf82c4dfb1e4654205edef48267ec43f87ceb3 Mon Sep 17 00:00:00 2001 From: liuyangkuan Date: Thu, 14 Mar 2019 16:05:18 +0800 Subject: [PATCH] add interpretation of PREWHERE in StorageBuffer::read --- dbms/src/Storages/StorageBuffer.cpp | 16 ++++++++++++++++ .../0_stateless/00910_buffer_prewhere.reference | 2 +- .../0_stateless/00910_buffer_prewhere.sql | 5 +++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/dbms/src/Storages/StorageBuffer.cpp b/dbms/src/Storages/StorageBuffer.cpp index 9706b1d5562..7d5244f959c 100644 --- a/dbms/src/Storages/StorageBuffer.cpp +++ b/dbms/src/Storages/StorageBuffer.cpp @@ -25,6 +25,8 @@ #include #include +#include +#include namespace ProfileEvents @@ -223,6 +225,20 @@ BlockInputStreams StorageBuffer::read( for (auto & stream : streams_from_buffers) stream = InterpreterSelectQuery(query_info.query, context, stream, processed_stage).execute().in; + if (query_info.prewhere_info) + { + for (auto & stream : streams_from_buffers) + stream = std::make_shared(stream, query_info.prewhere_info->prewhere_actions, + query_info.prewhere_info->prewhere_column_name, query_info.prewhere_info->remove_prewhere_column); + + if (query_info.prewhere_info->alias_actions) + { + for (auto & stream : streams_from_buffers) + stream = std::make_shared(stream, query_info.prewhere_info->alias_actions); + + } + } + streams_from_dst.insert(streams_from_dst.end(), streams_from_buffers.begin(), streams_from_buffers.end()); return streams_from_dst; } diff --git a/dbms/tests/queries/0_stateless/00910_buffer_prewhere.reference b/dbms/tests/queries/0_stateless/00910_buffer_prewhere.reference index 56a6051ca2b..d00491fd7e5 100644 --- a/dbms/tests/queries/0_stateless/00910_buffer_prewhere.reference +++ b/dbms/tests/queries/0_stateless/00910_buffer_prewhere.reference @@ -1 +1 @@ -1 \ No newline at end of file +1 diff --git a/dbms/tests/queries/0_stateless/00910_buffer_prewhere.sql b/dbms/tests/queries/0_stateless/00910_buffer_prewhere.sql index 43d7735d832..d7d9813c5f5 100644 --- a/dbms/tests/queries/0_stateless/00910_buffer_prewhere.sql +++ b/dbms/tests/queries/0_stateless/00910_buffer_prewhere.sql @@ -2,5 +2,6 @@ DROP DATABASE IF EXISTS test_buffer; CREATE DATABASE test_buffer; CREATE TABLE test_buffer.mt (uid UInt64, ts DateTime, val Float64) ENGINE = MergeTree PARTITION BY toDate(ts) ORDER BY (uid, ts); CREATE TABLE test_buffer.buf as test_buffer.mt ENGINE = Buffer(test_buffer, mt, 2, 10, 60, 10000, 100000, 1000000, 10000000); -INSERT INTO test_buffer.buf VALUES (1, '2019-03-01 10:00:00', 0.5), (2, '2019-03-02 10:00:00', 0.15), (1, '2019-03-03 10:00:00', 0.25) -SELECT count() from test_buffer.buf prewhere ts > toDateTime('2019-03-01 12:00:00') and ts < toDateTime('2019-03-02 12:00:00') \ No newline at end of file +INSERT INTO test_buffer.buf VALUES (1, '2019-03-01 10:00:00', 0.5), (2, '2019-03-02 10:00:00', 0.15), (1, '2019-03-03 10:00:00', 0.25); +SELECT count() from test_buffer.buf prewhere ts > toDateTime('2019-03-01 12:00:00') and ts < toDateTime('2019-03-02 12:00:00'); +DROP DATABASE test_buffer;