mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 09:02:00 +00:00
made using macroses
This commit is contained in:
parent
cf1be73977
commit
ad94e08b0b
@ -93,13 +93,13 @@
|
||||
|
||||
<url_scheme_mappers>
|
||||
<s3>
|
||||
<domain>.s3.amazonaws.com</domain>
|
||||
<to>https://{bucket}.s3.amazonaws.com</to>
|
||||
</s3>
|
||||
<gs>
|
||||
<domain>.storage.googleapis.com</domain>
|
||||
<to>https://{bucket}.storage.googleapis.com</to>
|
||||
</gs>
|
||||
<oss>
|
||||
<domain>.oss.aliyuncs.com</domain>
|
||||
<to>https://{bucket}.oss.aliyuncs.com</to>
|
||||
</oss>
|
||||
</url_scheme_mappers>
|
||||
|
||||
|
@ -36,6 +36,13 @@ Macros::Macros(const Poco::Util::AbstractConfiguration & config, const String &
|
||||
}
|
||||
}
|
||||
|
||||
Macros::Macros(const String & key, const String & value)
|
||||
{
|
||||
macros[key] = value;
|
||||
if (key == "database" || key == "table" || key == "uuid")
|
||||
enable_special_macros = false;
|
||||
}
|
||||
|
||||
String Macros::expand(const String & s,
|
||||
MacroExpansionInfo & info) const
|
||||
{
|
||||
|
@ -27,6 +27,7 @@ class Macros
|
||||
public:
|
||||
Macros() = default;
|
||||
Macros(const Poco::Util::AbstractConfiguration & config, const String & key, Poco::Logger * log = nullptr);
|
||||
Macros(const String & key, const String & value);
|
||||
|
||||
struct MacroExpansionInfo
|
||||
{
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <IO/S3/URI.h>
|
||||
#include <Poco/URI.h>
|
||||
#include "Common/Macros.h"
|
||||
#include <Interpreters/Context.h>
|
||||
#include <Storages/NamedCollectionsHelpers.h>
|
||||
#if USE_AWS_S3
|
||||
#include <Common/Exception.h>
|
||||
@ -23,13 +25,8 @@ struct URIConverter
|
||||
{
|
||||
static void modifyURI(Poco::URI & uri, std::unordered_map<std::string, std::string> mapper)
|
||||
{
|
||||
if (uri.getScheme() == "s3" || uri.getScheme() == "oss" || uri.getScheme() == "gs")
|
||||
{
|
||||
uri.setHost(uri.getHost() + mapper[uri.getScheme()]);
|
||||
uri.setScheme("https");
|
||||
}
|
||||
else if (!mapper["nc_s3"].empty()) /// Case for tests
|
||||
uri = Poco::URI(mapper["nc_s3"] + "/" + uri.getHost() + uri.getPath());
|
||||
Macros macros("bucket", uri.getHost());
|
||||
uri = Poco::URI(macros.expand(mapper[uri.getScheme()]) + "/" + uri.getPathAndQuery());
|
||||
}
|
||||
};
|
||||
|
||||
@ -71,13 +68,13 @@ URI::URI(const std::string & uri_)
|
||||
std::vector<String> config_keys;
|
||||
config->keys("url_scheme_mappers", config_keys);
|
||||
for (const std::string & config_key : config_keys)
|
||||
mapper[config_key] = config->getString("url_scheme_mappers." + config_key + ".domain");
|
||||
mapper[config_key] = config->getString("url_scheme_mappers." + config_key + ".to");
|
||||
}
|
||||
else
|
||||
{
|
||||
mapper["s3"] = ".s3.amazonaws.com";
|
||||
mapper["gs"] = ".storage.googleapis.com";
|
||||
mapper["oss"] = ".oss.aliyuncs.com";
|
||||
mapper["s3"] = "https://{bucket}.s3.amazonaws.com";
|
||||
mapper["gs"] = "https://{bucket}.storage.googleapis.com";
|
||||
mapper["oss"] = "https://{bucket}.oss.aliyuncs.com";
|
||||
}
|
||||
|
||||
if (!mapper.empty())
|
||||
|
@ -3,8 +3,8 @@
|
||||
<!-- Using named collections 22.4+ -->
|
||||
<clickhouse>
|
||||
<url_scheme_mappers>
|
||||
<nc_s3>
|
||||
<domain>http://minio1:9001/root</domain>
|
||||
</nc_s3>
|
||||
<minio>
|
||||
<to>http://minio1:9001/root/{bucket}</to>
|
||||
</minio>
|
||||
</url_scheme_mappers>
|
||||
</clickhouse>
|
||||
|
Loading…
Reference in New Issue
Block a user