mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Dictionary added Decimal256 attribute type support
This commit is contained in:
parent
2d4a8c4787
commit
7df43891c1
@ -601,6 +601,7 @@ private:
|
||||
PaddedPODArray<Decimal32>,
|
||||
PaddedPODArray<Decimal64>,
|
||||
PaddedPODArray<Decimal128>,
|
||||
PaddedPODArray<Decimal256>,
|
||||
PaddedPODArray<Float32>,
|
||||
PaddedPODArray<Float64>,
|
||||
PaddedPODArray<StringRef>,
|
||||
|
@ -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";
|
||||
}
|
||||
|
@ -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<Decimal128>());
|
||||
break;
|
||||
case AttributeUnderlyingType::utDecimal256:
|
||||
func(DictionaryAttributeType<Decimal256>());
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -120,6 +120,7 @@ private:
|
||||
Decimal32,
|
||||
Decimal64,
|
||||
Decimal128,
|
||||
Decimal256,
|
||||
Float32,
|
||||
Float64,
|
||||
StringRef>
|
||||
@ -137,6 +138,7 @@ private:
|
||||
ContainerType<Decimal32>,
|
||||
ContainerType<Decimal64>,
|
||||
ContainerType<Decimal128>,
|
||||
ContainerType<Decimal256>,
|
||||
ContainerType<Float32>,
|
||||
ContainerType<Float64>,
|
||||
ContainerType<StringRef>>
|
||||
|
@ -123,7 +123,7 @@ ColumnPtr HashedDictionary<dictionary_key_type, sparse>::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);
|
||||
|
@ -152,6 +152,7 @@ private:
|
||||
Decimal32,
|
||||
Decimal64,
|
||||
Decimal128,
|
||||
Decimal256,
|
||||
Float32,
|
||||
Float64,
|
||||
StringRef>
|
||||
@ -170,13 +171,13 @@ private:
|
||||
CollectionType<Decimal32>,
|
||||
CollectionType<Decimal64>,
|
||||
CollectionType<Decimal128>,
|
||||
CollectionType<Decimal256>,
|
||||
CollectionType<Float32>,
|
||||
CollectionType<Float64>,
|
||||
CollectionType<StringRef>>
|
||||
container;
|
||||
|
||||
std::unique_ptr<Arena> string_arena;
|
||||
|
||||
};
|
||||
|
||||
void createAttributes();
|
||||
|
@ -101,6 +101,7 @@ private:
|
||||
Decimal32,
|
||||
Decimal64,
|
||||
Decimal128,
|
||||
Decimal256,
|
||||
Float32,
|
||||
Float64,
|
||||
String>
|
||||
@ -118,6 +119,7 @@ private:
|
||||
ContainerType<Decimal32>,
|
||||
ContainerType<Decimal64>,
|
||||
ContainerType<Decimal128>,
|
||||
ContainerType<Decimal256>,
|
||||
ContainerType<Float32>,
|
||||
ContainerType<Float64>,
|
||||
ContainerType<StringRef>>
|
||||
|
@ -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;
|
||||
|
||||
|
@ -112,6 +112,7 @@ private:
|
||||
Decimal32,
|
||||
Decimal64,
|
||||
Decimal128,
|
||||
Decimal256,
|
||||
Float32,
|
||||
Float64,
|
||||
StringRef>
|
||||
@ -129,6 +130,7 @@ private:
|
||||
Ptr<Decimal32>,
|
||||
Ptr<Decimal64>,
|
||||
Ptr<Decimal128>,
|
||||
Ptr<Decimal256>,
|
||||
Ptr<Float32>,
|
||||
Ptr<Float64>,
|
||||
Ptr<StringRef>>
|
||||
|
@ -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
|
141
tests/queries/0_stateless/01804_dictionary_decimal256_type.sql
Normal file
141
tests/queries/0_stateless/01804_dictionary_decimal256_type.sql
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user