2018-11-28 15:05:53 +00:00
|
|
|
#pragma once
|
2020-04-02 16:28:50 +00:00
|
|
|
#include <Processors/Sources/SourceWithProgress.h>
|
2018-11-28 15:05:53 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
2019-10-10 16:30:30 +00:00
|
|
|
#include <Storages/MergeTree/IMergeTreeReader.h>
|
2018-11-28 15:05:53 +00:00
|
|
|
#include <Storages/MergeTree/MarkRange.h>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-11-29 09:19:42 +00:00
|
|
|
/// Lightweight (in terms of logic) stream for reading single part from MergeTree
|
2020-04-02 16:28:50 +00:00
|
|
|
class MergeTreeSequentialSource : public SourceWithProgress
|
2018-11-28 15:05:53 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-04-02 16:28:50 +00:00
|
|
|
MergeTreeSequentialSource(
|
2018-11-28 15:05:53 +00:00
|
|
|
const MergeTreeData & storage_,
|
2020-06-16 14:25:08 +00:00
|
|
|
const StorageMetadataPtr & metadata_snapshot_,
|
2020-04-02 16:28:50 +00:00
|
|
|
MergeTreeData::DataPartPtr data_part_,
|
2018-11-28 15:05:53 +00:00
|
|
|
Names columns_to_read_,
|
|
|
|
bool read_with_direct_io_,
|
2018-11-29 11:55:34 +00:00
|
|
|
bool take_column_types_from_storage,
|
2020-06-16 14:25:08 +00:00
|
|
|
bool quiet = false);
|
2018-11-28 15:05:53 +00:00
|
|
|
|
2020-04-02 16:28:50 +00:00
|
|
|
~MergeTreeSequentialSource() override;
|
2018-11-28 15:05:53 +00:00
|
|
|
|
2020-04-02 16:28:50 +00:00
|
|
|
String getName() const override { return "MergeTreeSequentialSource"; }
|
2018-11-28 15:05:53 +00:00
|
|
|
|
2018-11-29 09:19:42 +00:00
|
|
|
size_t getCurrentMark() const { return current_mark; }
|
|
|
|
|
|
|
|
size_t getCurrentRow() const { return current_row; }
|
|
|
|
|
2018-11-28 15:05:53 +00:00
|
|
|
protected:
|
2020-04-02 16:28:50 +00:00
|
|
|
Chunk generate() override;
|
2018-11-28 15:05:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
const MergeTreeData & storage;
|
2020-06-16 14:25:08 +00:00
|
|
|
StorageMetadataPtr metadata_snapshot;
|
2018-11-28 15:05:53 +00:00
|
|
|
|
|
|
|
/// Data part will not be removed if the pointer owns it
|
|
|
|
MergeTreeData::DataPartPtr data_part;
|
|
|
|
|
|
|
|
/// Columns we have to read (each Block from read will contain them)
|
|
|
|
Names columns_to_read;
|
|
|
|
|
|
|
|
/// Should read using direct IO
|
|
|
|
bool read_with_direct_io;
|
|
|
|
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log = &Poco::Logger::get("MergeTreeSequentialSource");
|
2018-11-28 15:05:53 +00:00
|
|
|
|
|
|
|
std::shared_ptr<MarkCache> mark_cache;
|
2019-10-10 16:30:30 +00:00
|
|
|
using MergeTreeReaderPtr = std::unique_ptr<IMergeTreeReader>;
|
2018-11-28 15:05:53 +00:00
|
|
|
MergeTreeReaderPtr reader;
|
|
|
|
|
|
|
|
/// current mark at which we stop reading
|
|
|
|
size_t current_mark = 0;
|
|
|
|
|
|
|
|
/// current row at which we stop reading
|
|
|
|
size_t current_row = 0;
|
|
|
|
|
|
|
|
private:
|
2020-04-02 16:28:50 +00:00
|
|
|
/// Closes readers and unlock part locks
|
|
|
|
void finish();
|
2018-11-28 15:05:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|