Ensure COMMENT clause works for all table engines

This commit is contained in:
joelynch 2024-07-21 20:00:38 +02:00
parent 3d00badef7
commit 8786d9b5dd
No known key found for this signature in database
18 changed files with 43 additions and 13 deletions

View File

@ -154,6 +154,7 @@ StoragePtr DatabaseSQLite::fetchTable(const String & table_name, ContextPtr loca
table_name,
ColumnsDescription{*columns},
ConstraintsDescription{},
/* comment = */ "",
local_context);
return storage;

View File

@ -418,8 +418,11 @@ namespace
}
StorageKafka::StorageKafka(
const StorageID & table_id_, ContextPtr context_,
const ColumnsDescription & columns_, std::unique_ptr<KafkaSettings> kafka_settings_,
const StorageID & table_id_,
ContextPtr context_,
const ColumnsDescription & columns_,
const String & comment,
std::unique_ptr<KafkaSettings> kafka_settings_,
const String & collection_name_)
: IStorage(table_id_)
, WithContext(context_->getGlobalContext())
@ -451,6 +454,7 @@ StorageKafka::StorageKafka(
StorageInMemoryMetadata storage_metadata;
storage_metadata.setColumns(columns_);
storage_metadata.setComment(comment);
setInMemoryMetadata(storage_metadata);
setVirtuals(createVirtuals(kafka_settings->kafka_handle_error_mode));
@ -1317,7 +1321,7 @@ void registerStorageKafka(StorageFactory & factory)
"See https://clickhouse.com/docs/en/engines/table-engines/integrations/kafka/#configuration");
}
return std::make_shared<StorageKafka>(args.table_id, args.getContext(), args.columns, std::move(kafka_settings), collection_name);
return std::make_shared<StorageKafka>(args.table_id, args.getContext(), args.columns, args.comment, std::move(kafka_settings), collection_name);
};
factory.registerStorage("Kafka", creator_fn, StorageFactory::StorageFeatures{ .supports_settings = true, });

View File

@ -40,6 +40,7 @@ public:
const StorageID & table_id_,
ContextPtr context_,
const ColumnsDescription & columns_,
const String & comment,
std::unique_ptr<KafkaSettings> kafka_settings_,
const String & collection_name_);

View File

@ -49,6 +49,7 @@ StorageNATS::StorageNATS(
const StorageID & table_id_,
ContextPtr context_,
const ColumnsDescription & columns_,
const String & comment,
std::unique_ptr<NATSSettings> nats_settings_,
LoadingStrictnessLevel mode)
: IStorage(table_id_)
@ -87,6 +88,7 @@ StorageNATS::StorageNATS(
StorageInMemoryMetadata storage_metadata;
storage_metadata.setColumns(columns_);
storage_metadata.setComment(comment);
setInMemoryMetadata(storage_metadata);
setVirtuals(createVirtuals(nats_settings->nats_handle_error_mode));
@ -760,7 +762,7 @@ void registerStorageNATS(StorageFactory & factory)
if (!nats_settings->nats_subjects.changed)
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "You must specify `nats_subjects` setting");
return std::make_shared<StorageNATS>(args.table_id, args.getContext(), args.columns, std::move(nats_settings), args.mode);
return std::make_shared<StorageNATS>(args.table_id, args.getContext(), args.columns, args.comment, std::move(nats_settings), args.mode);
};
factory.registerStorage("NATS", creator_fn, StorageFactory::StorageFeatures{ .supports_settings = true, });

View File

@ -23,6 +23,7 @@ public:
const StorageID & table_id_,
ContextPtr context_,
const ColumnsDescription & columns_,
const String & comment,
std::unique_ptr<NATSSettings> nats_settings_,
LoadingStrictnessLevel mode);

View File

@ -571,6 +571,7 @@ void registerStorageMaterializedPostgreSQL(StorageFactory & factory)
StorageInMemoryMetadata metadata;
metadata.setColumns(args.columns);
metadata.setConstraints(args.constraints);
metadata.setComment(args.comment);
if (args.mode <= LoadingStrictnessLevel::CREATE
&& !args.getLocalContext()->getSettingsRef().allow_experimental_materialized_postgresql_table)

View File

@ -70,6 +70,7 @@ StorageRabbitMQ::StorageRabbitMQ(
const StorageID & table_id_,
ContextPtr context_,
const ColumnsDescription & columns_,
const String & comment,
std::unique_ptr<RabbitMQSettings> rabbitmq_settings_,
LoadingStrictnessLevel mode)
: IStorage(table_id_)
@ -145,6 +146,7 @@ StorageRabbitMQ::StorageRabbitMQ(
StorageInMemoryMetadata storage_metadata;
storage_metadata.setColumns(columns_);
storage_metadata.setComment(comment);
setInMemoryMetadata(storage_metadata);
setVirtuals(createVirtuals(rabbitmq_settings->rabbitmq_handle_error_mode));
@ -1288,7 +1290,7 @@ void registerStorageRabbitMQ(StorageFactory & factory)
if (!rabbitmq_settings->rabbitmq_format.changed)
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "You must specify `rabbitmq_format` setting");
return std::make_shared<StorageRabbitMQ>(args.table_id, args.getContext(), args.columns, std::move(rabbitmq_settings), args.mode);
return std::make_shared<StorageRabbitMQ>(args.table_id, args.getContext(), args.columns, args.comment, std::move(rabbitmq_settings), args.mode);
};
factory.registerStorage("RabbitMQ", creator_fn, StorageFactory::StorageFeatures{ .supports_settings = true, });

View File

@ -26,6 +26,7 @@ public:
const StorageID & table_id_,
ContextPtr context_,
const ColumnsDescription & columns_,
const String & comment,
std::unique_ptr<RabbitMQSettings> rabbitmq_settings_,
LoadingStrictnessLevel mode);

View File

@ -691,6 +691,7 @@ static StoragePtr create(const StorageFactory::Arguments & args)
StorageInMemoryMetadata metadata;
metadata.setColumns(args.columns);
metadata.setConstraints(args.constraints);
metadata.setComment(args.comment);
if (!args.storage_def->primary_key)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "StorageEmbeddedRocksDB must require one column in primary key");

View File

@ -77,7 +77,8 @@ StorageExecutable::StorageExecutable(
const ExecutableSettings & settings_,
const std::vector<ASTPtr> & input_queries_,
const ColumnsDescription & columns,
const ConstraintsDescription & constraints)
const ConstraintsDescription & constraints,
const String & comment)
: IStorage(table_id_)
, settings(settings_)
, input_queries(input_queries_)
@ -86,6 +87,7 @@ StorageExecutable::StorageExecutable(
StorageInMemoryMetadata storage_metadata;
storage_metadata.setColumns(columns);
storage_metadata.setConstraints(constraints);
storage_metadata.setComment(comment);
setInMemoryMetadata(storage_metadata);
ShellCommandSourceCoordinator::Configuration configuration
@ -237,7 +239,7 @@ void registerStorageExecutable(StorageFactory & factory)
settings.loadFromQuery(*args.storage_def);
auto global_context = args.getContext()->getGlobalContext();
return std::make_shared<StorageExecutable>(args.table_id, format, settings, input_queries, columns, constraints);
return std::make_shared<StorageExecutable>(args.table_id, format, settings, input_queries, columns, constraints, args.comment);
};
StorageFactory::StorageFeatures storage_features;
@ -255,4 +257,3 @@ void registerStorageExecutable(StorageFactory & factory)
}
}

View File

@ -22,7 +22,8 @@ public:
const ExecutableSettings & settings,
const std::vector<ASTPtr> & input_queries,
const ColumnsDescription & columns,
const ConstraintsDescription & constraints);
const ConstraintsDescription & constraints,
const String & comment);
String getName() const override
{

View File

@ -1280,6 +1280,7 @@ StoragePtr create(const StorageFactory::Arguments & args)
StorageInMemoryMetadata metadata;
metadata.setColumns(args.columns);
metadata.setConstraints(args.constraints);
metadata.setComment(args.comment);
if (!args.storage_def->primary_key)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "StorageKeeperMap requires one column in primary key");

View File

@ -50,6 +50,7 @@ StorageSQLite::StorageSQLite(
const String & remote_table_name_,
const ColumnsDescription & columns_,
const ConstraintsDescription & constraints_,
const String & comment,
ContextPtr context_)
: IStorage(table_id_)
, WithContext(context_->getGlobalContext())
@ -71,6 +72,7 @@ StorageSQLite::StorageSQLite(
storage_metadata.setConstraints(constraints_);
setInMemoryMetadata(storage_metadata);
storage_metadata.setComment(comment);
}
@ -211,7 +213,7 @@ void registerStorageSQLite(StorageFactory & factory)
auto sqlite_db = openSQLiteDB(database_path, args.getContext(), /* throw_on_error */ args.mode <= LoadingStrictnessLevel::CREATE);
return std::make_shared<StorageSQLite>(args.table_id, sqlite_db, database_path,
table_name, args.columns, args.constraints, args.getContext());
table_name, args.columns, args.constraints, args.comment, args.getContext());
},
{
.supports_schema_inference = true,

View File

@ -27,6 +27,7 @@ public:
const String & remote_table_name_,
const ColumnsDescription & columns_,
const ConstraintsDescription & constraints_,
const String & comment,
ContextPtr context_);
std::string getName() const override { return "SQLite"; }

View File

@ -1188,6 +1188,7 @@ StorageWindowView::StorageWindowView(
ContextPtr context_,
const ASTCreateQuery & query,
const ColumnsDescription & columns_,
const String & comment,
LoadingStrictnessLevel mode)
: IStorage(table_id_)
, WithContext(context_->getGlobalContext())
@ -1206,6 +1207,7 @@ StorageWindowView::StorageWindowView(
StorageInMemoryMetadata storage_metadata;
storage_metadata.setColumns(columns_);
storage_metadata.setComment(comment);
setInMemoryMetadata(storage_metadata);
/// If the target table is not set, use inner target table
@ -1761,7 +1763,7 @@ void registerStorageWindowView(StorageFactory & factory)
"Experimental WINDOW VIEW feature "
"is not enabled (the setting 'allow_experimental_window_view')");
return std::make_shared<StorageWindowView>(args.table_id, args.getLocalContext(), args.query, args.columns, args.mode);
return std::make_shared<StorageWindowView>(args.table_id, args.getLocalContext(), args.query, args.columns, args.comment, args.mode);
});
}

View File

@ -111,6 +111,7 @@ public:
ContextPtr context_,
const ASTCreateQuery & query,
const ColumnsDescription & columns_,
const String & comment,
LoadingStrictnessLevel mode);
String getName() const override { return "WindowView"; }

View File

@ -170,7 +170,14 @@ StoragePtr TableFunctionExecutable::executeImpl(const ASTPtr & /*ast_function*/,
if (settings_query != nullptr)
settings.applyChanges(settings_query->as<ASTSetQuery>()->changes);
auto storage = std::make_shared<StorageExecutable>(storage_id, format, settings, input_queries, getActualTableStructure(context, is_insert_query), ConstraintsDescription{});
auto storage = std::make_shared<StorageExecutable>(
storage_id,
format,
settings,
input_queries,
getActualTableStructure(context, is_insert_query),
ConstraintsDescription{},
/* comment = */ "");
storage->startup();
return storage;
}

View File

@ -57,7 +57,7 @@ StoragePtr TableFunctionSQLite::executeImpl(const ASTPtr & /*ast_function*/,
sqlite_db,
database_path,
remote_table_name,
cached_columns, ConstraintsDescription{}, context);
cached_columns, ConstraintsDescription{}, /* comment = */ "", context);
storage->startup();
return storage;