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;
|
2021-02-28 05:24:39 +00:00
|
|
|
extern const int ALTER_OF_COLUMN_IS_FORBIDDEN;
|
2017-12-30 00:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-04-23 12:18:23 +00:00
|
|
|
return StorageNull::create(args.table_id, args.columns, args.constraints, args.comment);
|
2021-01-08 11:42:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.supports_parallel_insert = true,
|
2017-12-30 00:36:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void StorageNull::checkAlterIsPossible(const AlterCommands & commands, ContextPtr context) const
|
2019-12-26 18:17:05 +00:00
|
|
|
{
|
2021-02-28 07:42:08 +00:00
|
|
|
auto name_deps = getDependentViewsByColumn(context);
|
2019-12-26 18:17:05 +00:00
|
|
|
for (const auto & command : commands)
|
|
|
|
{
|
2021-09-06 15:59:46 +00:00
|
|
|
if (command.type != AlterCommand::Type::ADD_COLUMN
|
2021-09-06 14:24:03 +00:00
|
|
|
&& command.type != AlterCommand::Type::MODIFY_COLUMN
|
2021-09-06 15:59:46 +00:00
|
|
|
&& command.type != AlterCommand::Type::DROP_COLUMN
|
2021-09-06 14:24:03 +00:00
|
|
|
&& command.type != AlterCommand::Type::COMMENT_COLUMN)
|
|
|
|
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Alter of type '{}' is not supported by storage {}",
|
|
|
|
command.type, getName());
|
|
|
|
|
2021-04-30 05:02:32 +00:00
|
|
|
if (command.type == AlterCommand::DROP_COLUMN && !command.clear)
|
2021-02-28 05:24:39 +00:00
|
|
|
{
|
2021-02-28 07:42:08 +00:00
|
|
|
const auto & deps_mv = name_deps[command.column_name];
|
2021-02-28 05:24:39 +00:00
|
|
|
if (!deps_mv.empty())
|
|
|
|
{
|
|
|
|
throw Exception(
|
|
|
|
"Trying to ALTER DROP column " + backQuoteIfNeed(command.column_name) + " which is referenced by materialized view "
|
|
|
|
+ toString(deps_mv),
|
|
|
|
ErrorCodes::ALTER_OF_COLUMN_IS_FORBIDDEN);
|
|
|
|
}
|
|
|
|
}
|
2019-12-26 18:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void StorageNull::alter(const AlterCommands & params, ContextPtr context, TableLockHolder &)
|
2018-01-11 19:13:19 +00:00
|
|
|
{
|
2019-12-03 16:25:32 +00:00
|
|
|
auto table_id = getStorageID();
|
2019-08-26 14:50:34 +00:00
|
|
|
|
2020-06-09 17:28:29 +00:00
|
|
|
StorageInMemoryMetadata new_metadata = getInMemoryMetadata();
|
|
|
|
params.apply(new_metadata, context);
|
|
|
|
DatabaseCatalog::instance().getDatabase(table_id.database_name)->alterTable(context, table_id, new_metadata);
|
2020-06-15 16:55:33 +00:00
|
|
|
setInMemoryMetadata(new_metadata);
|
2018-01-11 19:13:19 +00:00
|
|
|
}
|
|
|
|
|
2017-12-30 00:36:06 +00:00
|
|
|
}
|