2019-03-22 12:08:30 +00:00
|
|
|
#include "Settings.h"
|
|
|
|
|
2018-06-03 20:39:06 +00:00
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
2018-05-17 16:01:41 +00:00
|
|
|
#include <Columns/ColumnArray.h>
|
2021-01-05 10:10:19 +00:00
|
|
|
#include <Columns/ColumnMap.h>
|
2018-05-17 16:01:41 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
|
|
|
#include <string.h>
|
2019-04-25 14:08:20 +00:00
|
|
|
#include <boost/program_options/options_description.hpp>
|
2016-06-07 08:23:15 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int THERE_IS_NO_PROFILE;
|
|
|
|
extern const int NO_ELEMENTS_IN_CONFIG;
|
2020-08-05 19:54:06 +00:00
|
|
|
extern const int UNKNOWN_ELEMENT_IN_CONFIG;
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 09:57:17 +00:00
|
|
|
IMPLEMENT_SETTINGS_TRAITS(SettingsTraits, LIST_OF_SETTINGS)
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-02 17:37:49 +00:00
|
|
|
/** Set the settings from the profile (in the server configuration, many settings can be listed in one profile).
|
|
|
|
* The profile can also be set using the `set` functions, like the `profile` setting.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
2018-07-08 04:54:37 +00:00
|
|
|
void Settings::setProfile(const String & profile_name, const Poco::Util::AbstractConfiguration & config)
|
2016-06-07 08:23:15 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
String elem = "profiles." + profile_name;
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!config.has(elem))
|
|
|
|
throw Exception("There is no profile '" + profile_name + "' in configuration file.", ErrorCodes::THERE_IS_NO_PROFILE);
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Poco::Util::AbstractConfiguration::Keys config_keys;
|
|
|
|
config.keys(elem, config_keys);
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (const std::string & key : config_keys)
|
|
|
|
{
|
2019-04-19 00:45:15 +00:00
|
|
|
if (key == "constraints")
|
|
|
|
continue;
|
2020-02-24 18:11:21 +00:00
|
|
|
if (key == "profile" || key.starts_with("profile[")) /// Inheritance of profiles from the current one.
|
2017-04-01 07:20:54 +00:00
|
|
|
setProfile(config.getString(elem + "." + key), config);
|
|
|
|
else
|
|
|
|
set(key, config.getString(elem + "." + key));
|
|
|
|
}
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::loadSettingsFromConfig(const String & path, const Poco::Util::AbstractConfiguration & config)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!config.has(path))
|
|
|
|
throw Exception("There is no path '" + path + "' in configuration file.", ErrorCodes::NO_ELEMENTS_IN_CONFIG);
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Poco::Util::AbstractConfiguration::Keys config_keys;
|
|
|
|
config.keys(path, config_keys);
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (const std::string & key : config_keys)
|
|
|
|
{
|
|
|
|
set(key, config.getString(path + "." + key));
|
|
|
|
}
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 10:10:19 +00:00
|
|
|
void Settings::dumpToMapColumn(IColumn * column, bool changed_only)
|
2018-05-17 16:01:41 +00:00
|
|
|
{
|
|
|
|
/// Convert ptr and make simple check
|
2021-01-05 10:10:19 +00:00
|
|
|
auto * column_map = column ? &typeid_cast<ColumnMap &>(*column) : nullptr;
|
|
|
|
if (!column_map)
|
|
|
|
return;
|
2018-05-17 16:01:41 +00:00
|
|
|
|
2021-01-05 10:10:19 +00:00
|
|
|
auto & offsets = column_map->getNestedColumn().getOffsets();
|
|
|
|
auto & tuple_column = column_map->getNestedData();
|
|
|
|
auto & key_column = tuple_column.getColumn(0);
|
|
|
|
auto & value_column = tuple_column.getColumn(1);
|
2018-05-17 16:01:41 +00:00
|
|
|
|
2021-01-05 10:10:19 +00:00
|
|
|
size_t size = 0;
|
2020-08-03 17:42:37 +00:00
|
|
|
for (const auto & setting : all(changed_only ? SKIP_UNCHANGED : SKIP_NONE))
|
2019-04-25 14:08:20 +00:00
|
|
|
{
|
2021-01-05 10:10:19 +00:00
|
|
|
auto name = setting.getName();
|
|
|
|
key_column.insertData(name.data(), name.size());
|
|
|
|
value_column.insert(setting.getValueString());
|
|
|
|
size++;
|
2018-05-17 16:01:41 +00:00
|
|
|
}
|
2021-06-28 11:42:21 +00:00
|
|
|
|
2021-01-05 10:10:19 +00:00
|
|
|
offsets.push_back(offsets.back() + size);
|
2018-05-17 16:01:41 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 14:08:20 +00:00
|
|
|
void Settings::addProgramOptions(boost::program_options::options_description & options)
|
|
|
|
{
|
2020-08-03 17:42:37 +00:00
|
|
|
for (const auto & field : all())
|
2019-04-25 14:08:20 +00:00
|
|
|
{
|
2020-07-20 09:57:17 +00:00
|
|
|
const std::string_view name = field.getName();
|
2019-04-25 14:08:20 +00:00
|
|
|
auto on_program_option
|
2020-07-20 09:57:17 +00:00
|
|
|
= boost::function1<void, const std::string &>([this, name](const std::string & value) { set(name, value); });
|
2019-04-25 14:08:20 +00:00
|
|
|
options.add(boost::shared_ptr<boost::program_options::option_description>(new boost::program_options::option_description(
|
2020-07-20 09:57:17 +00:00
|
|
|
name.data(),
|
2019-04-25 14:08:20 +00:00
|
|
|
boost::program_options::value<std::string>()->composing()->notifier(on_program_option),
|
2020-07-20 09:57:17 +00:00
|
|
|
field.getDescription())));
|
2019-04-25 14:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-05 19:54:06 +00:00
|
|
|
|
|
|
|
void Settings::checkNoSettingNamesAtTopLevel(const Poco::Util::AbstractConfiguration & config, const String & config_path)
|
|
|
|
{
|
|
|
|
if (config.getBool("skip_check_for_incorrect_settings", false))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Settings settings;
|
|
|
|
for (auto setting : settings.all())
|
|
|
|
{
|
|
|
|
const auto & name = setting.getName();
|
|
|
|
if (config.has(name))
|
|
|
|
{
|
|
|
|
throw Exception(fmt::format("A setting '{}' appeared at top level in config {}."
|
|
|
|
" But it is user-level setting that should be located in users.xml inside <profiles> section for specific profile."
|
|
|
|
" You can add it to <profiles><default> if you want to change default value of this setting."
|
|
|
|
" You can also disable the check - specify <skip_check_for_incorrect_settings>1</skip_check_for_incorrect_settings>"
|
|
|
|
" in the main configuration file.",
|
|
|
|
name, config_path),
|
|
|
|
ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 08:53:39 +00:00
|
|
|
IMPLEMENT_SETTINGS_TRAITS(FormatFactorySettingsTraits, FORMAT_FACTORY_SETTINGS)
|
|
|
|
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|