1#pragma once
2
3#include <ext/shared_ptr_helper.h>
4
5#include <Core/NamesAndTypes.h>
6#include <Storages/IStorage.h>
7#include <DataStreams/NullBlockInputStream.h>
8#include <DataStreams/NullBlockOutputStream.h>
9
10
11namespace DB
12{
13
14/** When writing, does nothing.
15 * When reading, returns nothing.
16 */
17class StorageNull : public ext::shared_ptr_helper<StorageNull>, public IStorage
18{
19 friend struct ext::shared_ptr_helper<StorageNull>;
20public:
21 std::string getName() const override { return "Null"; }
22 std::string getTableName() const override { return table_name; }
23 std::string getDatabaseName() const override { return database_name; }
24
25 BlockInputStreams read(
26 const Names & column_names,
27 const SelectQueryInfo &,
28 const Context & /*context*/,
29 QueryProcessingStage::Enum /*processing_stage*/,
30 size_t,
31 unsigned) override
32 {
33 return { std::make_shared<NullBlockInputStream>(getSampleBlockForColumns(column_names)) };
34 }
35
36 BlockOutputStreamPtr write(const ASTPtr &, const Context &) override
37 {
38 return std::make_shared<NullBlockOutputStream>(getSampleBlock());
39 }
40
41 void rename(const String & /*new_path_to_db*/, const String & new_database_name, const String & new_table_name, TableStructureWriteLockHolder &) override
42 {
43 table_name = new_table_name;
44 database_name = new_database_name;
45 }
46
47 void checkAlterIsPossible(const AlterCommands & commands, const Settings & /* settings */) override;
48
49 void alter(const AlterCommands & params, const Context & context, TableStructureWriteLockHolder & table_lock_holder) override;
50
51private:
52 String table_name;
53 String database_name;
54
55protected:
56 StorageNull(String database_name_, String table_name_, ColumnsDescription columns_description_, ConstraintsDescription constraints_)
57 : table_name(std::move(table_name_)), database_name(std::move(database_name_))
58 {
59 setColumns(std::move(columns_description_));
60 setConstraints(std::move(constraints_));
61 }
62};
63
64}
65