Add experimental ClickHouse HTTP client
-
Review changes -
-
Download -
Patches
-
Plain diff
What does this MR do and why?
This MR adds a lightweight gem for interacting with ClickHouse databases via HTTP interface. We're following the gem guidelines here: https://docs.gitlab.com/ee/development/gems.html
The client was created so groupoptimize can move forward with the PoC where we plan to rebuild a feature using ClickHouse.
The client should support executing an aggregation query and return counts. At a later step it should also support bulk inserts. Models and validations are out of the scope.
Why not use an already existing gem?
The original idea was to add an external gem (#414386 (closed)) however, the gem does much more than we need for this PoC and adding an external gem would require careful review of the codebase. This would eventually mean:
- Review the code and assess its quality.
- Forking the gem and making sure we have a running pipeline for the supported ruby versions.
How does it work?
The gem supports multiple databases which can be specified via a YAML file. The Gitlab::ClickHouse::Client::Configuration
object contains the databases and other options so we can use our utilities (Gitlab::HTTP
, Gitlab::Json
).
Without the YAML file the gem will not do anything, configuration is optional.
Query execution flow:
- Invoke the
execute
method using the configured database and by passing a raw SQL string. - The
Client
invokes thehttp_post_proc
callable object which invokes a HTTP request. - The response will be turned into a
Response
object which can tell whether the response is successful or not. - The body of the response contains a raw JSON string, this will be parsed with the configured
json_parser
. - The JSON response includes the returned columns with their respective data types. Using this data, the
Formatter
casts the values if necessary. - The raw data (array of hashes) are returned.
How to test it
- Set up a ClickHouse server and a user with password: https://clickhouse.com/docs/en/install
- Start a console:
clickhouse-client --password
- Create a new database:
create database gitlab_clickhouse_test;
- Connect to the new database:
clickhouse-client -d gitlab_clickhouse_test --password
- Create a new table:
CREATE TABLE issues (
`id` UInt64,
`title` String DEFAULT '',
`description` Nullable(String),
`created_at` DateTime64(6, 'UTC') DEFAULT now(),
`updated_at` DateTime64(6, 'UTC') DEFAULT now()
)
ENGINE = ReplacingMergeTree(updated_at)
ORDER BY (id)
- Insert some data:
insert into issues (id, title, description) values (1, 'Title 1', 'description');
insert into issues (id, title, description) values (2, 'Title 2', 'description');
insert into issues (id, title, description) values (3, 'Title 3', null);
- Create a config file in your gitlab dir:
config/click_house.yml
development:
main:
database: gitlab_clickhouse_test
url: 'http://localhost:8123'
username: default
password: clickhouse
- Start rails console and execute:
Gitlab::ClickHouse::Client.execute("select * from issues", :main)
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Merge request reports
- version 31738fcece
- version 3067ccccfd
- version 2952bc7cf5
- version 28dfc17dcb
- version 27bbb88486
- version 269e556925
- version 25ac3c71a0
- version 24c744989d
- version 23c6093adb
- version 22c28289ac
- version 2167ede638
- version 208b40ec72
- version 195aa8f788
- version 18616e6f54
- version 172d122fa4
- version 160d42db9d
- version 1533926db2
- version 14cfbebf3a
- version 13cbde021b
- version 12194a4394
- version 11194a4394
- version 10d8cf9ed1
- version 94105782f
- version 84fdd517e
- version 7ff052850
- version 6dd900094
- version 5ec9a991d
- version 46c9fdf17
- version 325760d4b
- version 2dee89bb5
- version 1c0e48f79
- master (base)
- latest versione29d32271 commit,
- version 31738fcece1 commit,
- version 3067ccccfd1 commit,
- version 2952bc7cf51 commit,
- version 28dfc17dcb1 commit,
- version 27bbb884862 commits,
- version 269e5569252 commits,
- version 25ac3c71a02 commits,
- version 24c744989d2 commits,
- version 23c6093adb2 commits,
- version 22c28289ac2 commits,
- version 2167ede6382 commits,
- version 208b40ec722 commits,
- version 195aa8f7882 commits,
- version 18616e6f541 commit,
- version 172d122fa41 commit,
- version 160d42db9d1 commit,
- version 1533926db21 commit,
- version 14cfbebf3a1 commit,
- version 13cbde021b1 commit,
- version 12194a43941 commit,
- version 11194a43941 commit,
- version 10d8cf9ed11 commit,
- version 94105782f1 commit,
- version 84fdd517e1 commit,
- version 7ff0528501 commit,
- version 6dd9000941 commit,
- version 5ec9a991d1 commit,
- version 46c9fdf171 commit,
- version 325760d4b1 commit,
- version 2dee89bb51 commit,
- version 1c0e48f791 commit,
- Side-by-side
- Inline
There are no changes yet
No changes between version 12 and version 12