Oct 16

ClickHouse: Dictionary 不指定

felix021 @ 2025-10-16 10:18 [IT » 数据库] 评论(0) , 引用(0) , 阅读(213) | Via 本站原创 | |
备查

CREATE DICTIONARY xxx.ip_region_dict
ON CLUSTER default_cluster
(
    `prefix` UInt32,
    `province` Nullable(String),
    `province_code` UInt32,
    `city` Nullable(String),
    `city_code` UInt32,
    `area` Nullable(String),
    `area_code` UInt32
)
PRIMARY KEY prefix
SOURCE(CLICKHOUSE(HOST '127.0.01' USER 'user' PASSWORD 'xxxx' DB 'test' TABLE 'ip_region' ))
LIFETIME(MIN 0 MAX 0) -- 需要手动刷新
LAYOUT(HASHED())


or from mysql:

SOURCE(MYSQL(HOST '127.0.0.1' PORT 3306 USER 'root' PASSWORD 'xxxxx' DB 'test' TABLE 'xxx'))
LIFETIME(MIN 300 MAX 600) -- 5~10分钟自动刷新
LAYOUT(HASHED())


Manually reload:
SYSTEM RELOAD DICTIONARY
ON CLUSTER default_cluster
ip_region_dict;


Usage
dictGet('xxx.ip_region_dict', 'city', intDiv(IPv4StringToNumOrDefault(ip), 256))



UDF:
CREATE FUNCTION getIPCity
ON CLUSTER default_cluster
AS (ip) ->
        dictGet('xxx.ip_region_dict', 'city', intDiv(IPv4StringToNumOrDefault(ip), 256));




欢迎扫码关注:




转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   *非必须
网址   电邮   [注册]