Skip to content

EXPRESSION clause is ignored for KEY columns in CREATE DICTIONARY #15156

@SaltTan

Description

@SaltTan

Tested on 20.9.2

I want to create a dictionary for a CH table without a UInt64 key.
It seems that the EXPRESSION clause is being completely ignored:

CREATE DICTIONARY test.query_log
(
    `query_key` UInt64 EXPRESSION cityHash64(query_id),
    `query_id` String,
    `query_duration_ms` UInt64
)
PRIMARY KEY query_key
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' PASSWORD '' DB 'system' TABLE 'query_log' WHERE 'type>1'))
LAYOUT(DIRECT())

Ok.


SELECT *
FROM test.query_log
LIMIT 3


Received exception from server (version 20.9.2):
Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Missing columns: 'query_key' while processing query: 'SELECT query_key, query_id, event_date, event_time, query_start_time, query_duration_ms, read_rows, read_bytes, written_rows, written_bytes, result_rows, result_bytes, memory_usage FROM system.query_log WHERE type > 1', required columns: 'query_key' 'query_id' 'written_rows' 'query_start_time' 'query_duration_ms' 'read_rows' 'read_bytes' 'event_time' 'written_bytes' 'event_date' 'memory_usage' 'type' 'result_rows' 'result_bytes', source columns: 'Settings.Values' 'Settings.Names' 'ProfileEvents.Values' 'revision' 'quota_key' 'http_user_agent' 'client_version_minor' 'client_revision' 'client_hostname' 'os_user' 'interface' 'client_name' 'initial_address' 'initial_user' 'address' 'query_id' 'client_version_patch' 'user' 'ProfileEvents.Names' 'client_version_major' 'is_initial_query' 'port' 'initial_query_id' 'stack_trace' 'result_bytes' 'type' 'written_bytes' 'result_rows' 'event_time' 'http_method' 'written_rows' 'exception_code' 'query' 'current_database' 'read_bytes' 'exception' 'initial_port' 'read_rows' 'query_duration_ms' 'thread_ids' 'query_start_time' 'memory_usage' 'event_date'.

An XML dictionary works, although I don't understand where the row with the empty query_id comes from.

<yandex>
    <dictionary>
        <name>query_log</name>
        <source>
            <clickhouse>
                <host>localhost</host>
                <port>9000</port>
                <user>default</user>
                <password></password>
                <db>system</db>
                <table>query_log</table>
                <where>type>1</where>
            </clickhouse>
        </source>
        <layout>
            <direct />
        </layout>
        <structure>
            <id>
                <name>query_key</name>
                <expression>cityHash64(query_id)</expression>
            </id>
            <attribute>
                <name>query_id</name>
                <type>String</type>
                <null_value></null_value>
            </attribute>
            <attribute>
                <name>query_duration_ms</name>
                <type>UInt64</type>
                <null_value>0</null_value>
            </attribute>
        </structure>
    </dictionary>
</yandex>

SELECT *
FROM dict.query_log
LIMIT 3

┌─query_key─┬─query_id─┬─query_duration_ms─┐
│         0 │          │                 0 │
└───────────┴──────────┴───────────────────┘
┌────────────query_key─┬─query_id─────────────────────────────┬─query_duration_ms─┐
│ 13232500466751825811 │ 5b9f6640-f0ec-4045-93d3-3fc9929f338f │                 8 │
│ 10671327996374602370 │ 37f41e52-9158-4f9d-b011-23a18c4121e6 │                 6 │
│  7431129089585880466 │ 7c6eb4ee-6aaa-4b6a-9095-7a97514aba97 │               636 │
└──────────────────────┴──────────────────────────────────────┴───────────────────┘

4 rows in set. Elapsed: 0.025 sec. Processed 84.58 thousand rows, 4.57 MB (3.37 million rows/s., 182.23 MB/s.)

Metadata

Metadata

Assignees

Labels

bugConfirmed user-visible misbehaviour in official releasecomp-dictionaryDictionaries (in-memory key-value, periodically refreshed from sources).

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions