click_house 1.5.0 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +4 -28
- data/.rubocop.yml +17 -1
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +51 -37
- data/README.md +38 -35
- data/click_house.gemspec +2 -4
- data/docker-compose.yml +1 -1
- data/lib/click_house/config.rb +3 -1
- data/lib/click_house/connection.rb +6 -6
- data/lib/click_house/extend/connection_selective.rb +3 -3
- data/lib/click_house/response/factory.rb +2 -1
- data/lib/click_house/response/result_set.rb +3 -2
- data/lib/click_house/type/float_type.rb +1 -1
- data/lib/click_house/type/integer_type.rb +1 -1
- data/lib/click_house/util/statement.rb +0 -9
- data/lib/click_house/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a24e10e60cd19671f70f521f6db773ef0d3b0f6f33a9ef40b5a26ed7aaf8106
|
4
|
+
data.tar.gz: 3a948f7381d345f6784a8a125bedbc62ba9df554920cc40eb217699c350cfc02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12af01d64fb80f0fbfff2df8654c79b6574bd09b6159bac8ae9425417a5fc48fbf7ae8bcf2b0e42efc80bd23bc55212f5ba232f187e606b76fb8d6f7193a6976
|
7
|
+
data.tar.gz: 2d819029b2030f25b68a85f623dcbbec497aa9756d6b69d2e223eccdc97ba35ef58299ceea47f45de568cfdd161f09ca75e1635f9bc3176e94de337ae88e4a59
|
data/.github/workflows/main.yml
CHANGED
@@ -8,13 +8,13 @@ jobs:
|
|
8
8
|
|
9
9
|
services:
|
10
10
|
clickhouse:
|
11
|
-
image:
|
11
|
+
image: clickhouse/clickhouse-server:22.6
|
12
12
|
ports:
|
13
13
|
- 8123:8123
|
14
14
|
|
15
15
|
strategy:
|
16
16
|
matrix:
|
17
|
-
ruby-version: [3.0, 2.7, 2.6
|
17
|
+
ruby-version: [3.1, '3.0', 2.7, 2.6]
|
18
18
|
|
19
19
|
steps:
|
20
20
|
- uses: actions/checkout@v2
|
@@ -23,19 +23,7 @@ jobs:
|
|
23
23
|
uses: ruby/setup-ruby@v1
|
24
24
|
with:
|
25
25
|
ruby-version: ${{ matrix.ruby-version }}
|
26
|
-
|
27
|
-
- name: Cache gems
|
28
|
-
uses: actions/cache@v1
|
29
|
-
with:
|
30
|
-
path: vendor/bundle
|
31
|
-
key: ${{ runner.os }}-${{ matrix.ruby-version }}-bundler-${{ hashFiles('**/Gemfile.lock') }}
|
32
|
-
restore-keys: |
|
33
|
-
${{ runner.os }}-${{ matrix.ruby-version }}-bundler-
|
34
|
-
|
35
|
-
- name: Install gems
|
36
|
-
run: |
|
37
|
-
bundle config path vendor/bundle
|
38
|
-
bundle install --jobs 4 --retry 3
|
26
|
+
bundler-cache: true # 'bundle install' and cache
|
39
27
|
|
40
28
|
- name: Run tests
|
41
29
|
run: bundle exec rspec
|
@@ -50,19 +38,7 @@ jobs:
|
|
50
38
|
uses: ruby/setup-ruby@v1
|
51
39
|
with:
|
52
40
|
ruby-version: 2.7
|
53
|
-
|
54
|
-
- name: Cache gems
|
55
|
-
uses: actions/cache@v1
|
56
|
-
with:
|
57
|
-
path: vendor/bundle
|
58
|
-
key: ${{ runner.os }}-bundler-${{ hashFiles('**/Gemfile.lock') }}
|
59
|
-
restore-keys: |
|
60
|
-
${{ runner.os }}-bundler-
|
61
|
-
|
62
|
-
- name: Install gems
|
63
|
-
run: |
|
64
|
-
bundle config path vendor/bundle
|
65
|
-
bundle install --jobs 4 --retry 3
|
41
|
+
bundler-cache: true # 'bundle install' and cache
|
66
42
|
|
67
43
|
- name: Run Rubocop
|
68
44
|
run: bundle exec rubocop
|
data/.rubocop.yml
CHANGED
@@ -50,6 +50,8 @@ Performance/RedundantEqualityComparisonBlock:
|
|
50
50
|
Enabled: true
|
51
51
|
Performance/RedundantSplitRegexpArgument:
|
52
52
|
Enabled: true
|
53
|
+
Performance/MapCompact:
|
54
|
+
Enabled: true
|
53
55
|
|
54
56
|
# ============================== Metrics ============================
|
55
57
|
Metrics/ClassLength:
|
@@ -73,6 +75,8 @@ Naming/MethodParameterName:
|
|
73
75
|
Enabled: false
|
74
76
|
Naming/AccessorMethodName:
|
75
77
|
Enabled: false
|
78
|
+
Naming/InclusiveLanguage:
|
79
|
+
Enabled: true
|
76
80
|
|
77
81
|
# ============================== Layout =============================
|
78
82
|
Layout/LineLength:
|
@@ -111,7 +115,7 @@ Layout/SpaceAroundMethodCallOperator:
|
|
111
115
|
Enabled: true
|
112
116
|
Layout/SpaceBeforeBrackets:
|
113
117
|
Enabled: true
|
114
|
-
|
118
|
+
Layout/LineEndStringConcatenationIndentation:
|
115
119
|
Enabled: true
|
116
120
|
|
117
121
|
# ============================== Style ==============================
|
@@ -235,6 +239,14 @@ Style/HashConversion:
|
|
235
239
|
Enabled: true
|
236
240
|
Style/Documentation:
|
237
241
|
Enabled: false
|
242
|
+
Style/InPatternThen:
|
243
|
+
Enabled: true
|
244
|
+
Style/MultilineInPatternThen:
|
245
|
+
Enabled: true
|
246
|
+
Style/QuotedSymbols:
|
247
|
+
Enabled: true
|
248
|
+
Style/StringChars:
|
249
|
+
Enabled: true
|
238
250
|
|
239
251
|
# ============================== Lint ==============================
|
240
252
|
Lint/DuplicateMethods:
|
@@ -319,3 +331,7 @@ Lint/SymbolConversion:
|
|
319
331
|
Enabled: true
|
320
332
|
Lint/TripleQuotes:
|
321
333
|
Enabled: true
|
334
|
+
Lint/AmbiguousAssignment:
|
335
|
+
Enabled: true
|
336
|
+
Lint/EmptyInPattern:
|
337
|
+
Enabled: true
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# 1.6.2
|
2
|
+
* [PR](https://github.com/shlima/click_house/pull/31) Add rows_before_limit_at_least to ResultSet
|
3
|
+
* [PR](https://github.com/shlima/click_house/pull/29) Force JSON format by using "default_format" instead of modifying the query
|
4
|
+
|
5
|
+
# 1.6.1
|
6
|
+
* [PR](https://github.com/shlima/click_house/pull/26) call logging middleware when an error is raised
|
7
|
+
|
8
|
+
# 1.6.0
|
9
|
+
* [PR](https://github.com/shlima/click_house/pull/19) handle value returned as nil in float and integer types (case of Aggregate Function Combinators)
|
10
|
+
* [PR](https://github.com/shlima/click_house/pull/18) Fix Faraday deprecation
|
11
|
+
|
1
12
|
# 1.5.0
|
2
13
|
* add support for 'WITH TOTALS' modifier in response
|
3
14
|
* send SQL in GET request's body [#12](https://github.com/shlima/click_house/pull/12)
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
click_house (1.
|
5
|
-
faraday
|
4
|
+
click_house (1.6.2)
|
5
|
+
faraday (>= 1.7)
|
6
6
|
faraday_middleware
|
7
7
|
|
8
8
|
GEM
|
@@ -10,60 +10,74 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
ast (2.4.2)
|
12
12
|
coderay (1.1.3)
|
13
|
-
diff-lcs (1.
|
14
|
-
faraday (1.
|
13
|
+
diff-lcs (1.5.0)
|
14
|
+
faraday (1.10.0)
|
15
|
+
faraday-em_http (~> 1.0)
|
16
|
+
faraday-em_synchrony (~> 1.0)
|
15
17
|
faraday-excon (~> 1.1)
|
18
|
+
faraday-httpclient (~> 1.0)
|
19
|
+
faraday-multipart (~> 1.0)
|
16
20
|
faraday-net_http (~> 1.0)
|
17
|
-
faraday-net_http_persistent (~> 1.
|
18
|
-
|
21
|
+
faraday-net_http_persistent (~> 1.0)
|
22
|
+
faraday-patron (~> 1.0)
|
23
|
+
faraday-rack (~> 1.0)
|
24
|
+
faraday-retry (~> 1.0)
|
19
25
|
ruby2_keywords (>= 0.0.4)
|
26
|
+
faraday-em_http (1.0.0)
|
27
|
+
faraday-em_synchrony (1.0.0)
|
20
28
|
faraday-excon (1.1.0)
|
29
|
+
faraday-httpclient (1.0.1)
|
30
|
+
faraday-multipart (1.0.4)
|
31
|
+
multipart-post (~> 2)
|
21
32
|
faraday-net_http (1.0.1)
|
22
|
-
faraday-net_http_persistent (1.
|
23
|
-
|
33
|
+
faraday-net_http_persistent (1.2.0)
|
34
|
+
faraday-patron (1.0.0)
|
35
|
+
faraday-rack (1.0.0)
|
36
|
+
faraday-retry (1.0.3)
|
37
|
+
faraday_middleware (1.2.0)
|
24
38
|
faraday (~> 1.0)
|
25
39
|
method_source (1.0.0)
|
26
|
-
multipart-post (2.
|
27
|
-
parallel (1.
|
28
|
-
parser (3.
|
40
|
+
multipart-post (2.2.3)
|
41
|
+
parallel (1.22.1)
|
42
|
+
parser (3.1.1.0)
|
29
43
|
ast (~> 2.4.1)
|
30
|
-
pry (0.14.
|
44
|
+
pry (0.14.1)
|
31
45
|
coderay (~> 1.1)
|
32
46
|
method_source (~> 1.0)
|
33
|
-
rainbow (3.
|
34
|
-
rake (13.0.
|
35
|
-
regexp_parser (2.
|
36
|
-
rexml (3.2.
|
37
|
-
rspec (3.
|
38
|
-
rspec-core (~> 3.
|
39
|
-
rspec-expectations (~> 3.
|
40
|
-
rspec-mocks (~> 3.
|
41
|
-
rspec-core (3.
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-expectations (3.
|
47
|
+
rainbow (3.1.1)
|
48
|
+
rake (13.0.6)
|
49
|
+
regexp_parser (2.2.1)
|
50
|
+
rexml (3.2.5)
|
51
|
+
rspec (3.11.0)
|
52
|
+
rspec-core (~> 3.11.0)
|
53
|
+
rspec-expectations (~> 3.11.0)
|
54
|
+
rspec-mocks (~> 3.11.0)
|
55
|
+
rspec-core (3.11.0)
|
56
|
+
rspec-support (~> 3.11.0)
|
57
|
+
rspec-expectations (3.11.0)
|
44
58
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.
|
46
|
-
rspec-mocks (3.
|
59
|
+
rspec-support (~> 3.11.0)
|
60
|
+
rspec-mocks (3.11.1)
|
47
61
|
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
-
rspec-support (~> 3.
|
49
|
-
rspec-support (3.
|
50
|
-
rubocop (1.
|
62
|
+
rspec-support (~> 3.11.0)
|
63
|
+
rspec-support (3.11.0)
|
64
|
+
rubocop (1.26.1)
|
51
65
|
parallel (~> 1.10)
|
52
|
-
parser (>= 3.
|
66
|
+
parser (>= 3.1.0.0)
|
53
67
|
rainbow (>= 2.2.2, < 4.0)
|
54
68
|
regexp_parser (>= 1.8, < 3.0)
|
55
69
|
rexml
|
56
|
-
rubocop-ast (>= 1.
|
70
|
+
rubocop-ast (>= 1.16.0, < 2.0)
|
57
71
|
ruby-progressbar (~> 1.7)
|
58
72
|
unicode-display_width (>= 1.4.0, < 3.0)
|
59
|
-
rubocop-ast (1.
|
60
|
-
parser (>=
|
61
|
-
rubocop-performance (1.
|
62
|
-
rubocop (>=
|
73
|
+
rubocop-ast (1.16.0)
|
74
|
+
parser (>= 3.1.1.0)
|
75
|
+
rubocop-performance (1.13.3)
|
76
|
+
rubocop (>= 1.7.0, < 2.0)
|
63
77
|
rubocop-ast (>= 0.4.0)
|
64
78
|
ruby-progressbar (1.11.0)
|
65
|
-
ruby2_keywords (0.0.
|
66
|
-
unicode-display_width (2.
|
79
|
+
ruby2_keywords (0.0.5)
|
80
|
+
unicode-display_width (2.1.0)
|
67
81
|
|
68
82
|
PLATFORMS
|
69
83
|
ruby
|
@@ -78,4 +92,4 @@ DEPENDENCIES
|
|
78
92
|
rubocop-performance
|
79
93
|
|
80
94
|
BUNDLED WITH
|
81
|
-
2.
|
95
|
+
2.3.3
|
data/README.md
CHANGED
@@ -10,8 +10,8 @@
|
|
10
10
|
gem install click_house
|
11
11
|
```
|
12
12
|
|
13
|
-
A modern Ruby database driver for ClickHouse. [ClickHouse](https://clickhouse.yandex)
|
14
|
-
is a high-performance column-oriented database management system developed by
|
13
|
+
A modern Ruby database driver for ClickHouse. [ClickHouse](https://clickhouse.yandex)
|
14
|
+
is a high-performance column-oriented database management system developed by
|
15
15
|
[Yandex](https://yandex.com/company) which operates Russia's most popular search engine.
|
16
16
|
|
17
17
|
> This development was inspired by currently [unmaintainable alternative](https://github.com/archan937/clickhouse)
|
@@ -24,7 +24,7 @@ Well, the developers of ClickHouse themselves [discourage](https://github.com/ya
|
|
24
24
|
> TCP transport is more specific, we don't want to expose details.
|
25
25
|
Despite we have full compatibility of protocol of different versions of client and server, we want to keep the ability to "break" it for very old clients. And that protocol is not too clean to make a specification.
|
26
26
|
|
27
|
-
Yandex uses HTTP interface for working from Java and Perl, Python and Go as well as shell scripts.
|
27
|
+
Yandex uses HTTP interface for working from Java and Perl, Python and Go as well as shell scripts.
|
28
28
|
|
29
29
|
# TOC
|
30
30
|
|
@@ -53,15 +53,18 @@ ClickHouse.config do |config|
|
|
53
53
|
config.open_timeout = 3
|
54
54
|
config.ssl_verify = false
|
55
55
|
config.headers = {}
|
56
|
-
|
56
|
+
|
57
57
|
# or provide connection options separately
|
58
|
-
config.scheme = 'http'
|
59
|
-
config.host = 'localhost'
|
60
|
-
config.port = 'port'
|
61
|
-
|
58
|
+
config.scheme = 'http'
|
59
|
+
config.host = 'localhost'
|
60
|
+
config.port = 'port'
|
61
|
+
|
62
62
|
# if you use HTTP basic Auth
|
63
|
-
config.username = 'user'
|
64
|
-
config.password = 'password'
|
63
|
+
config.username = 'user'
|
64
|
+
config.password = 'password'
|
65
|
+
|
66
|
+
# if you want to add settings to all queries
|
67
|
+
config.global_params = { mutations_sync: 1 }
|
65
68
|
end
|
66
69
|
```
|
67
70
|
|
@@ -76,7 +79,7 @@ Now you are able to communicate with ClickHouse:
|
|
76
79
|
```ruby
|
77
80
|
ClickHouse.connection.ping #=> true
|
78
81
|
```
|
79
|
-
You can easily build a new raw connection and override any configuration parameter
|
82
|
+
You can easily build a new raw connection and override any configuration parameter
|
80
83
|
(such as database name, connection address)
|
81
84
|
|
82
85
|
```ruby
|
@@ -126,8 +129,8 @@ Select all type-casted result set
|
|
126
129
|
@result.to_a #=> [{"date"=>#<Date: 2000-01-01>, "id"=>1}]
|
127
130
|
|
128
131
|
# you can access raw data
|
129
|
-
@result.meta #=> [{"name"=>"date", "type"=>"Date"}, {"name"=>"id", "type"=>"UInt32"}]
|
130
|
-
@result.data #=> [{"date"=>"2000-01-01", "id"=>1}, {"date"=>"2000-01-02", "id"=>2}]
|
132
|
+
@result.meta #=> [{"name"=>"date", "type"=>"Date"}, {"name"=>"id", "type"=>"UInt32"}]
|
133
|
+
@result.data #=> [{"date"=>"2000-01-01", "id"=>1}, {"date"=>"2000-01-02", "id"=>2}]
|
131
134
|
@result.statistics #=> {"elapsed"=>0.0002271, "rows_read"=>2, "bytes_read"=>12}
|
132
135
|
```
|
133
136
|
|
@@ -182,7 +185,7 @@ response = ClickHouse.connection.execute <<~SQL
|
|
182
185
|
SELECT count(*) AS counter FROM rspec FORMAT RowBinary
|
183
186
|
SQL
|
184
187
|
|
185
|
-
response.body #=> "\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
|
188
|
+
response.body #=> "\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
|
186
189
|
```
|
187
190
|
|
188
191
|
## Insert
|
@@ -193,7 +196,7 @@ When column names and values are transferred separately
|
|
193
196
|
ClickHouse.connection.insert('table', columns: %i[id name]) do |buffer|
|
194
197
|
buffer << [1, 'Mercury']
|
195
198
|
buffer << [2, 'Venus']
|
196
|
-
end
|
199
|
+
end
|
197
200
|
|
198
201
|
ClickHouse.connection.insert('table', columns: %i[id name], values: [[1, 'Mercury'], [2, 'Venus']])
|
199
202
|
#=> true
|
@@ -272,7 +275,7 @@ end
|
|
272
275
|
### Set table options
|
273
276
|
|
274
277
|
```ruby
|
275
|
-
ClickHouse.connection.create_table('visits',
|
278
|
+
ClickHouse.connection.create_table('visits',
|
276
279
|
order: 'year',
|
277
280
|
ttl: 'date + INTERVAL 1 DAY',
|
278
281
|
sample: 'year',
|
@@ -308,24 +311,24 @@ ClickHouse.connection.modify_column('table', 'column_name', type: :UInt64, defau
|
|
308
311
|
ClickHouse.connection.alter_table('table', 'DROP COLUMN user_id', cluster: nil)
|
309
312
|
|
310
313
|
# By SQL in a block
|
311
|
-
ClickHouse.connection.alter_table('table', cluster: nil) do
|
314
|
+
ClickHouse.connection.alter_table('table', cluster: nil) do
|
312
315
|
<<~SQL
|
313
316
|
MOVE PART '20190301_14343_16206_438' TO VOLUME 'slow'
|
314
|
-
SQL
|
317
|
+
SQL
|
315
318
|
end
|
316
319
|
```
|
317
320
|
|
318
321
|
## Type casting
|
319
322
|
|
320
323
|
By default gem provides all necessary type casting, but you may overwrite or define
|
321
|
-
your own logic
|
324
|
+
your own logic
|
322
325
|
|
323
326
|
```ruby
|
324
327
|
class DateType
|
325
328
|
def cast(value)
|
326
329
|
Date.parse(value)
|
327
|
-
end
|
328
|
-
|
330
|
+
end
|
331
|
+
|
329
332
|
def serialize(value)
|
330
333
|
value.strftime('%Y-%m-%d')
|
331
334
|
end
|
@@ -338,7 +341,7 @@ Actually `serialize` function is not used for now, but you may use it manually:
|
|
338
341
|
|
339
342
|
```ruby
|
340
343
|
time_type = ClickHouse::Type::DateTimeType.new
|
341
|
-
string_type = ClickHouse::Type::FixedStringType.new
|
344
|
+
string_type = ClickHouse::Type::FixedStringType.new
|
342
345
|
|
343
346
|
ClickHouse.connection.insert('table', columns: %i[name time]) do |buffer|
|
344
347
|
buffer << [string_type.serialize('a' * 1000, 20), time_type.serialize(Time.current, 'Europe/Moscow')]
|
@@ -353,20 +356,20 @@ data = @records.map do |record|
|
|
353
356
|
end
|
354
357
|
```
|
355
358
|
|
356
|
-
If native type supports arguments, define *String* type with `%s`
|
359
|
+
If native type supports arguments, define *String* type with `%s`
|
357
360
|
argument and *Numeric* type with `%d` argument:
|
358
361
|
|
359
362
|
```ruby
|
360
363
|
class DateTimeType
|
361
364
|
def cast(value, time_zone)
|
362
365
|
Time.parse("#{value} #{time_zone}")
|
363
|
-
end
|
366
|
+
end
|
364
367
|
end
|
365
368
|
|
366
369
|
ClickHouse.add_type('DateTime(%s)', DateTimeType.new)
|
367
370
|
```
|
368
371
|
|
369
|
-
if you need to redefine all built-in types with your implementation,
|
372
|
+
if you need to redefine all built-in types with your implementation,
|
370
373
|
just clear the default type system:
|
371
374
|
|
372
375
|
```ruby
|
@@ -406,7 +409,7 @@ development:
|
|
406
409
|
test:
|
407
410
|
database: ecliptic_test
|
408
411
|
<<: *default
|
409
|
-
|
412
|
+
|
410
413
|
production:
|
411
414
|
<<: *default
|
412
415
|
database: ecliptic_production
|
@@ -418,7 +421,7 @@ production:
|
|
418
421
|
ClickHouse.config do |config|
|
419
422
|
config.logger = Rails.logger
|
420
423
|
config.assign(Rails.application.config_for('click_house'))
|
421
|
-
end
|
424
|
+
end
|
422
425
|
```
|
423
426
|
|
424
427
|
```ruby
|
@@ -465,7 +468,7 @@ class CreateAdvertVisits < ActiveRecord::Migration[6.0]
|
|
465
468
|
end
|
466
469
|
end
|
467
470
|
|
468
|
-
def down
|
471
|
+
def down
|
469
472
|
ClickHouse.connection.drop_table('visits')
|
470
473
|
end
|
471
474
|
end
|
@@ -509,7 +512,7 @@ end
|
|
509
512
|
````
|
510
513
|
|
511
514
|
````ruby
|
512
|
-
# FAKE MODEL FOR ClickHouse
|
515
|
+
# FAKE MODEL FOR ClickHouse
|
513
516
|
class Visit < ClickHouseRecord
|
514
517
|
scope :with_os, -> { where.not(os_family_id: nil) }
|
515
518
|
end
|
@@ -517,12 +520,12 @@ end
|
|
517
520
|
Visit.with_os.select('COUNT(*) as counter').group(:ipv4).select_all
|
518
521
|
#=> [{ 'ipv4' => 1455869, 'counter' => 104 }]
|
519
522
|
|
520
|
-
Visit.with_os.select('COUNT(*)').select_value
|
523
|
+
Visit.with_os.select('COUNT(*)').select_value
|
521
524
|
#=> 20_345_678
|
522
|
-
|
523
|
-
Visit.where(user_id: 1).select_one
|
524
|
-
#=> { 'ipv4' => 1455869, 'user_id' => 1 }
|
525
|
-
````
|
525
|
+
|
526
|
+
Visit.where(user_id: 1).select_one
|
527
|
+
#=> { 'ipv4' => 1455869, 'user_id' => 1 }
|
528
|
+
````
|
526
529
|
|
527
530
|
## Using with RSpec
|
528
531
|
|
@@ -537,7 +540,7 @@ end
|
|
537
540
|
```
|
538
541
|
|
539
542
|
```ruby
|
540
|
-
RSpec.describe Api::MetricsCountroller, truncate_click_house: true do
|
543
|
+
RSpec.describe Api::MetricsCountroller, truncate_click_house: true do
|
541
544
|
it { }
|
542
545
|
it { }
|
543
546
|
end
|
data/click_house.gemspec
CHANGED
@@ -10,18 +10,16 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.summary = 'Modern Ruby database driver for ClickHouse'
|
11
11
|
spec.description = 'Yandex ClickHouse database interface for Ruby'
|
12
12
|
spec.homepage = 'https://github.com/shlima/click_house'
|
13
|
-
spec.required_ruby_version = '>= 2.
|
13
|
+
spec.required_ruby_version = '>= 2.6.0'
|
14
14
|
|
15
15
|
# Specify which files should be added to the gem when it is released.
|
16
16
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
17
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
18
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
19
|
end
|
20
|
-
spec.bindir = 'exe'
|
21
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
20
|
spec.require_paths = ['lib']
|
23
21
|
|
24
|
-
spec.add_dependency 'faraday'
|
22
|
+
spec.add_dependency 'faraday', '>= 1.7'
|
25
23
|
spec.add_dependency 'faraday_middleware'
|
26
24
|
spec.add_development_dependency 'bundler'
|
27
25
|
spec.add_development_dependency 'rake'
|
data/docker-compose.yml
CHANGED
data/lib/click_house/config.rb
CHANGED
@@ -15,7 +15,8 @@ module ClickHouse
|
|
15
15
|
timeout: nil,
|
16
16
|
open_timeout: nil,
|
17
17
|
ssl_verify: false,
|
18
|
-
headers: {}
|
18
|
+
headers: {},
|
19
|
+
global_params: {}
|
19
20
|
}.freeze
|
20
21
|
|
21
22
|
attr_accessor :adapter
|
@@ -31,6 +32,7 @@ module ClickHouse
|
|
31
32
|
attr_accessor :open_timeout
|
32
33
|
attr_accessor :ssl_verify
|
33
34
|
attr_accessor :headers
|
35
|
+
attr_accessor :global_params
|
34
36
|
|
35
37
|
def initialize(params = {})
|
36
38
|
assign(DEFAULTS.merge(params))
|
@@ -17,8 +17,8 @@ module ClickHouse
|
|
17
17
|
@config = config
|
18
18
|
end
|
19
19
|
|
20
|
-
def execute(query, body = nil, database: config.database)
|
21
|
-
post(body, query: { query: query }, database: database)
|
20
|
+
def execute(query, body = nil, database: config.database, params: {})
|
21
|
+
post(body, query: { query: query }, database: database, params: config.global_params.merge(params))
|
22
22
|
end
|
23
23
|
|
24
24
|
# @param path [String] Clickhouse HTTP endpoint, e.g. /ping, /replica_status
|
@@ -42,8 +42,8 @@ module ClickHouse
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def post(body = nil, query: {}, database: config.database)
|
46
|
-
transport.post(compose('/', query.merge(database: database)), body)
|
45
|
+
def post(body = nil, query: {}, database: config.database, params: {})
|
46
|
+
transport.post(compose('/', query.merge(database: database, **params)), body)
|
47
47
|
end
|
48
48
|
|
49
49
|
def transport
|
@@ -52,9 +52,9 @@ module ClickHouse
|
|
52
52
|
conn.options.open_timeout = config.open_timeout
|
53
53
|
conn.headers = config.headers
|
54
54
|
conn.ssl.verify = config.ssl_verify
|
55
|
-
conn.basic_auth
|
56
|
-
conn.response Middleware::Logging, logger: config.logger!
|
55
|
+
conn.request(:basic_auth, config.username, config.password) if config.auth?
|
57
56
|
conn.response Middleware::RaiseError
|
57
|
+
conn.response Middleware::Logging, logger: config.logger!
|
58
58
|
conn.response :json, content_type: %r{application/json}
|
59
59
|
conn.response Middleware::ParseCsv, content_type: %r{text/csv}
|
60
60
|
conn.adapter config.adapter
|
@@ -5,17 +5,17 @@ module ClickHouse
|
|
5
5
|
module ConnectionSelective
|
6
6
|
# @return [ResultSet]
|
7
7
|
def select_all(sql)
|
8
|
-
response = get(body:
|
8
|
+
response = get(body: sql, query: { default_format: 'JSON' })
|
9
9
|
Response::Factory[response]
|
10
10
|
end
|
11
11
|
|
12
12
|
def select_value(sql)
|
13
|
-
response = get(body:
|
13
|
+
response = get(body: sql, query: { default_format: 'JSON' })
|
14
14
|
Array(Response::Factory[response].first).dig(0, -1)
|
15
15
|
end
|
16
16
|
|
17
17
|
def select_one(sql)
|
18
|
-
response = get(body:
|
18
|
+
response = get(body: sql, query: { default_format: 'JSON' })
|
19
19
|
Response::Factory[response].first
|
20
20
|
end
|
21
21
|
end
|
@@ -14,7 +14,7 @@ module ClickHouse
|
|
14
14
|
:inspect, :each, :fetch, :length, :count, :size,
|
15
15
|
:first, :last, :[], :to_h
|
16
16
|
|
17
|
-
attr_reader :meta, :data, :totals, :statistics
|
17
|
+
attr_reader :meta, :data, :totals, :statistics, :rows_before_limit_at_least
|
18
18
|
|
19
19
|
class << self
|
20
20
|
# @return [Array<String, Array>]
|
@@ -51,10 +51,11 @@ module ClickHouse
|
|
51
51
|
# @param totals [Array|Hash|NilClass] Support for 'GROUP BY WITH TOTALS' modifier
|
52
52
|
# https://clickhouse.tech/docs/en/sql-reference/statements/select/group-by/#with-totals-modifier
|
53
53
|
# Hash in JSON format and Array in JSONCompact
|
54
|
-
def initialize(meta:, data:, totals: nil, statistics: nil)
|
54
|
+
def initialize(meta:, data:, totals: nil, statistics: nil, rows_before_limit_at_least: nil)
|
55
55
|
@meta = meta
|
56
56
|
@data = data
|
57
57
|
@totals = totals
|
58
|
+
@rows_before_limit_at_least = rows_before_limit_at_least
|
58
59
|
@statistics = Hash(statistics)
|
59
60
|
end
|
60
61
|
|
@@ -3,20 +3,11 @@
|
|
3
3
|
module ClickHouse
|
4
4
|
module Util
|
5
5
|
module Statement
|
6
|
-
END_OF_STATEMENT = ';'
|
7
|
-
END_OF_STATEMENT_RE = /#{END_OF_STATEMENT}(\s+|\Z)/.freeze
|
8
|
-
|
9
6
|
module_function
|
10
7
|
|
11
8
|
def ensure(truthful, value, fallback = nil)
|
12
9
|
truthful ? value : fallback
|
13
10
|
end
|
14
|
-
|
15
|
-
def format(sql, format)
|
16
|
-
return sql if sql.match?(/FORMAT/i)
|
17
|
-
|
18
|
-
"#{sql.sub(END_OF_STATEMENT_RE, '')} FORMAT #{format};"
|
19
|
-
end
|
20
11
|
end
|
21
12
|
end
|
22
13
|
end
|
data/lib/click_house/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: click_house
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aliaksandr Shylau
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday_middleware
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,14 +203,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
203
203
|
requirements:
|
204
204
|
- - ">="
|
205
205
|
- !ruby/object:Gem::Version
|
206
|
-
version: 2.
|
206
|
+
version: 2.6.0
|
207
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
208
|
requirements:
|
209
209
|
- - ">="
|
210
210
|
- !ruby/object:Gem::Version
|
211
211
|
version: '0'
|
212
212
|
requirements: []
|
213
|
-
rubygems_version: 3.
|
213
|
+
rubygems_version: 3.3.7
|
214
214
|
signing_key:
|
215
215
|
specification_version: 4
|
216
216
|
summary: Modern Ruby database driver for ClickHouse
|