From d9e079da4e8cf07532a3686fa4e430618f7965a2 Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Mon, 24 Jan 2022 11:44:19 +0000 Subject: [PATCH] Added tests --- ..._dictionary_outside_range_values.reference | 3 + ...hashed_dictionary_outside_range_values.sql | 36 +++++++++++ ...ge_hashed_dictionary_open_ranges.reference | 22 +++++++ ...85_range_hashed_dictionary_open_ranges.sql | 63 ++++++++++++++++++ ...ictionary_intersecting_intervals.reference | 18 ++++++ ...shed_dictionary_intersecting_intervals.sql | 64 +++++++++++++++++++ 6 files changed, 206 insertions(+) create mode 100644 tests/queries/0_stateless/02184_range_hashed_dictionary_outside_range_values.reference create mode 100644 tests/queries/0_stateless/02184_range_hashed_dictionary_outside_range_values.sql create mode 100644 tests/queries/0_stateless/02185_range_hashed_dictionary_open_ranges.reference create mode 100644 tests/queries/0_stateless/02185_range_hashed_dictionary_open_ranges.sql create mode 100644 tests/queries/0_stateless/02186_range_hashed_dictionary_intersecting_intervals.reference create mode 100644 tests/queries/0_stateless/02186_range_hashed_dictionary_intersecting_intervals.sql diff --git a/tests/queries/0_stateless/02184_range_hashed_dictionary_outside_range_values.reference b/tests/queries/0_stateless/02184_range_hashed_dictionary_outside_range_values.reference new file mode 100644 index 00000000000..9b43f375e11 --- /dev/null +++ b/tests/queries/0_stateless/02184_range_hashed_dictionary_outside_range_values.reference @@ -0,0 +1,3 @@ +1 0 18446744073709551615 value0 value1 value2 +('value0','value1','value2') +1 diff --git a/tests/queries/0_stateless/02184_range_hashed_dictionary_outside_range_values.sql b/tests/queries/0_stateless/02184_range_hashed_dictionary_outside_range_values.sql new file mode 100644 index 00000000000..6e892d9d246 --- /dev/null +++ b/tests/queries/0_stateless/02184_range_hashed_dictionary_outside_range_values.sql @@ -0,0 +1,36 @@ +DROP TABLE IF EXISTS 02184_range_dictionary_source_table; +CREATE TABLE 02184_range_dictionary_source_table +( + id UInt64, + start UInt64, + end UInt64, + value_0 String, + value_1 String, + value_2 String +) +ENGINE = TinyLog; + +INSERT INTO 02184_range_dictionary_source_table VALUES (1, 0, 18446744073709551615, 'value0', 'value1', 'value2'); + +DROP DICTIONARY IF EXISTS 02184_range_dictionary; +CREATE DICTIONARY 02184_range_dictionary +( + id UInt64, + start UInt64, + end UInt64, + value_0 String, + value_1 String, + value_2 String +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(TABLE '02184_range_dictionary_source_table')) +LAYOUT(RANGE_HASHED()) +RANGE(MIN start MAX end) +LIFETIME(0); + +SELECT * FROM 02184_range_dictionary; +SELECT dictGet('02184_range_dictionary', ('value_0', 'value_1', 'value_2'), 1, 18446744073709551615); +SELECT dictHas('02184_range_dictionary', 1, 18446744073709551615); + +DROP DICTIONARY 02184_range_dictionary; +DROP TABLE 02184_range_dictionary_source_table; diff --git a/tests/queries/0_stateless/02185_range_hashed_dictionary_open_ranges.reference b/tests/queries/0_stateless/02185_range_hashed_dictionary_open_ranges.reference new file mode 100644 index 00000000000..f8dc47039e9 --- /dev/null +++ b/tests/queries/0_stateless/02185_range_hashed_dictionary_open_ranges.reference @@ -0,0 +1,22 @@ +Source table +0 \N 5000 Value0 +0 5001 10000 Value1 +0 10001 \N Value2 +Dictionary convert_null_range_bound_to_open = 1 +0 5001 10000 Value1 +0 0 5000 Value0 +0 10001 18446744073709551615 Value2 +Value0 +Value1 +Value2 +1 +1 +1 +Dictionary convert_null_range_bound_to_open = 0 +0 5001 10000 Value1 +DefaultValue +Value1 +DefaultValue +0 +1 +0 diff --git a/tests/queries/0_stateless/02185_range_hashed_dictionary_open_ranges.sql b/tests/queries/0_stateless/02185_range_hashed_dictionary_open_ranges.sql new file mode 100644 index 00000000000..e6edee2ea18 --- /dev/null +++ b/tests/queries/0_stateless/02185_range_hashed_dictionary_open_ranges.sql @@ -0,0 +1,63 @@ +DROP TABLE IF EXISTS 02185_range_dictionary_source_table; +CREATE TABLE 02185_range_dictionary_source_table +( + id UInt64, + start Nullable(UInt64), + end Nullable(UInt64), + value String +) +ENGINE = TinyLog; + +INSERT INTO 02185_range_dictionary_source_table VALUES (0, NULL, 5000, 'Value0'), (0, 5001, 10000, 'Value1'), (0, 10001, NULL, 'Value2'); + +SELECT 'Source table'; +SELECT * FROM 02185_range_dictionary_source_table; + +DROP DICTIONARY IF EXISTS 02185_range_dictionary; +CREATE DICTIONARY 02185_range_dictionary +( + id UInt64, + start UInt64, + end UInt64, + value String DEFAULT 'DefaultValue' +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(TABLE '02185_range_dictionary_source_table')) +LAYOUT(RANGE_HASHED(convert_null_range_bound_to_open 1)) +RANGE(MIN start MAX end) +LIFETIME(0); + +SELECT 'Dictionary convert_null_range_bound_to_open = 1'; +SELECT * FROM 02185_range_dictionary; +SELECT dictGet('02185_range_dictionary', 'value', 0, 0); +SELECT dictGet('02185_range_dictionary', 'value', 0, 5001); +SELECT dictGet('02185_range_dictionary', 'value', 0, 10001); +SELECT dictHas('02185_range_dictionary', 0, 0); +SELECT dictHas('02185_range_dictionary', 0, 5001); +SELECT dictHas('02185_range_dictionary', 0, 10001); + +DROP DICTIONARY 02185_range_dictionary; + +CREATE DICTIONARY 02185_range_dictionary +( + id UInt64, + start UInt64, + end UInt64, + value String DEFAULT 'DefaultValue' +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(TABLE '02185_range_dictionary_source_table')) +LAYOUT(RANGE_HASHED(convert_null_range_bound_to_open 0)) +RANGE(MIN start MAX end) +LIFETIME(0); + +SELECT 'Dictionary convert_null_range_bound_to_open = 0'; +SELECT * FROM 02185_range_dictionary; +SELECT dictGet('02185_range_dictionary', 'value', 0, 0); +SELECT dictGet('02185_range_dictionary', 'value', 0, 5001); +SELECT dictGet('02185_range_dictionary', 'value', 0, 10001); +SELECT dictHas('02185_range_dictionary', 0, 0); +SELECT dictHas('02185_range_dictionary', 0, 5001); +SELECT dictHas('02185_range_dictionary', 0, 10001); + +DROP TABLE 02185_range_dictionary_source_table; diff --git a/tests/queries/0_stateless/02186_range_hashed_dictionary_intersecting_intervals.reference b/tests/queries/0_stateless/02186_range_hashed_dictionary_intersecting_intervals.reference new file mode 100644 index 00000000000..64994150f59 --- /dev/null +++ b/tests/queries/0_stateless/02186_range_hashed_dictionary_intersecting_intervals.reference @@ -0,0 +1,18 @@ +Source table +1 2020-01-01 2100-01-01 Value0 +1 2020-01-02 2100-01-01 Value1 +1 2020-01-03 2100-01-01 Value2 +Dictionary .range_lookup_strategy = min +1 2020-01-01 2100-01-01 Value0 +1 2020-01-02 2100-01-01 Value1 +1 2020-01-03 2100-01-01 Value2 +Value0 +Value0 +Value0 +Dictionary .range_lookup_strategy = max +1 2020-01-01 2100-01-01 Value0 +1 2020-01-02 2100-01-01 Value1 +1 2020-01-03 2100-01-01 Value2 +Value0 +Value1 +Value2 diff --git a/tests/queries/0_stateless/02186_range_hashed_dictionary_intersecting_intervals.sql b/tests/queries/0_stateless/02186_range_hashed_dictionary_intersecting_intervals.sql new file mode 100644 index 00000000000..caafc5e76a2 --- /dev/null +++ b/tests/queries/0_stateless/02186_range_hashed_dictionary_intersecting_intervals.sql @@ -0,0 +1,64 @@ +DROP TABLE IF EXISTS 02186_range_dictionary_source_table; +CREATE TABLE 02186_range_dictionary_source_table +( + id UInt64, + start Date, + end Date, + value String +) +Engine = TinyLog; + +INSERT INTO 02186_range_dictionary_source_table VALUES (1, '2020-01-01', '2100-01-01', 'Value0'); +INSERT INTO 02186_range_dictionary_source_table VALUES (1, '2020-01-02', '2100-01-01', 'Value1'); +INSERT INTO 02186_range_dictionary_source_table VALUES (1, '2020-01-03', '2100-01-01', 'Value2'); + +SELECT 'Source table'; +SELECT * FROM 02186_range_dictionary_source_table; + +DROP DICTIONARY IF EXISTS 02186_range_dictionary; +CREATE DICTIONARY 02186_range_dictionary +( + id UInt64, + start Date, + end Date, + value String +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(TABLE '02186_range_dictionary_source_table')) +LAYOUT(RANGE_HASHED(range_lookup_strategy 'min')) +RANGE(MIN start MAX end) +LIFETIME(0); + +SELECT 'Dictionary .range_lookup_strategy = min'; + +SELECT * FROM 02186_range_dictionary; + +select dictGet('02186_range_dictionary', 'value', toUInt64(1), toDate('2020-01-01')); +select dictGet('02186_range_dictionary', 'value', toUInt64(1), toDate('2020-01-02')); +select dictGet('02186_range_dictionary', 'value', toUInt64(1), toDate('2020-01-03')); + +DROP DICTIONARY 02186_range_dictionary; + +CREATE DICTIONARY 02186_range_dictionary +( + id UInt64, + start Date, + end Date, + value String +) +PRIMARY KEY id +SOURCE(CLICKHOUSE(TABLE '02186_range_dictionary_source_table')) +LAYOUT(RANGE_HASHED(range_lookup_strategy 'max')) +RANGE(MIN start MAX end) +LIFETIME(0); + +SELECT 'Dictionary .range_lookup_strategy = max'; + +SELECT * FROM 02186_range_dictionary; + +select dictGet('02186_range_dictionary', 'value', toUInt64(1), toDate('2020-01-01')); +select dictGet('02186_range_dictionary', 'value', toUInt64(1), toDate('2020-01-02')); +select dictGet('02186_range_dictionary', 'value', toUInt64(1), toDate('2020-01-03')); + +DROP DICTIONARY 02186_range_dictionary; +DROP TABLE 02186_range_dictionary_source_table;