2015-01-27 00:52:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-08-30 19:27:15 +00:00
|
|
|
#include <ext/shared_ptr_helper.hpp>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2015-01-27 00:52:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-14 09:00:19 +00:00
|
|
|
class Set;
|
|
|
|
using SetPtr = std::shared_ptr<Set>;
|
|
|
|
|
2015-01-27 21:24:24 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Common part of StorageSet and StorageJoin.
|
2015-01-27 21:24:24 +00:00
|
|
|
*/
|
2016-08-30 19:27:15 +00:00
|
|
|
class StorageSetOrJoinBase : private ext::shared_ptr_helper<StorageSetOrJoinBase>, public IStorage
|
2015-01-27 21:24:24 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
friend class ext::shared_ptr_helper<StorageSetOrJoinBase>;
|
|
|
|
friend class SetOrJoinBlockOutputStream;
|
2015-01-28 00:08:45 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
String getTableName() const override { return name; }
|
|
|
|
const NamesAndTypesList & getColumnsListImpl() const override { return *columns; }
|
2015-01-28 00:08:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void rename(const String & new_path_to_db, const String & new_database_name, const String & new_table_name) override;
|
2015-01-28 00:08:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockOutputStreamPtr write(ASTPtr query, const Settings & settings) override;
|
2015-01-28 00:08:45 +00:00
|
|
|
|
2015-01-27 21:24:24 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageSetOrJoinBase(
|
|
|
|
const String & path_,
|
|
|
|
const String & name_,
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
const ColumnDefaults & column_defaults_);
|
2015-01-28 00:08:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String path;
|
|
|
|
String name;
|
|
|
|
NamesAndTypesListPtr columns;
|
2015-01-27 21:24:24 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
UInt64 increment = 0; /// For the backup file names.
|
2015-01-27 21:24:24 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Restore from backup.
|
2017-04-01 07:20:54 +00:00
|
|
|
void restore();
|
2015-01-28 00:08:45 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
void restoreFromFile(const String & file_path);
|
2015-01-27 21:24:24 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Insert the block into the state.
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual void insertBlock(const Block & block) = 0;
|
|
|
|
virtual size_t getSize() const = 0;
|
2015-01-28 00:08:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Lets you save the set for later use on the right side of the IN statement.
|
|
|
|
* When inserted into a table, the data will be inserted into the set,
|
|
|
|
* and also written to a file-backup, for recovery after a restart.
|
|
|
|
* Reading from the table is not possible directly - it is possible to specify only the right part of the IN statement.
|
2015-01-27 00:52:03 +00:00
|
|
|
*/
|
2016-08-30 19:27:15 +00:00
|
|
|
class StorageSet : private ext::shared_ptr_helper<StorageSet>, public StorageSetOrJoinBase
|
2015-01-27 00:52:03 +00:00
|
|
|
{
|
2016-08-30 19:27:15 +00:00
|
|
|
friend class ext::shared_ptr_helper<StorageSet>;
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2015-01-27 00:52:03 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
static StoragePtr create(
|
|
|
|
const String & path_,
|
|
|
|
const String & name_,
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
const ColumnDefaults & column_defaults_)
|
|
|
|
{
|
|
|
|
return ext::shared_ptr_helper<StorageSet>::make_shared(path_, name_, columns_, materialized_columns_, alias_columns_, column_defaults_);
|
|
|
|
}
|
|
|
|
|
|
|
|
String getName() const override { return "Set"; }
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Access the insides.
|
2017-04-01 07:20:54 +00:00
|
|
|
SetPtr & getSet() { return set; }
|
2015-01-27 00:52:03 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
SetPtr set;
|
|
|
|
|
|
|
|
StorageSet(
|
|
|
|
const String & path_,
|
|
|
|
const String & name_,
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
const ColumnDefaults & column_defaults_);
|
|
|
|
|
|
|
|
void insertBlock(const Block & block) override;
|
|
|
|
size_t getSize() const override;
|
2015-01-27 00:52:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|