【问题标题】:dictGetString fails on DDL created dictionary in clickhousedictGetString 在 clickhouse 中创建的 DDL 字典上失败
【发布时间】:2020-09-14 20:42:19
【问题描述】:

尝试按照instructions 使用 DDL 创建字典:

-- source table
create table brands (
    id UInt64,
    brand String
)
ENGINE = ReplacingMergeTree(id)
partition by tuple()
order by id;

-- some data
insert into brands values (1, 'cool'), (2, 'neat'), (3, 'fun');

-- dictionary references source table
CREATE DICTIONARY IF NOT EXISTS brand_dict (
    id UInt64,
    brand String
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(
    host 'localhost'
    port 9000
    user 'default'
    password ''
    db 'default'
    table 'brands'
))
LIFETIME(MIN 1 MAX 10)
LAYOUT(FLAT())

-- looks good:
show dictionaries;


-- no work
-- Code: 36. DB::Exception: Received from localhost:9000. DB::Exception: external dictionary 'brand_dict' not found.
select dictGetString('brand_dict', 'id', toUInt64(1));

DB::Exception: external dictionary 'brand_dict' not found.

我还没有尝试过使用 XML 配置,所以不确定它是否特定于 DDL,或者我在那里做错了什么。

【问题讨论】:

    标签: clickhouse


    【解决方案1】:

    此类词典需要指定数据库

    dictGetString('DATABASE.brand_dict'


    UPD:从 21.4 开始函数 dictGet,如果没有为使用 DDL 创建的字典指定,dictHas 使用当前数据库名称

    【讨论】:

    • 不错。这有效:select dictGetString('default.brand_dict', 'brand', toUInt64(1));
    猜你喜欢
    • 2021-03-15
    • 2020-07-14
    • 2017-12-25
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 2019-08-07
    • 2011-07-13
    • 1970-01-01
    相关资源
    最近更新 更多