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
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getName() const override
|
|
|
|
{
|
|
|
|
return "File";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getTableName() const override
|
|
|
|
{
|
|
|
|
return table_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2017-06-02 15:54:39 +00:00
|
|
|
size_t max_block_size,
|
|
|
|
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,
|
2017-04-01 07:20:54 +00:00
|
|
|
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;
|
2016-10-18 14:18:37 +00:00
|
|
|
|
2018-02-21 19:26:59 +00:00
|
|
|
String getDataPath() const override { return path; }
|
|
|
|
|
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
|
|
|
|
2017-11-03 21:50:22 +00:00
|
|
|
/** there are three options (ordered by priority):
|
|
|
|
- use specified file descriptor if (fd >= 0)
|
|
|
|
- use specified table_path if it isn't empty
|
2018-03-06 20:18:34 +00:00
|
|
|
- create own table inside data/db/table/
|
2017-11-03 21:50:22 +00:00
|
|
|
*/
|
|
|
|
StorageFile(
|
|
|
|
const std::string & table_path_,
|
|
|
|
int table_fd_,
|
|
|
|
const std::string & db_dir_path,
|
|
|
|
const std::string & table_name_,
|
|
|
|
const std::string & format_name_,
|
2018-03-06 20:18:34 +00:00
|
|
|
const ColumnsDescription & columns_,
|
2017-11-03 21:50:22 +00:00
|
|
|
Context & context_);
|
|
|
|
|
2016-10-18 14:18:37 +00:00
|
|
|
private:
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string table_name;
|
|
|
|
std::string format_name;
|
|
|
|
Context & context_global;
|
2016-10-28 17:38:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string path;
|
|
|
|
int table_fd = -1;
|
2016-10-18 14:18:37 +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
|
|
|
|
bool use_table_fd = false; /// Use table_fd insted of path
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|