StorageNull.cpp 1.4 KB
Newer Older
1 2
#include <Storages/StorageNull.h>
#include <Storages/StorageFactory.h>
3
#include <Storages/AlterCommands.h>
4

5 6 7
#include <Interpreters/InterpreterAlterQuery.h>
#include <Databases/IDatabase.h>

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <IO/WriteHelpers.h>


namespace DB
{

namespace ErrorCodes
{
    extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}


void registerStorageNull(StorageFactory & factory)
{
    factory.registerStorage("Null", [](const StorageFactory::Arguments & args)
    {
        if (!args.engine_args.empty())
            throw Exception(
                "Engine " + args.engine_name + " doesn't support any arguments (" + toString(args.engine_args.size()) + " given)",
                ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);

29
        return StorageNull::create(args.database_name, args.table_name, args.columns);
30 31 32
    });
}

A
Alexey Zatelepin 已提交
33 34
void StorageNull::alter(
    const AlterCommands & params, const String & current_database_name, const String & current_table_name,
A
Alex Zatelepin 已提交
35
    const Context & context, TableStructureWriteLockHolder & table_lock_holder)
36
{
A
Alex Zatelepin 已提交
37
    lockStructureExclusively(table_lock_holder, context.getCurrentQueryId());
38

39
    ColumnsDescription new_columns = getColumns();
A
Alexey Milovidov 已提交
40
    IndicesDescription new_indices = getIndices();
41
    params.apply(new_columns);
N
Nikita Vasilev 已提交
42
    context.getDatabase(current_database_name)->alterTable(context, current_table_name, new_columns, new_indices, {});
43
    setColumns(std::move(new_columns));
44 45
}

46
}