コード例 #1
0
void SettingsConstraints::loadFromConfig(const String & path_to_constraints, const Poco::Util::AbstractConfiguration & config)
{
    if (!config.has(path_to_constraints))
        throw Exception("There is no path '" + path_to_constraints + "' in configuration file.", ErrorCodes::NO_ELEMENTS_IN_CONFIG);

    Poco::Util::AbstractConfiguration::Keys names;
    config.keys(path_to_constraints, names);

    for (const String & name : names)
    {
        String path_to_name = path_to_constraints + "." + name;
        Poco::Util::AbstractConfiguration::Keys constraint_types;
        config.keys(path_to_name, constraint_types);
        for (const String & constraint_type : constraint_types)
        {
            auto get_constraint_value = [&]{ return config.getString(path_to_name + "." + constraint_type); };
            if (constraint_type == "min")
                setMinValue(name, get_constraint_value());
            else if (constraint_type == "max")
                setMaxValue(name, get_constraint_value());
            else if (constraint_type == "readonly")
                setReadOnly(name, true);
            else
                throw Exception("Setting " + constraint_type + " value for " + name + " isn't supported", ErrorCodes::NOT_IMPLEMENTED);
        }
    }
}
コード例 #2
0
ファイル: Utility.cpp プロジェクト: macchina-io/macchina.io
void Utility::copyDeltaProperties(const Poco::Util::AbstractConfiguration& ref, const Poco::Util::AbstractConfiguration& source, Poco::Util::AbstractConfiguration& target, const std::set<std::string>& excludeSet, const std::string& root)
{
	Poco::Util::AbstractConfiguration::Keys keys;
	source.keys(root, keys);

	if (keys.empty() && source.hasProperty(root))
	{
		if ((ref.hasProperty(root) && ref.getRawString(root) != source.getRawString(root)) || !ref.hasProperty(root))
		{
			target.setString(root, source.getRawString(root));
		}
	}
	else
	{
		for (Poco::Util::AbstractConfiguration::Keys::const_iterator it = keys.begin(); it != keys.end(); ++it)
		{
			std::string fullKey = root;
			if (!fullKey.empty()) fullKey += '.';
			fullKey.append(*it);
			if (excludeSet.find(fullKey) == excludeSet.end())
			{
				copyDeltaProperties(ref, source, target, excludeSet, fullKey);
			}
		}
	}
}
コード例 #3
0
ファイル: Macros.cpp プロジェクト: chipitsine/ClickHouse
Macros::Macros(const Poco::Util::AbstractConfiguration & config, const String & root_key)
{
    Poco::Util::AbstractConfiguration::Keys keys;
    config.keys(root_key, keys);
    for (const String & key : keys)
    {
        macros[key] = config.getString(root_key + "." + key);
    }
}
コード例 #4
0
ファイル: Settings.cpp プロジェクト: Aahart911/ClickHouse
void Settings::loadSettingsFromConfig(const String & path, const Poco::Util::AbstractConfiguration & config)
{
	if (!config.has(path))
		throw Exception("There is no path '" + path + "' in configuration file.", ErrorCodes::NO_ELEMENTS_IN_CONFIG);

	Poco::Util::AbstractConfiguration::Keys config_keys;
	config.keys(path, config_keys);

	for (const std::string & key : config_keys)
	{
		set(key, config.getString(path + "." + key));
	}
}
コード例 #5
0
ファイル: SecurityManager.cpp プロジェクト: bamx23/ClickHouse
void SecurityManager::loadFromConfig(Poco::Util::AbstractConfiguration & config)
{
    Container new_users;

    Poco::Util::AbstractConfiguration::Keys config_keys;
    config.keys("users", config_keys);

    for (const std::string & key : config_keys)
    {
        auto user = std::make_shared<const User>(key, "users." + key, config);
        new_users.emplace(key, std::move(user));
    }

    users = std::move(new_users);
}
コード例 #6
0
ファイル: Quota.cpp プロジェクト: bamx23/ClickHouse
void Quotas::loadFromConfig(Poco::Util::AbstractConfiguration & config)
{
    pcg64 rng;

    Poco::Util::AbstractConfiguration::Keys config_keys;
    config.keys("quotas", config_keys);

    /// Remove keys, that now absent in config.
    std::set<std::string> keys_set(config_keys.begin(), config_keys.end());
    for (Container::iterator it = cont.begin(); it != cont.end();)
    {
        if (keys_set.count(it->first))
            ++it;
        else
            cont.erase(it++);
    }

    for (Poco::Util::AbstractConfiguration::Keys::const_iterator it = config_keys.begin(); it != config_keys.end(); ++it)
    {
        if (!cont.count(*it))
            cont.try_emplace(*it);
        cont[*it].loadFromConfig("quotas." + *it, *it, config, rng);
    }
}
コード例 #7
0
ファイル: Quota.cpp プロジェクト: bamx23/ClickHouse
void QuotaForIntervals::initFromConfig(const String & config_elem, Poco::Util::AbstractConfiguration & config, pcg64 & rng)
{
    Poco::Util::AbstractConfiguration::Keys config_keys;
    config.keys(config_elem, config_keys);

    for (Poco::Util::AbstractConfiguration::Keys::const_iterator it = config_keys.begin(); it != config_keys.end(); ++it)
    {
        if (!startsWith(*it, "interval"))
            continue;

        String interval_config_elem = config_elem + "." + *it;
        time_t duration = config.getInt(interval_config_elem + ".duration", 0);
        time_t offset = 0;

        if (!duration) /// Skip quotas with zero duration
            continue;

        bool randomize = config.getBool(interval_config_elem + ".randomize", false);
        if (randomize)
            offset = std::uniform_int_distribution<decltype(duration)>(0, duration - 1)(rng);

        cont[duration].initFromConfig(interval_config_elem, duration, randomize, offset, config);
    }
}
コード例 #8
0
std::vector<DictionaryAttribute> DictionaryStructure::getAttributes(
	const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix,
	const bool hierarchy_allowed, const bool allow_null_values)
{
	Poco::Util::AbstractConfiguration::Keys keys;
	config.keys(config_prefix, keys);
	auto has_hierarchy = false;

	std::vector<DictionaryAttribute> attributes;

	for (const auto & key : keys)
	{
		if (0 != strncmp(key.data(), "attribute", strlen("attribute")))
			continue;

		const auto prefix = config_prefix + '.' + key + '.';

		const auto name = config.getString(prefix + "name");
		const auto type_string = config.getString(prefix + "type");
		const auto type = DataTypeFactory::instance().get(type_string);
		const auto underlying_type = getAttributeUnderlyingType(type_string);

		const auto expression = config.getString(prefix + "expression", "");
		if (!expression.empty())
			has_expressions = true;

		Field null_value;
		if (allow_null_values)
		{
			const auto null_value_string = config.getString(prefix + "null_value");
			try
			{
				ReadBufferFromString null_value_buffer{null_value_string};
				ColumnPtr column_with_null_value = type->createColumn();
				type->deserializeTextEscaped(*column_with_null_value, null_value_buffer);
				null_value = (*column_with_null_value)[0];
			}
			catch (const std::exception & e)
			{
				throw Exception{
					std::string{"Error parsing null_value: "} + e.what(),
					ErrorCodes::BAD_ARGUMENTS};
			}
		}

		const auto hierarchical = config.getBool(prefix + "hierarchical", false);
		const auto injective = config.getBool(prefix + "injective", false);
		if (name.empty())
			throw Exception{
				"Properties 'name' and 'type' of an attribute cannot be empty",
				ErrorCodes::BAD_ARGUMENTS};

		if (has_hierarchy && !hierarchy_allowed)
			throw Exception{
				"Hierarchy not allowed in '" + prefix,
				ErrorCodes::BAD_ARGUMENTS};

		if (has_hierarchy && hierarchical)
			throw Exception{
				"Only one hierarchical attribute supported",
				ErrorCodes::BAD_ARGUMENTS};

		has_hierarchy = has_hierarchy || hierarchical;

		attributes.emplace_back(DictionaryAttribute{
			name, underlying_type, type, expression, null_value, hierarchical, injective
		});
	}

	return attributes;
}
コード例 #9
0
DictionaryPtr DictionaryFactory::create(const std::string & name, Poco::Util::AbstractConfiguration & config,
	const std::string & config_prefix, Context & context) const
{
	Poco::Util::AbstractConfiguration::Keys keys;
	const auto & layout_prefix = config_prefix + ".layout";
	config.keys(layout_prefix, keys);
	if (keys.size() != 1)
		throw Exception{name + ": element dictionary.layout should have exactly one child element",
			ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG};

	const DictionaryStructure dict_struct{config, config_prefix + ".structure"};

	auto source_ptr = DictionarySourceFactory::instance().create(
		name, config, config_prefix + ".source", dict_struct, context);

	const DictionaryLifetime dict_lifetime{config, config_prefix + ".lifetime"};

	const bool require_nonempty = config.getBool(config_prefix + ".require_nonempty", false);

	const auto & layout_type = keys.front();

	if ("range_hashed" == layout_type)
	{
		if (dict_struct.key)
			throw Exception{"'key' is not supported for dictionary of layout 'range_hashed'",
				ErrorCodes::UNSUPPORTED_METHOD};

		if (!dict_struct.range_min || !dict_struct.range_max)
			throw Exception{name + ": dictionary of layout 'range_hashed' requires .structure.range_min and .structure.range_max",
				ErrorCodes::BAD_ARGUMENTS};

		return std::make_unique<RangeHashedDictionary>(name, dict_struct, std::move(source_ptr), dict_lifetime, require_nonempty);
	}
	else if ("complex_key_hashed" == layout_type)
	{
		if (!dict_struct.key)
			throw Exception{"'key' is required for dictionary of layout 'complex_key_hashed'",
				ErrorCodes::BAD_ARGUMENTS};

		return std::make_unique<ComplexKeyHashedDictionary>(name, dict_struct, std::move(source_ptr), dict_lifetime, require_nonempty);
	}
	else if ("complex_key_cache" == layout_type)
	{
		if (!dict_struct.key)
			throw Exception{"'key' is required for dictionary of layout 'complex_key_hashed'",
				ErrorCodes::BAD_ARGUMENTS};

		const auto size = config.getInt(layout_prefix + ".complex_key_cache.size_in_cells");
		if (size == 0)
			throw Exception{name + ": dictionary of layout 'cache' cannot have 0 cells",
				ErrorCodes::TOO_SMALL_BUFFER_SIZE};

		if (require_nonempty)
			throw Exception{name + ": dictionary of layout 'cache' cannot have 'require_nonempty' attribute set",
				ErrorCodes::BAD_ARGUMENTS};

		return std::make_unique<ComplexKeyCacheDictionary>(name, dict_struct, std::move(source_ptr), dict_lifetime, size);
	}
	else
	{
		if (dict_struct.key)
			throw Exception{"'key' is not supported for dictionary of layout '" + layout_type + "'",
				ErrorCodes::UNSUPPORTED_METHOD};

		if (dict_struct.range_min || dict_struct.range_max)
			throw Exception{name + ": elements .structure.range_min and .structure.range_max should be defined only "
					"for a dictionary of layout 'range_hashed'",
				ErrorCodes::BAD_ARGUMENTS};

		if ("flat" == layout_type)
		{
			return std::make_unique<FlatDictionary>(name, dict_struct, std::move(source_ptr), dict_lifetime, require_nonempty);
		}
		else if ("hashed" == layout_type)
		{
			return std::make_unique<HashedDictionary>(name, dict_struct, std::move(source_ptr), dict_lifetime, require_nonempty);
		}
		else if ("cache" == layout_type)
		{
			const auto size = config.getInt(layout_prefix + ".cache.size_in_cells");
			if (size == 0)
				throw Exception{name + ": dictionary of layout 'cache' cannot have 0 cells",
					ErrorCodes::TOO_SMALL_BUFFER_SIZE};

			if (require_nonempty)
				throw Exception{name + ": dictionary of layout 'cache' cannot have 'require_nonempty' attribute set",
					ErrorCodes::BAD_ARGUMENTS};

			return std::make_unique<CacheDictionary>(name, dict_struct, std::move(source_ptr), dict_lifetime, size);
		}
	}

	throw Exception{name + ": unknown dictionary layout type: " + layout_type,
		ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG};
};