click_house 1.3.5 → 1.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd545a5ce410be500540a02ef1f46e57b9a7a2dfe2df8b5be47022ac2cd1f5b4
4
- data.tar.gz: 19b872a4901d7543ddf7fbb23ca53ac8f6731023b74ae5af24a52aac4b054fc3
3
+ metadata.gz: '095426f805a20574d725842799b3e09368ef4239bf8a262d4ca061ef7689cedd'
4
+ data.tar.gz: 77098569ba1c05b236bc6b68118116c63985c1cc91bc49cdc5ae49c2550459f6
5
5
  SHA512:
6
- metadata.gz: 6ad04e10ecb7acce32f3c18225b62aad8b83ef79f46e176678bbaadf0b274e8b0cefbe72c678e7ba9d047a22d98912a4de2e89b73957b721731e3666caf3850c
7
- data.tar.gz: 0155f69f8faf71b9fbf95a1d32f04dce4c3eb2a9b43752aac786ee29a3f0db882afd85c1e44178e366938a18053f99eead8d247267d53a49f6dffd63ac0223f5
6
+ metadata.gz: a71819d5ea5c61bf85907501e9b80ca713dc3e78e97a066a9f3e8fb1713dfc0a81b91aef0b12c51389afad53c518ccca913544be0f44d60182d02ecb722e0e1c
7
+ data.tar.gz: 95fb2a123492cb6f816ed4c8b1984ec1ba21b1784eceb489543081616ad5d0a5947d56623be63c7e8d5f4586977f4c2999a0bb8c229d20519e8d1f8fc2365749
@@ -8,13 +8,13 @@ jobs:
8
8
 
9
9
  services:
10
10
  clickhouse:
11
- image: yandex/clickhouse-server:20.11.4.13
11
+ image: yandex/clickhouse-server:21.1.4
12
12
  ports:
13
13
  - 8123:8123
14
14
 
15
15
  strategy:
16
16
  matrix:
17
- ruby-version: [2.7, 2.6, 2.5]
17
+ ruby-version: [3.0, 2.7, 2.6, 2.5, 2.4]
18
18
 
19
19
  steps:
20
20
  - uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -54,8 +54,6 @@ Metrics/BlockLength:
54
54
  Enabled: true
55
55
  Metrics/MethodLength:
56
56
  Max: 25
57
- Metrics/LineLength:
58
- Max: 140
59
57
  Metrics/AbcSize:
60
58
  Max: 40
61
59
 
@@ -73,6 +71,8 @@ Naming/AccessorMethodName:
73
71
  Enabled: false
74
72
 
75
73
  # ============================== Layout =============================
74
+ Layout/LineLength:
75
+ Max: 140
76
76
  Layout/HashAlignment:
77
77
  EnforcedHashRocketStyle: key
78
78
  EnforcedColonStyle: key
@@ -105,6 +105,10 @@ Layout/EmptyLinesAroundAttributeAccessor:
105
105
  Enabled: true
106
106
  Layout/SpaceAroundMethodCallOperator:
107
107
  Enabled: true
108
+ Layout/SpaceBeforeBrackets:
109
+ Enabled: true
110
+ Lint/AmbiguousAssignment:
111
+ Enabled: true
108
112
 
109
113
  # ============================== Style ==============================
110
114
  Style/RescueModifier:
@@ -217,6 +221,12 @@ Style/SwapValues:
217
221
  Enabled: true
218
222
  Style/RedundantArgument:
219
223
  Enabled: true
224
+ Style/HashExcept:
225
+ Enabled: true
226
+ Style/EndlessMethod:
227
+ Enabled: true
228
+ Style/IfWithBooleanLiteralBranches:
229
+ Enabled: true
220
230
 
221
231
  # ============================== Lint ==============================
222
232
  Lint/DuplicateMethods:
@@ -287,3 +297,17 @@ Lint/UnmodifiedReduceAccumulator:
287
297
  Enabled: true
288
298
  Lint/UnexpectedBlockArity:
289
299
  Enabled: true
300
+ Lint/DeprecatedConstants:
301
+ Enabled: true
302
+ Lint/LambdaWithoutLiteralBlock:
303
+ Enabled: true
304
+ Lint/NumberedParameterAssignment:
305
+ Enabled: true
306
+ Lint/OrAssignmentToConstant:
307
+ Enabled: true
308
+ Lint/RedundantDirGlobSort:
309
+ Enabled: true
310
+ Lint/SymbolConversion:
311
+ Enabled: true
312
+ Lint/TripleQuotes:
313
+ Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
+ # 1.4.0
2
+ * fizx decimal type casting [#11](https://github.com/shlima/click_house/issues/11)
3
+
4
+ # 1.3.9
5
+ * add `ClickHouse.connection.add_index`, `ClickHouse.connection.drop_index`
6
+
7
+ # 1.3.8
8
+ * fix `DateTime` casting for queries like `ClickHouse.connection.select_value('select NOW()')`
9
+ * fix resulting set console inspection
10
+
11
+ # 1.3.7
12
+ * specify required ruby version [#10](https://github.com/shlima/click_house/issues/10)
13
+
14
+ # 1.3.6
15
+ * fix ruby 2.7 warning `maybe ** should be added to the call` on `ClickHouse.connection.databases`
16
+
1
17
  # 1.3.5
2
- * added `ClickHouse.connexction.explain("sql")`
18
+ * added `ClickHouse.connection.explain("sql")`
3
19
 
4
20
  # 1.3.4
5
21
  * added `ClickHouse.type_names(nullable: false)`
data/Gemfile.lock CHANGED
@@ -1,63 +1,65 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- click_house (1.3.5)
4
+ click_house (1.4.0)
5
5
  faraday
6
6
  faraday_middleware
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- ast (2.4.1)
11
+ ast (2.4.2)
12
12
  coderay (1.1.3)
13
13
  diff-lcs (1.4.4)
14
- faraday (1.1.0)
14
+ faraday (1.3.0)
15
+ faraday-net_http (~> 1.0)
15
16
  multipart-post (>= 1.2, < 3)
16
17
  ruby2_keywords
18
+ faraday-net_http (1.0.1)
17
19
  faraday_middleware (1.0.0)
18
20
  faraday (~> 1.0)
19
21
  method_source (1.0.0)
20
22
  multipart-post (2.1.1)
21
23
  parallel (1.20.1)
22
- parser (2.7.2.0)
24
+ parser (3.0.0.0)
23
25
  ast (~> 2.4.1)
24
- pry (0.13.1)
26
+ pry (0.14.0)
25
27
  coderay (~> 1.1)
26
28
  method_source (~> 1.0)
27
29
  rainbow (3.0.0)
28
- rake (13.0.1)
29
- regexp_parser (2.0.0)
30
+ rake (13.0.3)
31
+ regexp_parser (2.0.3)
30
32
  rexml (3.2.4)
31
33
  rspec (3.10.0)
32
34
  rspec-core (~> 3.10.0)
33
35
  rspec-expectations (~> 3.10.0)
34
36
  rspec-mocks (~> 3.10.0)
35
- rspec-core (3.10.0)
37
+ rspec-core (3.10.1)
36
38
  rspec-support (~> 3.10.0)
37
- rspec-expectations (3.10.0)
39
+ rspec-expectations (3.10.1)
38
40
  diff-lcs (>= 1.2.0, < 2.0)
39
41
  rspec-support (~> 3.10.0)
40
- rspec-mocks (3.10.0)
42
+ rspec-mocks (3.10.2)
41
43
  diff-lcs (>= 1.2.0, < 2.0)
42
44
  rspec-support (~> 3.10.0)
43
- rspec-support (3.10.0)
44
- rubocop (1.5.2)
45
+ rspec-support (3.10.2)
46
+ rubocop (1.9.1)
45
47
  parallel (~> 1.10)
46
- parser (>= 2.7.1.5)
48
+ parser (>= 3.0.0.0)
47
49
  rainbow (>= 2.2.2, < 4.0)
48
50
  regexp_parser (>= 1.8, < 3.0)
49
51
  rexml
50
52
  rubocop-ast (>= 1.2.0, < 2.0)
51
53
  ruby-progressbar (~> 1.7)
52
- unicode-display_width (>= 1.4.0, < 2.0)
53
- rubocop-ast (1.3.0)
54
+ unicode-display_width (>= 1.4.0, < 3.0)
55
+ rubocop-ast (1.4.1)
54
56
  parser (>= 2.7.1.5)
55
- rubocop-performance (1.9.1)
57
+ rubocop-performance (1.9.2)
56
58
  rubocop (>= 0.90.0, < 2.0)
57
59
  rubocop-ast (>= 0.4.0)
58
- ruby-progressbar (1.10.1)
59
- ruby2_keywords (0.0.2)
60
- unicode-display_width (1.7.0)
60
+ ruby-progressbar (1.11.0)
61
+ ruby2_keywords (0.0.4)
62
+ unicode-display_width (2.0.0)
61
63
 
62
64
  PLATFORMS
63
65
  ruby
@@ -72,4 +74,4 @@ DEPENDENCIES
72
74
  rubocop-performance
73
75
 
74
76
  BUNDLED WITH
75
- 2.1.4
77
+ 2.2.3
data/README.md CHANGED
@@ -7,7 +7,6 @@
7
7
  [![Gem Version](https://badge.fury.io/rb/click_house.svg)](https://badge.fury.io/rb/click_house)
8
8
 
9
9
  ```bash
10
- # Requires Ruby >= 2.5
11
10
  gem install click_house
12
11
  ```
13
12
 
@@ -105,6 +104,9 @@ ClickHouse.connection.truncate_tables(['table_1', 'table_2'], if_exists: true, c
105
104
  ClickHouse.connection.truncate_tables # will truncate all tables in database
106
105
  ClickHouse.connection.rename_table('old_name', 'new_name', cluster: nil)
107
106
  ClickHouse.connection.rename_table(%w[table_1 table_2], %w[new_1 new_2], cluster: nil)
107
+ ClickHouse.connection.alter_table('table', 'DROP COLUMN user_id', cluster: nil)
108
+ ClickHouse.connection.add_index('table', 'ix', 'has(b, a)', type: 'minmax', granularity: 2, cluster: nil)
109
+ ClickHouse.connection.drop_index('table', 'ix', cluster: nil)
108
110
 
109
111
  ClickHouse.connection.select_all('SELECT * FROM visits')
110
112
  ClickHouse.connection.select_one('SELECT * FROM visits LIMIT 1')
@@ -498,6 +500,10 @@ class ClickHouseRecord < ActiveRecord::Base
498
500
  def select_all
499
501
  agent.select_all(current_scope.to_sql)
500
502
  end
503
+
504
+ def explain
505
+ agent.explain(current_scope.to_sql)
506
+ end
501
507
  end
502
508
  end
503
509
  ````
data/click_house.gemspec CHANGED
@@ -10,6 +10,7 @@ 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.4.0'
13
14
 
14
15
  # Specify which files should be added to the gem when it is released.
15
16
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
data/docker-compose.yml CHANGED
@@ -2,7 +2,7 @@ version: '3.5'
2
2
 
3
3
  services:
4
4
  clickhouse:
5
- image: yandex/clickhouse-server:20.11.4.13
5
+ image: yandex/clickhouse-server:21.1.4
6
6
  ports:
7
7
  - "8123:8123"
8
8
  - "9000:9000"
data/lib/click_house.rb CHANGED
@@ -34,7 +34,7 @@ module ClickHouse
34
34
  add_type column, Type::StringType.new
35
35
  end
36
36
 
37
- ['DateTime(%s)'].each do |column|
37
+ %w[DateTime DateTime(%s)].each do |column|
38
38
  add_type column, Type::DateTimeType.new
39
39
  end
40
40
 
@@ -2,10 +2,6 @@
2
2
 
3
3
  module ClickHouse
4
4
  class Config
5
- DEFAULT_SCHEME = 'http'
6
- DEFAULT_HOST = 'localhost'
7
- DEFAULT_PORT = '8123'
8
-
9
5
  DEFAULTS = {
10
6
  adapter: Faraday.default_adapter,
11
7
  url: nil,
@@ -66,6 +66,33 @@ module ClickHouse
66
66
 
67
67
  execute(format(template, pattern)).success?
68
68
  end
69
+
70
+ def add_index(
71
+ table_name,
72
+ name,
73
+ expression,
74
+ type:,
75
+ granularity: nil,
76
+ after: nil,
77
+ cluster: nil
78
+ )
79
+ template = 'ADD INDEX %<name>s %<expression>s TYPE %<type>s GRANULARITY %<granularity>d %<after>s'
80
+ pattern = {
81
+ name: name,
82
+ expression: expression,
83
+ type: type,
84
+ granularity: granularity,
85
+ after: Util::Statement.ensure(after, "AFTER #{after}"),
86
+ }
87
+
88
+ alter_table(table_name, format(template, pattern), cluster: cluster)
89
+ end
90
+
91
+ def drop_index(table_name, name, cluster: nil)
92
+ alter_table(table_name, <<~SQL, cluster: cluster)
93
+ DROP INDEX #{name}
94
+ SQL
95
+ end
69
96
  end
70
97
  end
71
98
  end
@@ -10,7 +10,7 @@ module ClickHouse
10
10
  end
11
11
 
12
12
  define_parser do |body, parser_options|
13
- CSV.parse(body, parser_options || {}) unless body.strip.empty?
13
+ CSV.parse(body, **Hash.new(parser_options)) unless body.strip.empty?
14
14
  end
15
15
  end
16
16
  end
@@ -11,7 +11,8 @@ module ClickHouse
11
11
  NULLABLE_TYPE_RE = /#{NULLABLE}\((.+)\)/i.freeze
12
12
 
13
13
  def_delegators :to_a,
14
- :each, :fetch, :length, :count, :size, :first, :last, :[], :to_h
14
+ :inspect, :each, :fetch, :length, :count, :size,
15
+ :first, :last, :[], :to_h
15
16
 
16
17
  attr_reader :meta, :data, :statistics
17
18
 
@@ -72,10 +73,6 @@ module ClickHouse
72
73
  }
73
74
  end
74
75
  end
75
-
76
- def inspect
77
- to_a
78
- end
79
76
  end
80
77
  end
81
78
  end
@@ -4,11 +4,11 @@ module ClickHouse
4
4
  module Type
5
5
  class DecimalType < BaseType
6
6
  def cast(value, precision = Float::DIG, _scale = nil)
7
- BigDecimal(value, precision.to_f)
7
+ BigDecimal(value, precision.to_i)
8
8
  end
9
9
 
10
10
  def serialize(value, precision = Float::DIG, _scale = nil)
11
- BigDecimal(value, precision.to_f) unless value.nil?
11
+ BigDecimal(value, precision.to_i).to_f unless value.nil?
12
12
  end
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClickHouse
4
- VERSION = '1.3.5'
4
+ VERSION = '1.4.0'
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.3.5
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aliaksandr Shylau
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-05 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -203,14 +203,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
203
  requirements:
204
204
  - - ">="
205
205
  - !ruby/object:Gem::Version
206
- version: '0'
206
+ version: 2.4.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.1.2
213
+ rubygems_version: 3.2.3
214
214
  signing_key:
215
215
  specification_version: 4
216
216
  summary: Modern Ruby database driver for ClickHouse