1#include <Storages/StorageNull.h>
2#include <Storages/StorageFactory.h>
3#include <Storages/AlterCommands.h>
4
5#include <Interpreters/InterpreterAlterQuery.h>
6#include <Databases/IDatabase.h>
7
8#include <IO/WriteHelpers.h>
9
10
11namespace DB
12{
13
14namespace ErrorCodes
15{
16 extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
17}
18
19
20void registerStorageNull(StorageFactory & factory)
21{
22 factory.registerStorage("Null", [](const StorageFactory::Arguments & args)
23 {
24 if (!args.engine_args.empty())
25 throw Exception(
26 "Engine " + args.engine_name + " doesn't support any arguments (" + toString(args.engine_args.size()) + " given)",
27 ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
28
29 return StorageNull::create(args.database_name, args.table_name, args.columns, args.constraints);
30 });
31}
32
33void StorageNull::checkAlterIsPossible(const AlterCommands & commands, const Settings & /* settings */)
34{
35 for (const auto & command : commands)
36 {
37 if (command.type != AlterCommand::Type::ADD_COLUMN && command.type != AlterCommand::Type::MODIFY_COLUMN
38 && command.type != AlterCommand::Type::DROP_COLUMN && command.type != AlterCommand::Type::COMMENT_COLUMN)
39 throw Exception(
40 "Alter of type '" + alterTypeToString(command.type) + "' is not supported by storage " + getName(),
41 ErrorCodes::NOT_IMPLEMENTED);
42 }
43}
44
45
46void StorageNull::alter(
47 const AlterCommands & params, const Context & context, TableStructureWriteLockHolder & table_lock_holder)
48{
49 lockStructureExclusively(table_lock_holder, context.getCurrentQueryId());
50
51 const String current_database_name = getDatabaseName();
52 const String current_table_name = getTableName();
53
54 StorageInMemoryMetadata metadata = getInMemoryMetadata();
55 params.apply(metadata);
56 context.getDatabase(current_database_name)->alterTable(context, current_table_name, metadata);
57 setColumns(std::move(metadata.columns));
58}
59
60}
61