diff --git a/src/Dictionaries/CacheDictionaryStorage.h b/src/Dictionaries/CacheDictionaryStorage.h index 98031801b11..d91ffbbb279 100644 --- a/src/Dictionaries/CacheDictionaryStorage.h +++ b/src/Dictionaries/CacheDictionaryStorage.h @@ -601,6 +601,7 @@ private: PaddedPODArray, PaddedPODArray, PaddedPODArray, + PaddedPODArray, PaddedPODArray, PaddedPODArray, PaddedPODArray, diff --git a/src/Dictionaries/DictionaryStructure.cpp b/src/Dictionaries/DictionaryStructure.cpp index 806ee0b80e0..7d2f826b4f1 100644 --- a/src/Dictionaries/DictionaryStructure.cpp +++ b/src/Dictionaries/DictionaryStructure.cpp @@ -65,6 +65,7 @@ AttributeUnderlyingType getAttributeUnderlyingType(const DataTypePtr & type) case TypeIndex::Decimal32: return AttributeUnderlyingType::utDecimal32; case TypeIndex::Decimal64: return AttributeUnderlyingType::utDecimal64; case TypeIndex::Decimal128: return AttributeUnderlyingType::utDecimal128; + case TypeIndex::Decimal256: return AttributeUnderlyingType::utDecimal256; case TypeIndex::Date: return AttributeUnderlyingType::utUInt16; case TypeIndex::DateTime: return AttributeUnderlyingType::utUInt32; @@ -85,7 +86,7 @@ AttributeUnderlyingType getAttributeUnderlyingType(const DataTypePtr & type) } -std::string toString(const AttributeUnderlyingType type) +std::string toString(AttributeUnderlyingType type) { switch (type) { @@ -117,6 +118,8 @@ std::string toString(const AttributeUnderlyingType type) return "Decimal64"; case AttributeUnderlyingType::utDecimal128: return "Decimal128"; + case AttributeUnderlyingType::utDecimal256: + return "Decimal256"; case AttributeUnderlyingType::utString: return "String"; } diff --git a/src/Dictionaries/DictionaryStructure.h b/src/Dictionaries/DictionaryStructure.h index 4f03b4ff09e..ce5dd3dd422 100644 --- a/src/Dictionaries/DictionaryStructure.h +++ b/src/Dictionaries/DictionaryStructure.h @@ -32,13 +32,14 @@ enum class AttributeUnderlyingType utDecimal32, utDecimal64, utDecimal128, + utDecimal256, utString }; AttributeUnderlyingType getAttributeUnderlyingType(const std::string & type); -std::string toString(const AttributeUnderlyingType type); +std::string toString(AttributeUnderlyingType type); /// Min and max lifetimes for a dictionary or it's entry using DictionaryLifetime = ExternalLoadableLifetime; @@ -125,6 +126,9 @@ void callOnDictionaryAttributeType(AttributeUnderlyingType type, F&& func) case AttributeUnderlyingType::utDecimal128: func(DictionaryAttributeType()); break; + case AttributeUnderlyingType::utDecimal256: + func(DictionaryAttributeType()); + break; } }; diff --git a/src/Dictionaries/FlatDictionary.h b/src/Dictionaries/FlatDictionary.h index 27d361da1e1..0a5f88f270a 100644 --- a/src/Dictionaries/FlatDictionary.h +++ b/src/Dictionaries/FlatDictionary.h @@ -120,6 +120,7 @@ private: Decimal32, Decimal64, Decimal128, + Decimal256, Float32, Float64, StringRef> @@ -137,6 +138,7 @@ private: ContainerType, ContainerType, ContainerType, + ContainerType, ContainerType, ContainerType, ContainerType> diff --git a/src/Dictionaries/HashedDictionary.cpp b/src/Dictionaries/HashedDictionary.cpp index 913f06b5e92..8c1081ebea0 100644 --- a/src/Dictionaries/HashedDictionary.cpp +++ b/src/Dictionaries/HashedDictionary.cpp @@ -123,7 +123,7 @@ ColumnPtr HashedDictionary::getColumn( [&](const size_t row, const auto value) { return out[row] = value; }, [&](const size_t row) { - out[row] = 0; + out[row] = ValueType(); (*vec_null_map_to)[row] = true; }, default_value_extractor); diff --git a/src/Dictionaries/HashedDictionary.h b/src/Dictionaries/HashedDictionary.h index bc66d10d7fa..0d0ab8dcb43 100644 --- a/src/Dictionaries/HashedDictionary.h +++ b/src/Dictionaries/HashedDictionary.h @@ -152,6 +152,7 @@ private: Decimal32, Decimal64, Decimal128, + Decimal256, Float32, Float64, StringRef> @@ -170,13 +171,13 @@ private: CollectionType, CollectionType, CollectionType, + CollectionType, CollectionType, CollectionType, CollectionType> container; std::unique_ptr string_arena; - }; void createAttributes(); diff --git a/src/Dictionaries/IPAddressDictionary.h b/src/Dictionaries/IPAddressDictionary.h index cf79caa75fc..619d1579e4e 100644 --- a/src/Dictionaries/IPAddressDictionary.h +++ b/src/Dictionaries/IPAddressDictionary.h @@ -101,6 +101,7 @@ private: Decimal32, Decimal64, Decimal128, + Decimal256, Float32, Float64, String> @@ -118,6 +119,7 @@ private: ContainerType, ContainerType, ContainerType, + ContainerType, ContainerType, ContainerType, ContainerType> diff --git a/src/Dictionaries/MongoDBDictionarySource.cpp b/src/Dictionaries/MongoDBDictionarySource.cpp index 5b5d0c4d20f..782174ded6f 100644 --- a/src/Dictionaries/MongoDBDictionarySource.cpp +++ b/src/Dictionaries/MongoDBDictionarySource.cpp @@ -198,6 +198,7 @@ BlockInputStreamPtr MongoDBDictionarySource::loadKeys(const Columns & key_column case AttributeUnderlyingType::utDecimal32: case AttributeUnderlyingType::utDecimal64: case AttributeUnderlyingType::utDecimal128: + case AttributeUnderlyingType::utDecimal256: key.add(attr.second.name, Int32(key_columns[attr.first]->get64(row_idx))); break; diff --git a/src/Dictionaries/RangeHashedDictionary.h b/src/Dictionaries/RangeHashedDictionary.h index ca2a925df5e..8a286f530ba 100644 --- a/src/Dictionaries/RangeHashedDictionary.h +++ b/src/Dictionaries/RangeHashedDictionary.h @@ -112,6 +112,7 @@ private: Decimal32, Decimal64, Decimal128, + Decimal256, Float32, Float64, StringRef> @@ -129,6 +130,7 @@ private: Ptr, Ptr, Ptr, + Ptr, Ptr, Ptr, Ptr> diff --git a/tests/queries/0_stateless/01804_dictionary_decimal256_type.reference b/tests/queries/0_stateless/01804_dictionary_decimal256_type.reference new file mode 100644 index 00000000000..1af9d45f72b --- /dev/null +++ b/tests/queries/0_stateless/01804_dictionary_decimal256_type.reference @@ -0,0 +1,14 @@ +Flat dictionary +5.00000 +Hashed dictionary +5.00000 +Cache dictionary +5.00000 +SSDCache dictionary +5.00000 +Direct dictionary +5.00000 +IPTrie dictionary +5.00000 +Polygon dictionary +5.00000 diff --git a/tests/queries/0_stateless/01804_dictionary_decimal256_type.sql b/tests/queries/0_stateless/01804_dictionary_decimal256_type.sql new file mode 100644 index 00000000000..5bb8f662acd --- /dev/null +++ b/tests/queries/0_stateless/01804_dictionary_decimal256_type.sql @@ -0,0 +1,141 @@ +SET allow_experimental_bigint_types = 1; + +DROP TABLE IF EXISTS dictionary_decimal_source_table; +CREATE TABLE dictionary_decimal_source_table +( + id UInt64, + decimal_value Decimal256(5) +) ENGINE = TinyLog; + +INSERT INTO dictionary_decimal_source_table VALUES (1, 5.0); + +DROP DICTIONARY IF EXISTS flat_dictionary; +CREATE DICTIONARY flat_dictionary +( + id UInt64, + decimal_value Decimal256(5) +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'dictionary_decimal_source_table')) +LIFETIME(MIN 1 MAX 1000) +LAYOUT(FLAT()); + +SELECT 'Flat dictionary'; +SELECT dictGet('flat_dictionary', 'decimal_value', toUInt64(1)); + +DROP DICTIONARY IF EXISTS hashed_dictionary; +CREATE DICTIONARY hashed_dictionary +( + id UInt64, + decimal_value Decimal256(5) +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'dictionary_decimal_source_table')) +LIFETIME(MIN 1 MAX 1000) +LAYOUT(HASHED()); + +SELECT 'Hashed dictionary'; +SELECT dictGet('hashed_dictionary', 'decimal_value', toUInt64(1)); + +DROP DICTIONARY hashed_dictionary; + +DROP DICTIONARY IF EXISTS cache_dictionary; +CREATE DICTIONARY cache_dictionary +( + id UInt64, + decimal_value Decimal256(5) +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'dictionary_decimal_source_table')) +LIFETIME(MIN 1 MAX 1000) +LAYOUT(CACHE(SIZE_IN_CELLS 10)); + +SELECT 'Cache dictionary'; +SELECT dictGet('cache_dictionary', 'decimal_value', toUInt64(1)); + +DROP DICTIONARY cache_dictionary; + +DROP DICTIONARY IF EXISTS ssd_cache_dictionary; +CREATE DICTIONARY ssd_cache_dictionary +( + id UInt64, + decimal_value Decimal256(5) +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'dictionary_decimal_source_table')) +LIFETIME(MIN 1 MAX 1000) +LAYOUT(SSD_CACHE(BLOCK_SIZE 4096 FILE_SIZE 8192 PATH './user_files/0d')); + +SELECT 'SSDCache dictionary'; +SELECT dictGet('ssd_cache_dictionary', 'decimal_value', toUInt64(1)); + +DROP DICTIONARY ssd_cache_dictionary; + +DROP DICTIONARY IF EXISTS direct_dictionary; +CREATE DICTIONARY direct_dictionary +( + id UInt64, + decimal_value Decimal256(5) +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'dictionary_decimal_source_table')) +LAYOUT(DIRECT()); + +SELECT 'Direct dictionary'; +SELECT dictGet('direct_dictionary', 'decimal_value', toUInt64(1)); + +DROP DICTIONARY direct_dictionary; + +DROP TABLE dictionary_decimal_source_table; + +DROP TABLE IF EXISTS ip_trie_dictionary_decimal_source_table; +CREATE TABLE ip_trie_dictionary_decimal_source_table +( + prefix String, + decimal_value Decimal256(5) +) ENGINE = TinyLog; + +INSERT INTO ip_trie_dictionary_decimal_source_table VALUES ('127.0.0.0', 5.0); + +DROP DICTIONARY IF EXISTS ip_trie_dictionary; +CREATE DICTIONARY ip_trie_dictionary +( + prefix String, + decimal_value Decimal256(5) +) +PRIMARY KEY prefix +SOURCE(CLICKHOUSE(HOST 'localhost' port tcpPort() TABLE 'ip_trie_dictionary_decimal_source_table')) +LIFETIME(MIN 10 MAX 1000) +LAYOUT(IP_TRIE()); + +SELECT 'IPTrie dictionary'; +SELECT dictGet('ip_trie_dictionary', 'decimal_value', tuple(IPv4StringToNum('127.0.0.0'))); + +DROP DICTIONARY ip_trie_dictionary; +DROP TABLE ip_trie_dictionary_decimal_source_table; + +DROP TABLE IF EXISTS dictionary_decimal_polygons_source_table; +CREATE TABLE dictionary_decimal_polygons_source_table +( + key Array(Array(Array(Tuple(Float64, Float64)))), + decimal_value Decimal256(5) +) ENGINE = TinyLog; + +INSERT INTO dictionary_decimal_polygons_source_table VALUES ([[[(0, 0), (0, 1), (1, 1), (1, 0)]]], 5.0); + +DROP DICTIONARY IF EXISTS polygon_dictionary; +CREATE DICTIONARY polygon_dictionary +( + key Array(Array(Array(Tuple(Float64, Float64)))), + decimal_value Decimal256(5) +) +PRIMARY KEY key +SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'dictionary_decimal_polygons_source_table')) +LIFETIME(MIN 0 MAX 1000) +LAYOUT(POLYGON()); + +SELECT 'Polygon dictionary'; +SELECT dictGet('polygon_dictionary', 'decimal_value', tuple(0.5, 0.5)); + +DROP DICTIONARY polygon_dictionary; +DROP TABLE dictionary_decimal_polygons_source_table;