Skip to content

Commit b516685

Browse files
committed
Turn off encoding only when required
1 parent 38a7629 commit b516685

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/IO/S3/URI.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ namespace DB
1616

1717
struct URIConverter
1818
{
19-
static void modifyURI(Poco::URI & uri, std::unordered_map<std::string, std::string> mapper)
19+
static void modifyURI(Poco::URI & uri, std::unordered_map<std::string, std::string> mapper, bool enable_url_encoding)
2020
{
2121
Macros macros({{"bucket", uri.getHost()}});
2222
uri = macros.expand(mapper[uri.getScheme()]).empty()
2323
? uri
24-
: Poco::URI(macros.expand(mapper[uri.getScheme()]) + uri.getPathAndQuery(), /*enable_url_encoding*/ false);
24+
: Poco::URI(macros.expand(mapper[uri.getScheme()]) + uri.getPathAndQuery(), enable_url_encoding);
2525
}
2626
};
2727

@@ -33,7 +33,7 @@ namespace ErrorCodes
3333
namespace S3
3434
{
3535

36-
URI::URI(const std::string & uri_, bool allow_archive_path_syntax)
36+
URI::URI(const std::string & uri_, bool allow_archive_path_syntax, bool enable_url_encoding)
3737
{
3838
/// Case when bucket name represented in domain name of S3 URL.
3939
/// E.g. (https://bucket-name.s3.region.amazonaws.com/key)
@@ -55,7 +55,7 @@ URI::URI(const std::string & uri_, bool allow_archive_path_syntax)
5555
else
5656
uri_str = uri_;
5757

58-
uri = Poco::URI(uri_str, /*enable_url_encoding*/ false);
58+
uri = Poco::URI(uri_str, enable_url_encoding);
5959

6060
std::unordered_map<std::string, std::string> mapper;
6161
auto context = Context::getGlobalContextInstance();
@@ -77,7 +77,7 @@ URI::URI(const std::string & uri_, bool allow_archive_path_syntax)
7777
}
7878

7979
if (!mapper.empty())
80-
URIConverter::modifyURI(uri, mapper);
80+
URIConverter::modifyURI(uri, mapper, enable_url_encoding);
8181
}
8282

8383
storage_name = "S3";

src/IO/S3/URI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct URI
3636
bool is_virtual_hosted_style;
3737

3838
URI() = default;
39-
explicit URI(const std::string & uri_, bool allow_archive_path_syntax = false);
39+
explicit URI(const std::string & uri_, bool allow_archive_path_syntax = false, bool enable_url_encoding = true);
4040
void addRegionToURI(const std::string & region);
4141

4242
static void validateBucket(const std::string & bucket, const Poco::URI & uri);

src/Storages/ObjectStorage/Utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ std::pair<DB::ObjectStoragePtr, std::string> resolveObjectStorageForPath(
341341
{
342342
normalized_path = "s3://" + target_decomposed.authority + "/" + target_decomposed.key;
343343
}
344-
S3::URI s3_uri(normalized_path);
344+
// enable_url_encoding=false, path from metadata must have correct encoding already
345+
S3::URI s3_uri(normalized_path, /*allow_archive_path_syntax*/ false, /*enable_url_encoding*/ false);
345346

346347
std::string key_to_use = s3_uri.key;
347348

@@ -365,7 +366,7 @@ std::pair<DB::ObjectStoragePtr, std::string> resolveObjectStorageForPath(
365366
{
366367
normalized_table_location = "s3://" + table_location_decomposed.authority + "/" + table_location_decomposed.key;
367368
}
368-
S3::URI base_s3_uri(normalized_table_location);
369+
S3::URI base_s3_uri(normalized_table_location, /*allow_archive_path_syntax*/ false, /*enable_url_encoding*/ false);
369370

370371
if (s3URIMatches(s3_uri, base_s3_uri.bucket, base_s3_uri.endpoint, target_scheme_normalized))
371372
use_base_storage = true;

0 commit comments

Comments
 (0)