#pragma once #include #include #include #include #include #include namespace DB { /** Implements a repository that is suitable for small pieces of the log. * It differs from StorageLog in the absence of mark files. */ class StorageTinyLog : private ext::shared_ptr_helper, public IStorage { friend class ext::shared_ptr_helper; friend class TinyLogBlockInputStream; friend class TinyLogBlockOutputStream; public: /** hook the table with the appropriate name, along the appropriate path (with / at the end), * (the correctness of names and paths is not verified) * consisting of the specified columns. * If not specified `attach` - create a directory if it does not exist. */ 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, const ASTPtr & query, const Context & context, QueryProcessingStage::Enum & processed_stage, size_t max_block_size, unsigned num_streams) override; BlockOutputStreamPtr write(const 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; /// Column data struct ColumnData { Poco::File data_file; }; using Files_t = std::map; std::string full_path() { return path + escapeForFileName(name) + '/';} private: String path; String name; NamesAndTypesListPtr columns; size_t max_compress_block_size; Files_t files; FileChecker file_checker; Logger * log; 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_); void addFile(const String & column_name, const IDataType & type, size_t level = 0); }; }