click_house 1.3.8 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +2 -2
- data/.gitignore +1 -0
- data/.rubocop.yml +51 -3
- data/CHANGELOG.md +16 -1
- data/Gemfile.lock +50 -30
- data/README.md +7 -0
- data/click_house.gemspec +2 -2
- data/docker-compose.yml +1 -1
- data/lib/click_house/config.rb +5 -1
- data/lib/click_house/connection.rb +20 -3
- data/lib/click_house/extend/connection_altering.rb +27 -0
- data/lib/click_house/extend/connection_explaining.rb +4 -2
- data/lib/click_house/extend/connection_healthy.rb +1 -2
- data/lib/click_house/extend/connection_selective.rb +3 -3
- data/lib/click_house/middleware/logging.rb +24 -5
- data/lib/click_house/response/factory.rb +6 -1
- data/lib/click_house/response/result_set.rb +6 -2
- data/lib/click_house/type/decimal_type.rb +2 -2
- data/lib/click_house/type/float_type.rb +1 -1
- data/lib/click_house/type/integer_type.rb +1 -1
- data/lib/click_house/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 402590e2de7189b46fca70711b33bf8428ccbc677d8d98ad4205b470bcf5eeb4
|
4
|
+
data.tar.gz: b3a33602650115c46c638347b993d118921e7254a2ed9f20bdb92ad30c50a05a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d71565e61efb57711463fa3b4071d418ad8136656d64e3de15fbb7f4b48134ab284e9b2dc13b0dcbdf77dd9bee19aa4757593b0dee98480ac6cd64cc4e85a5f
|
7
|
+
data.tar.gz: c2d45bd01a211acfb8be077d38ac93807c191c95a3a6fe2a6ac63a7a097b5c599351f0c6282b86d533eff2dd59d2820c0f824ffd975d0cd6692636eb0bb31e48
|
data/.github/workflows/main.yml
CHANGED
@@ -8,13 +8,13 @@ jobs:
|
|
8
8
|
|
9
9
|
services:
|
10
10
|
clickhouse:
|
11
|
-
image: yandex/clickhouse-server:
|
11
|
+
image: yandex/clickhouse-server:22.1
|
12
12
|
ports:
|
13
13
|
- 8123:8123
|
14
14
|
|
15
15
|
strategy:
|
16
16
|
matrix:
|
17
|
-
ruby-version: [
|
17
|
+
ruby-version: [3.1, 3.0, 2.7, 2.6]
|
18
18
|
|
19
19
|
steps:
|
20
20
|
- uses: actions/checkout@v2
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -13,9 +13,9 @@ AllCops:
|
|
13
13
|
Bundler/OrderedGems:
|
14
14
|
Enabled: false
|
15
15
|
|
16
|
-
# ==============================
|
17
|
-
|
18
|
-
Enabled:
|
16
|
+
# ============================== Gemspec ======================
|
17
|
+
Gemspec/DateAssignment:
|
18
|
+
Enabled: true
|
19
19
|
|
20
20
|
# =============================== Performance =======================
|
21
21
|
Performance/AncestorsInclude:
|
@@ -46,6 +46,12 @@ Performance/ConstantRegexp:
|
|
46
46
|
Enabled: true
|
47
47
|
Performance/MethodObjectAsBlock:
|
48
48
|
Enabled: false
|
49
|
+
Performance/RedundantEqualityComparisonBlock:
|
50
|
+
Enabled: true
|
51
|
+
Performance/RedundantSplitRegexpArgument:
|
52
|
+
Enabled: true
|
53
|
+
Performance/MapCompact:
|
54
|
+
Enabled: true
|
49
55
|
|
50
56
|
# ============================== Metrics ============================
|
51
57
|
Metrics/ClassLength:
|
@@ -69,6 +75,8 @@ Naming/MethodParameterName:
|
|
69
75
|
Enabled: false
|
70
76
|
Naming/AccessorMethodName:
|
71
77
|
Enabled: false
|
78
|
+
Naming/InclusiveLanguage:
|
79
|
+
Enabled: true
|
72
80
|
|
73
81
|
# ============================== Layout =============================
|
74
82
|
Layout/LineLength:
|
@@ -105,6 +113,10 @@ Layout/EmptyLinesAroundAttributeAccessor:
|
|
105
113
|
Enabled: true
|
106
114
|
Layout/SpaceAroundMethodCallOperator:
|
107
115
|
Enabled: true
|
116
|
+
Layout/SpaceBeforeBrackets:
|
117
|
+
Enabled: true
|
118
|
+
Layout/LineEndStringConcatenationIndentation:
|
119
|
+
Enabled: true
|
108
120
|
|
109
121
|
# ============================== Style ==============================
|
110
122
|
Style/RescueModifier:
|
@@ -217,6 +229,24 @@ Style/SwapValues:
|
|
217
229
|
Enabled: true
|
218
230
|
Style/RedundantArgument:
|
219
231
|
Enabled: true
|
232
|
+
Style/HashExcept:
|
233
|
+
Enabled: true
|
234
|
+
Style/EndlessMethod:
|
235
|
+
Enabled: true
|
236
|
+
Style/IfWithBooleanLiteralBranches:
|
237
|
+
Enabled: true
|
238
|
+
Style/HashConversion:
|
239
|
+
Enabled: true
|
240
|
+
Style/Documentation:
|
241
|
+
Enabled: false
|
242
|
+
Style/InPatternThen:
|
243
|
+
Enabled: true
|
244
|
+
Style/MultilineInPatternThen:
|
245
|
+
Enabled: true
|
246
|
+
Style/QuotedSymbols:
|
247
|
+
Enabled: true
|
248
|
+
Style/StringChars:
|
249
|
+
Enabled: true
|
220
250
|
|
221
251
|
# ============================== Lint ==============================
|
222
252
|
Lint/DuplicateMethods:
|
@@ -287,3 +317,21 @@ Lint/UnmodifiedReduceAccumulator:
|
|
287
317
|
Enabled: true
|
288
318
|
Lint/UnexpectedBlockArity:
|
289
319
|
Enabled: true
|
320
|
+
Lint/DeprecatedConstants:
|
321
|
+
Enabled: true
|
322
|
+
Lint/LambdaWithoutLiteralBlock:
|
323
|
+
Enabled: true
|
324
|
+
Lint/NumberedParameterAssignment:
|
325
|
+
Enabled: true
|
326
|
+
Lint/OrAssignmentToConstant:
|
327
|
+
Enabled: true
|
328
|
+
Lint/RedundantDirGlobSort:
|
329
|
+
Enabled: true
|
330
|
+
Lint/SymbolConversion:
|
331
|
+
Enabled: true
|
332
|
+
Lint/TripleQuotes:
|
333
|
+
Enabled: true
|
334
|
+
Lint/AmbiguousAssignment:
|
335
|
+
Enabled: true
|
336
|
+
Lint/EmptyInPattern:
|
337
|
+
Enabled: true
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# 1.6.0
|
2
|
+
* [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
|
+
* [PR](https://github.com/shlima/click_house/pull/18) Fix Faraday deprecation
|
4
|
+
|
5
|
+
# 1.5.0
|
6
|
+
* add support for 'WITH TOTALS' modifier in response
|
7
|
+
* send SQL in GET request's body [#12](https://github.com/shlima/click_house/pull/12)
|
8
|
+
* add support of 'WITH TOTALS' on a resulting set
|
9
|
+
|
10
|
+
# 1.4.0
|
11
|
+
* fix decimal type casting [#11](https://github.com/shlima/click_house/issues/11)
|
12
|
+
|
13
|
+
# 1.3.9
|
14
|
+
* add `ClickHouse.connection.add_index`, `ClickHouse.connection.drop_index`
|
15
|
+
|
1
16
|
# 1.3.8
|
2
17
|
* fix `DateTime` casting for queries like `ClickHouse.connection.select_value('select NOW()')`
|
3
18
|
* fix resulting set console inspection
|
@@ -9,7 +24,7 @@
|
|
9
24
|
* fix ruby 2.7 warning `maybe ** should be added to the call` on `ClickHouse.connection.databases`
|
10
25
|
|
11
26
|
# 1.3.5
|
12
|
-
* added `ClickHouse.
|
27
|
+
* added `ClickHouse.connection.explain("sql")`
|
13
28
|
|
14
29
|
# 1.3.4
|
15
30
|
* added `ClickHouse.type_names(nullable: false)`
|
data/Gemfile.lock
CHANGED
@@ -1,63 +1,83 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
click_house (1.
|
5
|
-
faraday
|
4
|
+
click_house (1.5.0)
|
5
|
+
faraday (>= 1.7)
|
6
6
|
faraday_middleware
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
ast (2.4.
|
11
|
+
ast (2.4.2)
|
12
12
|
coderay (1.1.3)
|
13
|
-
diff-lcs (1.
|
14
|
-
faraday (1.
|
13
|
+
diff-lcs (1.5.0)
|
14
|
+
faraday (1.9.3)
|
15
|
+
faraday-em_http (~> 1.0)
|
16
|
+
faraday-em_synchrony (~> 1.0)
|
17
|
+
faraday-excon (~> 1.1)
|
18
|
+
faraday-httpclient (~> 1.0)
|
19
|
+
faraday-multipart (~> 1.0)
|
20
|
+
faraday-net_http (~> 1.0)
|
21
|
+
faraday-net_http_persistent (~> 1.0)
|
22
|
+
faraday-patron (~> 1.0)
|
23
|
+
faraday-rack (~> 1.0)
|
24
|
+
faraday-retry (~> 1.0)
|
25
|
+
ruby2_keywords (>= 0.0.4)
|
26
|
+
faraday-em_http (1.0.0)
|
27
|
+
faraday-em_synchrony (1.0.0)
|
28
|
+
faraday-excon (1.1.0)
|
29
|
+
faraday-httpclient (1.0.1)
|
30
|
+
faraday-multipart (1.0.3)
|
15
31
|
multipart-post (>= 1.2, < 3)
|
16
|
-
|
17
|
-
|
32
|
+
faraday-net_http (1.0.1)
|
33
|
+
faraday-net_http_persistent (1.2.0)
|
34
|
+
faraday-patron (1.0.0)
|
35
|
+
faraday-rack (1.0.0)
|
36
|
+
faraday-retry (1.0.3)
|
37
|
+
faraday_middleware (1.2.0)
|
18
38
|
faraday (~> 1.0)
|
19
39
|
method_source (1.0.0)
|
20
40
|
multipart-post (2.1.1)
|
21
|
-
parallel (1.
|
22
|
-
parser (
|
41
|
+
parallel (1.21.0)
|
42
|
+
parser (3.1.0.0)
|
23
43
|
ast (~> 2.4.1)
|
24
|
-
pry (0.
|
44
|
+
pry (0.14.1)
|
25
45
|
coderay (~> 1.1)
|
26
46
|
method_source (~> 1.0)
|
27
|
-
rainbow (3.
|
28
|
-
rake (13.0.
|
29
|
-
regexp_parser (2.0
|
30
|
-
rexml (3.2.
|
47
|
+
rainbow (3.1.1)
|
48
|
+
rake (13.0.6)
|
49
|
+
regexp_parser (2.2.0)
|
50
|
+
rexml (3.2.5)
|
31
51
|
rspec (3.10.0)
|
32
52
|
rspec-core (~> 3.10.0)
|
33
53
|
rspec-expectations (~> 3.10.0)
|
34
54
|
rspec-mocks (~> 3.10.0)
|
35
|
-
rspec-core (3.10.
|
55
|
+
rspec-core (3.10.1)
|
36
56
|
rspec-support (~> 3.10.0)
|
37
|
-
rspec-expectations (3.10.
|
57
|
+
rspec-expectations (3.10.2)
|
38
58
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
59
|
rspec-support (~> 3.10.0)
|
40
|
-
rspec-mocks (3.10.
|
60
|
+
rspec-mocks (3.10.2)
|
41
61
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
62
|
rspec-support (~> 3.10.0)
|
43
|
-
rspec-support (3.10.
|
44
|
-
rubocop (1.
|
63
|
+
rspec-support (3.10.3)
|
64
|
+
rubocop (1.25.0)
|
45
65
|
parallel (~> 1.10)
|
46
|
-
parser (>=
|
66
|
+
parser (>= 3.1.0.0)
|
47
67
|
rainbow (>= 2.2.2, < 4.0)
|
48
68
|
regexp_parser (>= 1.8, < 3.0)
|
49
69
|
rexml
|
50
|
-
rubocop-ast (>= 1.
|
70
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
51
71
|
ruby-progressbar (~> 1.7)
|
52
|
-
unicode-display_width (>= 1.4.0, <
|
53
|
-
rubocop-ast (1.
|
54
|
-
parser (>=
|
55
|
-
rubocop-performance (1.
|
56
|
-
rubocop (>=
|
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)
|
76
|
+
rubocop (>= 1.7.0, < 2.0)
|
57
77
|
rubocop-ast (>= 0.4.0)
|
58
|
-
ruby-progressbar (1.
|
59
|
-
ruby2_keywords (0.0.
|
60
|
-
unicode-display_width (1.
|
78
|
+
ruby-progressbar (1.11.0)
|
79
|
+
ruby2_keywords (0.0.5)
|
80
|
+
unicode-display_width (2.1.0)
|
61
81
|
|
62
82
|
PLATFORMS
|
63
83
|
ruby
|
@@ -72,4 +92,4 @@ DEPENDENCIES
|
|
72
92
|
rubocop-performance
|
73
93
|
|
74
94
|
BUNDLED WITH
|
75
|
-
2.
|
95
|
+
2.3.3
|
data/README.md
CHANGED
@@ -104,6 +104,9 @@ ClickHouse.connection.truncate_tables(['table_1', 'table_2'], if_exists: true, c
|
|
104
104
|
ClickHouse.connection.truncate_tables # will truncate all tables in database
|
105
105
|
ClickHouse.connection.rename_table('old_name', 'new_name', cluster: nil)
|
106
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)
|
107
110
|
|
108
111
|
ClickHouse.connection.select_all('SELECT * FROM visits')
|
109
112
|
ClickHouse.connection.select_one('SELECT * FROM visits LIMIT 1')
|
@@ -497,6 +500,10 @@ class ClickHouseRecord < ActiveRecord::Base
|
|
497
500
|
def select_all
|
498
501
|
agent.select_all(current_scope.to_sql)
|
499
502
|
end
|
503
|
+
|
504
|
+
def explain
|
505
|
+
agent.explain(current_scope.to_sql)
|
506
|
+
end
|
500
507
|
end
|
501
508
|
end
|
502
509
|
````
|
data/click_house.gemspec
CHANGED
@@ -10,7 +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.
|
13
|
+
spec.required_ruby_version = '>= 2.6.0'
|
14
14
|
|
15
15
|
# Specify which files should be added to the gem when it is released.
|
16
16
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_dependency 'faraday'
|
24
|
+
spec.add_dependency 'faraday', '>= 1.7'
|
25
25
|
spec.add_dependency 'faraday_middleware'
|
26
26
|
spec.add_development_dependency 'bundler'
|
27
27
|
spec.add_development_dependency 'rake'
|
data/docker-compose.yml
CHANGED
data/lib/click_house/config.rb
CHANGED
@@ -49,11 +49,15 @@ module ClickHouse
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def logger!
|
52
|
-
@logger ||
|
52
|
+
@logger || null_logger
|
53
53
|
end
|
54
54
|
|
55
55
|
def url!
|
56
56
|
@url || "#{scheme}://#{host}:#{port}"
|
57
57
|
end
|
58
|
+
|
59
|
+
def null_logger
|
60
|
+
@null_logger ||= Logger.new(IO::NULL)
|
61
|
+
end
|
58
62
|
end
|
59
63
|
end
|
@@ -21,8 +21,25 @@ module ClickHouse
|
|
21
21
|
post(body, query: { query: query }, database: database)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# @param path [String] Clickhouse HTTP endpoint, e.g. /ping, /replica_status
|
25
|
+
# @param body [String] SQL to run
|
26
|
+
# @param database [String|NilClass] database to use, nil to skip
|
27
|
+
# @param query [Hash] other CH settings to send through params, e.g. max_rows_to_read=1
|
28
|
+
# @example get(body: 'select number from system.numbers limit 100', query: { max_rows_to_read: 10 })
|
29
|
+
# @return [Faraday::Response]
|
30
|
+
def get(path = '/', body: '', query: {}, database: config.database)
|
31
|
+
# backward compatibility since
|
32
|
+
# https://github.com/shlima/click_house/pull/12/files#diff-9c6f3f06d3b575731eae4b6b95ddbcdcc20452c432b8f6e87a3a8e8645818107R24
|
33
|
+
if query.is_a?(String)
|
34
|
+
query = { query: query }
|
35
|
+
config.logger!.warn('since v1.4.0 use connection.get(body: "SELECT 1") instead of connection.get(query: "SELECT 1")')
|
36
|
+
end
|
37
|
+
|
38
|
+
transport.get(path) do |conn|
|
39
|
+
conn.params = query.merge(database: database).compact
|
40
|
+
conn.params[:send_progress_in_http_headers] = 1 unless body.empty?
|
41
|
+
conn.body = body
|
42
|
+
end
|
26
43
|
end
|
27
44
|
|
28
45
|
def post(body = nil, query: {}, database: config.database)
|
@@ -35,7 +52,7 @@ module ClickHouse
|
|
35
52
|
conn.options.open_timeout = config.open_timeout
|
36
53
|
conn.headers = config.headers
|
37
54
|
conn.ssl.verify = config.ssl_verify
|
38
|
-
conn.basic_auth
|
55
|
+
conn.request(:basic_auth, config.username, config.password) if config.auth?
|
39
56
|
conn.response Middleware::Logging, logger: config.logger!
|
40
57
|
conn.response Middleware::RaiseError
|
41
58
|
conn.response :json, content_type: %r{application/json}
|
@@ -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
|
@@ -6,9 +6,11 @@ module ClickHouse
|
|
6
6
|
EXPLAIN = 'EXPLAIN'
|
7
7
|
EXPLAIN_RE = /\A(\s*#{EXPLAIN})/io.freeze
|
8
8
|
|
9
|
-
|
9
|
+
# @return String
|
10
|
+
def explain(sql, io: StringIO.new)
|
10
11
|
res = execute("#{EXPLAIN} #{sql.gsub(EXPLAIN_RE, '')}")
|
11
|
-
io
|
12
|
+
io.puts(res.body)
|
13
|
+
io.string
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -4,8 +4,7 @@ module ClickHouse
|
|
4
4
|
module Extend
|
5
5
|
module ConnectionHealthy
|
6
6
|
def ping
|
7
|
-
|
8
|
-
get(database: nil, query: { send_progress_in_http_headers: nil }).success?
|
7
|
+
get('/ping', database: nil).success?
|
9
8
|
end
|
10
9
|
|
11
10
|
def replicas_status
|
@@ -5,17 +5,17 @@ module ClickHouse
|
|
5
5
|
module ConnectionSelective
|
6
6
|
# @return [ResultSet]
|
7
7
|
def select_all(sql)
|
8
|
-
response =
|
8
|
+
response = get(body: Util::Statement.format(sql, 'JSON'))
|
9
9
|
Response::Factory[response]
|
10
10
|
end
|
11
11
|
|
12
12
|
def select_value(sql)
|
13
|
-
response =
|
13
|
+
response = get(body: Util::Statement.format(sql, 'JSON'))
|
14
14
|
Array(Response::Factory[response].first).dig(0, -1)
|
15
15
|
end
|
16
16
|
|
17
17
|
def select_one(sql)
|
18
|
-
response =
|
18
|
+
response = get(body: Util::Statement.format(sql, 'JSON'))
|
19
19
|
Response::Factory[response].first
|
20
20
|
end
|
21
21
|
end
|
@@ -29,11 +29,8 @@ module ClickHouse
|
|
29
29
|
# rubocop:disable Layout/LineLength
|
30
30
|
def on_complete(env)
|
31
31
|
summary = extract_summary(env.response_headers)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
logger.info("\e[1m[35mSQL (#{Util::Pretty.measure(elapsed)})\e[0m #{query};")
|
36
|
-
logger.debug(body) if body
|
32
|
+
logger.info("\e[1m[35mSQL (#{duration_stats_log(env.body)})\e[0m #{query(env)};")
|
33
|
+
logger.debug(body) if body && !query_in_body?(env)
|
37
34
|
logger.info("\e[1m[36mRead: #{summary.fetch(:read_rows)} rows, #{summary.fetch(:read_bytes)}. Written: #{summary.fetch(:written_rows)} rows, #{summary.fetch(:written_bytes)}\e[0m")
|
38
35
|
end
|
39
36
|
# rubocop:enable Layout/LineLength
|
@@ -46,6 +43,28 @@ module ClickHouse
|
|
46
43
|
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
47
44
|
end
|
48
45
|
|
46
|
+
def query_in_body?(env)
|
47
|
+
env.method == :get
|
48
|
+
end
|
49
|
+
|
50
|
+
def query(env)
|
51
|
+
if query_in_body?(env)
|
52
|
+
body
|
53
|
+
else
|
54
|
+
CGI.parse(env.url.query.to_s).dig('query', 0) || '[NO QUERY]'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def duration_stats_log(body)
|
59
|
+
elapsed = duration
|
60
|
+
clickhouse_elapsed = body['statistics'].fetch('elapsed') if body.is_a?(Hash) && body.key?('statistics')
|
61
|
+
|
62
|
+
[
|
63
|
+
"Total: #{Util::Pretty.measure(elapsed * 1000)}",
|
64
|
+
("CH: #{Util::Pretty.measure(clickhouse_elapsed * 1000)}" if clickhouse_elapsed)
|
65
|
+
].compact.join(', ')
|
66
|
+
end
|
67
|
+
|
49
68
|
def extract_summary(headers)
|
50
69
|
JSON.parse(headers.fetch('x-clickhouse-summary', '{}')).tap do |summary|
|
51
70
|
summary[:read_rows] = summary['read_rows']
|
@@ -10,7 +10,12 @@ module ClickHouse
|
|
10
10
|
|
11
11
|
return body if !body.is_a?(Hash) || !(body.key?('meta') && body.key?('data'))
|
12
12
|
|
13
|
-
ResultSet.new(
|
13
|
+
ResultSet.new(
|
14
|
+
meta: body.fetch('meta'),
|
15
|
+
data: body.fetch('data'),
|
16
|
+
totals: body['totals'],
|
17
|
+
statistics: body['statistics']
|
18
|
+
)
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -14,7 +14,7 @@ module ClickHouse
|
|
14
14
|
:inspect, :each, :fetch, :length, :count, :size,
|
15
15
|
:first, :last, :[], :to_h
|
16
16
|
|
17
|
-
attr_reader :meta, :data, :statistics
|
17
|
+
attr_reader :meta, :data, :totals, :statistics
|
18
18
|
|
19
19
|
class << self
|
20
20
|
# @return [Array<String, Array>]
|
@@ -48,9 +48,13 @@ module ClickHouse
|
|
48
48
|
|
49
49
|
# @param meta [Array]
|
50
50
|
# @param data [Array]
|
51
|
-
|
51
|
+
# @param totals [Array|Hash|NilClass] Support for 'GROUP BY WITH TOTALS' modifier
|
52
|
+
# https://clickhouse.tech/docs/en/sql-reference/statements/select/group-by/#with-totals-modifier
|
53
|
+
# Hash in JSON format and Array in JSONCompact
|
54
|
+
def initialize(meta:, data:, totals: nil, statistics: nil)
|
52
55
|
@meta = meta
|
53
56
|
@data = data
|
57
|
+
@totals = totals
|
54
58
|
@statistics = Hash(statistics)
|
55
59
|
end
|
56
60
|
|
@@ -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.
|
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
|
11
|
+
BigDecimal(value, precision.to_i).to_f unless value.nil?
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/click_house/version.rb
CHANGED
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.
|
4
|
+
version: 1.6.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:
|
11
|
+
date: 2022-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday_middleware
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,14 +203,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
203
203
|
requirements:
|
204
204
|
- - ">="
|
205
205
|
- !ruby/object:Gem::Version
|
206
|
-
version: 2.
|
206
|
+
version: 2.6.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.
|
213
|
+
rubygems_version: 3.3.3
|
214
214
|
signing_key:
|
215
215
|
specification_version: 4
|
216
216
|
summary: Modern Ruby database driver for ClickHouse
|