diff --git a/dbms/include/DB/Client/Connection.h b/dbms/include/DB/Client/Connection.h index ab9fab5c06b..ae38abc2839 100644 --- a/dbms/include/DB/Client/Connection.h +++ b/dbms/include/DB/Client/Connection.h @@ -109,7 +109,7 @@ public: bool poll(size_t timeout_microseconds = 0); /// Проверить, есть ли данные в буфере для чтения. - bool hasReadBufferPendingData(); + bool hasReadBufferPendingData() const; /// Получить пакет от сервера. Packet receivePacket(); diff --git a/dbms/include/DB/IO/ReadBuffer.h b/dbms/include/DB/IO/ReadBuffer.h index 48e4ab60c8e..d3175042fc4 100644 --- a/dbms/include/DB/IO/ReadBuffer.h +++ b/dbms/include/DB/IO/ReadBuffer.h @@ -144,9 +144,9 @@ public: } /** Проверить, есть ли данные в буфере для чтения. */ - bool hasPendingData() + bool hasPendingData() const { - return offset() != buffer().size(); + return offset() != working_buffer.size(); } private: diff --git a/dbms/include/DB/Storages/MergeTree/PartsWithRangesSplitter.h b/dbms/include/DB/Storages/MergeTree/PartsWithRangesSplitter.h index 4945e991803..a12a4f2c4a9 100644 --- a/dbms/include/DB/Storages/MergeTree/PartsWithRangesSplitter.h +++ b/dbms/include/DB/Storages/MergeTree/PartsWithRangesSplitter.h @@ -5,6 +5,8 @@ namespace DB { +using Segments = std::vector; + /** Этот класс разбивает объект типа RangesInDataParts (см. MergeTreeDataSelectExecutor) * на не больше, чем указанное количество сегментов. */ @@ -18,7 +20,7 @@ public: PartsWithRangesSplitter(const PartsWithRangesSplitter &) = delete; PartsWithRangesSplitter & operator=(const PartsWithRangesSplitter &) = delete; - std::vector perform(); + Segments perform(); private: void init(); @@ -35,11 +37,11 @@ private: // Входные данные. const MergeTreeDataSelectExecutor::RangesInDataParts & input; MergeTreeDataSelectExecutor::RangesInDataParts::const_iterator input_part; - std::vector::const_iterator input_range; + MarkRanges::const_iterator input_range; // Выходные данные. - std::vector output_segments; - std::vector::iterator current_output_segment; + Segments output_segments; + Segments::iterator current_output_segment; MergeTreeDataSelectExecutor::RangesInDataPart * current_output_part; size_t total_size; diff --git a/dbms/src/Client/Connection.cpp b/dbms/src/Client/Connection.cpp index 2ab93f91b1d..059c27f5c8e 100644 --- a/dbms/src/Client/Connection.cpp +++ b/dbms/src/Client/Connection.cpp @@ -360,9 +360,9 @@ bool Connection::poll(size_t timeout_microseconds) } -bool Connection::hasReadBufferPendingData() +bool Connection::hasReadBufferPendingData() const { - return static_cast(*in).hasPendingData(); + return static_cast(*in).hasPendingData(); } diff --git a/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp b/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp index c93aed31bda..27a1e950009 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp @@ -15,10 +15,10 @@ namespace { -std::pair computeHash(const DB::MergeTreeDataSelectExecutor::RangesInDataParts & cluster) +std::pair computeHash(const DB::MergeTreeDataSelectExecutor::RangesInDataParts & segment) { SipHash hash; - for (const auto & part_with_ranges : cluster) + for (const auto & part_with_ranges : segment) { const auto & part = *(part_with_ranges.data_part); hash.update(part.name.c_str(), part.name.length()); diff --git a/dbms/src/Storages/MergeTree/PartsWithRangesSplitter.cpp b/dbms/src/Storages/MergeTree/PartsWithRangesSplitter.cpp index e9322f7d58f..2f2e4304575 100644 --- a/dbms/src/Storages/MergeTree/PartsWithRangesSplitter.cpp +++ b/dbms/src/Storages/MergeTree/PartsWithRangesSplitter.cpp @@ -29,13 +29,13 @@ PartsWithRangesSplitter::PartsWithRangesSplitter(const MergeTreeDataSelectExecut } total_size *= granularity; - if ((total_size == 0) || (min_segment_size == 0) || (max_segments_count < 2)) + if ((granularity == 0) || (min_segment_size == 0) || (max_segments_count == 0) || (total_size == 0)) throw Exception("One or more arguments are invalid.", ErrorCodes::BAD_ARGUMENTS); } -std::vector PartsWithRangesSplitter::perform() +Segments PartsWithRangesSplitter::perform() { - if (total_size > min_segment_size) + if ((max_segments_count > 1) && (total_size > min_segment_size)) { init(); while (emitRange()) {}