click_house 1.3.4 → 1.3.9

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: 55de5fd75c50aca5227537365eca6c1042bdff12833c8803f66b1022b6bbefd4
4
- data.tar.gz: 101d57eeb3a903a9b95a9955a0ac093c80796ef5fc6163837d49fc7fc64464b2
3
+ metadata.gz: a840e675477999a80f7ceee3f2364df83fc0efcc4ee4d0e16212dba1bb495acf
4
+ data.tar.gz: 1d8ad01d6dc2e1720c0d499f2f7168cdf83018151bc24dbbe1f8a8244da1d5ee
5
5
  SHA512:
6
- metadata.gz: 860b3f17e95893e7cdd0d43c37ca42557492b7e44b8e0c61d326a8d83c9211a942775131d5a4705d53b6cdab3dc8acd716b5c2d629e7f95f9f95c74b9310398f
7
- data.tar.gz: dc0fd575a9b1c22ae571fda8edb639a8d16df3ddb6497b97b63b3886933b8904e9d94a97f0f8b17619b4c4dca987282265a3002833c3318775e74d201c6f23fa
6
+ metadata.gz: 76172279bdf916f3b1ff68e55ad576a3e05a5651e47e22547a20b8d87159b7920edc72c5bb8b449833d50409c30738dc4374259df7096af53a99141e8d67c9d5
7
+ data.tar.gz: 5542180b24e7d7e7b747cfd09eca9a999371b26b0013d783ef1fa888623eb6854803e38286aa3f0fb3893b158ffed6977ea92aa089c91f25523f0882a99b514e
@@ -0,0 +1,68 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ rspec:
7
+ runs-on: ubuntu-latest
8
+
9
+ services:
10
+ clickhouse:
11
+ image: yandex/clickhouse-server:20.12.3.3
12
+ ports:
13
+ - 8123:8123
14
+
15
+ strategy:
16
+ matrix:
17
+ ruby-version: [2.7, 2.6, 2.5, 2.4]
18
+
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+
22
+ - name: Set up Ruby ${{ matrix.ruby-version }}
23
+ uses: ruby/setup-ruby@v1
24
+ with:
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
39
+
40
+ - name: Run tests
41
+ run: bundle exec rspec
42
+
43
+ rubocop:
44
+ runs-on: ubuntu-latest
45
+
46
+ steps:
47
+ - uses: actions/checkout@v2
48
+
49
+ - name: Set up Ruby 2.7
50
+ uses: ruby/setup-ruby@v1
51
+ with:
52
+ 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
66
+
67
+ - name: Run Rubocop
68
+ run: bundle exec rubocop
@@ -3,13 +3,13 @@ require:
3
3
 
4
4
  AllCops:
5
5
  AutoCorrect: false
6
+ SuggestExtensions: false
6
7
  Exclude:
7
8
  - 'click_house.gemspec'
8
9
  - 'bin/*'
9
10
  - 'spec/**/*'
10
11
  - 'vendor/**/*'
11
12
  TargetRubyVersion: 2.7
12
-
13
13
  Bundler/OrderedGems:
14
14
  Enabled: false
15
15
 
@@ -36,6 +36,16 @@ Performance/StringInclude:
36
36
  Enabled: true
37
37
  Performance/Sum:
38
38
  Enabled: true
39
+ Performance/ArraySemiInfiniteRangeSlice:
40
+ Enabled: true
41
+ Performance/BlockGivenWithExplicitBlock:
42
+ Enabled: true
43
+ Performance/CollectionLiteralInLoop:
44
+ Enabled: true
45
+ Performance/ConstantRegexp:
46
+ Enabled: true
47
+ Performance/MethodObjectAsBlock:
48
+ Enabled: false
39
49
 
40
50
  # ============================== Metrics ============================
41
51
  Metrics/ClassLength:
@@ -44,8 +54,6 @@ Metrics/BlockLength:
44
54
  Enabled: true
45
55
  Metrics/MethodLength:
46
56
  Max: 25
47
- Metrics/LineLength:
48
- Max: 140
49
57
  Metrics/AbcSize:
50
58
  Max: 40
51
59
 
@@ -63,6 +71,8 @@ Naming/AccessorMethodName:
63
71
  Enabled: false
64
72
 
65
73
  # ============================== Layout =============================
74
+ Layout/LineLength:
75
+ Max: 140
66
76
  Layout/HashAlignment:
67
77
  EnforcedHashRocketStyle: key
68
78
  EnforcedColonStyle: key
@@ -193,6 +203,20 @@ Style/RedundantSelfAssignment:
193
203
  Enabled: true
194
204
  Style/SoleNestedConditional:
195
205
  Enabled: true
206
+ Style/ArgumentsForwarding:
207
+ Enabled: true
208
+ Style/CollectionCompact:
209
+ Enabled: true
210
+ Style/DocumentDynamicEvalDefinition:
211
+ Enabled: false
212
+ Style/NegatedIfElseCondition:
213
+ Enabled: true
214
+ Style/NilLambda:
215
+ Enabled: true
216
+ Style/SwapValues:
217
+ Enabled: true
218
+ Style/RedundantArgument:
219
+ Enabled: true
196
220
 
197
221
  # ============================== Lint ==============================
198
222
  Lint/DuplicateMethods:
@@ -247,3 +271,19 @@ Lint/UselessMethodDefinition:
247
271
  Enabled: true
248
272
  Lint/UselessTimes:
249
273
  Enabled: true
274
+ Lint/DuplicateBranch:
275
+ Enabled: true
276
+ Lint/DuplicateRegexpCharacterClassElement:
277
+ Enabled: true
278
+ Lint/EmptyBlock:
279
+ Enabled: true
280
+ Lint/EmptyClass:
281
+ Enabled: true
282
+ Lint/NoReturnInBeginEndBlocks:
283
+ Enabled: true
284
+ Lint/ToEnumArguments:
285
+ Enabled: true
286
+ Lint/UnmodifiedReduceAccumulator:
287
+ Enabled: true
288
+ Lint/UnexpectedBlockArity:
289
+ Enabled: true
@@ -1,6 +1,23 @@
1
+ # 1.3.9
2
+ * add `ClickHouse.connection.add_index`, `ClickHouse.connection.drop_index`
3
+
4
+ # 1.3.8
5
+ * fix `DateTime` casting for queries like `ClickHouse.connection.select_value('select NOW()')`
6
+ * fix resulting set console inspection
7
+
8
+ # 1.3.7
9
+ * specify required ruby version [#10](https://github.com/shlima/click_house/issues/10)
10
+
11
+ # 1.3.6
12
+ * fix ruby 2.7 warning `maybe ** should be added to the call` on `ClickHouse.connection.databases`
13
+
14
+ # 1.3.5
15
+ * added `ClickHouse.connection.explain("sql")`
16
+
1
17
  # 1.3.4
2
18
  * added `ClickHouse.type_names(nullable: false)`
3
19
  * fixed `connection#create_table` column definitions
20
+ * `ClickHouse.add_type` now handles Nullable types automatically
4
21
 
5
22
  # 1.3.3
6
23
  * fix logger typo
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- click_house (1.3.4)
4
+ click_house (1.3.9)
5
5
  faraday
6
6
  faraday_middleware
7
7
 
@@ -18,42 +18,42 @@ GEM
18
18
  faraday (~> 1.0)
19
19
  method_source (1.0.0)
20
20
  multipart-post (2.1.1)
21
- parallel (1.19.2)
21
+ parallel (1.20.1)
22
22
  parser (2.7.2.0)
23
23
  ast (~> 2.4.1)
24
24
  pry (0.13.1)
25
25
  coderay (~> 1.1)
26
26
  method_source (~> 1.0)
27
27
  rainbow (3.0.0)
28
- rake (13.0.1)
29
- regexp_parser (1.8.2)
28
+ rake (13.0.3)
29
+ regexp_parser (2.0.1)
30
30
  rexml (3.2.4)
31
- rspec (3.9.0)
32
- rspec-core (~> 3.9.0)
33
- rspec-expectations (~> 3.9.0)
34
- rspec-mocks (~> 3.9.0)
35
- rspec-core (3.9.3)
36
- rspec-support (~> 3.9.3)
37
- rspec-expectations (3.9.2)
31
+ rspec (3.10.0)
32
+ rspec-core (~> 3.10.0)
33
+ rspec-expectations (~> 3.10.0)
34
+ rspec-mocks (~> 3.10.0)
35
+ rspec-core (3.10.0)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-expectations (3.10.0)
38
38
  diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.9.0)
40
- rspec-mocks (3.9.1)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-mocks (3.10.0)
41
41
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.9.0)
43
- rspec-support (3.9.3)
44
- rubocop (0.93.1)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-support (3.10.0)
44
+ rubocop (1.6.1)
45
45
  parallel (~> 1.10)
46
46
  parser (>= 2.7.1.5)
47
47
  rainbow (>= 2.2.2, < 4.0)
48
- regexp_parser (>= 1.8)
48
+ regexp_parser (>= 1.8, < 3.0)
49
49
  rexml
50
- rubocop-ast (>= 0.6.0)
50
+ rubocop-ast (>= 1.2.0, < 2.0)
51
51
  ruby-progressbar (~> 1.7)
52
52
  unicode-display_width (>= 1.4.0, < 2.0)
53
- rubocop-ast (0.8.0)
53
+ rubocop-ast (1.3.0)
54
54
  parser (>= 2.7.1.5)
55
- rubocop-performance (1.8.1)
56
- rubocop (>= 0.87.0)
55
+ rubocop-performance (1.9.1)
56
+ rubocop (>= 0.90.0, < 2.0)
57
57
  rubocop-ast (>= 0.4.0)
58
58
  ruby-progressbar (1.10.1)
59
59
  ruby2_keywords (0.0.2)
data/README.md CHANGED
@@ -2,12 +2,11 @@
2
2
 
3
3
  # ClickHouse Ruby driver
4
4
 
5
- [![pipeline status](https://travis-ci.com/shlima/click_house.svg?branch=master)](https://travis-ci.com/shlima/click_house)
5
+ ![CI](https://github.com/shlima/click_house/workflows/CI/badge.svg)
6
6
  [![Code Climate](https://codeclimate.com/github/shlima/click_house/badges/gpa.svg)](https://codeclimate.com/github/shlima/click_house)
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,13 @@ 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.add_index('table', 'ix', 'has(b, a)', type: 'minmax', granularity: 2, cluster: nil)
108
+ ClickHouse.connection.drop_index('table', 'ix', cluster: nil)
109
+
110
+ ClickHouse.connection.select_all('SELECT * FROM visits')
111
+ ClickHouse.connection.select_one('SELECT * FROM visits LIMIT 1')
112
+ ClickHouse.connection.select_value('SELECT ip FROM visits LIMIT 1')
113
+ ClickHouse.connection.explain('SELECT * FROM visits CROSS JOIN visits')
108
114
  ```
109
115
 
110
116
  ## Queries
@@ -399,6 +405,10 @@ development:
399
405
  test:
400
406
  database: ecliptic_test
401
407
  <<: *default
408
+
409
+ production:
410
+ <<: *default
411
+ database: ecliptic_production
402
412
  ```
403
413
 
404
414
  ```ruby
@@ -489,6 +499,10 @@ class ClickHouseRecord < ActiveRecord::Base
489
499
  def select_all
490
500
  agent.select_all(current_scope.to_sql)
491
501
  end
502
+
503
+ def explain
504
+ agent.explain(current_scope.to_sql)
505
+ end
492
506
  end
493
507
  end
494
508
  ````
@@ -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.
@@ -2,7 +2,7 @@ version: '3.5'
2
2
 
3
3
  services:
4
4
  clickhouse:
5
- image: yandex/clickhouse-server:20.10.3.30
5
+ image: yandex/clickhouse-server:20.12.3.3
6
6
  ports:
7
7
  - "8123:8123"
8
8
  - "9000:9000"
@@ -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,
@@ -8,6 +8,7 @@ module ClickHouse
8
8
  include Extend::ConnectionSelective
9
9
  include Extend::ConnectionInserting
10
10
  include Extend::ConnectionAltering
11
+ include Extend::ConnectionExplaining
11
12
 
12
13
  attr_reader :config
13
14
 
@@ -11,5 +11,6 @@ module ClickHouse
11
11
  autoload :ConnectionSelective, 'click_house/extend/connection_selective'
12
12
  autoload :ConnectionInserting, 'click_house/extend/connection_inserting'
13
13
  autoload :ConnectionAltering, 'click_house/extend/connection_altering'
14
+ autoload :ConnectionExplaining, 'click_house/extend/connection_explaining'
14
15
  end
15
16
  end
@@ -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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClickHouse
4
+ module Extend
5
+ module ConnectionExplaining
6
+ EXPLAIN = 'EXPLAIN'
7
+ EXPLAIN_RE = /\A(\s*#{EXPLAIN})/io.freeze
8
+
9
+ def explain(sql, io: $stdout)
10
+ res = execute("#{EXPLAIN} #{sql.gsub(EXPLAIN_RE, '')}")
11
+ io << res.body
12
+ end
13
+ end
14
+ end
15
+ end
@@ -4,6 +4,7 @@ module ClickHouse
4
4
  module Extend
5
5
  module TypeDefinition
6
6
  NULLABLE = 'Nullable'
7
+ NULLABLE_RE = /#{NULLABLE}/i.freeze
7
8
 
8
9
  def types
9
10
  @types ||= Hash.new(Type::UndefinedType.new)
@@ -16,7 +17,7 @@ module ClickHouse
16
17
 
17
18
  # @return [Enum<String>]
18
19
  def type_names(nullable:)
19
- nullable ? types.keys : types.keys.grep_v(/#{NULLABLE}/i)
20
+ nullable ? types.keys : types.keys.grep_v(NULLABLE_RE)
20
21
  end
21
22
  end
22
23
  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
@@ -8,9 +8,11 @@ module ClickHouse
8
8
 
9
9
  TYPE_ARGV_DELIM = ','
10
10
  NULLABLE = 'Nullable'
11
+ NULLABLE_TYPE_RE = /#{NULLABLE}\((.+)\)/i.freeze
11
12
 
12
13
  def_delegators :to_a,
13
- :each, :fetch, :length, :count, :size, :first, :last, :[], :to_h
14
+ :inspect, :each, :fetch, :length, :count, :size,
15
+ :first, :last, :[], :to_h
14
16
 
15
17
  attr_reader :meta, :data, :statistics
16
18
 
@@ -28,7 +30,7 @@ module ClickHouse
28
30
  # @input "Decimal(10, 5)"
29
31
  # @output "Decimal(%s, %s)"
30
32
  def extract_type_info(type)
31
- type = type.gsub(/#{NULLABLE}\((.+)\)/i, '\1')
33
+ type = type.gsub(NULLABLE_TYPE_RE, '\1')
32
34
  nullable = Regexp.last_match(1)
33
35
  argv = []
34
36
 
@@ -71,10 +73,6 @@ module ClickHouse
71
73
  }
72
74
  end
73
75
  end
74
-
75
- def inspect
76
- to_a
77
- end
78
76
  end
79
77
  end
80
78
  end
@@ -4,6 +4,7 @@ module ClickHouse
4
4
  module Util
5
5
  module Statement
6
6
  END_OF_STATEMENT = ';'
7
+ END_OF_STATEMENT_RE = /#{END_OF_STATEMENT}(\s+|\Z)/.freeze
7
8
 
8
9
  module_function
9
10
 
@@ -14,7 +15,7 @@ module ClickHouse
14
15
  def format(sql, format)
15
16
  return sql if sql.match?(/FORMAT/i)
16
17
 
17
- "#{sql.sub(/#{END_OF_STATEMENT}(\s+|\Z)/, '')} FORMAT #{format};"
18
+ "#{sql.sub(END_OF_STATEMENT_RE, '')} FORMAT #{format};"
18
19
  end
19
20
  end
20
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClickHouse
4
- VERSION = '1.3.4'
4
+ VERSION = '1.3.9'
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.4
4
+ version: 1.3.9
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-11-02 00:00:00.000000000 Z
11
+ date: 2020-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -129,10 +129,10 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - ".github/workflows/main.yml"
132
133
  - ".gitignore"
133
134
  - ".rspec"
134
135
  - ".rubocop.yml"
135
- - ".travis.yml"
136
136
  - CHANGELOG.md
137
137
  - Gemfile
138
138
  - Gemfile.lock
@@ -158,6 +158,7 @@ files:
158
158
  - lib/click_house/extend/connectible.rb
159
159
  - lib/click_house/extend/connection_altering.rb
160
160
  - lib/click_house/extend/connection_database.rb
161
+ - lib/click_house/extend/connection_explaining.rb
161
162
  - lib/click_house/extend/connection_healthy.rb
162
163
  - lib/click_house/extend/connection_inserting.rb
163
164
  - lib/click_house/extend/connection_selective.rb
@@ -202,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
203
  requirements:
203
204
  - - ">="
204
205
  - !ruby/object:Gem::Version
205
- version: '0'
206
+ version: 2.4.0
206
207
  required_rubygems_version: !ruby/object:Gem::Requirement
207
208
  requirements:
208
209
  - - ">="
@@ -1,16 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.6.5
5
-
6
- services:
7
- - docker
8
-
9
- before_install:
10
- - docker pull yandex/clickhouse-server
11
- - docker run -d -p 127.0.0.1:8123:8123 yandex/clickhouse-server
12
- - bundle install
13
-
14
- script:
15
- - bundle exec rubocop
16
- - bundle exec rspec