mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
better
This commit is contained in:
parent
e75f885ac1
commit
82c6467a5d
@ -661,13 +661,13 @@ void CacheDictionary::setAttributeInPlace(AttributeValue & place, AttributeUnder
|
||||
switch (type)
|
||||
{
|
||||
case AttributeUnderlyingType::utUInt8:
|
||||
place = value.get<UInt8>();
|
||||
place = static_cast<UInt8>(value.get<UInt64>());
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt16:
|
||||
place = value.get<UInt16>();
|
||||
place = static_cast<UInt16>(value.get<UInt64>());
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt32:
|
||||
place = value.get<UInt32>();
|
||||
place = static_cast<UInt32>(value.get<UInt64>());
|
||||
break;
|
||||
case AttributeUnderlyingType::utUInt64:
|
||||
place = value.get<UInt64>();
|
||||
@ -676,20 +676,22 @@ void CacheDictionary::setAttributeInPlace(AttributeValue & place, AttributeUnder
|
||||
place = value.get<UInt128>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt8:
|
||||
place = value.get<Int8>();
|
||||
place = static_cast<Int8>(value.get<Int64>());
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt16:
|
||||
place = value.get<Int16>();
|
||||
place = static_cast<Int16>(value.get<Int64>());
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt32:
|
||||
place = value.get<Int32>();
|
||||
place = static_cast<Int32>(value.get<Int64>());
|
||||
break;
|
||||
case AttributeUnderlyingType::utInt64:
|
||||
place = value.get<Int64>();
|
||||
break;
|
||||
case AttributeUnderlyingType::utFloat32:
|
||||
place = value.get<Float32>();
|
||||
{
|
||||
place = static_cast<Float32>(value.get<Float64>());
|
||||
break;
|
||||
}
|
||||
case AttributeUnderlyingType::utFloat64:
|
||||
place = value.get<Float64>();
|
||||
break;
|
||||
|
@ -1,58 +0,0 @@
|
||||
CREATE TABLE table_cache_dict(
|
||||
KeyField UInt64,
|
||||
UInt8_ UInt8,
|
||||
UInt16_ UInt16,
|
||||
UInt32_ UInt32,
|
||||
UInt64_ UInt64,
|
||||
Int8_ Int8,
|
||||
Int16_ Int16,
|
||||
Int32_ Int32,
|
||||
Int64_ Int64,
|
||||
UUID_ UUID,
|
||||
Date_ Date,
|
||||
DateTime_ DateTime,
|
||||
String_ String,
|
||||
Float32_ Float32,
|
||||
Float64_ Float64,
|
||||
ParentKeyField UInt64)
|
||||
ENGINE = MergeTree() ORDER BY KeyField;
|
||||
|
||||
|
||||
CREATE DICTIONARY IF NOT EXISTS cache_dict (
|
||||
KeyField UInt64 DEFAULT 9999999,
|
||||
UInt8_ UInt8 DEFAULT 55,
|
||||
UInt16_ UInt16 DEFAULT 65535,
|
||||
UInt32_ UInt32 DEFAULT 4294967295,
|
||||
UInt64_ UInt64 DEFAULT 18446744073709551615,
|
||||
Int8_ Int8 DEFAULT -128,
|
||||
Int16_ Int16 DEFAULT -32768,
|
||||
Int32_ Int32 DEFAULT -2147483648,
|
||||
Int64_ Int64 DEFAULT -9223372036854775808,
|
||||
UUID_ UUID DEFAULT '550e8400-0000-0000-0000-000000000000',
|
||||
Date_ Date DEFAULT '2018-12-30',
|
||||
DateTime_ DateTime DEFAULT '2018-12-30 00:00:00',
|
||||
String_ String DEFAULT 'hi',
|
||||
Float32_ Float32 DEFAULT 555.11,
|
||||
Float64_ Float64 DEFAULT 777.11,
|
||||
ParentKeyField UInt64 DEFAULT 444)
|
||||
PRIMARY KEY KeyField
|
||||
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_cache_dict' DB 'default'))
|
||||
LIFETIME(2) LAYOUT(CACHE(SIZE_IN_CELLS 1));
|
||||
|
||||
|
||||
INSERT INTO table_cache_dict VALUES (1, 22, 333, 4444, 55555, -6, -77, -888, -999, '550e8400-e29b-41d4-a716-446655440003', '1973-06-28', '1985-02-28 23:43:25', 'clickhouse', 22.543, 3332154213.4, 0);
|
||||
INSERT INTO table_cache_dict VALUES (2, 3, 4, 5, 6, -7, -8, -9, -10, '550e8400-e29b-41d4-a716-446655440002', '1978-06-28', '1986-02-28 23:42:25', 'hello', 21.543, 3222154213.4, 1]);
|
||||
|
||||
|
||||
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt8('default.cache_dict', 'UInt8_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt16('default.cache_dict', 'UInt16_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt32('default.cache_dict', 'UInt32_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt64('default.cache_dict', 'UInt64_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetInt8('default.cache_dict', 'Int8_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetInt16('default.cache_dict', 'Int16_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetInt32('default.cache_dict', 'Int32_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetInt64('default.cache_dict', 'Int64_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetFloat32('default.cache_dict', 'Float32_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetFloat64('default.cache_dict', 'Float64_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetString('default.cache_dict', 'String_', toUInt64(number)))) from numbers(10);
|
@ -5,12 +5,12 @@
|
||||
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
. "$CURDIR"/../shell_config.sh
|
||||
|
||||
$CLICKHOUSE_CLIENT --query="CREATE DATABASE dictdb_01076; "
|
||||
$CLICKHOUSE_CLIENT --query="CREATE DATABASE IF NOT EXISTS dictdb_01076; "
|
||||
|
||||
$CLICKHOUSE_CLIENT --query="
|
||||
CREATE TABLE dictdb_01076.table_datarace
|
||||
(
|
||||
key_column UInt8,
|
||||
key_column UUID,
|
||||
value Float64
|
||||
)
|
||||
ENGINE = MergeTree()
|
||||
@ -18,7 +18,7 @@ ORDER BY key_column;
|
||||
"
|
||||
|
||||
$CLICKHOUSE_CLIENT --query="
|
||||
INSERT INTO dictdb_01076.table_datarace VALUES (1, 1.1), (2, 2.2), (3, 3.3);
|
||||
INSERT INTO dictdb_01076.table_datarace VALUES ('cd5db34f-0c25-4375-b10e-bfb3708ddc72', 1.1), ('cd5db34f-0c25-4375-b10e-bfb3708ddc72', 2.2), ('cd5db34f-0c25-4375-b10e-bfb3708ddc72', 3.3);
|
||||
"
|
||||
|
||||
$CLICKHOUSE_CLIENT --query="
|
||||
@ -30,14 +30,14 @@ CREATE DICTIONARY IF NOT EXISTS dictdb_01076.dict_datarace
|
||||
PRIMARY KEY key_column
|
||||
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_datarace' DB 'dictdb_01076'))
|
||||
LIFETIME(1)
|
||||
LAYOUT(CACHE());
|
||||
LAYOUT(CACHE(SIZE_IN_CELLS 10));
|
||||
"
|
||||
|
||||
function thread1()
|
||||
{
|
||||
for _ in {1..50}
|
||||
do
|
||||
# This query will be ended with exception, because source dictionary has UInt8 as a key type.
|
||||
# This query will be ended with exception, because source dictionary has UUID as a key type.
|
||||
$CLICKHOUSE_CLIENT --query="SELECT dictGetFloat64('dictdb_01076.dict_datarace', 'value', toUInt64(1));"
|
||||
done
|
||||
}
|
||||
@ -47,7 +47,7 @@ function thread2()
|
||||
{
|
||||
for _ in {1..50}
|
||||
do
|
||||
# This query will be ended with exception, because source dictionary has UInt8 as a key type.
|
||||
# This query will be ended with exception, because source dictionary has UUID as a key type.
|
||||
$CLICKHOUSE_CLIENT --query="SELECT dictGetFloat64('dictdb_01076.dict_datarace', 'value', toUInt64(2));"
|
||||
done
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
[55,2,22,222,174,206]
|
||||
[65535,3,33,333,3333,33333]
|
||||
[4294967295,4,44,444,4444,44444]
|
||||
[18446744073709551615,5,55,555,5555,55555]
|
||||
[-128,-1,-11,-111,-87,-103]
|
||||
[-32768,-2,-22,-222,-2222,-22222]
|
||||
[-2147483648,-3,-33,-333,-3333,-33333]
|
||||
[-9223372036854775808,-4,-44,-444,-4444,-44444]
|
||||
[111.11,22.543,21.543,13.334,52.001,33.333]
|
||||
[222.11,3332154213.4,3111154213.9,3222187213.1,3237554213.5,3222193713.7]
|
||||
[333.11000,0.00001,0.00002,0.00003,0.00004,0.00005]
|
||||
[444.110000000000000,0.000000000000001,0.000000000000002,0.000000000000003,0.000000000000004,0.000000000000005]
|
||||
[555.11000000000000000000000000000000000,0.00000000000000000000000000000000001,0.00000000000000000000000000000000002,0.00000000000000000000000000000000003,0.00000000000000000000000000000000004,0.00000000000000000000000000000000005]
|
||||
['hi','clickhouse','hello','dbms','MergeTree','dictionary']
|
||||
[55,2,22,222,174,206]
|
||||
[65535,3,33,333,3333,33333]
|
||||
[4294967295,4,44,444,4444,44444]
|
||||
[18446744073709551615,5,55,555,5555,55555]
|
||||
[-128,-1,-11,-111,-87,-103]
|
||||
[-32768,-2,-22,-222,-2222,-22222]
|
||||
[-2147483648,-3,-33,-333,-3333,-33333]
|
||||
[-9223372036854775808,-4,-44,-444,-4444,-44444]
|
||||
[111.11,22.543,21.543,13.334,52.001,33.333]
|
||||
[222.11,3332154213.4,3111154213.9,3222187213.1,3237554213.5,3222193713.7]
|
||||
[333.11000,0.00001,0.00002,0.00003,0.00004,0.00005]
|
||||
[444.110000000000000,0.000000000000001,0.000000000000002,0.000000000000003,0.000000000000004,0.000000000000005]
|
||||
[555.11000000000000000000000000000000000,0.00000000000000000000000000000000001,0.00000000000000000000000000000000002,0.00000000000000000000000000000000003,0.00000000000000000000000000000000004,0.00000000000000000000000000000000005]
|
||||
['hi','clickhouse','hello','dbms','MergeTree','dictionary']
|
||||
[0,1,1,1,1,1,0,0,0,0]
|
||||
[0,1,1,1,1,1,0,0,0,0]
|
||||
[0,1,1,1,1,1,0,0,0,0]
|
||||
[0,1,1,1,1,1,0,0,0,0]
|
||||
[0,1,1,1,1,1,0,0,0,0]
|
115
tests/queries/0_stateless/01501_cache_dictionary_all_fields.sql
Normal file
115
tests/queries/0_stateless/01501_cache_dictionary_all_fields.sql
Normal file
@ -0,0 +1,115 @@
|
||||
drop table if exists table_cache_dict;
|
||||
drop dictionary if exists cache_dict;
|
||||
|
||||
CREATE TABLE table_cache_dict(
|
||||
KeyField UInt64,
|
||||
UInt8_ UInt8,
|
||||
UInt16_ UInt16,
|
||||
UInt32_ UInt32,
|
||||
UInt64_ UInt64,
|
||||
Int8_ Int8,
|
||||
Int16_ Int16,
|
||||
Int32_ Int32,
|
||||
Int64_ Int64,
|
||||
UUID_ UUID,
|
||||
Date_ Date,
|
||||
DateTime_ DateTime,
|
||||
String_ String,
|
||||
Float32_ Float32,
|
||||
Float64_ Float64,
|
||||
Decimal32_ Decimal32(5),
|
||||
Decimal64_ Decimal64(15),
|
||||
Decimal128_ Decimal128(35),
|
||||
ParentKeyField UInt64)
|
||||
ENGINE = MergeTree() ORDER BY KeyField;
|
||||
|
||||
|
||||
CREATE DICTIONARY IF NOT EXISTS cache_dict (
|
||||
KeyField UInt64 DEFAULT 9999999,
|
||||
UInt8_ UInt8 DEFAULT 55,
|
||||
UInt16_ UInt16 DEFAULT 65535,
|
||||
UInt32_ UInt32 DEFAULT 4294967295,
|
||||
UInt64_ UInt64 DEFAULT 18446744073709551615,
|
||||
Int8_ Int8 DEFAULT -128,
|
||||
Int16_ Int16 DEFAULT -32768,
|
||||
Int32_ Int32 DEFAULT -2147483648,
|
||||
Int64_ Int64 DEFAULT -9223372036854775808,
|
||||
UUID_ UUID DEFAULT '550e8400-0000-0000-0000-000000000000',
|
||||
Date_ Date DEFAULT '2018-12-30',
|
||||
DateTime_ DateTime DEFAULT '2018-12-30 00:00:00',
|
||||
String_ String DEFAULT 'hi',
|
||||
Float32_ Float32 DEFAULT 111.11,
|
||||
Float64_ Float64 DEFAULT 222.11,
|
||||
Decimal32_ Decimal32(5) DEFAULT 333.11,
|
||||
Decimal64_ Decimal64(15) DEFAULT 444.11,
|
||||
Decimal128_ Decimal128(35) DEFAULT 555.11,
|
||||
ParentKeyField UInt64 DEFAULT 444)
|
||||
PRIMARY KEY KeyField
|
||||
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_cache_dict' DB 'default'))
|
||||
LIFETIME(5) LAYOUT(CACHE(SIZE_IN_CELLS 20));
|
||||
|
||||
|
||||
INSERT INTO table_cache_dict VALUES (1, 2, 3, 4, 5, -1, -2, -3, -4, '550e8400-e29b-41d4-a716-446655440003', '1973-06-28', '1985-02-28 23:43:25', 'clickhouse', 22.543, 3332154213.4, toDecimal32('1e-5', 5), toDecimal64('1e-15', 15), toDecimal128('1e-35', 35), 0);
|
||||
INSERT INTO table_cache_dict VALUES (2, 22, 33, 44, 55, -11, -22, -33, -44, 'cb307805-44f0-49e7-9ae9-9954c543be46', '1978-06-28', '1986-02-28 23:42:25', 'hello', 21.543, 3111154213.9, toDecimal32('2e-5', 5), toDecimal64('2e-15', 15), toDecimal128('2e-35', 35), 1);
|
||||
INSERT INTO table_cache_dict VALUES (3, 222, 333, 444, 555, -111, -222, -333, -444, 'de7f7ec3-f851-4f8c-afe5-c977cb8cea8d', '1982-06-28', '1999-02-28 23:42:25', 'dbms', 13.334, 3222187213.1, toDecimal32('3e-5', 5), toDecimal64('3e-15', 15), toDecimal128('3e-35', 35), 1);
|
||||
INSERT INTO table_cache_dict VALUES (4, 2222, 3333, 4444, 5555, -1111, -2222, -3333, -4444, '4bd3829f-0669-43b7-b884-a8e034a68224', '1987-06-28', '2000-02-28 23:42:25', 'MergeTree', 52.001, 3237554213.5, toDecimal32('4e-5', 5), toDecimal64('4e-15', 15), toDecimal128('4e-35', 35), 1);
|
||||
INSERT INTO table_cache_dict VALUES (5, 22222, 33333, 44444, 55555, -11111, -22222, -33333, -44444, 'ff99a408-78bb-4939-93cc-65e657e347c6', '1991-06-28', '2007-02-28 23:42:25', 'dictionary', 33.333, 3222193713.7, toDecimal32('5e-5', 5), toDecimal64('5e-15', 15), toDecimal128('5e-35', 35), 1);
|
||||
|
||||
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt8('default.cache_dict', 'UInt8_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt16('default.cache_dict', 'UInt16_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt32('default.cache_dict', 'UInt32_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt64('default.cache_dict', 'UInt64_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGetInt8('default.cache_dict', 'Int8_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGetInt16('default.cache_dict', 'Int16_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGetInt32('default.cache_dict', 'Int32_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGetInt64('default.cache_dict', 'Int64_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGetFloat32('default.cache_dict', 'Float32_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGetFloat64('default.cache_dict', 'Float64_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGet('default.cache_dict', 'Decimal32_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGet('default.cache_dict', 'Decimal64_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGet('default.cache_dict', 'Decimal128_', toUInt64(number)))) from numbers(10);
|
||||
system reload dictionaries;
|
||||
SELECT arrayDistinct(groupArray(dictGetString('default.cache_dict', 'String_', toUInt64(number)))) from numbers(10);
|
||||
|
||||
|
||||
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt8('default.cache_dict', 'UInt8_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt16('default.cache_dict', 'UInt16_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt32('default.cache_dict', 'UInt32_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetUInt64('default.cache_dict', 'UInt64_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetInt8('default.cache_dict', 'Int8_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetInt16('default.cache_dict', 'Int16_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetInt32('default.cache_dict', 'Int32_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetInt64('default.cache_dict', 'Int64_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetFloat32('default.cache_dict', 'Float32_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetFloat64('default.cache_dict', 'Float64_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGet('default.cache_dict', 'Decimal32_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGet('default.cache_dict', 'Decimal64_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGet('default.cache_dict', 'Decimal128_', toUInt64(number)))) from numbers(10);
|
||||
SELECT arrayDistinct(groupArray(dictGetString('default.cache_dict', 'String_', toUInt64(number)))) from numbers(10);
|
||||
|
||||
|
||||
system reload dictionaries;
|
||||
|
||||
|
||||
SELECT groupArray(dictHas('default.cache_dict', toUInt64(number))) from numbers(10);
|
||||
SELECT groupArray(dictHas('default.cache_dict', toUInt64(number))) from numbers(10);
|
||||
SELECT groupArray(dictHas('default.cache_dict', toUInt64(number))) from numbers(10);
|
||||
SELECT groupArray(dictHas('default.cache_dict', toUInt64(number))) from numbers(10);
|
||||
SELECT groupArray(dictHas('default.cache_dict', toUInt64(number))) from numbers(10);
|
||||
|
||||
drop table if exists table_cache_dict;
|
||||
drop dictionary if exists cache_dict;
|
Loading…
Reference in New Issue
Block a user