ClickHouse/tests/queries/0_stateless/01778_hierarchical_dictionaries.sql

98 lines
3.5 KiB
MySQL
Raw Normal View History

2021-09-12 12:35:27 +00:00
-- Tags: no-parallel
2021-03-26 13:57:21 +00:00
DROP DATABASE IF EXISTS 01778_db;
CREATE DATABASE 01778_db;
CREATE TABLE 01778_db.hierarchy_source_table (id UInt64, parent_id UInt64) ENGINE = TinyLog;
INSERT INTO 01778_db.hierarchy_source_table VALUES (1, 0), (2, 1), (3, 1), (4, 2);
2021-03-26 13:57:21 +00:00
CREATE DICTIONARY 01778_db.hierarchy_flat_dictionary
2021-03-26 13:57:21 +00:00
(
id UInt64,
parent_id UInt64 HIERARCHICAL
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'hierarchy_source_table' DB '01778_db'))
2021-03-26 13:57:21 +00:00
LAYOUT(FLAT())
LIFETIME(MIN 1 MAX 1000);
SELECT 'Flat dictionary';
SELECT 'Get hierarchy';
SELECT dictGetHierarchy('01778_db.hierarchy_flat_dictionary', number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
SELECT 'Get is in hierarchy';
SELECT dictIsIn('01778_db.hierarchy_flat_dictionary', number, number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
SELECT 'Get children';
SELECT dictGetChildren('01778_db.hierarchy_flat_dictionary', number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
SELECT 'Get all descendants';
SELECT dictGetDescendants('01778_db.hierarchy_flat_dictionary', number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
SELECT 'Get descendants at first level';
SELECT dictGetDescendants('01778_db.hierarchy_flat_dictionary', number, 1) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
DROP DICTIONARY 01778_db.hierarchy_flat_dictionary;
2021-03-26 13:57:21 +00:00
CREATE DICTIONARY 01778_db.hierarchy_hashed_dictionary
2021-03-26 13:57:21 +00:00
(
id UInt64,
parent_id UInt64 HIERARCHICAL
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'hierarchy_source_table' DB '01778_db'))
LAYOUT(HASHED())
2021-03-26 13:57:21 +00:00
LIFETIME(MIN 1 MAX 1000);
SELECT 'Hashed dictionary';
SELECT 'Get hierarchy';
SELECT dictGetHierarchy('01778_db.hierarchy_hashed_dictionary', number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
SELECT 'Get is in hierarchy';
SELECT dictIsIn('01778_db.hierarchy_hashed_dictionary', number, number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
SELECT 'Get children';
SELECT dictGetChildren('01778_db.hierarchy_hashed_dictionary', number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
SELECT 'Get all descendants';
SELECT dictGetDescendants('01778_db.hierarchy_hashed_dictionary', number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
SELECT 'Get descendants at first level';
SELECT dictGetDescendants('01778_db.hierarchy_hashed_dictionary', number, 1) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
DROP DICTIONARY 01778_db.hierarchy_hashed_dictionary;
2021-03-26 13:57:21 +00:00
CREATE DICTIONARY 01778_db.hierarchy_cache_dictionary
2021-03-26 13:57:21 +00:00
(
id UInt64,
parent_id UInt64 HIERARCHICAL
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'hierarchy_source_table' DB '01778_db'))
2021-03-26 13:57:21 +00:00
LAYOUT(CACHE(SIZE_IN_CELLS 10))
LIFETIME(MIN 1 MAX 1000);
SELECT 'Cache dictionary';
SELECT 'Get hierarchy';
SELECT dictGetHierarchy('01778_db.hierarchy_cache_dictionary', number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
SELECT 'Get is in hierarchy';
SELECT dictIsIn('01778_db.hierarchy_cache_dictionary', number, number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
DROP DICTIONARY 01778_db.hierarchy_cache_dictionary;
2021-03-26 13:57:21 +00:00
CREATE DICTIONARY 01778_db.hierarchy_direct_dictionary
2021-03-26 13:57:21 +00:00
(
id UInt64,
parent_id UInt64 HIERARCHICAL
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'hierarchy_source_table' DB '01778_db'))
2021-03-26 13:57:21 +00:00
LAYOUT(DIRECT());
SELECT 'Direct dictionary';
SELECT 'Get hierarchy';
SELECT dictGetHierarchy('01778_db.hierarchy_direct_dictionary', number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
SELECT 'Get is in hierarchy';
SELECT dictIsIn('01778_db.hierarchy_direct_dictionary', number, number) FROM system.numbers LIMIT 6;
2021-03-26 13:57:21 +00:00
DROP DICTIONARY 01778_db.hierarchy_direct_dictionary;
2021-03-26 13:57:21 +00:00
DROP TABLE 01778_db.hierarchy_source_table;
2021-03-26 13:57:21 +00:00
DROP DATABASE 01778_db;