click_house 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 402590e2de7189b46fca70711b33bf8428ccbc677d8d98ad4205b470bcf5eeb4
4
- data.tar.gz: b3a33602650115c46c638347b993d118921e7254a2ed9f20bdb92ad30c50a05a
3
+ metadata.gz: 85fbf603cf09ee0a076a3ca0fa0add17c167919c458008a5616a4a7b064b0790
4
+ data.tar.gz: 95cf0f595c70a2943bba62a0d8568b4f432b3fdf27365b036377a66960733efe
5
5
  SHA512:
6
- metadata.gz: 4d71565e61efb57711463fa3b4071d418ad8136656d64e3de15fbb7f4b48134ab284e9b2dc13b0dcbdf77dd9bee19aa4757593b0dee98480ac6cd64cc4e85a5f
7
- data.tar.gz: c2d45bd01a211acfb8be077d38ac93807c191c95a3a6fe2a6ac63a7a097b5c599351f0c6282b86d533eff2dd59d2820c0f824ffd975d0cd6692636eb0bb31e48
6
+ metadata.gz: 8a31451c3ed68aa5ff213cabaa51578723212fe43d0e63a1b58a1d68b135facece27f2d52025512d41862ba7495dcd05972f3a9cd8a4d01cc25916e2e502f42b
7
+ data.tar.gz: 0d78cbad863fcb89e8d58da4c10eeec60013877c5097480c0e6bc190c9698641f5ac95c116bd3b938f7ce927aa58ad10abae73729ce579149d40a51e529320c7
@@ -14,7 +14,7 @@ jobs:
14
14
 
15
15
  strategy:
16
16
  matrix:
17
- ruby-version: [3.1, 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/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 1.6.1
2
+ * [PR](https://github.com/shlima/click_house/pull/26) call logging middleware when an error is raised
3
+
1
4
  # 1.6.0
2
5
  * [PR](https://github.com/shlima/click_house/pull/19) handle value returned as nil in float and integer types (case of Aggregate Function Combinators)
3
6
  * [PR](https://github.com/shlima/click_house/pull/18) Fix Faraday deprecation
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- click_house (1.5.0)
4
+ click_house (1.6.1)
5
5
  faraday (>= 1.7)
6
6
  faraday_middleware
7
7
 
@@ -11,7 +11,7 @@ GEM
11
11
  ast (2.4.2)
12
12
  coderay (1.1.3)
13
13
  diff-lcs (1.5.0)
14
- faraday (1.9.3)
14
+ faraday (1.10.0)
15
15
  faraday-em_http (~> 1.0)
16
16
  faraday-em_synchrony (~> 1.0)
17
17
  faraday-excon (~> 1.1)
@@ -38,41 +38,41 @@ GEM
38
38
  faraday (~> 1.0)
39
39
  method_source (1.0.0)
40
40
  multipart-post (2.1.1)
41
- parallel (1.21.0)
42
- parser (3.1.0.0)
41
+ parallel (1.22.1)
42
+ parser (3.1.1.0)
43
43
  ast (~> 2.4.1)
44
44
  pry (0.14.1)
45
45
  coderay (~> 1.1)
46
46
  method_source (~> 1.0)
47
47
  rainbow (3.1.1)
48
48
  rake (13.0.6)
49
- regexp_parser (2.2.0)
49
+ regexp_parser (2.2.1)
50
50
  rexml (3.2.5)
51
- rspec (3.10.0)
52
- rspec-core (~> 3.10.0)
53
- rspec-expectations (~> 3.10.0)
54
- rspec-mocks (~> 3.10.0)
55
- rspec-core (3.10.1)
56
- rspec-support (~> 3.10.0)
57
- rspec-expectations (3.10.2)
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)
58
58
  diff-lcs (>= 1.2.0, < 2.0)
59
- rspec-support (~> 3.10.0)
60
- rspec-mocks (3.10.2)
59
+ rspec-support (~> 3.11.0)
60
+ rspec-mocks (3.11.1)
61
61
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.10.0)
63
- rspec-support (3.10.3)
64
- rubocop (1.25.0)
62
+ rspec-support (~> 3.11.0)
63
+ rspec-support (3.11.0)
64
+ rubocop (1.26.1)
65
65
  parallel (~> 1.10)
66
66
  parser (>= 3.1.0.0)
67
67
  rainbow (>= 2.2.2, < 4.0)
68
68
  regexp_parser (>= 1.8, < 3.0)
69
69
  rexml
70
- rubocop-ast (>= 1.15.1, < 2.0)
70
+ rubocop-ast (>= 1.16.0, < 2.0)
71
71
  ruby-progressbar (~> 1.7)
72
72
  unicode-display_width (>= 1.4.0, < 3.0)
73
- rubocop-ast (1.15.1)
74
- parser (>= 3.0.1.1)
75
- rubocop-performance (1.13.2)
73
+ rubocop-ast (1.16.0)
74
+ parser (>= 3.1.1.0)
75
+ rubocop-performance (1.13.3)
76
76
  rubocop (>= 1.7.0, < 2.0)
77
77
  rubocop-ast (>= 0.4.0)
78
78
  ruby-progressbar (1.11.0)
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
@@ -17,8 +17,6 @@ Gem::Specification.new do |spec|
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
22
  spec.add_dependency 'faraday', '>= 1.7'
@@ -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
@@ -53,8 +53,8 @@ module ClickHouse
53
53
  conn.headers = config.headers
54
54
  conn.ssl.verify = config.ssl_verify
55
55
  conn.request(:basic_auth, config.username, config.password) if config.auth?
56
- conn.response Middleware::Logging, logger: config.logger!
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClickHouse
4
- VERSION = '1.6.0'
4
+ VERSION = '1.6.1'
5
5
  end
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.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aliaksandr Shylau
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-21 00:00:00.000000000 Z
11
+ date: 2022-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  - !ruby/object:Gem::Version
211
211
  version: '0'
212
212
  requirements: []
213
- rubygems_version: 3.3.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