{"id":3254,"date":"2021-09-03T08:13:31","date_gmt":"2021-09-03T07:13:31","guid":{"rendered":"https:\/\/kudzia.eu\/b\/?p=3254"},"modified":"2022-02-24T12:13:06","modified_gmt":"2022-02-24T11:13:06","slug":"clickhouse-dictionary-with-string-keys","status":"publish","type":"post","link":"https:\/\/kudzia.eu\/b\/2021\/09\/clickhouse-dictionary-with-string-keys\/","title":{"rendered":"ClickHouse &#8211; dictionary with string keys"},"content":{"rendered":"<p>i wanted to create a clickhouse dictionary that used String as a key, not an int. docs mention <a href=\"https:\/\/clickhouse.tech\/docs\/en\/sql-reference\/dictionaries\/external-dictionaries\/external-dicts-dict-structure\/#composite-key\">here<\/a>: &#8220;A composite key can consist of a single element. This makes it possible to use a string as the key, for instance&#8221;. I&#8217;ve been trying this and failed few times. creation worked but i could not query the dictionary:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nCREATE DICTIONARY tmp ( `id` UInt64, `short_name` String,\u3000`long_name` String)\u3000PRIMARY KEY short_name SOURCE(MYSQL(PORT 3306 HOST 'some.sql.server' DB 'db' TABLE 'some_table' USER 'login' PASSWORD 'pass'))\u3000LIFETIME(MIN 1800 MAX 3600)\u3000LAYOUT(HASHED());\r\n\r\nselect * from tmp;\r\n\r\n0 rows in set. Elapsed: 0.036 sec.\r\n\r\nReceived exception from server (version 21.8.4):\r\nCode: 1000. DB::Exception: Received from 127.0.0.1:9000. DB::Exception: Exception: Cannot parse unsigned integer: text, query: SELECT `short_name`, `id`, `long_name` FROM `db`.`some_table`;\r\n<\/pre>\n<p>it turned out that i using wrong layout &#8211; instead of &#8220;LAYOUT(HASHED());&#8221; i should have used &#8220;LAYOUT(COMPLEX_KEY_HASHED());&#8221;.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nCREATE DICTIONARY tmp ( `id` UInt64, `short_name` String,\u3000`long_name` String)\u3000PRIMARY KEY short_name SOURCE(MYSQL(PORT 3306 HOST 'some.sql.server' DB 'db' TABLE 'some_table' USER 'login' PASSWORD 'pass'))\u3000LIFETIME(MIN 1800 MAX 3600)\u3000LAYOUT(COMPLEX_KEY_HASHED());\r\nSELECT * FROM tmp;\r\n# works fine\r\nSELECT dictGet('mydb.tmp', 'id', 'text')\r\n# also works\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>i wanted to create a clickhouse dictionary that used String as a key, not an int. docs mention here: &#8220;A composite key can consist of a single element. This makes it possible to use a string as the key, for instance&#8221;. I&#8217;ve been trying this and failed few times. creation worked but i could not [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[112],"class_list":["post-3254","post","type-post","status-publish","format-standard","hentry","category-unimportant","tag-clickhouse"],"_links":{"self":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/comments?post=3254"}],"version-history":[{"count":3,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3254\/revisions"}],"predecessor-version":[{"id":3325,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3254\/revisions\/3325"}],"wp:attachment":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/media?parent=3254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/categories?post=3254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/tags?post=3254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}