Merge pull request #54373 from Avogar/fix-s3-url-invalid-characters-error

Fix possible error 'URI contains invalid characters' in s3 table function
This commit is contained in:
Kruglov Pavel 2023-09-11 20:52:28 +02:00 committed by GitHub
commit 00fcb8aceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View File

@ -58,6 +58,11 @@ void TableFunctionS3::parseArgumentsImpl(ASTs & args, const ContextPtr & context
if (auto named_collection = tryGetNamedCollectionWithOverrides(args, context))
{
StorageS3::processNamedCollectionResult(configuration, *named_collection);
if (configuration.format == "auto")
{
String file_path = named_collection->getOrDefault<String>("filename", Poco::URI(named_collection->get<String>("url")).getPath());
configuration.format = FormatFactory::instance().getFormatFromFileName(file_path, true);
}
}
else
{
@ -152,7 +157,8 @@ void TableFunctionS3::parseArgumentsImpl(ASTs & args, const ContextPtr & context
}
/// This argument is always the first
configuration.url = S3::URI(checkAndGetLiteralArgument<String>(args[0], "url"));
String url = checkAndGetLiteralArgument<String>(args[0], "url");
configuration.url = S3::URI(url);
if (args_to_idx.contains("format"))
{
@ -176,12 +182,12 @@ void TableFunctionS3::parseArgumentsImpl(ASTs & args, const ContextPtr & context
configuration.auth_settings.secret_access_key = checkAndGetLiteralArgument<String>(args[args_to_idx["secret_access_key"]], "secret_access_key");
configuration.auth_settings.no_sign_request = no_sign_request;
if (configuration.format == "auto")
configuration.format = FormatFactory::instance().getFormatFromFileName(Poco::URI(url).getPath(), true);
}
configuration.keys = {configuration.url.key};
if (configuration.format == "auto")
configuration.format = FormatFactory::instance().getFormatFromFileName(Poco::URI(configuration.url.uri.getPath()).getPath(), true);
}
void TableFunctionS3::parseArguments(const ASTPtr & ast_function, ContextPtr context)

View File

@ -0,0 +1,6 @@
-- Tags: no-fasttest
select * from s3('https://datasets-documentation.s3.eu-west-3.amazonaws.com/MyPrefix/BU%20-%20UNIT%20-%201/*.parquet'); -- { serverError CANNOT_EXTRACT_TABLE_STRUCTURE }
select * from s3('https://datasets-documentation.s3.eu-west-3.amazonaws.com/MyPrefix/*.parquet?some_tocken=ABCD'); -- { serverError CANNOT_EXTRACT_TABLE_STRUCTURE }