2015-01-26 15:27:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-04 17:46:36 +00:00
|
|
|
#include <Core/Field.h>
|
2017-12-09 06:32:22 +00:00
|
|
|
#include <DataTypes/IDataType.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBufferFromString.h>
|
2017-10-06 10:31:06 +00:00
|
|
|
#include <Interpreters/IExternalLoadable.h>
|
2015-01-26 16:53:44 +00:00
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
2017-12-09 06:32:22 +00:00
|
|
|
|
2015-01-27 13:00:20 +00:00
|
|
|
#include <map>
|
2017-11-20 04:15:43 +00:00
|
|
|
#include <optional>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2015-09-07 17:22:54 +00:00
|
|
|
|
2015-01-26 15:27:51 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2019-05-28 14:03:45 +00:00
|
|
|
|
2015-03-20 15:21:29 +00:00
|
|
|
enum class AttributeUnderlyingType
|
2015-01-27 13:00:20 +00:00
|
|
|
{
|
2019-08-03 11:02:40 +00:00
|
|
|
utUInt8,
|
|
|
|
utUInt16,
|
|
|
|
utUInt32,
|
|
|
|
utUInt64,
|
|
|
|
utUInt128,
|
|
|
|
utInt8,
|
|
|
|
utInt16,
|
|
|
|
utInt32,
|
|
|
|
utInt64,
|
|
|
|
utFloat32,
|
|
|
|
utFloat64,
|
|
|
|
utDecimal32,
|
|
|
|
utDecimal64,
|
|
|
|
utDecimal128,
|
|
|
|
utString
|
2015-01-27 13:00:20 +00:00
|
|
|
};
|
|
|
|
|
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-02-10 14:50:43 +00:00
|
|
|
/// Min and max lifetimes for a dictionary or it's entry
|
2017-10-06 10:31:06 +00:00
|
|
|
using DictionaryLifetime = ExternalLoadableLifetime;
|
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:
|
2017-04-01 07:20:54 +00:00
|
|
|
* - name, used for lookup into dictionary and source;
|
|
|
|
* - type, used in conjunction with DataTypeFactory and getAttributeUnderlyingTypeByname;
|
|
|
|
* - 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?)
|
2018-02-06 21:34:56 +00:00
|
|
|
* - is_object_id, used in mongo dictionary, converts string key to objectid
|
2015-02-10 14:50:43 +00:00
|
|
|
*/
|
2015-05-26 12:24:31 +00:00
|
|
|
struct DictionaryAttribute final
|
2015-01-26 15:27:51 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +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;
|
2018-02-06 21:34:56 +00:00
|
|
|
const bool is_object_id;
|
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
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string name;
|
|
|
|
const std::string expression;
|
2015-09-07 17:22:54 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DictionarySpecialAttribute(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix);
|
2015-09-07 17:22:54 +00:00
|
|
|
};
|
|
|
|
|
2018-09-13 13:33:44 +00:00
|
|
|
struct DictionaryTypedSpecialAttribute final
|
|
|
|
{
|
|
|
|
const std::string name;
|
|
|
|
const std::string expression;
|
|
|
|
const DataTypePtr type;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2017-11-20 04:15:43 +00:00
|
|
|
std::optional<DictionarySpecialAttribute> id;
|
|
|
|
std::optional<std::vector<DictionaryAttribute>> key;
|
2017-04-01 07:20:54 +00:00
|
|
|
std::vector<DictionaryAttribute> attributes;
|
2018-09-13 13:33:44 +00:00
|
|
|
std::optional<DictionaryTypedSpecialAttribute> range_min;
|
|
|
|
std::optional<DictionaryTypedSpecialAttribute> range_max;
|
2017-04-01 07:20:54 +00:00
|
|
|
bool has_expressions = false;
|
2015-01-26 15:27:51 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DictionaryStructure(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix);
|
2015-09-07 17:22:54 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void validateKeyTypes(const DataTypes & key_types) const;
|
|
|
|
std::string getKeyDescription() const;
|
|
|
|
bool isKeySizeFixed() const;
|
2017-07-21 06:35:58 +00:00
|
|
|
size_t getKeySize() const;
|
2015-11-18 11:53:01 +00:00
|
|
|
|
2015-11-12 14:28:23 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
std::vector<DictionaryAttribute> getAttributes(
|
2018-12-10 15:25:45 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & config_prefix,
|
|
|
|
const bool hierarchy_allowed = true,
|
|
|
|
const bool allow_null_values = true);
|
2015-01-26 15:27:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|