2012-06-25 00:17:19 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2015-01-25 05:07:51 +00:00
|
|
|
|
#include <map>
|
2013-07-16 14:55:01 +00:00
|
|
|
|
|
2016-08-30 19:27:15 +00:00
|
|
|
|
#include <ext/shared_ptr_helper.hpp>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
|
2012-06-25 00:17:19 +00:00
|
|
|
|
#include <Poco/File.h>
|
|
|
|
|
|
|
|
|
|
#include <DB/Storages/IStorage.h>
|
2014-08-01 13:19:27 +00:00
|
|
|
|
#include <DB/Common/FileChecker.h>
|
2015-09-29 00:53:10 +00:00
|
|
|
|
#include <DB/Common/escapeForFileName.h>
|
2012-06-25 00:17:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Реализует хранилище, подходящее для маленьких кусочков лога.
|
|
|
|
|
* Отличается от StorageLog отсутствием файлов с засечками.
|
|
|
|
|
*/
|
2016-08-30 19:27:15 +00:00
|
|
|
|
class StorageTinyLog : private ext::shared_ptr_helper<StorageTinyLog>, public IStorage
|
2012-06-25 00:17:19 +00:00
|
|
|
|
{
|
2016-08-30 19:27:15 +00:00
|
|
|
|
friend class ext::shared_ptr_helper<StorageTinyLog>;
|
2012-06-25 00:17:19 +00:00
|
|
|
|
friend class TinyLogBlockInputStream;
|
|
|
|
|
friend class TinyLogBlockOutputStream;
|
|
|
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
|
/** Подцепить таблицу с соответствующим именем, по соответствующему пути (с / на конце),
|
|
|
|
|
* (корректность имён и путей не проверяется)
|
|
|
|
|
* состоящую из указанных столбцов.
|
|
|
|
|
* Если не указано 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 "TinyLog"; }
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
BlockOutputStreamPtr write(ASTPtr query, const Settings & settings) override;
|
|
|
|
|
|
|
|
|
|
void drop() override;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
using Files_t = std::map<String, ColumnData>;
|
|
|
|
|
|
|
|
|
|
std::string full_path() { return path + escapeForFileName(name) + '/';}
|
2014-08-29 18:44:44 +00:00
|
|
|
|
|
2012-06-25 00:17:19 +00:00
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
|
String path;
|
|
|
|
|
String name;
|
|
|
|
|
NamesAndTypesListPtr columns;
|
2012-06-25 00:17:19 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
size_t max_compress_block_size;
|
2014-03-28 14:36:24 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
Files_t files;
|
2012-08-29 18:49:54 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
FileChecker file_checker;
|
2014-07-31 13:39:23 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
Logger * log;
|
2014-07-31 13:39:23 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
StorageTinyLog(
|
|
|
|
|
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_);
|
2014-09-30 03:08:47 +00:00
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
|
void addFile(const String & column_name, const IDataType & type, size_t level = 0);
|
2012-06-25 00:17:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|