range_hashed dictionary layout types
range_hashed
The dictionary is stored in memory in the form of a hash table with an ordered array of ranges and their corresponding values.
This storage method works the same way as hashed and allows using date/time (arbitrary numeric type) ranges in addition to the key.
Example: The table contains discounts for each advertiser in the format:
To use a sample for date ranges, define the range_min and range_max elements in the structure. These elements must contain elements name and type (if type is not specified, the default type will be used - Date). type can be any numeric type (Date / DateTime / UInt64 / Int32 / others).
Values of range_min and range_max should fit in Int64 type.
Example:
- DDL
- Configuration file
To work with these dictionaries, you need to pass an additional argument to the dictGet function, for which a range is selected:
Query example:
This function returns the value for the specified ids and the date range that includes the passed date.
Details of the algorithm:
- If the
idis not found or a range is not found for theid, it returns the default value of the attribute's type. - If there are overlapping ranges and
range_lookup_strategy=min, it returns a matching range with minimalrange_min, if several ranges found, it returns a range with minimalrange_max, if again several ranges found (several ranges had the samerange_minandrange_maxit returns a random range of them. - If there are overlapping ranges and
range_lookup_strategy=max, it returns a matching range with maximalrange_min, if several ranges found, it returns a range with maximalrange_max, if again several ranges found (several ranges had the samerange_minandrange_maxit returns a random range of them. - If the
range_maxisNULL, the range is open.NULLis treated as maximal possible value. For therange_min1970-01-01or0(-MAX_INT) can be used as the open value.
Configuration example:
- DDL
- Configuration file
Configuration example with overlapping ranges and open ranges:
complex_key_range_hashed
The dictionary is stored in memory in the form of a hash table with an ordered array of ranges and their corresponding values (see range_hashed). This type of storage is for use with composite keys.
Configuration example: