2015-01-26 15:27:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-03-20 15:21:29 +00:00
|
|
|
#include <DB/DataTypes/DataTypeFactory.h>
|
|
|
|
#include <DB/IO/ReadBufferFromString.h>
|
2015-10-12 07:05:54 +00:00
|
|
|
#include <DB/IO/WriteBuffer.h>
|
|
|
|
#include <DB/IO/WriteHelpers.h>
|
2015-01-26 16:53:44 +00:00
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
2015-11-20 16:20:54 +00:00
|
|
|
#include <ext/range.hpp>
|
2016-05-23 00:40:28 +00:00
|
|
|
#include <numeric>
|
2015-01-26 15:27:51 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2015-01-27 13:00:20 +00:00
|
|
|
#include <map>
|
2015-09-07 17:22:54 +00:00
|
|
|
#include <experimental/optional>
|
|
|
|
|
2015-01-26 15:27:51 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2015-03-20 15:21:29 +00:00
|
|
|
enum class AttributeUnderlyingType
|
2015-01-27 13:00:20 +00:00
|
|
|
{
|
2015-03-20 15:21:29 +00:00
|
|
|
UInt8,
|
|
|
|
UInt16,
|
|
|
|
UInt32,
|
|
|
|
UInt64,
|
|
|
|
Int8,
|
|
|
|
Int16,
|
|
|
|
Int32,
|
|
|
|
Int64,
|
|
|
|
Float32,
|
|
|
|
Float64,
|
|
|
|
String
|
2015-01-27 13:00:20 +00:00
|
|
|
};
|
|
|
|
|
2016-06-07 19:11:04 +00:00
|
|
|
|
|
|
|
/** Для неявных преобразований в функциях dictGet.
|
|
|
|
*/
|
2016-06-07 21:07:44 +00:00
|
|
|
bool isAttributeTypeConvertibleTo(AttributeUnderlyingType from, AttributeUnderlyingType to);
|
2016-06-07 19:11:04 +00:00
|
|
|
|
2016-06-07 21:07:44 +00:00
|
|
|
AttributeUnderlyingType getAttributeUnderlyingType(const std::string & type);
|
2016-06-07 19:11:04 +00:00
|
|
|
|
2016-06-07 21:07:44 +00:00
|
|
|
std::string toString(const AttributeUnderlyingType type);
|
2015-01-27 13:00:20 +00:00
|
|
|
|
2015-01-28 13:20:20 +00:00
|
|
|
|
2015-02-10 14:50:43 +00:00
|
|
|
/// Min and max lifetimes for a dictionary or it's entry
|
2015-05-26 12:24:31 +00:00
|
|
|
struct DictionaryLifetime final
|
2015-01-30 15:18:13 +00:00
|
|
|
{
|
2016-10-26 22:27:38 +00:00
|
|
|
UInt64 min_sec;
|
|
|
|
UInt64 max_sec;
|
2015-01-30 15:18:13 +00:00
|
|
|
|
2016-06-07 21:07:44 +00:00
|
|
|
DictionaryLifetime(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix);
|
2015-01-30 15:18:13 +00:00
|
|
|
};
|
|
|
|
|
2016-06-07 21:07:44 +00:00
|
|
|
|
2015-02-10 14:50:43 +00:00
|
|
|
/** Holds the description of a single dictionary attribute:
|
|
|
|
* - name, used for lookup into dictionary and source;
|
2015-03-20 15:21:29 +00:00
|
|
|
* - type, used in conjunction with DataTypeFactory and getAttributeUnderlyingTypeByname;
|
2015-02-10 14:50:43 +00:00
|
|
|
* - null_value, used as a default value for non-existent entries in the dictionary,
|
|
|
|
* decimal representation for numeric attributes;
|
|
|
|
* - hierarchical, whether this attribute defines a hierarchy;
|
|
|
|
* - injective, whether the mapping to parent is injective (can be used for optimization of GROUP BY?)
|
|
|
|
*/
|
2015-05-26 12:24:31 +00:00
|
|
|
struct DictionaryAttribute final
|
2015-01-26 15:27:51 +00:00
|
|
|
{
|
2015-05-26 12:24:31 +00:00
|
|
|
const std::string name;
|
|
|
|
const AttributeUnderlyingType underlying_type;
|
|
|
|
const DataTypePtr type;
|
|
|
|
const std::string expression;
|
|
|
|
const Field null_value;
|
|
|
|
const bool hierarchical;
|
|
|
|
const bool injective;
|
2015-01-26 15:27:51 +00:00
|
|
|
};
|
|
|
|
|
2016-06-07 21:07:44 +00:00
|
|
|
|
2015-09-07 17:22:54 +00:00
|
|
|
struct DictionarySpecialAttribute final
|
|
|
|
{
|
|
|
|
const std::string name;
|
|
|
|
const std::string expression;
|
|
|
|
|
2016-06-07 21:07:44 +00:00
|
|
|
DictionarySpecialAttribute(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix);
|
2015-09-07 17:22:54 +00:00
|
|
|
};
|
|
|
|
|
2016-06-07 21:07:44 +00:00
|
|
|
|
2015-02-10 14:50:43 +00:00
|
|
|
/// Name of identifier plus list of attributes
|
2015-05-26 12:24:31 +00:00
|
|
|
struct DictionaryStructure final
|
2015-01-26 15:27:51 +00:00
|
|
|
{
|
2015-11-12 14:28:23 +00:00
|
|
|
std::experimental::optional<DictionarySpecialAttribute> id;
|
|
|
|
std::experimental::optional<std::vector<DictionaryAttribute>> key;
|
2015-01-26 15:27:51 +00:00
|
|
|
std::vector<DictionaryAttribute> attributes;
|
2015-09-07 17:22:54 +00:00
|
|
|
std::experimental::optional<DictionarySpecialAttribute> range_min;
|
|
|
|
std::experimental::optional<DictionarySpecialAttribute> range_max;
|
|
|
|
bool has_expressions = false;
|
2015-01-26 15:27:51 +00:00
|
|
|
|
2016-06-07 21:07:44 +00:00
|
|
|
DictionaryStructure(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix);
|
2015-09-07 17:22:54 +00:00
|
|
|
|
2016-06-07 21:07:44 +00:00
|
|
|
void validateKeyTypes(const DataTypes & key_types) const;
|
|
|
|
std::string getKeyDescription() const;
|
|
|
|
bool isKeySizeFixed() const;
|
|
|
|
std::size_t getKeySize() const;
|
2015-11-18 11:53:01 +00:00
|
|
|
|
2015-11-12 14:28:23 +00:00
|
|
|
private:
|
|
|
|
std::vector<DictionaryAttribute> getAttributes(
|
|
|
|
const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix,
|
2016-06-07 21:07:44 +00:00
|
|
|
const bool hierarchy_allowed = true, const bool allow_null_values = true);
|
2015-01-26 15:27:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|