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>
|
|
|
|
#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;
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 21:03:19 +00:00
|
|
|
IMPLEMENT_SETTINGS_COLLECTION(Settings, LIST_OF_SETTINGS)
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-07-06 14:42:31 +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;
|
2017-04-02 17:37:49 +00:00
|
|
|
if (key == "profile") /// Inheritance of one profile from another.
|
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
|
|
|
}
|
|
|
|
|
2018-05-17 16:01:41 +00:00
|
|
|
void Settings::dumpToArrayColumns(IColumn * column_names_, IColumn * column_values_, bool changed_only)
|
|
|
|
{
|
|
|
|
/// Convert ptr and make simple check
|
|
|
|
auto column_names = (column_names_) ? &typeid_cast<ColumnArray &>(*column_names_) : nullptr;
|
|
|
|
auto column_values = (column_values_) ? &typeid_cast<ColumnArray &>(*column_values_) : nullptr;
|
|
|
|
|
|
|
|
size_t size = 0;
|
|
|
|
|
2019-04-25 14:08:20 +00:00
|
|
|
for (const auto & setting : *this)
|
|
|
|
{
|
|
|
|
if (!changed_only || setting.isChanged())
|
|
|
|
{
|
|
|
|
if (column_names)
|
|
|
|
{
|
|
|
|
StringRef name = setting.getName();
|
|
|
|
column_names->getData().insertData(name.data, name.size);
|
|
|
|
}
|
|
|
|
if (column_values)
|
|
|
|
column_values->getData().insert(setting.getValueAsString());
|
|
|
|
++size;
|
|
|
|
}
|
2018-05-17 16:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (column_names)
|
|
|
|
{
|
|
|
|
auto & offsets = column_names->getOffsets();
|
2019-01-08 10:07:33 +00:00
|
|
|
offsets.push_back(offsets.back() + size);
|
2018-05-17 16:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Nested columns case
|
|
|
|
bool the_same_offsets = column_names && column_values && column_names->getOffsetsPtr() == column_values->getOffsetsPtr();
|
|
|
|
|
|
|
|
if (column_values && !the_same_offsets)
|
|
|
|
{
|
|
|
|
auto & offsets = column_values->getOffsets();
|
2019-01-08 10:07:33 +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)
|
|
|
|
{
|
|
|
|
for (size_t index = 0; index != Settings::size(); ++index)
|
|
|
|
{
|
|
|
|
auto on_program_option
|
|
|
|
= boost::function1<void, const std::string &>([this, index](const std::string & value) { set(index, value); });
|
|
|
|
options.add(boost::shared_ptr<boost::program_options::option_description>(new boost::program_options::option_description(
|
2019-04-30 14:09:10 +00:00
|
|
|
Settings::getName(index).data,
|
2019-04-25 14:08:20 +00:00
|
|
|
boost::program_options::value<std::string>()->composing()->notifier(on_program_option),
|
2019-04-30 14:09:10 +00:00
|
|
|
Settings::getDescription(index).data)));
|
2019-04-25 14:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|