2015-08-16 07:01:41 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <Poco/File.h>
|
|
|
|
|
|
|
|
|
|
#include <DB/Storages/IStorage.h>
|
|
|
|
|
#include <DB/Common/FileChecker.h>
|
2015-09-29 00:53:10 +00:00
|
|
|
|
#include <DB/Common/escapeForFileName.h>
|
2015-08-16 07:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Реализует хранилище, подходящее для маленьких кусочков лога.
|
|
|
|
|
* При этом, хранит все столбцы в одном файле формата Native, с расположенным рядом индексом.
|
|
|
|
|
*/
|
|
|
|
|
class StorageStripeLog : public IStorage
|
|
|
|
|
{
|
|
|
|
|
friend class StripeLogBlockInputStream;
|
|
|
|
|
friend class StripeLogBlockOutputStream;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/** Подцепить таблицу с соответствующим именем, по соответствующему пути (с / на конце),
|
|
|
|
|
* (корректность имён и путей не проверяется)
|
|
|
|
|
* состоящую из указанных столбцов.
|
|
|
|
|
* Если не указано attach - создать директорию, если её нет.
|
|
|
|
|
*/
|
|
|
|
|
static StoragePtr create(
|
|
|
|
|
const std::string & path_,
|
|
|
|
|
const std::string & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_,
|
|
|
|
|
bool attach,
|
|
|
|
|
size_t max_compress_block_size_ = DEFAULT_MAX_COMPRESS_BLOCK_SIZE);
|
|
|
|
|
|
|
|
|
|
std::string getName() const override { return "StripeLog"; }
|
|
|
|
|
std::string getTableName() const override { return name; }
|
|
|
|
|
|
|
|
|
|
const NamesAndTypesList & getColumnsListImpl() const override { return *columns; }
|
|
|
|
|
|
|
|
|
|
BlockInputStreams read(
|
|
|
|
|
const Names & column_names,
|
|
|
|
|
ASTPtr query,
|
|
|
|
|
const Context & context,
|
|
|
|
|
const Settings & settings,
|
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
|
|
|
|
size_t max_block_size = DEFAULT_BLOCK_SIZE,
|
|
|
|
|
unsigned threads = 1) override;
|
|
|
|
|
|
2015-09-10 20:43:42 +00:00
|
|
|
|
BlockOutputStreamPtr write(ASTPtr query, const Settings & settings) override;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
|
|
|
|
|
void rename(const String & new_path_to_db, const String & new_database_name, const String & new_table_name) override;
|
|
|
|
|
|
|
|
|
|
bool checkData() const override;
|
|
|
|
|
|
|
|
|
|
/// Данные файла.
|
|
|
|
|
struct ColumnData
|
|
|
|
|
{
|
|
|
|
|
Poco::File data_file;
|
|
|
|
|
};
|
2016-05-28 10:35:44 +00:00
|
|
|
|
using Files_t = std::map<String, ColumnData>;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
|
|
|
|
|
std::string full_path() { return path + escapeForFileName(name) + '/';}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
String path;
|
|
|
|
|
String name;
|
|
|
|
|
NamesAndTypesListPtr columns;
|
|
|
|
|
|
|
|
|
|
size_t max_compress_block_size;
|
|
|
|
|
|
|
|
|
|
FileChecker file_checker;
|
2015-08-16 08:18:34 +00:00
|
|
|
|
Poco::RWLock rwlock;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
|
|
|
|
|
Logger * log;
|
|
|
|
|
|
|
|
|
|
StorageStripeLog(
|
|
|
|
|
const std::string & path_,
|
|
|
|
|
const std::string & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_,
|
|
|
|
|
bool attach,
|
|
|
|
|
size_t max_compress_block_size_);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|