2017-12-30 00:36:06 +00:00
|
|
|
#include <Storages/StorageNull.h>
|
|
|
|
#include <Storages/StorageFactory.h>
|
2018-12-25 23:18:07 +00:00
|
|
|
#include <Storages/AlterCommands.h>
|
2017-12-30 00:36:06 +00:00
|
|
|
|
2018-01-11 19:13:19 +00:00
|
|
|
#include <Interpreters/InterpreterAlterQuery.h>
|
2020-02-10 15:50:12 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2018-01-11 19:13:19 +00:00
|
|
|
#include <Databases/IDatabase.h>
|
|
|
|
|
2017-12-30 00:36:06 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2020-02-25 18:02:41 +00:00
|
|
|
extern const int NOT_IMPLEMENTED;
|
2017-12-30 00:36:06 +00:00
|
|
|
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);
|
|
|
|
|
2019-12-04 16:06:55 +00:00
|
|
|
return StorageNull::create(args.table_id, args.columns, args.constraints);
|
2017-12-30 00:36:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-26 18:17:05 +00:00
|
|
|
void StorageNull::checkAlterIsPossible(const AlterCommands & commands, const Settings & /* settings */)
|
|
|
|
{
|
|
|
|
for (const auto & command : commands)
|
|
|
|
{
|
|
|
|
if (command.type != AlterCommand::Type::ADD_COLUMN && command.type != AlterCommand::Type::MODIFY_COLUMN
|
|
|
|
&& command.type != AlterCommand::Type::DROP_COLUMN && command.type != AlterCommand::Type::COMMENT_COLUMN)
|
|
|
|
throw Exception(
|
|
|
|
"Alter of type '" + alterTypeToString(command.type) + "' is not supported by storage " + getName(),
|
|
|
|
ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-05 10:12:20 +00:00
|
|
|
void StorageNull::alter(
|
2019-08-26 14:50:34 +00:00
|
|
|
const AlterCommands & params, const Context & context, TableStructureWriteLockHolder & table_lock_holder)
|
2018-01-11 19:13:19 +00:00
|
|
|
{
|
2020-04-09 18:10:27 +00:00
|
|
|
lockStructureExclusively(table_lock_holder, context.getCurrentQueryId(), context.getSettingsRef().lock_acquire_timeout);
|
2019-12-03 16:25:32 +00:00
|
|
|
auto table_id = getStorageID();
|
2019-08-26 14:50:34 +00:00
|
|
|
|
2019-12-26 18:17:05 +00:00
|
|
|
StorageInMemoryMetadata metadata = getInMemoryMetadata();
|
2020-05-28 12:37:05 +00:00
|
|
|
params.apply(metadata, context);
|
2020-03-23 22:40:40 +00:00
|
|
|
DatabaseCatalog::instance().getDatabase(table_id.database_name)->alterTable(context, table_id, metadata);
|
2019-12-26 18:17:05 +00:00
|
|
|
setColumns(std::move(metadata.columns));
|
2018-01-11 19:13:19 +00:00
|
|
|
}
|
|
|
|
|
2017-12-30 00:36:06 +00:00
|
|
|
}
|