2017-12-12 15:54:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-06-10 19:22:49 +00:00
|
|
|
#include <Formats/FormatSettings.h>
|
2017-12-12 15:54:03 +00:00
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class Context;
|
|
|
|
|
2019-05-20 16:24:36 +00:00
|
|
|
struct StoragesInfo
|
|
|
|
{
|
2019-05-21 13:58:55 +00:00
|
|
|
StoragePtr storage = nullptr;
|
2020-06-18 16:10:47 +00:00
|
|
|
TableLockHolder table_lock;
|
2019-05-20 16:24:36 +00:00
|
|
|
|
|
|
|
String database;
|
|
|
|
String table;
|
|
|
|
String engine;
|
|
|
|
|
2019-05-21 13:58:55 +00:00
|
|
|
bool need_inactive_parts = false;
|
|
|
|
MergeTreeData * data = nullptr;
|
2019-05-20 16:24:36 +00:00
|
|
|
|
2022-05-20 15:29:54 +00:00
|
|
|
explicit operator bool() const { return storage != nullptr; }
|
2022-05-13 10:59:24 +00:00
|
|
|
|
|
|
|
MergeTreeData::DataPartsVector getParts(MergeTreeData::DataPartStateVector & state, bool has_state_column) const;
|
|
|
|
MergeTreeData::ProjectionPartsVector getProjectionParts(MergeTreeData::DataPartStateVector & state, bool has_state_column) const;
|
2019-05-20 16:24:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** A helper class that enumerates the storages that match given query. */
|
|
|
|
class StoragesInfoStream
|
|
|
|
{
|
|
|
|
public:
|
2021-04-10 23:33:54 +00:00
|
|
|
StoragesInfoStream(const SelectQueryInfo & query_info, ContextPtr context);
|
2019-05-20 16:24:36 +00:00
|
|
|
StoragesInfo next();
|
|
|
|
|
|
|
|
private:
|
|
|
|
String query_id;
|
2020-04-09 18:10:27 +00:00
|
|
|
Settings settings;
|
|
|
|
|
2019-05-20 16:24:36 +00:00
|
|
|
|
|
|
|
ColumnPtr database_column;
|
|
|
|
ColumnPtr table_column;
|
|
|
|
ColumnPtr active_column;
|
|
|
|
|
|
|
|
size_t next_row;
|
|
|
|
size_t rows;
|
|
|
|
|
|
|
|
using StoragesMap = std::map<std::pair<String, String>, StoragePtr>;
|
|
|
|
StoragesMap storages;
|
|
|
|
};
|
2017-12-12 15:54:03 +00:00
|
|
|
|
|
|
|
/** Implements system table 'parts' which allows to get information about data parts for tables of MergeTree family.
|
|
|
|
*/
|
|
|
|
class StorageSystemPartsBase : public IStorage
|
|
|
|
{
|
|
|
|
public:
|
2020-08-06 12:24:05 +00:00
|
|
|
Pipe read(
|
2020-06-15 19:08:58 +00:00
|
|
|
const Names & column_names,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
2020-06-15 19:08:58 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
|
|
|
size_t max_block_size,
|
|
|
|
unsigned num_streams) override;
|
2017-12-12 15:54:03 +00:00
|
|
|
|
2020-04-28 10:38:57 +00:00
|
|
|
NamesAndTypesList getVirtuals() const override;
|
2020-04-27 13:55:30 +00:00
|
|
|
|
2021-11-19 10:25:55 +00:00
|
|
|
bool isSystemStorage() const override { return true; }
|
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
private:
|
2022-03-17 11:05:22 +00:00
|
|
|
static bool hasStateColumn(const Names & column_names, const StorageSnapshotPtr & storage_snapshot);
|
2017-12-12 15:54:03 +00:00
|
|
|
|
|
|
|
protected:
|
2018-06-08 01:51:55 +00:00
|
|
|
const FormatSettings format_settings;
|
|
|
|
|
2020-08-12 20:40:13 +00:00
|
|
|
StorageSystemPartsBase(const StorageID & table_id_, NamesAndTypesList && columns_);
|
2017-12-12 15:54:03 +00:00
|
|
|
|
2021-02-21 14:04:55 +00:00
|
|
|
virtual void
|
2021-06-02 20:03:44 +00:00
|
|
|
processNextStorage(ContextPtr context, MutableColumns & columns, std::vector<UInt8> & columns_mask, const StoragesInfo & info, bool has_state_column) = 0;
|
2017-12-12 15:54:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|