/clickhouse_url_dict

Example of using ClickHouse's URL dictionaries

Primary LanguageRuby

clickhouse_url_dict

Example of using ClickHouse's URL dictionaries

Simple Ruby HTTP server that reads and returns CSV

  • It should respond to POST request
  • It should also return input columns
    • For example in our case we send app_id and user_id from ClickHouse
    • HTTP server return app_id, user_id and result columns back

How to test

docker compose up -d # start ClickHouse and Ruby server

docker compose exec clickhouse clickhouse-client
SELECT
    dictGet('default.http_test', 'result', (number, number * 2)) AS response,
    (number * number) * 2 AS assert
FROM numbers(10)

┌─response─┬─assert─┐
│        00 │
│        22 │
│        88 │
│       1818 │
│       3232 │
│       5050 │
│       7272 │
│       9898 │
│      128128 │
│      162162 │
└──────────┴────────┘

10 rows in set. Elapsed: 0.015 sec.

Reading 10 Mln rows from HTTP dict takes less than 4 seconds

SELECT dictGet('default.http_test', 'result', (number, number * 2)) AS id
FROM numbers(10000000)
FORMAT `Null`

Ok.

0 rows in set. Elapsed: 3.770 sec. Processed 10.01 million rows, 80.06 MB (2.65 million rows/s., 21.24 MB/s.)

Bonus

Connection details defined using named collection and API KEY is loaded through env variables, so it is not available in dictionary DDL