umbrellio-utils 1.12.1 → 1.13.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 +4 -4
- data/.github/workflows/test.yml +1 -1
- data/.rubocop.yml +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +181 -175
- data/bin/clickhouse-server +1 -2
- data/lib/umbrellio_utils/cards.rb +4 -3
- data/lib/umbrellio_utils/click_house/backends/base.rb +178 -0
- data/lib/umbrellio_utils/click_house/backends/legacy.rb +92 -0
- data/lib/umbrellio_utils/click_house/backends/native.rb +112 -0
- data/lib/umbrellio_utils/click_house/backends.rb +12 -0
- data/lib/umbrellio_utils/click_house/config.rb +13 -0
- data/lib/umbrellio_utils/click_house.rb +28 -166
- data/lib/umbrellio_utils/control.rb +2 -2
- data/lib/umbrellio_utils/database.rb +5 -2
- data/lib/umbrellio_utils/http_client.rb +6 -6
- data/lib/umbrellio_utils/migrations.rb +6 -3
- data/lib/umbrellio_utils/sql.rb +8 -8
- data/lib/umbrellio_utils/tasks/clickhouse_connect.rake +6 -5
- data/lib/umbrellio_utils/version.rb +1 -1
- data/lib/umbrellio_utils.rb +17 -1
- data/umbrellio_utils.gemspec +1 -1
- metadata +9 -4
|
@@ -200,16 +200,19 @@ module UmbrellioUtils
|
|
|
200
200
|
end
|
|
201
201
|
|
|
202
202
|
def create_distributed_table!(table_name, sharding_key, db_name: UmbrellioUtils::ClickHouse.db_name)
|
|
203
|
+
cluster = UmbrellioUtils.config.clickhouse_cluster
|
|
204
|
+
on_cluster = UmbrellioUtils::ClickHouse.on_cluster
|
|
205
|
+
|
|
203
206
|
UmbrellioUtils::ClickHouse.execute(<<~SQL.squish)
|
|
204
207
|
DROP TABLE IF EXISTS #{db_name}.#{table_name}_distributed
|
|
205
|
-
|
|
208
|
+
#{on_cluster}
|
|
206
209
|
SQL
|
|
207
210
|
|
|
208
211
|
UmbrellioUtils::ClickHouse.execute(<<~SQL.squish)
|
|
209
212
|
CREATE TABLE #{db_name}.#{table_name}_distributed
|
|
210
|
-
|
|
213
|
+
#{on_cluster}
|
|
211
214
|
AS #{db_name}.#{table_name}
|
|
212
|
-
ENGINE = Distributed(
|
|
215
|
+
ENGINE = Distributed(#{cluster}, #{db_name}, #{table_name}, #{sharding_key})
|
|
213
216
|
SQL
|
|
214
217
|
end
|
|
215
218
|
|
data/lib/umbrellio_utils/sql.rb
CHANGED
|
@@ -6,8 +6,8 @@ module UmbrellioUtils
|
|
|
6
6
|
|
|
7
7
|
UniqueConstraintViolation = Sequel::UniqueConstraintViolation
|
|
8
8
|
|
|
9
|
-
def [](*
|
|
10
|
-
Sequel[*
|
|
9
|
+
def [](*)
|
|
10
|
+
Sequel[*]
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def func(...)
|
|
@@ -47,8 +47,8 @@ module UmbrellioUtils
|
|
|
47
47
|
Sequel.|(*Array(conditions.flatten.presence || true))
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
def pg_range(from_value, to_value, **
|
|
51
|
-
Sequel::Postgres::PGRange.new(from_value, to_value, **
|
|
50
|
+
def pg_range(from_value, to_value, **)
|
|
51
|
+
Sequel::Postgres::PGRange.new(from_value, to_value, **)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def pg_range_by_range(range)
|
|
@@ -79,8 +79,8 @@ module UmbrellioUtils
|
|
|
79
79
|
expr ? func(:count, expr) : func(:count).*
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
-
def ch_count(*
|
|
83
|
-
Sequel.function(:count, *
|
|
82
|
+
def ch_count(*)
|
|
83
|
+
Sequel.function(:count, *)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
def avg(expr)
|
|
@@ -107,8 +107,8 @@ module UmbrellioUtils
|
|
|
107
107
|
func(:coalesce, *exprs)
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
def coalesce0(*
|
|
111
|
-
coalesce(
|
|
110
|
+
def coalesce0(*)
|
|
111
|
+
coalesce(*, 0)
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
def nullif(main_expr, checking_expr)
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
namespace :ch do
|
|
4
4
|
desc "run clickhouse client"
|
|
5
5
|
task connect: :environment do
|
|
6
|
+
cfg = UmbrellioUtils::ClickHouse.config
|
|
6
7
|
params = {
|
|
7
|
-
host: ENV.fetch("CLICKHOUSE_HOST",
|
|
8
|
-
user: ENV.fetch("CLICKHOUSE_USER",
|
|
9
|
-
password: ENV.fetch("CLICKHOUSE_PASSWORD",
|
|
10
|
-
database: ENV.fetch("CLICKHOUSE_DATABASE",
|
|
11
|
-
**
|
|
8
|
+
host: ENV.fetch("CLICKHOUSE_HOST", cfg.host),
|
|
9
|
+
user: ENV.fetch("CLICKHOUSE_USER", cfg.username),
|
|
10
|
+
password: ENV.fetch("CLICKHOUSE_PASSWORD", cfg.password),
|
|
11
|
+
database: ENV.fetch("CLICKHOUSE_DATABASE", cfg.database),
|
|
12
|
+
**(cfg.try(:global_params) || {}),
|
|
12
13
|
}.compact_blank
|
|
13
14
|
|
|
14
15
|
cmd = Shellwords.join(["clickhouse", "client", *params.map { |k, v| "--#{k}=#{v}" }])
|
data/lib/umbrellio_utils.rb
CHANGED
|
@@ -16,7 +16,16 @@ module UmbrellioUtils
|
|
|
16
16
|
def config
|
|
17
17
|
synchronize do
|
|
18
18
|
@@config ||= Struct
|
|
19
|
-
.new(
|
|
19
|
+
.new(
|
|
20
|
+
:store_table_name,
|
|
21
|
+
:http_client_name,
|
|
22
|
+
:ch_optimize_timeout,
|
|
23
|
+
:clickhouse_backend,
|
|
24
|
+
:clickhouse_native_settings,
|
|
25
|
+
:clickhouse_native_logger,
|
|
26
|
+
:clickhouse_cluster,
|
|
27
|
+
keyword_init: true,
|
|
28
|
+
)
|
|
20
29
|
.new(**default_settings)
|
|
21
30
|
end
|
|
22
31
|
end
|
|
@@ -25,6 +34,10 @@ module UmbrellioUtils
|
|
|
25
34
|
|
|
26
35
|
def configure
|
|
27
36
|
synchronize { yield config }
|
|
37
|
+
# Consumers on the native backend rely on `::ClickHouse.config`
|
|
38
|
+
# being available at rake/runtime (e.g. umbrellio-sequel-plugins'
|
|
39
|
+
# ch:create). Load the shim eagerly once the backend is selected.
|
|
40
|
+
require_relative "umbrellio_utils/click_house/config" if config.clickhouse_backend == :native
|
|
28
41
|
end
|
|
29
42
|
|
|
30
43
|
def extend_util!(module_name, &block)
|
|
@@ -39,6 +52,9 @@ module UmbrellioUtils
|
|
|
39
52
|
store_table_name: :store,
|
|
40
53
|
http_client_name: :application_httpclient,
|
|
41
54
|
ch_optimize_timeout: 5.minutes,
|
|
55
|
+
clickhouse_backend: :legacy,
|
|
56
|
+
clickhouse_native_settings: {},
|
|
57
|
+
clickhouse_cluster: "click_cluster",
|
|
42
58
|
}
|
|
43
59
|
end
|
|
44
60
|
|
data/umbrellio_utils.gemspec
CHANGED
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.description = "UmbrellioUtils is collection of utility classes and helpers"
|
|
13
13
|
spec.homepage = "https://github.com/umbrellio/utils"
|
|
14
14
|
spec.license = "MIT"
|
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 3.
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.3.0")
|
|
16
16
|
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
18
|
spec.metadata["source_code_uri"] = "https://github.com/umbrellio/utils"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: umbrellio-utils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Team Umbrellio
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-04-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: memery
|
|
@@ -51,6 +51,11 @@ files:
|
|
|
51
51
|
- lib/umbrellio_utils/cards.rb
|
|
52
52
|
- lib/umbrellio_utils/checks.rb
|
|
53
53
|
- lib/umbrellio_utils/click_house.rb
|
|
54
|
+
- lib/umbrellio_utils/click_house/backends.rb
|
|
55
|
+
- lib/umbrellio_utils/click_house/backends/base.rb
|
|
56
|
+
- lib/umbrellio_utils/click_house/backends/legacy.rb
|
|
57
|
+
- lib/umbrellio_utils/click_house/backends/native.rb
|
|
58
|
+
- lib/umbrellio_utils/click_house/config.rb
|
|
54
59
|
- lib/umbrellio_utils/constants.rb
|
|
55
60
|
- lib/umbrellio_utils/control.rb
|
|
56
61
|
- lib/umbrellio_utils/database.rb
|
|
@@ -90,14 +95,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
90
95
|
requirements:
|
|
91
96
|
- - ">="
|
|
92
97
|
- !ruby/object:Gem::Version
|
|
93
|
-
version: 3.
|
|
98
|
+
version: 3.3.0
|
|
94
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
100
|
requirements:
|
|
96
101
|
- - ">="
|
|
97
102
|
- !ruby/object:Gem::Version
|
|
98
103
|
version: '0'
|
|
99
104
|
requirements: []
|
|
100
|
-
rubygems_version: 3.
|
|
105
|
+
rubygems_version: 3.5.22
|
|
101
106
|
signing_key:
|
|
102
107
|
specification_version: 4
|
|
103
108
|
summary: A set of utilities that speed up development
|