2016-10-18 14:18:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2016-10-18 14:18:37 +00:00
|
|
|
|
|
|
|
#include <Poco/File.h>
|
|
|
|
#include <Poco/Path.h>
|
|
|
|
|
|
|
|
#include <common/logger_useful.h>
|
|
|
|
|
2017-04-08 01:32:05 +00:00
|
|
|
#include <atomic>
|
2017-07-28 17:34:02 +00:00
|
|
|
#include <shared_mutex>
|
2017-11-04 03:20:18 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
2017-04-08 01:32:05 +00:00
|
|
|
|
|
|
|
|
2016-10-18 14:18:37 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class StorageFileBlockInputStream;
|
|
|
|
class StorageFileBlockOutputStream;
|
|
|
|
|
2017-11-04 03:20:18 +00:00
|
|
|
class StorageFile : public ext::shared_ptr_helper<StorageFile>, public IStorage
|
2016-10-18 14:18:37 +00:00
|
|
|
{
|
2019-08-26 19:07:29 +00:00
|
|
|
friend struct ext::shared_ptr_helper<StorageFile>;
|
2016-10-18 14:18:37 +00:00
|
|
|
public:
|
2019-07-09 15:40:21 +00:00
|
|
|
std::string getName() const override { return "File"; }
|
|
|
|
std::string getTableName() const override { return table_name; }
|
|
|
|
std::string getDatabaseName() const override { return database_name; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
BlockInputStreams read(
|
|
|
|
const Names & column_names,
|
2017-07-15 03:48:36 +00:00
|
|
|
const SelectQueryInfo & query_info,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context,
|
2018-04-19 14:47:09 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
2019-02-18 23:38:44 +00:00
|
|
|
size_t max_block_size,
|
2017-06-02 15:54:39 +00:00
|
|
|
unsigned num_streams) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
BlockOutputStreamPtr write(
|
2017-05-21 22:25:25 +00:00
|
|
|
const ASTPtr & query,
|
2019-02-27 18:26:24 +00:00
|
|
|
const Context & context) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-08-27 23:47:30 +00:00
|
|
|
void rename(const String & new_path_to_db, const String & new_database_name, const String & new_table_name, TableStructureWriteLockHolder &) override;
|
2016-10-18 14:18:37 +00:00
|
|
|
|
2019-09-06 08:53:32 +00:00
|
|
|
Strings getDataPaths() const override;
|
2018-02-21 19:26:59 +00:00
|
|
|
|
2019-10-30 14:17:55 +00:00
|
|
|
struct CommonArguments
|
|
|
|
{
|
|
|
|
const std::string & database_name;
|
|
|
|
const std::string & table_name;
|
|
|
|
const std::string & format_name;
|
|
|
|
const ColumnsDescription & columns;
|
|
|
|
const ConstraintsDescription & constraints;
|
|
|
|
Context & context;
|
|
|
|
};
|
|
|
|
|
2016-10-28 17:38:32 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
friend class StorageFileBlockInputStream;
|
|
|
|
friend class StorageFileBlockOutputStream;
|
2016-10-18 14:18:37 +00:00
|
|
|
|
2019-10-30 14:17:55 +00:00
|
|
|
/// From file descriptor
|
|
|
|
StorageFile(int table_fd_, CommonArguments args);
|
|
|
|
|
|
|
|
/// From user's file
|
|
|
|
StorageFile(const std::string & table_path_, const std::string & user_files_absolute_path, CommonArguments args);
|
|
|
|
|
|
|
|
/// From table in database
|
|
|
|
StorageFile(const std::string & relative_table_dir_path, CommonArguments args);
|
2017-11-03 21:50:22 +00:00
|
|
|
|
2016-10-18 14:18:37 +00:00
|
|
|
private:
|
2019-10-30 14:17:55 +00:00
|
|
|
explicit StorageFile(CommonArguments args);
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string table_name;
|
2019-07-09 15:40:21 +00:00
|
|
|
std::string database_name;
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string format_name;
|
|
|
|
Context & context_global;
|
2016-10-28 17:38:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
int table_fd = -1;
|
2016-10-18 14:18:37 +00:00
|
|
|
|
2019-09-06 18:29:41 +00:00
|
|
|
std::vector<std::string> paths;
|
2019-07-21 13:15:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool is_db_table = true; /// Table is stored in real database, not user's file
|
2019-09-06 18:29:41 +00:00
|
|
|
bool use_table_fd = false; /// Use table_fd instead of path
|
2017-04-01 07:20:54 +00:00
|
|
|
std::atomic<bool> table_fd_was_used{false}; /// To detect repeating reads from stdin
|
|
|
|
off_t table_fd_init_offset = -1; /// Initial position of fd, used for repeating reads
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-07-28 17:34:02 +00:00
|
|
|
mutable std::shared_mutex rwlock;
|
2016-10-18 14:18:37 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Logger * log = &Logger::get("StorageFile");
|
2016-10-18 14:18:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|