Check format name on storage creation

This commit is contained in:
avogar 2022-05-23 12:48:48 +00:00
parent 008de5c779
commit 37b66c8a9e
8 changed files with 19 additions and 0 deletions

View File

@ -585,6 +585,13 @@ bool FormatFactory::checkIfFormatHasAnySchemaReader(const String & name)
return checkIfFormatHasSchemaReader(name) || checkIfFormatHasExternalSchemaReader(name);
}
void FormatFactory::checkFormatName(const String & name) const
{
auto it = dict.find(name);
if (it == dict.end())
throw Exception("Unknown format " + name, ErrorCodes::UNKNOWN_FORMAT);
}
FormatFactory & FormatFactory::instance()
{
static FormatFactory ret;

View File

@ -210,6 +210,9 @@ public:
bool isInputFormat(const String & name) const;
bool isOutputFormat(const String & name) const;
/// Check that format with specified name exists and throw an exception otherwise.
void checkFormatName(const String & name) const;
private:
FormatsDictionary dict;
FileExtensionFormats file_extension_formats;

View File

@ -146,6 +146,7 @@ StorageHDFS::StorageHDFS(
, distributed_processing(distributed_processing_)
, partition_by(partition_by_)
{
FormatFactory::instance().checkFormatName(format_name);
context_->getRemoteHostFilter().checkURL(Poco::URI(uri_));
checkHDFSURL(uri_);

View File

@ -382,6 +382,8 @@ StorageFile::StorageFile(CommonArguments args)
, compression_method(args.compression_method)
, base_path(args.getContext()->getPath())
{
if (format_name != "Distributed")
FormatFactory::instance().checkFormatName(format_name);
}
void StorageFile::setStorageMetadata(CommonArguments args)

View File

@ -609,6 +609,7 @@ StorageS3::StorageS3(
, partition_by(partition_by_)
, is_key_with_globs(uri_.key.find_first_of("*?{") != std::string::npos)
{
FormatFactory::instance().checkFormatName(format_name);
context_->getGlobalContext()->getRemoteHostFilter().checkURL(uri_.uri);
StorageInMemoryMetadata storage_metadata;

View File

@ -74,6 +74,7 @@ IStorageURLBase::IStorageURLBase(
, http_method(http_method_)
, partition_by(partition_by_)
{
FormatFactory::instance().checkFormatName(format_name);
StorageInMemoryMetadata storage_metadata;
if (columns_.empty())

View File

@ -0,0 +1,4 @@
create table test_02311 (x UInt32) engine=File(UnknownFormat); -- {serverError UNKNOWN_FORMAT}
create table test_02311 (x UInt32) engine=URL('http://some/url', UnknownFormat); -- {serverError UNKNOWN_FORMAT}
create table test_02311 (x UInt32) engine=S3('http://host:2020/test/data', UnknownFormat); -- {serverError UNKNOWN_FORMAT}
create table test_02311 (x UInt32) engine=HDFS('http://hdfs:9000/data', UnknownFormat); -- {serverError UNKNOWN_FORMAT}