click_house 1.2.7 → 1.3.4

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: 51b0ca346ad1346979535a0824660870e242190fe29290ffead5e86176aa33d8
4
- data.tar.gz: 9abff05f31db9370d318a6641d7ac5f5e285b887e5a962248021e26e5cf04b81
3
+ metadata.gz: 55de5fd75c50aca5227537365eca6c1042bdff12833c8803f66b1022b6bbefd4
4
+ data.tar.gz: 101d57eeb3a903a9b95a9955a0ac093c80796ef5fc6163837d49fc7fc64464b2
5
5
  SHA512:
6
- metadata.gz: cc743a762b55addf1529d62977c2e8a31863433e42f7af8d35cb13be62a0d8bdf6aaf6dddcadee31bfea829027cc304bcff84334e4374fc1b3253b0ed3bf5eae
7
- data.tar.gz: e4797984cb3ea107d6772819c96204b6517bfba908b2f52b595a340eb474b7ebb655999f960e37f32eb383d7a62b1b81592764599cf20165fa5965aa140d49dc
6
+ metadata.gz: 860b3f17e95893e7cdd0d43c37ca42557492b7e44b8e0c61d326a8d83c9211a942775131d5a4705d53b6cdab3dc8acd716b5c2d629e7f95f9f95c74b9310398f
7
+ data.tar.gz: dc0fd575a9b1c22ae571fda8edb639a8d16df3ddb6497b97b63b3886933b8904e9d94a97f0f8b17619b4c4dca987282265a3002833c3318775e74d201c6f23fa
@@ -34,6 +34,8 @@ Performance/Squeeze:
34
34
  Enabled: true
35
35
  Performance/StringInclude:
36
36
  Enabled: true
37
+ Performance/Sum:
38
+ Enabled: true
37
39
 
38
40
  # ============================== Metrics ============================
39
41
  Metrics/ClassLength:
@@ -171,6 +173,26 @@ Style/RedundantAssignment:
171
173
  Enabled: true
172
174
  Style/RedundantFileExtensionInRequire:
173
175
  Enabled: true
176
+ Style/ExplicitBlockArgument:
177
+ Enabled: true
178
+ Style/GlobalStdStream:
179
+ Enabled: true
180
+ Style/OptionalBooleanParameter:
181
+ Enabled: true
182
+ Style/SingleArgumentDig:
183
+ Enabled: true
184
+ Style/StringConcatenation:
185
+ Enabled: true
186
+ Style/ClassEqualityComparison:
187
+ Enabled: true
188
+ Style/CombinableLoops:
189
+ Enabled: true
190
+ Style/KeywordParametersOrder:
191
+ Enabled: false
192
+ Style/RedundantSelfAssignment:
193
+ Enabled: true
194
+ Style/SoleNestedConditional:
195
+ Enabled: true
174
196
 
175
197
  # ============================== Lint ==============================
176
198
  Lint/DuplicateMethods:
@@ -187,3 +209,41 @@ Lint/StructNewOverride:
187
209
  Enabled: true
188
210
  Lint/DuplicateElsifCondition:
189
211
  Enabled: true
212
+ Lint/BinaryOperatorWithIdenticalOperands:
213
+ Enabled: true
214
+ Lint/DuplicateRescueException:
215
+ Enabled: true
216
+ Lint/EmptyConditionalBody:
217
+ Enabled: true
218
+ Lint/FloatComparison:
219
+ Enabled: true
220
+ Lint/MissingSuper:
221
+ Enabled: false
222
+ Lint/OutOfRangeRegexpRef:
223
+ Enabled: true
224
+ Lint/SelfAssignment:
225
+ Enabled: true
226
+ Lint/TopLevelReturnWithArgument:
227
+ Enabled: true
228
+ Lint/UnreachableLoop:
229
+ Enabled: true
230
+ Layout/BeginEndAlignment:
231
+ Enabled: true
232
+ Lint/ConstantDefinitionInBlock:
233
+ Enabled: true
234
+ Lint/DuplicateRequire:
235
+ Enabled: true
236
+ Lint/EmptyFile:
237
+ Enabled: true
238
+ Lint/HashCompareByIdentity:
239
+ Enabled: true
240
+ Lint/IdentityComparison:
241
+ Enabled: true
242
+ Lint/RedundantSafeNavigation:
243
+ Enabled: true
244
+ Lint/TrailingCommaInAttributeDeclaration:
245
+ Enabled: true
246
+ Lint/UselessMethodDefinition:
247
+ Enabled: true
248
+ Lint/UselessTimes:
249
+ Enabled: true
@@ -1,3 +1,19 @@
1
+ # 1.3.4
2
+ * added `ClickHouse.type_names(nullable: false)`
3
+ * fixed `connection#create_table` column definitions
4
+
5
+ # 1.3.3
6
+ * fix logger typo
7
+
8
+ # 1.3.2
9
+ * fix null logger for windows users
10
+
11
+ # 1.3.1
12
+ * added request [headers](https://github.com/shlima/click_house/pull/8) support
13
+
14
+ # 1.3.0
15
+ * added support for IPv4/IPv6 types
16
+
1
17
  # 1.2.7
2
18
  * rubocop version bump
3
19
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- click_house (1.2.6)
4
+ click_house (1.3.4)
5
5
  faraday
6
6
  faraday_middleware
7
7
 
@@ -11,27 +11,28 @@ GEM
11
11
  ast (2.4.1)
12
12
  coderay (1.1.3)
13
13
  diff-lcs (1.4.4)
14
- faraday (1.0.1)
14
+ faraday (1.1.0)
15
15
  multipart-post (>= 1.2, < 3)
16
+ ruby2_keywords
16
17
  faraday_middleware (1.0.0)
17
18
  faraday (~> 1.0)
18
19
  method_source (1.0.0)
19
20
  multipart-post (2.1.1)
20
21
  parallel (1.19.2)
21
- parser (2.7.1.4)
22
+ parser (2.7.2.0)
22
23
  ast (~> 2.4.1)
23
24
  pry (0.13.1)
24
25
  coderay (~> 1.1)
25
26
  method_source (~> 1.0)
26
27
  rainbow (3.0.0)
27
28
  rake (13.0.1)
28
- regexp_parser (1.7.1)
29
+ regexp_parser (1.8.2)
29
30
  rexml (3.2.4)
30
31
  rspec (3.9.0)
31
32
  rspec-core (~> 3.9.0)
32
33
  rspec-expectations (~> 3.9.0)
33
34
  rspec-mocks (~> 3.9.0)
34
- rspec-core (3.9.2)
35
+ rspec-core (3.9.3)
35
36
  rspec-support (~> 3.9.3)
36
37
  rspec-expectations (3.9.2)
37
38
  diff-lcs (>= 1.2.0, < 2.0)
@@ -40,20 +41,22 @@ GEM
40
41
  diff-lcs (>= 1.2.0, < 2.0)
41
42
  rspec-support (~> 3.9.0)
42
43
  rspec-support (3.9.3)
43
- rubocop (0.88.0)
44
+ rubocop (0.93.1)
44
45
  parallel (~> 1.10)
45
- parser (>= 2.7.1.1)
46
+ parser (>= 2.7.1.5)
46
47
  rainbow (>= 2.2.2, < 4.0)
47
- regexp_parser (>= 1.7)
48
+ regexp_parser (>= 1.8)
48
49
  rexml
49
- rubocop-ast (>= 0.1.0, < 1.0)
50
+ rubocop-ast (>= 0.6.0)
50
51
  ruby-progressbar (~> 1.7)
51
52
  unicode-display_width (>= 1.4.0, < 2.0)
52
- rubocop-ast (0.3.0)
53
- parser (>= 2.7.1.4)
54
- rubocop-performance (1.7.1)
55
- rubocop (>= 0.82.0)
53
+ rubocop-ast (0.8.0)
54
+ parser (>= 2.7.1.5)
55
+ rubocop-performance (1.8.1)
56
+ rubocop (>= 0.87.0)
57
+ rubocop-ast (>= 0.4.0)
56
58
  ruby-progressbar (1.10.1)
59
+ ruby2_keywords (0.0.2)
57
60
  unicode-display_width (1.7.0)
58
61
 
59
62
  PLATFORMS
data/README.md CHANGED
@@ -7,7 +7,7 @@
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 modern Ruby (>= 2.5), tested with Yandex.Clickhouse v 19.16.2.2
10
+ # Requires Ruby >= 2.5
11
11
  gem install click_house
12
12
  ```
13
13
 
@@ -53,6 +53,7 @@ ClickHouse.config do |config|
53
53
  config.timeout = 60
54
54
  config.open_timeout = 3
55
55
  config.ssl_verify = false
56
+ config.headers = {}
56
57
 
57
58
  # or provide connection options separately
58
59
  config.scheme = 'http'
@@ -216,7 +217,8 @@ ClickHouse.connection.create_table('visits', if_not_exists: true, engine: 'Merge
216
217
  t.Decimal :money, 5, 4
217
218
  t.String :event
218
219
  t.UInt32 :user_id
219
- t.UInt32 :Float32
220
+ t.IPv4 :ipv4
221
+ t.IPv6 :ipv6
220
222
  end
221
223
  ```
222
224
 
@@ -328,11 +330,11 @@ ClickHouse.add_type('Date', DateType.new)
328
330
  Actually `serialize` function is not used for now, but you may use it manually:
329
331
 
330
332
  ```ruby
331
- time_type = DateTimeType.new
332
- string_type = FixedStringType.new
333
+ time_type = ClickHouse::Type::DateTimeType.new
334
+ string_type = ClickHouse::Type::FixedStringType.new
333
335
 
334
336
  ClickHouse.connection.insert('table', columns: %i[name time]) do |buffer|
335
- buffer << [string_type.serialize('a' * 1000, 20), time.serialize(Time.current, 'Europe/Moscow')]
337
+ buffer << [string_type.serialize('a' * 1000, 20), time_type.serialize(Time.current, 'Europe/Moscow')]
336
338
  end
337
339
 
338
340
  ## alternatively
@@ -344,7 +346,8 @@ data = @records.map do |record|
344
346
  end
345
347
  ```
346
348
 
347
- If native type supports arguments, define type with `%s` argument:
349
+ If native type supports arguments, define *String* type with `%s`
350
+ argument and *Numeric* type with `%d` argument:
348
351
 
349
352
  ```ruby
350
353
  class DateTimeType
@@ -448,11 +451,6 @@ class CreateAdvertVisits < ActiveRecord::Migration[6.0]
448
451
  t.UInt16 :account_id
449
452
  t.UInt16 :user_id
450
453
  t.Date :date
451
- t.DateTime :time, 'UTC'
452
- t.UInt32 :ipv4
453
- t.UInt64 :ipv6
454
- t.UInt32 :device_type_id
455
- t.UInt32 :os_family_id
456
454
  end
457
455
  end
458
456
 
@@ -2,7 +2,7 @@ version: '3.5'
2
2
 
3
3
  services:
4
4
  clickhouse:
5
- image: yandex/clickhouse-server:20.5.4.40
5
+ image: yandex/clickhouse-server:20.10.3.30
6
6
  ports:
7
7
  - "8123:8123"
8
8
  - "9000:9000"
@@ -28,36 +28,33 @@ module ClickHouse
28
28
 
29
29
  %w[Date].each do |column|
30
30
  add_type column, Type::DateType.new
31
- add_type "Nullable(#{column})", Type::NullableType.new(Type::DateType.new)
32
31
  end
33
32
 
34
- %w[String].each do |column|
33
+ %w[String FixedString(%d) UUID].each do |column|
35
34
  add_type column, Type::StringType.new
36
- add_type "Nullable(#{column})", Type::NullableType.new(Type::StringType.new)
37
35
  end
38
36
 
39
37
  ['DateTime(%s)'].each do |column|
40
38
  add_type column, Type::DateTimeType.new
41
- add_type "Nullable(#{column})", Type::NullableType.new(Type::DateTimeType.new)
42
39
  end
43
40
 
44
41
  ['DateTime64(%d, %s)'].each do |column|
45
42
  add_type column, Type::DateTime64Type.new
46
- add_type "Nullable(#{column})", Type::NullableType.new(Type::DateTime64Type.new)
47
43
  end
48
44
 
49
- ['Decimal(%s, %s)', 'Decimal32(%s)', 'Decimal64(%s)', 'Decimal128(%s)'].each do |column|
45
+ ['Decimal(%d, %d)', 'Decimal32(%d)', 'Decimal64(%d)', 'Decimal128(%d)'].each do |column|
50
46
  add_type column, Type::DecimalType.new
51
- add_type "Nullable(#{column})", Type::NullableType.new(Type::DecimalType.new)
52
47
  end
53
48
 
54
49
  %w[UInt8 UInt16 UInt32 UInt64 Int8 Int16 Int32 Int64].each do |column|
55
50
  add_type column, Type::IntegerType.new
56
- add_type "Nullable(#{column})", Type::NullableType.new(Type::IntegerType.new)
57
51
  end
58
52
 
59
53
  %w[Float32 Float64].each do |column|
60
54
  add_type column, Type::FloatType.new
61
- add_type "Nullable(#{column})", Type::NullableType.new(Type::IntegerType.new)
55
+ end
56
+
57
+ %w[IPv4 IPv6].each do |column|
58
+ add_type column, Type::IPType.new
62
59
  end
63
60
  end
@@ -18,7 +18,8 @@ module ClickHouse
18
18
  password: nil,
19
19
  timeout: nil,
20
20
  open_timeout: nil,
21
- ssl_verify: false
21
+ ssl_verify: false,
22
+ headers: {}
22
23
  }.freeze
23
24
 
24
25
  attr_accessor :adapter
@@ -33,6 +34,7 @@ module ClickHouse
33
34
  attr_accessor :timeout
34
35
  attr_accessor :open_timeout
35
36
  attr_accessor :ssl_verify
37
+ attr_accessor :headers
36
38
 
37
39
  def initialize(params = {})
38
40
  assign(DEFAULTS.merge(params))
@@ -51,7 +53,7 @@ module ClickHouse
51
53
  end
52
54
 
53
55
  def logger!
54
- @logger || Logger.new('/dev/null')
56
+ @logger || Logger.new(IO::NULL)
55
57
  end
56
58
 
57
59
  def url!
@@ -11,6 +11,7 @@ module ClickHouse
11
11
 
12
12
  attr_reader :config
13
13
 
14
+ # @param [Config]
14
15
  def initialize(config)
15
16
  @config = config
16
17
  end
@@ -31,6 +32,7 @@ module ClickHouse
31
32
  @transport ||= Faraday.new(config.url!) do |conn|
32
33
  conn.options.timeout = config.timeout
33
34
  conn.options.open_timeout = config.open_timeout
35
+ conn.headers = config.headers
34
36
  conn.ssl.verify = config.ssl_verify
35
37
  conn.basic_auth(config.username, config.password) if config.auth?
36
38
  conn.response Middleware::Logging, logger: config.logger!
@@ -3,16 +3,7 @@
3
3
  module ClickHouse
4
4
  module Definition
5
5
  class ColumnSet
6
- TYPES = [
7
- 'UInt8', 'UInt16', 'UInt32', 'UInt64', 'Int8', 'Int16', 'Int32', 'Int64',
8
- 'Float32', 'Float64',
9
- 'Decimal(%d, %d)', 'Decimal32(%d)', 'Decimal64(%d)', 'Decimal128(%d)',
10
- 'String',
11
- 'FixedString(%d)',
12
- 'UUID',
13
- 'Date',
14
- "DateTime('%s')", "DateTime64(%d, '%s')"
15
- ].freeze
6
+ TYPES = ClickHouse.type_names(nullable: false).map { |s| s.sub('%s', "'%s'") }.freeze
16
7
 
17
8
  class << self
18
9
  # @input "DateTime('%s')"
@@ -3,12 +3,20 @@
3
3
  module ClickHouse
4
4
  module Extend
5
5
  module TypeDefinition
6
+ NULLABLE = 'Nullable'
7
+
6
8
  def types
7
9
  @types ||= Hash.new(Type::UndefinedType.new)
8
10
  end
9
11
 
10
- def add_type(type, klass)
12
+ def add_type(type, klass, nullable: true)
11
13
  types[type] = klass
14
+ types["#{NULLABLE}(#{type})"] = Type::NullableType.new(klass) if nullable
15
+ end
16
+
17
+ # @return [Enum<String>]
18
+ def type_names(nullable:)
19
+ nullable ? types.keys : types.keys.grep_v(/#{NULLABLE}/i)
12
20
  end
13
21
  end
14
22
  end
@@ -34,7 +34,7 @@ module ClickHouse
34
34
 
35
35
  logger.info("\e[1mSQL (#{Util::Pretty.measure(elapsed)})\e[0m #{query};")
36
36
  logger.debug(body) if body
37
- logger.info("\e[1mRead: #{summary.fetch(:read_rows)} rows, #{summary.fetch(:read_bytes)}. Written: #{summary.fetch(:written_rows)}, rows #{summary.fetch(:written_bytes)}\e[0m")
37
+ logger.info("\e[1mRead: #{summary.fetch(:read_rows)} rows, #{summary.fetch(:read_bytes)}. Written: #{summary.fetch(:written_rows)} rows, #{summary.fetch(:written_bytes)}\e[0m")
38
38
  end
39
39
  # rubocop:enable Layout/LineLength
40
40
 
@@ -15,5 +15,6 @@ module ClickHouse
15
15
  autoload :FixedStringType, 'click_house/type/fixed_string_type'
16
16
  autoload :ArrayType, 'click_house/type/array_type'
17
17
  autoload :StringType, 'click_house/type/string_type'
18
+ autoload :IPType, 'click_house/type/ip_type'
18
19
  end
19
20
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClickHouse
4
+ module Type
5
+ class IPType < BaseType
6
+ def cast(value)
7
+ IPAddr.new(value) unless value.nil?
8
+ end
9
+
10
+ def serialize(value)
11
+ value.to_s unless value.nil?
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClickHouse
4
- VERSION = '1.2.7'
4
+ VERSION = '1.3.4'
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.2.7
4
+ version: 1.3.4
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-08-05 00:00:00.000000000 Z
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -181,6 +181,7 @@ files:
181
181
  - lib/click_house/type/fixed_string_type.rb
182
182
  - lib/click_house/type/float_type.rb
183
183
  - lib/click_house/type/integer_type.rb
184
+ - lib/click_house/type/ip_type.rb
184
185
  - lib/click_house/type/nullable_type.rb
185
186
  - lib/click_house/type/string_type.rb
186
187
  - lib/click_house/type/undefined_type.rb