2014-08-11 15:59:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2018-04-20 13:48:42 +00:00
|
|
|
#include <Core/Names.h>
|
2020-07-10 09:19:32 +00:00
|
|
|
#include <Interpreters/StorageID.h>
|
2018-09-28 19:13:16 +00:00
|
|
|
|
2014-08-11 15:59:01 +00:00
|
|
|
#include <map>
|
2018-03-13 23:44:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
namespace Util
|
|
|
|
{
|
|
|
|
class AbstractConfiguration;
|
|
|
|
}
|
2020-09-26 19:18:28 +00:00
|
|
|
class Logger;
|
2018-03-13 23:44:23 +00:00
|
|
|
}
|
2014-08-11 15:59:01 +00:00
|
|
|
|
2017-05-10 04:00:19 +00:00
|
|
|
|
2014-08-11 15:59:01 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-05-10 04:00:19 +00:00
|
|
|
/** Apply substitutions from the macros in config to the string.
|
2014-08-11 15:59:01 +00:00
|
|
|
*/
|
|
|
|
class Macros
|
|
|
|
{
|
|
|
|
public:
|
2020-03-08 21:04:10 +00:00
|
|
|
Macros() = default;
|
2020-09-27 11:10:45 +00:00
|
|
|
Macros(const Poco::Util::AbstractConfiguration & config, const String & key, Poco::Logger * log = nullptr);
|
2014-08-11 15:59:01 +00:00
|
|
|
|
2020-09-23 18:28:59 +00:00
|
|
|
struct MacroExpansionInfo
|
|
|
|
{
|
|
|
|
/// Settings
|
2020-09-26 19:18:28 +00:00
|
|
|
StorageID table_id = StorageID::createEmpty();
|
2020-09-23 18:28:59 +00:00
|
|
|
bool ignore_unknown = false;
|
2020-09-26 19:18:28 +00:00
|
|
|
bool expand_special_macros_only = false;
|
2021-11-23 09:41:54 +00:00
|
|
|
std::optional<String> shard;
|
|
|
|
std::optional<String> replica;
|
2020-09-23 18:28:59 +00:00
|
|
|
|
|
|
|
/// Information about macro expansion
|
|
|
|
size_t level = 0;
|
2020-09-26 19:18:28 +00:00
|
|
|
bool expanded_database = false;
|
|
|
|
bool expanded_table = false;
|
2020-09-23 18:28:59 +00:00
|
|
|
bool expanded_uuid = false;
|
2021-03-16 20:01:20 +00:00
|
|
|
bool expanded_other = false;
|
2020-09-23 18:28:59 +00:00
|
|
|
bool has_unknown = false;
|
|
|
|
};
|
|
|
|
|
2017-05-07 20:25:26 +00:00
|
|
|
/** Replace the substring of the form {macro_name} with the value for macro_name, obtained from the config file.
|
2018-10-01 18:45:39 +00:00
|
|
|
* If {database} and {table} macros aren`t defined explicitly, expand them as database_name and table_name respectively.
|
2017-05-07 20:25:26 +00:00
|
|
|
* level - the level of recursion.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
2020-07-10 09:19:32 +00:00
|
|
|
String expand(const String & s,
|
2020-09-23 18:28:59 +00:00
|
|
|
MacroExpansionInfo & info) const;
|
|
|
|
|
|
|
|
String expand(const String & s) const;
|
2018-05-07 02:01:11 +00:00
|
|
|
|
2020-07-10 09:19:32 +00:00
|
|
|
String expand(const String & s, const StorageID & table_id, bool allow_uuid) const;
|
2018-10-01 09:01:50 +00:00
|
|
|
|
|
|
|
|
2018-04-20 16:09:43 +00:00
|
|
|
/** Apply expand for the list.
|
|
|
|
*/
|
|
|
|
Names expand(const Names & source_names, size_t level = 0) const;
|
2014-08-11 15:59:01 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
using MacroMap = std::map<String, String>;
|
2022-03-11 21:47:28 +00:00
|
|
|
MacroMap getMacroMap() const { return macros; }
|
2014-08-11 15:59:01 +00:00
|
|
|
|
2019-10-09 01:14:57 +00:00
|
|
|
String getValue(const String & key) const;
|
|
|
|
|
2018-03-12 18:38:00 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
MacroMap macros;
|
2020-09-26 19:18:28 +00:00
|
|
|
bool enable_special_macros = true;
|
2014-08-11 15:59:01 +00:00
|
|
|
};
|
|
|
|
|
2018-03-12 18:16:51 +00:00
|
|
|
|
2014-08-11 15:59:01 +00:00
|
|
|
}
|