Skip to content

Commit

Permalink
Merge pull request #54516 from ClickHouse/backport/23.8/54373
Browse files Browse the repository at this point in the history
Backport #54373 to 23.8: Fix possible error 'URI contains invalid characters' in s3 table function
  • Loading branch information
Avogar committed Sep 12, 2023
2 parents 311d53e + a2adaf1 commit f273f04
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/TableFunctions/TableFunctionS3.cpp
Expand Up @@ -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
{
Expand Down Expand Up @@ -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"))
{
Expand All @@ -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)
Expand Down
Empty 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 }

0 comments on commit f273f04

Please sign in to comment.