click_house-client 0.1.0 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +73 -0
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +40 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +144 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/click_house-client.gemspec +32 -0
- data/lib/click_house/client/bind_index_manager.rb +17 -0
- data/lib/click_house/client/configuration.rb +78 -0
- data/lib/click_house/client/database.rb +48 -0
- data/lib/click_house/client/formatter.rb +35 -0
- data/lib/click_house/client/query.rb +82 -0
- data/lib/click_house/client/query_like.rb +31 -0
- data/lib/click_house/client/quoting.rb +18 -0
- data/lib/click_house/client/response.rb +19 -0
- data/lib/click_house/client/version.rb +7 -0
- data/lib/click_house/client.rb +132 -0
- metadata +29 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f36b8d9ccc7b257b2ab60133e35f73f118dc748cf5029aafb97cdd90e4451590
|
4
|
+
data.tar.gz: d553c4a604ad4a1eee9c3cce940cca796000c80d4950ee021d7d3e780d26bca4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e9a05e8fb98eef88eb042747100d36acb76b532099d323c799588d6ba0fa1db83616ff952155c3a305e87b93a8ba183d1fff6dc6884a3447b624b188c0a4647
|
7
|
+
data.tar.gz: f13f21ece21e0a9d98df50482965c288fe51ef2314b3662137085ea4150a9108bd5f04a7538c28a7689b1dcfd30889302360228f434d8643c6d3bc7d0bc05309
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
stages:
|
2
|
+
- test
|
3
|
+
- deploy
|
4
|
+
|
5
|
+
include:
|
6
|
+
- component: gitlab.com/gitlab-org/components/gem-release/gem-release@~latest
|
7
|
+
|
8
|
+
workflow:
|
9
|
+
rules:
|
10
|
+
# For merge requests, create a pipeline.
|
11
|
+
- if: '$CI_MERGE_REQUEST_IID'
|
12
|
+
# For `master` branch, create a pipeline (this includes on schedules, pushes, merges, etc.).
|
13
|
+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
14
|
+
# For tags, create a pipeline.
|
15
|
+
- if: '$CI_COMMIT_TAG'
|
16
|
+
|
17
|
+
default:
|
18
|
+
tags:
|
19
|
+
- gitlab-org
|
20
|
+
cache:
|
21
|
+
key:
|
22
|
+
files:
|
23
|
+
- Gemfile
|
24
|
+
- click_house-client.gemspec
|
25
|
+
paths:
|
26
|
+
- vendor/ruby
|
27
|
+
|
28
|
+
.default-test-job:
|
29
|
+
image: "${GITLAB_DEPENDENCY_PROXY}ruby:${RUBY_VERSION}"
|
30
|
+
stage: test
|
31
|
+
needs: []
|
32
|
+
before_script:
|
33
|
+
- gem install bundler
|
34
|
+
- bundle install -j $(nproc) --path vendor
|
35
|
+
parallel:
|
36
|
+
matrix:
|
37
|
+
- RUBY_VERSION: ['3.0', '3.1', '3.2', '3.3']
|
38
|
+
|
39
|
+
test:rspec:
|
40
|
+
extends: .default-test-job
|
41
|
+
script:
|
42
|
+
- bundle exec rspec
|
43
|
+
|
44
|
+
test:rubocop:
|
45
|
+
extends: .default-test-job
|
46
|
+
script:
|
47
|
+
- bundle exec rubocop -P -E .
|
48
|
+
|
49
|
+
include:
|
50
|
+
- component: gitlab.com/components/sast/sast@~latest
|
51
|
+
- component: gitlab.com/components/secret-detection/secret-detection@~latest
|
52
|
+
- component: gitlab.com/gitlab-org/components/gem-release/gem-release@~latest
|
53
|
+
inputs:
|
54
|
+
gem_name: click_house-client
|
55
|
+
file_pattern_to_trigger_release: "lib/**/version.rb"
|
56
|
+
- template: Security/Dependency-Scanning.gitlab-ci.yml
|
57
|
+
|
58
|
+
# run security jobs on MRs
|
59
|
+
# see: https://gitlab.com/gitlab-org/gitlab/-/issues/218444#note_478761991
|
60
|
+
|
61
|
+
gemnasium-dependency_scanning:
|
62
|
+
rules:
|
63
|
+
- if: '$CI_MERGE_REQUEST_IID'
|
64
|
+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
65
|
+
|
66
|
+
secret_detection:
|
67
|
+
variables:
|
68
|
+
# Use a different scanning mode that doesn't rely on commit comparison
|
69
|
+
SECURE_ANALYZERS_MODE: "full_repository_scan"
|
70
|
+
|
71
|
+
rules:
|
72
|
+
- if: '$CI_MERGE_REQUEST_IID'
|
73
|
+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at remy@rymai.me. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
## Developer Certificate of Origin and License
|
2
|
+
|
3
|
+
By contributing to GitLab B.V., you accept and agree to the following terms and
|
4
|
+
conditions for your present and future contributions submitted to GitLab B.V.
|
5
|
+
Except for the license granted herein to GitLab B.V. and recipients of software
|
6
|
+
distributed by GitLab B.V., you reserve all right, title, and interest in and to
|
7
|
+
your Contributions.
|
8
|
+
|
9
|
+
All contributions are subject to the Developer Certificate of Origin and license set out at [docs.gitlab.com/ce/legal/developer_certificate_of_origin](https://docs.gitlab.com/ce/legal/developer_certificate_of_origin).
|
10
|
+
|
11
|
+
_This notice should stay as the first item in the CONTRIBUTING.md file._
|
12
|
+
|
13
|
+
## Code of conduct
|
14
|
+
|
15
|
+
As contributors and maintainers of this project, we pledge to respect all people
|
16
|
+
who contribute through reporting issues, posting feature requests, updating
|
17
|
+
documentation, submitting pull requests or patches, and other activities.
|
18
|
+
|
19
|
+
We are committed to making participation in this project a harassment-free
|
20
|
+
experience for everyone, regardless of level of experience, gender, gender
|
21
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
22
|
+
body size, race, ethnicity, age, or religion.
|
23
|
+
|
24
|
+
Examples of unacceptable behavior by participants include the use of sexual
|
25
|
+
language or imagery, derogatory comments or personal attacks, trolling, public
|
26
|
+
or private harassment, insults, or other unprofessional conduct.
|
27
|
+
|
28
|
+
Project maintainers have the right and responsibility to remove, edit, or reject
|
29
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
30
|
+
not aligned to this Code of Conduct. Project maintainers who do not follow the
|
31
|
+
Code of Conduct may be removed from the project team.
|
32
|
+
|
33
|
+
This code of conduct applies both within project spaces and in public spaces
|
34
|
+
when an individual is representing the project or its community.
|
35
|
+
|
36
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior can be
|
37
|
+
reported by emailing contact@gitlab.com.
|
38
|
+
|
39
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://contributor-covenant.org), version 1.1.0,
|
40
|
+
available at [https://contributor-covenant.org/version/1/1/0/](https://contributor-covenant.org/version/1/1/0/).
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
click_house-client (0.2.4)
|
5
|
+
activesupport (< 8)
|
6
|
+
addressable (~> 2.8)
|
7
|
+
json (~> 2.7)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (7.0.8.7)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
addressable (2.8.4)
|
18
|
+
public_suffix (>= 2.0.2, < 6.0)
|
19
|
+
ast (2.4.2)
|
20
|
+
concurrent-ruby (1.2.2)
|
21
|
+
diff-lcs (1.5.0)
|
22
|
+
gitlab-styles (12.0.1)
|
23
|
+
rubocop (~> 1.62.1)
|
24
|
+
rubocop-factory_bot (~> 2.25.1)
|
25
|
+
rubocop-graphql (~> 1.5.0)
|
26
|
+
rubocop-performance (~> 1.20.2)
|
27
|
+
rubocop-rails (~> 2.24.0)
|
28
|
+
rubocop-rspec (~> 2.27.1)
|
29
|
+
i18n (1.14.1)
|
30
|
+
concurrent-ruby (~> 1.0)
|
31
|
+
json (2.10.1)
|
32
|
+
language_server-protocol (3.17.0.3)
|
33
|
+
minitest (5.18.1)
|
34
|
+
parallel (1.23.0)
|
35
|
+
parser (3.3.3.0)
|
36
|
+
ast (~> 2.4.1)
|
37
|
+
racc
|
38
|
+
public_suffix (5.0.3)
|
39
|
+
racc (1.7.1)
|
40
|
+
rack (3.1.8)
|
41
|
+
rainbow (3.1.1)
|
42
|
+
rake (13.0.6)
|
43
|
+
regexp_parser (2.8.1)
|
44
|
+
rexml (3.3.9)
|
45
|
+
rspec (3.12.0)
|
46
|
+
rspec-core (~> 3.12.0)
|
47
|
+
rspec-expectations (~> 3.12.0)
|
48
|
+
rspec-mocks (~> 3.12.0)
|
49
|
+
rspec-core (3.12.2)
|
50
|
+
rspec-support (~> 3.12.0)
|
51
|
+
rspec-expectations (3.12.3)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.12.0)
|
54
|
+
rspec-mocks (3.12.5)
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
+
rspec-support (~> 3.12.0)
|
57
|
+
rspec-support (3.12.1)
|
58
|
+
rubocop (1.62.1)
|
59
|
+
json (~> 2.3)
|
60
|
+
language_server-protocol (>= 3.17.0)
|
61
|
+
parallel (~> 1.10)
|
62
|
+
parser (>= 3.3.0.2)
|
63
|
+
rainbow (>= 2.2.2, < 4.0)
|
64
|
+
regexp_parser (>= 1.8, < 3.0)
|
65
|
+
rexml (>= 3.2.5, < 4.0)
|
66
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
67
|
+
ruby-progressbar (~> 1.7)
|
68
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
69
|
+
rubocop-ast (1.31.3)
|
70
|
+
parser (>= 3.3.1.0)
|
71
|
+
rubocop-capybara (2.18.0)
|
72
|
+
rubocop (~> 1.41)
|
73
|
+
rubocop-factory_bot (2.25.1)
|
74
|
+
rubocop (~> 1.41)
|
75
|
+
rubocop-graphql (1.5.2)
|
76
|
+
rubocop (>= 0.90, < 2)
|
77
|
+
rubocop-performance (1.20.2)
|
78
|
+
rubocop (>= 1.48.1, < 2.0)
|
79
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
80
|
+
rubocop-rails (2.24.1)
|
81
|
+
activesupport (>= 4.2.0)
|
82
|
+
rack (>= 1.1)
|
83
|
+
rubocop (>= 1.33.0, < 2.0)
|
84
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
85
|
+
rubocop-rspec (2.27.1)
|
86
|
+
rubocop (~> 1.40)
|
87
|
+
rubocop-capybara (~> 2.17)
|
88
|
+
rubocop-factory_bot (~> 2.22)
|
89
|
+
ruby-progressbar (1.13.0)
|
90
|
+
tzinfo (2.0.6)
|
91
|
+
concurrent-ruby (~> 1.0)
|
92
|
+
unicode-display_width (2.4.2)
|
93
|
+
|
94
|
+
PLATFORMS
|
95
|
+
ruby
|
96
|
+
|
97
|
+
DEPENDENCIES
|
98
|
+
click_house-client!
|
99
|
+
gitlab-styles (~> 12.0.1)
|
100
|
+
rake (~> 13.0)
|
101
|
+
rspec (~> 3.0)
|
102
|
+
rubocop
|
103
|
+
rubocop-rspec
|
104
|
+
|
105
|
+
CHECKSUMS
|
106
|
+
activesupport (7.0.8.7) sha256=df4702375de924aae81709c831605317c5417f0bd9e502a0373ff84a067204ff
|
107
|
+
addressable (2.8.4) sha256=40a88af5285625b7fb14070e550e667d5b0cc91f748068701b4d897cacda4897
|
108
|
+
ast (2.4.2) sha256=1e280232e6a33754cde542bc5ef85520b74db2aac73ec14acef453784447cc12
|
109
|
+
click_house-client (0.2.4)
|
110
|
+
concurrent-ruby (1.2.2) sha256=3879119b8b75e3b62616acc256c64a134d0b0a7a9a3fcba5a233025bcde22c4f
|
111
|
+
diff-lcs (1.5.0) sha256=49b934001c8c6aedb37ba19daec5c634da27b318a7a3c654ae979d6ba1929b67
|
112
|
+
gitlab-styles (12.0.1) sha256=d8a302b0ab0e1f18e2d11501760f1b85c5e70b5e5ca628828a0786c7984ed133
|
113
|
+
i18n (1.14.1) sha256=9d03698903547c060928e70a9bc8b6b87fda674453cda918fc7ab80235ae4a61
|
114
|
+
json (2.10.1) sha256=ddc88ad91a1baf3f0038c174f253af3b086d30dc74db17ca4259bbde982f94dc
|
115
|
+
language_server-protocol (3.17.0.3) sha256=3d5c58c02f44a20d972957a9febe386d7e7468ab3900ce6bd2b563dd910c6b3f
|
116
|
+
minitest (5.18.1) sha256=ab5ee381871aaddc3a6aa2a6abcab5c4590fec9affc20947d63f312a0fe4e9cd
|
117
|
+
parallel (1.23.0) sha256=27154713ad6ef32fa3dcb7788a721d6c07bca77e72443b4c6080a14145288c49
|
118
|
+
parser (3.3.3.0) sha256=a2e23c90918d9b7e866b18dca2b6835f227769dd2fa8e59c5841f3389cf53eeb
|
119
|
+
public_suffix (5.0.3) sha256=337d475da2bd2ea1de0446751cb972ad43243b4b00aa8cf91cb904fa593d3259
|
120
|
+
racc (1.7.1) sha256=af64124836fdd3c00e830703d7f873ea5deabde923f37006a39f5a5e0da16387
|
121
|
+
rack (3.1.8) sha256=d3fbcbca43dc2b43c9c6d7dfbac01667ae58643c42cea10013d0da970218a1b1
|
122
|
+
rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
|
123
|
+
rake (13.0.6) sha256=5ce4bf5037b4196c24ac62834d8db1ce175470391026bd9e557d669beeb19097
|
124
|
+
regexp_parser (2.8.1) sha256=83f63e2bfae3db38f988c66f114485140ff1791321fd827480bc75aa42cacb8c
|
125
|
+
rexml (3.3.9) sha256=d71875b85299f341edf47d44df0212e7658cbdf35aeb69cefdb63f57af3137c9
|
126
|
+
rspec (3.12.0) sha256=ccc41799a43509dc0be84070e3f0410ac95cbd480ae7b6c245543eb64162399c
|
127
|
+
rspec-core (3.12.2) sha256=155b54480f28e2b2813185077fe435c2d663031616360ed3b179a9d6a55d2551
|
128
|
+
rspec-expectations (3.12.3) sha256=093d18e2e7e0a2c619ef8f7343d442fc6c0793fb7897d56f16f26c8a9d244416
|
129
|
+
rspec-mocks (3.12.5) sha256=82030d2bfa1e4eef0a2ee36af5d3d224672598912a3f3384f27cbba9fa09d5c1
|
130
|
+
rspec-support (3.12.1) sha256=f969b85d0068ff97bc47c9d6fc2bca9706d73406f2b4e5d3b346443d8734c8cf
|
131
|
+
rubocop (1.62.1) sha256=aeb1ec501aef5833617b3b6a1512303806218c349c28ce5b3ea72e3782ad4a35
|
132
|
+
rubocop-ast (1.31.3) sha256=1b07d618d8776993ec6053a706d1c09f0bf15139fd69415924656cbff07e7818
|
133
|
+
rubocop-capybara (2.18.0) sha256=66b256755101f76dc455ba9694e2414bc957db5200401d204b00bc835401d605
|
134
|
+
rubocop-factory_bot (2.25.1) sha256=62751bde7af789878b8a31cbd2a82e69515ce7b23a2ad1820cb0fcc3e0150134
|
135
|
+
rubocop-graphql (1.5.2) sha256=9e5fb5909607d0d68bb6e924d8f916476c9706e81d8676c53960c7c5f3eadb85
|
136
|
+
rubocop-performance (1.20.2) sha256=1bb1fa8c427fac7ba3c8dd2decb9860f23cb2d6c40350bedc88538de8875c731
|
137
|
+
rubocop-rails (2.24.1) sha256=03edf766954947468f3686cedb69142fae4f10e2007287f89cc0ea7072eeac19
|
138
|
+
rubocop-rspec (2.27.1) sha256=2f27ce04700be75db65afe83d7993a36e0fafd07ec062222f4b3cc10137a7a9e
|
139
|
+
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
|
140
|
+
tzinfo (2.0.6) sha256=8daf828cc77bcf7d63b0e3bdb6caa47e2272dcfaf4fbfe46f8c3a9df087a829b
|
141
|
+
unicode-display_width (2.4.2) sha256=6a10205d1a19ca790c4e53064ba93f09d9eb234bf6bd135d9deb6001c21428be
|
142
|
+
|
143
|
+
BUNDLED WITH
|
144
|
+
2.6.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024-present GitLab Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# ClickHouse::Client
|
2
|
+
|
3
|
+
This Gem provides a simple way to query ClickHouse databases using the HTTP interface.
|
4
|
+
|
5
|
+
## Example usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'logger'
|
9
|
+
require 'net/http'
|
10
|
+
|
11
|
+
ClickHouse::Client.configure do |config|
|
12
|
+
# Register your database(s)
|
13
|
+
config.register_database(:main,
|
14
|
+
database: 'default',
|
15
|
+
url: 'http://localhost:8123',
|
16
|
+
username: 'default',
|
17
|
+
password: 'clickhouse',
|
18
|
+
variables: { mutations_sync: 1 }
|
19
|
+
)
|
20
|
+
|
21
|
+
config.logger = Logger.new(STDOUT)
|
22
|
+
|
23
|
+
# Use any HTTP client to build the POST request, here we use Net::HTTP
|
24
|
+
config.http_post_proc = ->(url, headers, body) do
|
25
|
+
# Query placeholders go to the URI
|
26
|
+
params = URI.encode_www_form(body.except("query"))
|
27
|
+
|
28
|
+
uri = URI.parse("#{url}&#{params}")
|
29
|
+
request = Net::HTTP::Post.new(uri)
|
30
|
+
|
31
|
+
headers.each do |header, value|
|
32
|
+
request[header] = value
|
33
|
+
end
|
34
|
+
|
35
|
+
request['Content-type'] = 'application/x-www-form-urlencoded'
|
36
|
+
request.body = body["query"]
|
37
|
+
|
38
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
39
|
+
http.request(request)
|
40
|
+
end
|
41
|
+
|
42
|
+
ClickHouse::Client::Response.new(response.body, response.code.to_i, response.each_header.to_h)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Run some statements
|
47
|
+
puts ClickHouse::Client.select('SELECT 1+1', :main)
|
48
|
+
|
49
|
+
query = ClickHouse::Client::Query.new(raw_query: 'SELECT {number1:Int64} + {number2:Int64}', placeholders: { number1: 11, number2: 4 })
|
50
|
+
puts ClickHouse::Client.select(query, :main)
|
51
|
+
|
52
|
+
puts ClickHouse::Client.execute('CREATE TABLE IF NOT EXISTS t1 (id Int64) ENGINE=MergeTree PRIMARY KEY id', :main)
|
53
|
+
puts ClickHouse::Client.execute('DROP TABLE IF EXISTS t1', :main)
|
54
|
+
```
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
59
|
+
|
60
|
+
## Code of Conduct
|
61
|
+
|
62
|
+
Everyone interacting in the Gitlab::Danger project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/gitlab-org/ruby/gems/clickhouse-client/-/blob/main/CODE_OF_CONDUCT.md?ref_type=heads).
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/click_house/client/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "click_house-client"
|
7
|
+
spec.version = ClickHouse::Client::VERSION
|
8
|
+
spec.authors = ["group::optimize"]
|
9
|
+
spec.email = ["engineering@gitlab.com"]
|
10
|
+
|
11
|
+
spec.summary = "GitLab's client to interact with ClickHouse"
|
12
|
+
spec.description = "This Gem provides a simple way to query ClickHouse databases using the HTTP interface."
|
13
|
+
spec.homepage = "https://gitlab.com/gitlab-org/ruby/gems/clickhouse-client"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.0"
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_runtime_dependency "activesupport", "< 8"
|
24
|
+
spec.add_runtime_dependency "addressable", "~> 2.8"
|
25
|
+
spec.add_runtime_dependency 'json', '~> 2.7'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'gitlab-styles', '~> 12.0.1'
|
28
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency 'rubocop'
|
31
|
+
spec.add_development_dependency 'rubocop-rspec'
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ClickHouse
|
4
|
+
module Client
|
5
|
+
class BindIndexManager
|
6
|
+
def initialize(start_index = 1)
|
7
|
+
@current_index = start_index
|
8
|
+
end
|
9
|
+
|
10
|
+
def next_bind_str
|
11
|
+
bind_str = "$#{@current_index}"
|
12
|
+
@current_index += 1
|
13
|
+
bind_str
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ClickHouse
|
4
|
+
module Client
|
5
|
+
class Configuration
|
6
|
+
# Configuration options:
|
7
|
+
#
|
8
|
+
# *register_database* (method): registers a database, the following arguments are required:
|
9
|
+
# - database: database name
|
10
|
+
# - url: URL and port to the HTTP interface
|
11
|
+
# - username
|
12
|
+
# - password
|
13
|
+
# - variables (optional): configuration for the client
|
14
|
+
#
|
15
|
+
# *http_post_proc*: A callable object for invoking the HTTP request.
|
16
|
+
# The object must handle the following parameters: url, headers, body
|
17
|
+
# and return a ClickHouse::Client::Response object.
|
18
|
+
#
|
19
|
+
# *json_parser*: object for parsing JSON strings, it should respond to the "parse" method
|
20
|
+
#
|
21
|
+
# *logger*: object for receiving logger commands. Default `$stdout`
|
22
|
+
# *log_proc*: any output (e.g. structure) to wrap around the query for every statement
|
23
|
+
#
|
24
|
+
# Example:
|
25
|
+
#
|
26
|
+
# ClickHouse::Client.configure do |c|
|
27
|
+
# c.register_database(:main,
|
28
|
+
# database: 'gitlab_clickhouse_test',
|
29
|
+
# url: 'http://localhost:8123',
|
30
|
+
# username: 'default',
|
31
|
+
# password: 'clickhouse',
|
32
|
+
# variables: {
|
33
|
+
# join_use_nulls: 1 # treat JOINs as per SQL standard
|
34
|
+
# }
|
35
|
+
# )
|
36
|
+
#
|
37
|
+
# c.logger = MyLogger.new
|
38
|
+
# c.log_proc = ->(query) do
|
39
|
+
# { query_body: query.to_redacted_sql }
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# c.http_post_proc = lambda do |url, headers, body|
|
43
|
+
# options = {
|
44
|
+
# headers: headers,
|
45
|
+
# body: body,
|
46
|
+
# allow_local_requests: false
|
47
|
+
# }
|
48
|
+
#
|
49
|
+
# response = Gitlab::HTTP.post(url, options)
|
50
|
+
# ClickHouse::Client::Response.new(response.body, response.code)
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# c.json_parser = JSON
|
54
|
+
# end
|
55
|
+
attr_accessor :http_post_proc, :json_parser, :logger, :log_proc
|
56
|
+
attr_reader :databases
|
57
|
+
|
58
|
+
def initialize
|
59
|
+
@databases = {}
|
60
|
+
@http_post_proc = nil
|
61
|
+
@json_parser = JSON
|
62
|
+
@logger = ::Logger.new($stdout)
|
63
|
+
@log_proc = ->(query) { query.to_sql }
|
64
|
+
end
|
65
|
+
|
66
|
+
def register_database(name, **args)
|
67
|
+
raise ConfigurationError, "The database '#{name}' is already registered" if @databases.key?(name)
|
68
|
+
|
69
|
+
@databases[name] = Database.new(**args)
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate!
|
73
|
+
raise ConfigurationError, "The 'http_post_proc' option is not configured" unless @http_post_proc
|
74
|
+
raise ConfigurationError, "The 'json_parser' option is not configured" unless @json_parser
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ClickHouse
|
4
|
+
module Client
|
5
|
+
class Database
|
6
|
+
attr_reader :database
|
7
|
+
|
8
|
+
def initialize(database:, url:, username:, password:, variables: {})
|
9
|
+
@database = database
|
10
|
+
@url = url
|
11
|
+
@username = username
|
12
|
+
@password = password
|
13
|
+
@variables = {
|
14
|
+
database: database,
|
15
|
+
enable_http_compression: 1 # enable HTTP compression by default
|
16
|
+
}.merge(variables).freeze
|
17
|
+
end
|
18
|
+
|
19
|
+
def uri
|
20
|
+
@uri ||= build_custom_uri
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_custom_uri(extra_variables: {})
|
24
|
+
parsed = Addressable::URI.parse(@url)
|
25
|
+
parsed.query_values = @variables.merge(extra_variables)
|
26
|
+
parsed
|
27
|
+
end
|
28
|
+
|
29
|
+
def headers
|
30
|
+
@headers ||= {
|
31
|
+
'X-ClickHouse-User' => @username,
|
32
|
+
'X-ClickHouse-Key' => @password,
|
33
|
+
'X-ClickHouse-Format' => 'JSON' # always return JSON data
|
34
|
+
}.freeze
|
35
|
+
end
|
36
|
+
|
37
|
+
def with_default_database
|
38
|
+
self.class.new(
|
39
|
+
database: 'default',
|
40
|
+
url: @url,
|
41
|
+
username: @username,
|
42
|
+
password: @password,
|
43
|
+
variables: @variables.merge(database: 'default')
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ClickHouse
|
4
|
+
module Client
|
5
|
+
class Formatter
|
6
|
+
DEFAULT = ->(value) { value }
|
7
|
+
|
8
|
+
BASIC_TYPE_CASTERS = {
|
9
|
+
'UInt64' => ->(value) { Integer(value) },
|
10
|
+
"DateTime64(6, 'UTC')" => ->(value) { ActiveSupport::TimeZone['UTC'].parse(value) },
|
11
|
+
"IntervalSecond" => ->(value) { ActiveSupport::Duration.build(value.to_i) },
|
12
|
+
"IntervalMillisecond" => ->(value) { ActiveSupport::Duration.build(value.to_i / 1000.0) }
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
TYPE_CASTERS = BASIC_TYPE_CASTERS.merge(
|
16
|
+
BASIC_TYPE_CASTERS.transform_keys { |type| "Nullable(#{type})" }
|
17
|
+
.transform_values { |caster| ->(value) { value.nil? ? nil : caster.call(value) } }
|
18
|
+
)
|
19
|
+
|
20
|
+
def self.format(result)
|
21
|
+
name_type_mapping = result['meta'].each_with_object({}) do |column, hash|
|
22
|
+
hash[column['name']] = column['type']
|
23
|
+
end
|
24
|
+
|
25
|
+
result['data'].map do |row|
|
26
|
+
row.each_with_object({}) do |(column, value), casted_row|
|
27
|
+
caster = TYPE_CASTERS.fetch(name_type_mapping[column], DEFAULT)
|
28
|
+
|
29
|
+
casted_row[column] = caster.call(value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ClickHouse
|
4
|
+
module Client
|
5
|
+
class Query < QueryLike
|
6
|
+
SUBQUERY_PLACEHOLDER_REGEX = /{\w+:Subquery}/ # example: {var:Subquery}, special "internal" type for subqueries
|
7
|
+
PLACEHOLDER_REGEX = /{\w+:(\w|[()])+}/ # example: {var:UInt8} or {var:Array(UInt8)}
|
8
|
+
PLACEHOLDER_NAME_REGEX = /{(\w+):/ # example: {var:UInt8} => var
|
9
|
+
|
10
|
+
def self.build(query)
|
11
|
+
return query if query.is_a?(ClickHouse::Client::QueryLike)
|
12
|
+
|
13
|
+
new(raw_query: query)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(raw_query:, placeholders: {})
|
17
|
+
raise QueryError, 'Empty query string given' if raw_query.blank?
|
18
|
+
|
19
|
+
@raw_query = raw_query
|
20
|
+
@placeholders = placeholders || {}
|
21
|
+
end
|
22
|
+
|
23
|
+
# List of placeholders to be sent to ClickHouse for replacement.
|
24
|
+
# If there are subqueries, merge their placeholders as well.
|
25
|
+
def prepared_placeholders
|
26
|
+
all_placeholders = placeholders.select { |_, v| !v.is_a?(QueryLike) }
|
27
|
+
all_placeholders.transform_values! { |v| prepared_placeholder_value(v) }
|
28
|
+
|
29
|
+
placeholders.each_value do |value|
|
30
|
+
next unless value.is_a?(QueryLike)
|
31
|
+
|
32
|
+
all_placeholders.merge!(value.prepared_placeholders) do |key, a, b|
|
33
|
+
raise QueryError, "mismatching values for the '#{key}' placeholder: #{a} vs #{b}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
all_placeholders
|
38
|
+
end
|
39
|
+
|
40
|
+
# Placeholder replacement is handled by ClickHouse, only subquery placeholders
|
41
|
+
# will be replaced.
|
42
|
+
def to_sql
|
43
|
+
raw_query.gsub(SUBQUERY_PLACEHOLDER_REGEX) do |placeholder_in_query|
|
44
|
+
value = placeholder_value(placeholder_in_query)
|
45
|
+
|
46
|
+
if value.is_a?(QueryLike)
|
47
|
+
value.to_sql
|
48
|
+
else
|
49
|
+
placeholder_in_query
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_redacted_sql(bind_index_manager = BindIndexManager.new)
|
55
|
+
raw_query.gsub(PLACEHOLDER_REGEX) do |placeholder_in_query|
|
56
|
+
value = placeholder_value(placeholder_in_query)
|
57
|
+
|
58
|
+
if value.is_a?(QueryLike)
|
59
|
+
value.to_redacted_sql(bind_index_manager)
|
60
|
+
else
|
61
|
+
bind_index_manager.next_bind_str
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
attr_reader :raw_query, :placeholders
|
69
|
+
|
70
|
+
def placeholder_value(placeholder_in_query)
|
71
|
+
placeholder = placeholder_in_query[PLACEHOLDER_NAME_REGEX, 1]
|
72
|
+
placeholders.fetch(placeholder.to_sym)
|
73
|
+
end
|
74
|
+
|
75
|
+
def prepared_placeholder_value(value)
|
76
|
+
return value unless value.is_a?(Array)
|
77
|
+
|
78
|
+
Quoting.quote(value)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ClickHouse
|
4
|
+
module Client
|
5
|
+
class QueryLike
|
6
|
+
# Build a SQL string that can be executed on a ClickHouse database.
|
7
|
+
def to_sql
|
8
|
+
raise NotImplementedError
|
9
|
+
end
|
10
|
+
|
11
|
+
# Redacted version of the SQL query generated by the to_sql method where the
|
12
|
+
# placeholders are stripped. These queries are meant to be exported to external
|
13
|
+
# log aggregation systems.
|
14
|
+
def to_redacted_sql(bind_index_manager = BindIndexManager.new)
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
# Override when placeholders should be supported
|
19
|
+
def prepared_placeholders
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Override when placeholders should be supported
|
26
|
+
def placeholders
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ClickHouse
|
4
|
+
module Client
|
5
|
+
module Quoting
|
6
|
+
class << self
|
7
|
+
def quote(value)
|
8
|
+
case value
|
9
|
+
when String, Symbol then "'#{value.gsub('\\', '\&\&').gsub("'", "''")}'"
|
10
|
+
when Array then "[#{value.map { |v| quote(v) }.join(',')}]"
|
11
|
+
when nil then "NULL"
|
12
|
+
else value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ClickHouse
|
4
|
+
module Client
|
5
|
+
class Response
|
6
|
+
attr_reader :body, :headers
|
7
|
+
|
8
|
+
def initialize(body, http_status_code, headers = {})
|
9
|
+
@body = body
|
10
|
+
@http_status_code = http_status_code
|
11
|
+
@headers = headers
|
12
|
+
end
|
13
|
+
|
14
|
+
def success?
|
15
|
+
@http_status_code == 200
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'addressable'
|
4
|
+
require 'json'
|
5
|
+
require 'active_support/time'
|
6
|
+
require 'active_support/notifications'
|
7
|
+
require 'active_support/core_ext/object/blank'
|
8
|
+
require_relative "client/version"
|
9
|
+
require_relative "client/database"
|
10
|
+
require_relative "client/configuration"
|
11
|
+
require_relative "client/bind_index_manager"
|
12
|
+
require_relative "client/quoting"
|
13
|
+
require_relative "client/query_like"
|
14
|
+
require_relative "client/query"
|
15
|
+
require_relative "client/formatter"
|
16
|
+
require_relative "client/response"
|
17
|
+
|
18
|
+
module ClickHouse
|
19
|
+
module Client
|
20
|
+
class << self
|
21
|
+
def configuration
|
22
|
+
@configuration ||= Configuration.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def configure
|
26
|
+
yield(configuration)
|
27
|
+
configuration.validate!
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Error = Class.new(StandardError)
|
32
|
+
ConfigurationError = Class.new(Error)
|
33
|
+
DatabaseError = Class.new(Error)
|
34
|
+
QueryError = Class.new(Error)
|
35
|
+
|
36
|
+
def self.database_configured?(database, configuration = self.configuration)
|
37
|
+
!!configuration.databases[database]
|
38
|
+
end
|
39
|
+
|
40
|
+
# Executes a SELECT database query
|
41
|
+
def self.select(query, database, configuration = self.configuration)
|
42
|
+
instrumented_execute(query, database, configuration) do |response, instrument|
|
43
|
+
parsed_response = configuration.json_parser.parse(response.body)
|
44
|
+
|
45
|
+
instrument[:statistics] = parsed_response['statistics']&.symbolize_keys
|
46
|
+
|
47
|
+
Formatter.format(parsed_response)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Executes any kinds of database query without returning any data (INSERT, DELETE)
|
52
|
+
def self.execute(query, database, configuration = self.configuration)
|
53
|
+
instrumented_execute(query, database, configuration) do |response, instrument|
|
54
|
+
expose_summary(response.headers, instrument)
|
55
|
+
end
|
56
|
+
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
# Inserts a gzip-compressed CSV to ClickHouse
|
61
|
+
#
|
62
|
+
# Usage:
|
63
|
+
#
|
64
|
+
# Create a compressed CSV file:
|
65
|
+
# > File.binwrite("my_csv.csv", ActiveSupport::Gzip.compress("id\n10\n20"))
|
66
|
+
#
|
67
|
+
# Invoke the INSERT query:
|
68
|
+
# > ClickHouse::Client.insert_csv('INSERT INTO events (id) FORMAT CSV', File.open("my_csv.csv"), :main)
|
69
|
+
def self.insert_csv(query, io, database, configuration = self.configuration)
|
70
|
+
db = lookup_database(configuration, database)
|
71
|
+
|
72
|
+
headers = db.headers.merge(
|
73
|
+
'Transfer-Encoding' => 'chunked',
|
74
|
+
'Content-Length' => File.size(io).to_s,
|
75
|
+
'Content-Encoding' => 'gzip'
|
76
|
+
)
|
77
|
+
|
78
|
+
query = ClickHouse::Client::Query.build(query)
|
79
|
+
ActiveSupport::Notifications.instrument('sql.click_house', { query: query, database: database }) do |instrument|
|
80
|
+
response = configuration.http_post_proc.call(
|
81
|
+
db.build_custom_uri(extra_variables: { query: query.to_sql }).to_s,
|
82
|
+
headers,
|
83
|
+
io
|
84
|
+
)
|
85
|
+
raise DatabaseError, response.body unless response.success?
|
86
|
+
|
87
|
+
expose_summary(response.headers, instrument)
|
88
|
+
end
|
89
|
+
|
90
|
+
true
|
91
|
+
end
|
92
|
+
|
93
|
+
private_class_method def self.expose_summary(headers, instrument)
|
94
|
+
return unless headers['x-clickhouse-summary']
|
95
|
+
|
96
|
+
instrument[:statistics] =
|
97
|
+
configuration.json_parser.parse(headers['x-clickhouse-summary']).symbolize_keys
|
98
|
+
end
|
99
|
+
|
100
|
+
private_class_method def self.lookup_database(configuration, database)
|
101
|
+
configuration.databases[database].tap do |db|
|
102
|
+
raise ConfigurationError, "The database '#{database}' is not configured" unless db
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
private_class_method def self.instrumented_execute(query, database, configuration)
|
107
|
+
db = lookup_database(configuration, database)
|
108
|
+
|
109
|
+
query = ClickHouse::Client::Query.build(query)
|
110
|
+
|
111
|
+
log_contents = configuration.log_proc.call(query)
|
112
|
+
configuration.logger.info(log_contents)
|
113
|
+
|
114
|
+
ActiveSupport::Notifications.instrument('sql.click_house', { query: query, database: database }) do |instrument|
|
115
|
+
# Use a multipart POST request where the placeholders are sent with the param_ prefix
|
116
|
+
# See: https://github.com/ClickHouse/ClickHouse/issues/8842
|
117
|
+
query_with_params = query.prepared_placeholders.transform_keys { |key| "param_#{key}" }
|
118
|
+
query_with_params['query'] = query.to_sql
|
119
|
+
|
120
|
+
response = configuration.http_post_proc.call(
|
121
|
+
db.uri.to_s,
|
122
|
+
db.headers,
|
123
|
+
query_with_params
|
124
|
+
)
|
125
|
+
|
126
|
+
raise DatabaseError, response.body unless response.success?
|
127
|
+
|
128
|
+
yield response, instrument
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: click_house-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- group::optimize
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
47
|
+
version: '2.7'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
54
|
+
version: '2.7'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: gitlab-styles
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 12.0.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 12.0.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,8 +129,28 @@ email:
|
|
129
129
|
executables: []
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
|
-
files:
|
133
|
-
|
132
|
+
files:
|
133
|
+
- ".gitlab-ci.yml"
|
134
|
+
- ".rspec"
|
135
|
+
- ".rubocop.yml"
|
136
|
+
- CODE_OF_CONDUCT.md
|
137
|
+
- CONTRIBUTING.md
|
138
|
+
- Gemfile
|
139
|
+
- Gemfile.lock
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.md
|
142
|
+
- click_house-client.gemspec
|
143
|
+
- lib/click_house/client.rb
|
144
|
+
- lib/click_house/client/bind_index_manager.rb
|
145
|
+
- lib/click_house/client/configuration.rb
|
146
|
+
- lib/click_house/client/database.rb
|
147
|
+
- lib/click_house/client/formatter.rb
|
148
|
+
- lib/click_house/client/query.rb
|
149
|
+
- lib/click_house/client/query_like.rb
|
150
|
+
- lib/click_house/client/quoting.rb
|
151
|
+
- lib/click_house/client/response.rb
|
152
|
+
- lib/click_house/client/version.rb
|
153
|
+
homepage: https://gitlab.com/gitlab-org/ruby/gems/clickhouse-client
|
134
154
|
licenses:
|
135
155
|
- MIT
|
136
156
|
metadata: {}
|
@@ -149,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
169
|
- !ruby/object:Gem::Version
|
150
170
|
version: '0'
|
151
171
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
172
|
+
rubygems_version: 3.5.22
|
153
173
|
signing_key:
|
154
174
|
specification_version: 4
|
155
175
|
summary: GitLab's client to interact with ClickHouse
|