2021-07-09 03:15:41 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Storages/StorageInMemoryMetadata.h>
|
2021-07-21 14:45:19 +00:00
|
|
|
// #include <sparsehash/dense_hash_map>
|
2021-07-09 03:15:41 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class IStorage;
|
|
|
|
|
2021-07-21 14:45:19 +00:00
|
|
|
// #if !defined(ARCADIA_BUILD)
|
|
|
|
// using NamesAndTypesMap = google::dense_hash_map<StringRef, DataTypePtr, StringRefHash>;
|
|
|
|
// #else
|
|
|
|
// using NamesAndTypesMap = google::sparsehash::dense_hash_map<StringRef, DataTypePtr, StringRefHash>;
|
|
|
|
// #endif
|
|
|
|
|
2021-07-09 03:15:41 +00:00
|
|
|
struct StorageSnapshot
|
|
|
|
{
|
|
|
|
const IStorage & storage;
|
|
|
|
const StorageMetadataPtr metadata;
|
2021-07-23 16:30:18 +00:00
|
|
|
const ColumnsDescription object_columns;
|
|
|
|
|
|
|
|
struct Data{};
|
|
|
|
using DataPtr = std::unique_ptr<const Data>;
|
|
|
|
|
|
|
|
const DataPtr data;
|
2021-07-09 03:15:41 +00:00
|
|
|
|
2021-07-12 13:45:35 +00:00
|
|
|
/// TODO: fix
|
|
|
|
mutable const ProjectionDescription * projection = nullptr;
|
|
|
|
|
2021-07-09 03:15:41 +00:00
|
|
|
StorageSnapshot(
|
|
|
|
const IStorage & storage_,
|
|
|
|
const StorageMetadataPtr & metadata_)
|
|
|
|
: storage(storage_), metadata(metadata_)
|
|
|
|
{
|
2021-07-21 14:45:19 +00:00
|
|
|
init();
|
2021-07-09 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StorageSnapshot(
|
|
|
|
const IStorage & storage_,
|
|
|
|
const StorageMetadataPtr & metadata_,
|
2021-07-23 16:30:18 +00:00
|
|
|
const ColumnsDescription & object_columns_)
|
|
|
|
: storage(storage_), metadata(metadata_), object_columns(object_columns_)
|
2021-07-09 03:15:41 +00:00
|
|
|
{
|
2021-07-21 14:45:19 +00:00
|
|
|
init();
|
2021-07-09 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StorageSnapshot(
|
|
|
|
const IStorage & storage_,
|
|
|
|
const StorageMetadataPtr & metadata_,
|
2021-07-23 16:30:18 +00:00
|
|
|
const ColumnsDescription & object_columns_,
|
|
|
|
DataPtr data_)
|
|
|
|
: storage(storage_), metadata(metadata_), object_columns(object_columns_), data(std::move(data_))
|
2021-07-09 03:15:41 +00:00
|
|
|
{
|
2021-07-21 14:45:19 +00:00
|
|
|
init();
|
2021-07-09 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NamesAndTypesList getColumns(const GetColumnsOptions & options) const;
|
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
|
|
|
|
|
|
|
/// Block with ordinary + materialized + aliases + virtuals + subcolumns.
|
|
|
|
Block getSampleBlockForColumns(const Names & column_names) const;
|
|
|
|
|
|
|
|
/// 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_; }
|
|
|
|
|
|
|
|
StorageMetadataPtr getMetadataForQuery() const { return (projection ? projection->metadata : metadata); }
|
2021-07-20 15:20:21 +00:00
|
|
|
|
2021-07-23 16:30:18 +00:00
|
|
|
bool isSubcolumnOfObject(const String & name) const;
|
|
|
|
|
2021-07-20 15:20:21 +00:00
|
|
|
private:
|
2021-07-21 14:45:19 +00:00
|
|
|
void init();
|
|
|
|
|
2021-07-23 16:30:18 +00:00
|
|
|
std::unordered_map<String, DataTypePtr> virtual_columns;
|
2021-07-09 03:15:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using StorageSnapshotPtr = std::shared_ptr<const StorageSnapshot>;
|
|
|
|
|
|
|
|
}
|