From 82c6467a5d4dd45101fd190cdc350a183e05d4dc Mon Sep 17 00:00:00 2001 From: nikitamikhaylov Date: Thu, 24 Sep 2020 16:49:59 +0300 Subject: [PATCH] better --- src/Dictionaries/CacheDictionary.cpp | 16 +-- .../001501_cache_dictionary_all_fields.sql | 58 --------- ...cache_dictionary_datarace_exception_ptr.sh | 12 +- ...1501_cache_dictionary_all_fields.reference | 33 +++++ .../01501_cache_dictionary_all_fields.sql | 115 ++++++++++++++++++ 5 files changed, 163 insertions(+), 71 deletions(-) delete mode 100644 tests/queries/0_stateless/001501_cache_dictionary_all_fields.sql create mode 100644 tests/queries/0_stateless/01501_cache_dictionary_all_fields.reference create mode 100644 tests/queries/0_stateless/01501_cache_dictionary_all_fields.sql diff --git a/src/Dictionaries/CacheDictionary.cpp b/src/Dictionaries/CacheDictionary.cpp index 3305671dec7..a1fb60033fc 100644 --- a/src/Dictionaries/CacheDictionary.cpp +++ b/src/Dictionaries/CacheDictionary.cpp @@ -661,13 +661,13 @@ void CacheDictionary::setAttributeInPlace(AttributeValue & place, AttributeUnder switch (type) { case AttributeUnderlyingType::utUInt8: - place = value.get(); + place = static_cast(value.get()); break; case AttributeUnderlyingType::utUInt16: - place = value.get(); + place = static_cast(value.get()); break; case AttributeUnderlyingType::utUInt32: - place = value.get(); + place = static_cast(value.get()); break; case AttributeUnderlyingType::utUInt64: place = value.get(); @@ -676,20 +676,22 @@ void CacheDictionary::setAttributeInPlace(AttributeValue & place, AttributeUnder place = value.get(); break; case AttributeUnderlyingType::utInt8: - place = value.get(); + place = static_cast(value.get()); break; case AttributeUnderlyingType::utInt16: - place = value.get(); + place = static_cast(value.get()); break; case AttributeUnderlyingType::utInt32: - place = value.get(); + place = static_cast(value.get()); break; case AttributeUnderlyingType::utInt64: place = value.get(); break; case AttributeUnderlyingType::utFloat32: - place = value.get(); + { + place = static_cast(value.get()); break; + } case AttributeUnderlyingType::utFloat64: place = value.get(); break; diff --git a/tests/queries/0_stateless/001501_cache_dictionary_all_fields.sql b/tests/queries/0_stateless/001501_cache_dictionary_all_fields.sql deleted file mode 100644 index 61918aecffe..00000000000 --- a/tests/queries/0_stateless/001501_cache_dictionary_all_fields.sql +++ /dev/null @@ -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); \ No newline at end of file diff --git a/tests/queries/0_stateless/01076_cache_dictionary_datarace_exception_ptr.sh b/tests/queries/0_stateless/01076_cache_dictionary_datarace_exception_ptr.sh index 9add67053c9..b37884bda0d 100755 --- a/tests/queries/0_stateless/01076_cache_dictionary_datarace_exception_ptr.sh +++ b/tests/queries/0_stateless/01076_cache_dictionary_datarace_exception_ptr.sh @@ -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 } diff --git a/tests/queries/0_stateless/01501_cache_dictionary_all_fields.reference b/tests/queries/0_stateless/01501_cache_dictionary_all_fields.reference new file mode 100644 index 00000000000..a67d5f46131 --- /dev/null +++ b/tests/queries/0_stateless/01501_cache_dictionary_all_fields.reference @@ -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] diff --git a/tests/queries/0_stateless/01501_cache_dictionary_all_fields.sql b/tests/queries/0_stateless/01501_cache_dictionary_all_fields.sql new file mode 100644 index 00000000000..d9d8c79e33e --- /dev/null +++ b/tests/queries/0_stateless/01501_cache_dictionary_all_fields.sql @@ -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; \ No newline at end of file