2021-07-09 03:15:41 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Storages/StorageInMemoryMetadata.h>
|
2024-02-21 00:57:35 +00:00
|
|
|
#include <Storages/VirtualColumnsDescription.h>
|
2021-07-09 03:15:41 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class IStorage;
|
2024-02-21 00:57:35 +00:00
|
|
|
class ICompressionCodec;
|
|
|
|
|
|
|
|
using CompressionCodecPtr = std::shared_ptr<ICompressionCodec>;
|
2021-07-09 03:15:41 +00:00
|
|
|
|
2022-03-01 16:32:55 +00:00
|
|
|
/// Snapshot of storage that fixes set columns that can be read in query.
|
|
|
|
/// There are 3 sources of columns: regular columns from metadata,
|
|
|
|
/// dynamic columns from object Types, virtual columns.
|
2021-07-09 03:15:41 +00:00
|
|
|
struct StorageSnapshot
|
|
|
|
{
|
|
|
|
const IStorage & storage;
|
|
|
|
const StorageMetadataPtr metadata;
|
2024-02-21 00:57:35 +00:00
|
|
|
const VirtualColumnsDescription virtual_columns;
|
2021-07-23 16:30:18 +00:00
|
|
|
const ColumnsDescription object_columns;
|
|
|
|
|
2022-03-01 16:32:55 +00:00
|
|
|
/// Additional data, on which set of columns may depend.
|
|
|
|
/// E.g. data parts in MergeTree, list of blocks in Memory, etc.
|
2021-08-02 19:49:52 +00:00
|
|
|
struct Data
|
|
|
|
{
|
|
|
|
virtual ~Data() = default;
|
|
|
|
};
|
2021-07-23 16:30:18 +00:00
|
|
|
|
2022-06-07 18:35:02 +00:00
|
|
|
using DataPtr = std::unique_ptr<Data>;
|
|
|
|
DataPtr data;
|
2021-07-09 03:15:41 +00:00
|
|
|
|
2022-03-01 16:32:55 +00:00
|
|
|
/// Projection that is used in query.
|
2021-07-12 13:45:35 +00:00
|
|
|
mutable const ProjectionDescription * projection = nullptr;
|
|
|
|
|
2021-07-09 03:15:41 +00:00
|
|
|
StorageSnapshot(
|
|
|
|
const IStorage & storage_,
|
2024-02-21 00:57:35 +00:00
|
|
|
StorageMetadataPtr metadata_);
|
2021-07-09 03:15:41 +00:00
|
|
|
|
|
|
|
StorageSnapshot(
|
|
|
|
const IStorage & storage_,
|
2023-05-25 22:54:54 +00:00
|
|
|
StorageMetadataPtr metadata_,
|
2024-02-21 00:57:35 +00:00
|
|
|
ColumnsDescription object_columns_);
|
2021-07-09 03:15:41 +00:00
|
|
|
|
|
|
|
StorageSnapshot(
|
|
|
|
const IStorage & storage_,
|
2023-05-25 22:54:54 +00:00
|
|
|
StorageMetadataPtr metadata_,
|
|
|
|
ColumnsDescription object_columns_,
|
2024-02-21 00:57:35 +00:00
|
|
|
DataPtr data_);
|
2021-07-09 03:15:41 +00:00
|
|
|
|
2023-08-24 10:32:56 +00:00
|
|
|
std::shared_ptr<StorageSnapshot> clone(DataPtr data_) const;
|
|
|
|
|
2022-03-01 16:32:55 +00:00
|
|
|
/// Get all available columns with types according to options.
|
2021-07-09 03:15:41 +00:00
|
|
|
NamesAndTypesList getColumns(const GetColumnsOptions & options) const;
|
2022-03-01 16:32:55 +00:00
|
|
|
|
|
|
|
/// Get columns with types according to options only for requested names.
|
2021-07-20 15:20:21 +00:00
|
|
|
NamesAndTypesList getColumnsByNames(const GetColumnsOptions & options, const Names & names) const;
|
2021-07-09 03:15:41 +00:00
|
|
|
|
2022-03-28 17:21:47 +00:00
|
|
|
/// Get column with type according to options for requested name.
|
|
|
|
std::optional<NameAndTypePair> tryGetColumn(const GetColumnsOptions & options, const String & column_name) const;
|
|
|
|
NameAndTypePair getColumn(const GetColumnsOptions & options, const String & column_name) const;
|
|
|
|
|
2024-02-21 00:57:35 +00:00
|
|
|
CompressionCodecPtr getCodecOrDefault(const String & column_name, CompressionCodecPtr default_codec) const;
|
|
|
|
CompressionCodecPtr getCodecOrDefault(const String & column_name) const;
|
|
|
|
ASTPtr getCodecDescOrDefault(const String & column_name, CompressionCodecPtr default_codec) const;
|
|
|
|
|
2021-07-09 03:15:41 +00:00
|
|
|
/// Block with ordinary + materialized + aliases + virtuals + subcolumns.
|
2023-07-25 12:04:55 +00:00
|
|
|
Block getSampleBlockForColumns(const Names & column_names) const;
|
2021-07-09 03:15:41 +00:00
|
|
|
|
2022-05-16 14:19:44 +00:00
|
|
|
ColumnsDescription getDescriptionForColumns(const Names & column_names) const;
|
|
|
|
|
2021-07-09 03:15:41 +00:00
|
|
|
/// Verify that all the requested names are in the table and are set correctly:
|
|
|
|
/// list of names is not empty and the names do not repeat.
|
|
|
|
void check(const Names & column_names) const;
|
2021-07-09 14:54:53 +00:00
|
|
|
|
|
|
|
DataTypePtr getConcreteType(const String & column_name) const;
|
2021-07-12 13:45:35 +00:00
|
|
|
|
|
|
|
void addProjection(const ProjectionDescription * projection_) const { projection = projection_; }
|
|
|
|
|
2022-03-01 16:32:55 +00:00
|
|
|
/// If we have a projection then we should use its metadata.
|
|
|
|
StorageMetadataPtr getMetadataForQuery() const { return projection ? projection->metadata : metadata; }
|
2021-07-23 16:30:18 +00:00
|
|
|
|
2021-07-20 15:20:21 +00:00
|
|
|
private:
|
2021-07-21 14:45:19 +00:00
|
|
|
void init();
|
2021-07-09 03:15:41 +00:00
|
|
|
};
|
|
|
|
|
2022-06-07 18:35:02 +00:00
|
|
|
using StorageSnapshotPtr = std::shared_ptr<StorageSnapshot>;
|
2021-07-09 03:15:41 +00:00
|
|
|
|
|
|
|
}
|