click_house 1.6.2 → 1.7.0

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: 6a24e10e60cd19671f70f521f6db773ef0d3b0f6f33a9ef40b5a26ed7aaf8106
4
- data.tar.gz: 3a948f7381d345f6784a8a125bedbc62ba9df554920cc40eb217699c350cfc02
3
+ metadata.gz: 49f4230ea84634e1cfed295d8cc41239d1212bb48807b68636ce82c6cba08039
4
+ data.tar.gz: e78054a1f0e3094746adfea54b8fcf649d306cbaa1fce636e822a073ac446376
5
5
  SHA512:
6
- metadata.gz: 12af01d64fb80f0fbfff2df8654c79b6574bd09b6159bac8ae9425417a5fc48fbf7ae8bcf2b0e42efc80bd23bc55212f5ba232f187e606b76fb8d6f7193a6976
7
- data.tar.gz: 2d819029b2030f25b68a85f623dcbbec497aa9756d6b69d2e223eccdc97ba35ef58299ceea47f45de568cfdd161f09ca75e1635f9bc3176e94de337ae88e4a59
6
+ metadata.gz: 280540bf287f99f4fc87e90c47bd94312cc4a82047ada6f193ca4e77b84527c7733e2260f8cb7c960a04d726ffbe449612cf9ee3f297bf30cc6ba27e2ccb9b7c
7
+ data.tar.gz: 8a4e4213c46c99181a521e749e57fd63857cb0f135fa41ef9e25781947ecbef4eb8844a9062305a5080abeea85e4dee652d50b432e9c1b1cd65f12bf43006624
@@ -8,7 +8,7 @@ jobs:
8
8
 
9
9
  services:
10
10
  clickhouse:
11
- image: clickhouse/clickhouse-server:22.6
11
+ image: clickhouse/clickhouse-server:22.9
12
12
  ports:
13
13
  - 8123:8123
14
14
 
data/.rubocop.yml CHANGED
@@ -14,7 +14,9 @@ Bundler/OrderedGems:
14
14
  Enabled: false
15
15
 
16
16
  # ============================== Gemspec ======================
17
- Gemspec/DateAssignment:
17
+ Gemspec/DeprecatedAttributeAssignment:
18
+ Enabled: true
19
+ Gemspec/RequireMFA: # new in 1.23
18
20
  Enabled: true
19
21
 
20
22
  # =============================== Performance =======================
@@ -52,6 +54,10 @@ Performance/RedundantSplitRegexpArgument:
52
54
  Enabled: true
53
55
  Performance/MapCompact:
54
56
  Enabled: true
57
+ Performance/ConcurrentMonotonicTime: # new in 1.12
58
+ Enabled: true
59
+ Performance/StringIdentifierArgument: # new in 1.13
60
+ Enabled: true
55
61
 
56
62
  # ============================== Metrics ============================
57
63
  Metrics/ClassLength:
@@ -77,6 +83,8 @@ Naming/AccessorMethodName:
77
83
  Enabled: false
78
84
  Naming/InclusiveLanguage:
79
85
  Enabled: true
86
+ Naming/BlockForwarding: # new in 1.24
87
+ Enabled: true
80
88
 
81
89
  # ============================== Layout =============================
82
90
  Layout/LineLength:
@@ -117,6 +125,10 @@ Layout/SpaceBeforeBrackets:
117
125
  Enabled: true
118
126
  Layout/LineEndStringConcatenationIndentation:
119
127
  Enabled: true
128
+ Layout/LineContinuationLeadingSpace: # new in 1.31
129
+ Enabled: true
130
+ Layout/LineContinuationSpacing: # new in 1.31
131
+ Enabled: true
120
132
 
121
133
  # ============================== Style ==============================
122
134
  Style/RescueModifier:
@@ -247,6 +259,50 @@ Style/QuotedSymbols:
247
259
  Enabled: true
248
260
  Style/StringChars:
249
261
  Enabled: true
262
+ Style/EmptyHeredoc: # new in 1.32
263
+ Enabled: true
264
+ Style/EnvHome: # new in 1.29
265
+ Enabled: true
266
+ Style/FetchEnvVar: # new in 1.28
267
+ Enabled: true
268
+ Style/FileRead: # new in 1.24
269
+ Enabled: true
270
+ Style/FileWrite: # new in 1.24
271
+ Enabled: true
272
+ Style/MagicCommentFormat: # new in 1.35
273
+ Enabled: true
274
+ Style/MapCompactWithConditionalBlock: # new in 1.30
275
+ Enabled: true
276
+ Style/MapToHash: # new in 1.24
277
+ Enabled: true
278
+ Style/NestedFileDirname: # new in 1.26
279
+ Enabled: true
280
+ Style/NumberedParameters: # new in 1.22
281
+ Enabled: true
282
+ Style/NumberedParametersLimit: # new in 1.22
283
+ Enabled: true
284
+ Style/ObjectThen: # new in 1.28
285
+ Enabled: true
286
+ Style/OpenStructUse: # new in 1.23
287
+ Enabled: true
288
+ Style/OperatorMethodCall: # new in 1.37
289
+ Enabled: true
290
+ Style/RedundantEach: # new in 1.38
291
+ Enabled: true
292
+ Style/RedundantInitialize: # new in 1.27
293
+ Enabled: true
294
+ Style/RedundantSelfAssignmentBranch: # new in 1.19
295
+ Enabled: true
296
+ Style/RedundantStringEscape: # new in 1.37
297
+ Enabled: true
298
+ Style/SelectByRegexp: # new in 1.22
299
+ Enabled: true
300
+
301
+ # ============================== Security ==============================
302
+ Security/CompoundHash: # new in 1.28
303
+ Enabled: true
304
+ Security/IoMethods: # new in 1.22
305
+ Enabled: true
250
306
 
251
307
  # ============================== Lint ==============================
252
308
  Lint/DuplicateMethods:
@@ -335,3 +391,23 @@ Lint/AmbiguousAssignment:
335
391
  Enabled: true
336
392
  Lint/EmptyInPattern:
337
393
  Enabled: true
394
+ Lint/AmbiguousOperatorPrecedence: # new in 1.21
395
+ Enabled: true
396
+ Lint/AmbiguousRange: # new in 1.19
397
+ Enabled: true
398
+ Lint/ConstantOverwrittenInRescue: # new in 1.31
399
+ Enabled: true
400
+ Lint/DuplicateMagicComment: # new in 1.37
401
+ Enabled: true
402
+ Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
403
+ Enabled: true
404
+ Lint/NonAtomicFileOperation: # new in 1.31
405
+ Enabled: true
406
+ Lint/RefinementImportMethods: # new in 1.27
407
+ Enabled: true
408
+ Lint/RequireRangeParentheses: # new in 1.32
409
+ Enabled: true
410
+ Lint/RequireRelativeSelfPath: # new in 1.22
411
+ Enabled: true
412
+ Lint/UselessRuby2Keywords: # new in 1.23
413
+ Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 1.6.3
2
+ * [PR](https://github.com/shlima/click_house/pull/38) Add option format for insert
3
+ * [PR](https://github.com/shlima/click_house/pull/34) Support X-ClickHouse-Exception-Code header
4
+ * [ISSUE](https://github.com/shlima/click_house/issues/33) Fix parameterized types parsing
5
+ * Added LowCardinality DDL support
6
+ * Fixed body logging with POST queries
7
+
1
8
  # 1.6.2
2
9
  * [PR](https://github.com/shlima/click_house/pull/31) Add rows_before_limit_at_least to ResultSet
3
10
  * [PR](https://github.com/shlima/click_house/pull/29) Force JSON format by using "default_format" instead of modifying the query
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- click_house (1.6.2)
4
+ click_house (1.7.0)
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.10.0)
14
+ faraday (1.10.2)
15
15
  faraday-em_http (~> 1.0)
16
16
  faraday-em_synchrony (~> 1.0)
17
17
  faraday-excon (~> 1.1)
@@ -36,48 +36,50 @@ GEM
36
36
  faraday-retry (1.0.3)
37
37
  faraday_middleware (1.2.0)
38
38
  faraday (~> 1.0)
39
+ json (2.6.2)
39
40
  method_source (1.0.0)
40
41
  multipart-post (2.2.3)
41
42
  parallel (1.22.1)
42
- parser (3.1.1.0)
43
+ parser (3.1.2.1)
43
44
  ast (~> 2.4.1)
44
45
  pry (0.14.1)
45
46
  coderay (~> 1.1)
46
47
  method_source (~> 1.0)
47
48
  rainbow (3.1.1)
48
49
  rake (13.0.6)
49
- regexp_parser (2.2.1)
50
+ regexp_parser (2.6.0)
50
51
  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)
52
+ rspec (3.12.0)
53
+ rspec-core (~> 3.12.0)
54
+ rspec-expectations (~> 3.12.0)
55
+ rspec-mocks (~> 3.12.0)
56
+ rspec-core (3.12.0)
57
+ rspec-support (~> 3.12.0)
58
+ rspec-expectations (3.12.0)
58
59
  diff-lcs (>= 1.2.0, < 2.0)
59
- rspec-support (~> 3.11.0)
60
- rspec-mocks (3.11.1)
60
+ rspec-support (~> 3.12.0)
61
+ rspec-mocks (3.12.0)
61
62
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.11.0)
63
- rspec-support (3.11.0)
64
- rubocop (1.26.1)
63
+ rspec-support (~> 3.12.0)
64
+ rspec-support (3.12.0)
65
+ rubocop (1.38.0)
66
+ json (~> 2.3)
65
67
  parallel (~> 1.10)
66
- parser (>= 3.1.0.0)
68
+ parser (>= 3.1.2.1)
67
69
  rainbow (>= 2.2.2, < 4.0)
68
70
  regexp_parser (>= 1.8, < 3.0)
69
- rexml
70
- rubocop-ast (>= 1.16.0, < 2.0)
71
+ rexml (>= 3.2.5, < 4.0)
72
+ rubocop-ast (>= 1.23.0, < 2.0)
71
73
  ruby-progressbar (~> 1.7)
72
74
  unicode-display_width (>= 1.4.0, < 3.0)
73
- rubocop-ast (1.16.0)
75
+ rubocop-ast (1.23.0)
74
76
  parser (>= 3.1.1.0)
75
- rubocop-performance (1.13.3)
77
+ rubocop-performance (1.15.0)
76
78
  rubocop (>= 1.7.0, < 2.0)
77
79
  rubocop-ast (>= 0.4.0)
78
80
  ruby-progressbar (1.11.0)
79
81
  ruby2_keywords (0.0.5)
80
- unicode-display_width (2.1.0)
82
+ unicode-display_width (2.3.0)
81
83
 
82
84
  PLATFORMS
83
85
  ruby
data/README.md CHANGED
@@ -221,7 +221,7 @@ end
221
221
  ```ruby
222
222
  ClickHouse.connection.create_table('visits', if_not_exists: true, engine: 'MergeTree(date, (year, date), 8192)') do |t|
223
223
  t.FixedString :id, 16
224
- t.UInt16 :year
224
+ t.UInt16 :year, low_cardinality: true
225
225
  t.Date :date
226
226
  t.DateTime :time, 'UTC'
227
227
  t.Decimal :money, 5, 4
data/docker-compose.yml CHANGED
@@ -2,7 +2,7 @@ version: '3.5'
2
2
 
3
3
  services:
4
4
  clickhouse:
5
- image: clickhouse/clickhouse-server:22.6
5
+ image: clickhouse/clickhouse-server:22.9
6
6
  ports:
7
7
  - "8123:8123"
8
8
  - "9000:9000"
@@ -53,9 +53,9 @@ 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 :json, content_type: %r{application/json}
56
57
  conn.response Middleware::RaiseError
57
58
  conn.response Middleware::Logging, logger: config.logger!
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
61
61
  end
@@ -6,6 +6,7 @@ module ClickHouse
6
6
  attr_accessor :name
7
7
  attr_accessor :type
8
8
  attr_accessor :nullable
9
+ attr_accessor :low_cardinality
9
10
  attr_accessor :extensions
10
11
  attr_accessor :default
11
12
  attr_accessor :materialized
@@ -17,10 +18,12 @@ module ClickHouse
17
18
  end
18
19
 
19
20
  def to_s
20
- nullable ? "#{name} Nullable(#{extension_type}) #{opts}" : "#{name} #{extension_type} #{opts}"
21
- end
21
+ type = extension_type
22
+ type = "Nullable(#{type})" if nullable
23
+ type = "LowCardinality(#{type})" if low_cardinality
22
24
 
23
- private
25
+ "#{name} #{type} #{opts}"
26
+ end
24
27
 
25
28
  def opts
26
29
  options = {
@@ -14,8 +14,8 @@ module ClickHouse
14
14
  # end
15
15
  #
16
16
  # == Example with a param
17
- # subject.insert('rspec', values: [{ name: 'Sun', id: 1 }, { name: 'Moon', id: 2 }])
18
- def insert(table, columns: [], values: [])
17
+ # subject.insert('rspec', values: [{ name: 'Sun', id: 1 }, { name: 'Moon', id: 2 }], format: 'JSONStringsEachRow')
18
+ def insert(table, columns: [], values: [], format: 'JSONEachRow')
19
19
  yield(values) if block_given?
20
20
 
21
21
  body = if columns.empty?
@@ -26,7 +26,7 @@ module ClickHouse
26
26
 
27
27
  return EMPTY_INSERT if values.empty?
28
28
 
29
- execute("INSERT INTO #{table} FORMAT JSONEachRow", body.join("\n")).success?
29
+ execute("INSERT INTO #{table} FORMAT #{format}", body.join("\n")).success?
30
30
  end
31
31
  end
32
32
  end
@@ -5,6 +5,7 @@ module ClickHouse
5
5
  module TypeDefinition
6
6
  NULLABLE = 'Nullable'
7
7
  NULLABLE_RE = /#{NULLABLE}/i.freeze
8
+ LOW_CARDINALITY = 'LowCardinality'
8
9
 
9
10
  def types
10
11
  @types ||= Hash.new(Type::UndefinedType.new)
@@ -30,7 +30,7 @@ module ClickHouse
30
30
  def on_complete(env)
31
31
  summary = extract_summary(env.response_headers)
32
32
  logger.info("\e[1mSQL (#{duration_stats_log(env.body)})\e[0m #{query(env)};")
33
- logger.debug(body) if body && !query_in_body?(env)
33
+ logger.debug(body) if body
34
34
  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")
35
35
  end
36
36
  # rubocop:enable Layout/LineLength
@@ -4,6 +4,7 @@ module ClickHouse
4
4
  module Middleware
5
5
  class RaiseError < Faraday::Middleware
6
6
  SUCCEED_STATUSES = (200..299).freeze
7
+ EXCEPTION_CODE_HEADER = 'x-clickhouse-exception-code'
7
8
 
8
9
  Faraday::Response.register_middleware self => self
9
10
 
@@ -16,6 +17,11 @@ module ClickHouse
16
17
  private
17
18
 
18
19
  def on_complete(env)
20
+ # Valid since Clickhouse 22.6
21
+ if env.response_headers.key?(EXCEPTION_CODE_HEADER)
22
+ raise DbException, env.body
23
+ end
24
+
19
25
  return if SUCCEED_STATUSES.include?(env.status)
20
26
 
21
27
  raise DbException, "[#{env.status}] #{env.body}"
@@ -9,6 +9,9 @@ module ClickHouse
9
9
  TYPE_ARGV_DELIM = ','
10
10
  NULLABLE = 'Nullable'
11
11
  NULLABLE_TYPE_RE = /#{NULLABLE}\((.+)\)/i.freeze
12
+ ARG_D_RE = /\A-?\d+\Z/.freeze
13
+ PLACEHOLDER_D = '%d'
14
+ PLACEHOLDER_S = '%s'
12
15
 
13
16
  def_delegators :to_a,
14
17
  :inspect, :each, :fetch, :length, :count, :size,
@@ -25,10 +28,10 @@ module ClickHouse
25
28
  # @output "DateTime(%s)"
26
29
  #
27
30
  # @input "Nullable(Decimal(10, 5))"
28
- # @output "Nullable(Decimal(%s, %s))"
31
+ # @output "Nullable(Decimal(%d, %d))"
29
32
  #
30
33
  # @input "Decimal(10, 5)"
31
- # @output "Decimal(%s, %s)"
34
+ # @output "Decimal(%d, %d)"
32
35
  def extract_type_info(type)
33
36
  type = type.gsub(NULLABLE_TYPE_RE, '\1')
34
37
  nullable = Regexp.last_match(1)
@@ -37,9 +40,11 @@ module ClickHouse
37
40
  type = type.gsub(/\((.+)\)/, '')
38
41
 
39
42
  if (match = Regexp.last_match(1))
40
- counter = Array.new(match.count(TYPE_ARGV_DELIM).next) { '%s' }
41
- type = "#{type}(#{counter.join("#{TYPE_ARGV_DELIM} ")})"
42
43
  argv = match.split("#{TYPE_ARGV_DELIM} ")
44
+ placeholder = argv.map do |value|
45
+ value.match?(ARG_D_RE) ? PLACEHOLDER_D : PLACEHOLDER_S
46
+ end
47
+ type = "#{type}(#{placeholder.join("#{TYPE_ARGV_DELIM} ")})"
43
48
  end
44
49
 
45
50
  [nullable ? "#{NULLABLE}(#{type})" : type, argv]
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClickHouse
4
+ module Type
5
+ class LowCardinalityType < BaseType
6
+ attr_reader :subtype
7
+
8
+ def initialize(subtype)
9
+ @subtype = subtype
10
+ end
11
+
12
+ def cast(*argv)
13
+ subtype.cast(*argv)
14
+ end
15
+
16
+ def serialize(*argv)
17
+ subtype.serialize(*argv)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -16,5 +16,6 @@ module ClickHouse
16
16
  autoload :ArrayType, 'click_house/type/array_type'
17
17
  autoload :StringType, 'click_house/type/string_type'
18
18
  autoload :IPType, 'click_house/type/ip_type'
19
+ autoload :LowCardinalityType, 'click_house/type/low_cardinality_type'
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.6.2'
4
+ VERSION = '1.7.0'
5
5
  end
data/lib/click_house.rb CHANGED
@@ -38,7 +38,7 @@ module ClickHouse
38
38
  add_type column, Type::DateTimeType.new
39
39
  end
40
40
 
41
- ['DateTime64(%d, %s)'].each do |column|
41
+ ['DateTime64(%d)', 'DateTime64(%d, %s)'].each do |column|
42
42
  add_type column, Type::DateTime64Type.new
43
43
  end
44
44
 
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.2
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aliaksandr Shylau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-28 00:00:00.000000000 Z
11
+ date: 2022-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -183,6 +183,7 @@ files:
183
183
  - lib/click_house/type/float_type.rb
184
184
  - lib/click_house/type/integer_type.rb
185
185
  - lib/click_house/type/ip_type.rb
186
+ - lib/click_house/type/low_cardinality_type.rb
186
187
  - lib/click_house/type/nullable_type.rb
187
188
  - lib/click_house/type/string_type.rb
188
189
  - lib/click_house/type/undefined_type.rb