clickhouse-activerecord 1.2.1 → 1.3.1
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/.docker/docker-compose.cluster.yml +0 -2
- data/.docker/docker-compose.yml +0 -1
- data/.github/workflows/testing.yml +9 -5
- data/README.md +5 -1
- data/clickhouse-activerecord.gemspec +1 -1
- data/lib/active_record/connection_adapters/clickhouse/schema_statements.rb +6 -4
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +4 -2
- data/lib/arel/visitors/clickhouse.rb +16 -6
- data/lib/clickhouse-activerecord/tasks.rb +1 -1
- data/lib/clickhouse-activerecord/version.rb +1 -1
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8710787ab541533a020ea884090c897bd47a7bfefb0cd93bf552e6776ae2583
|
4
|
+
data.tar.gz: 104eb3ec2a235899004ecc1c0ff01432da4b1fccfdfa5144e041351aaedc9dfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8346c11c2f912c78f82129f66f0fcc09e4c6689fe64a3d31cbb951c4046ae7102e7e33cd05258eb8b8136c4aa41a0f0297562b2228b8540480a8a6d6d4554edf
|
7
|
+
data.tar.gz: bae4f5c8a7b2ceb3eb9341f0b64cd1c57694791db3aecbdb3b92b4ed98ac4b76246ca0941e19f1f66ca28c96b51b82dbbde98d7552e7c856978de7abf3667db6
|
data/.docker/docker-compose.yml
CHANGED
@@ -28,13 +28,15 @@ jobs:
|
|
28
28
|
rails: 7.1.3
|
29
29
|
- ruby: 3.2
|
30
30
|
rails: 7.2.1
|
31
|
-
|
31
|
+
- ruby: 3.2
|
32
|
+
rails: 8.0.1
|
33
|
+
clickhouse: [ '22.1', '24.9' ]
|
32
34
|
|
33
35
|
steps:
|
34
36
|
- uses: actions/checkout@v4
|
35
37
|
|
36
38
|
- name: Start ClickHouse ${{ matrix.clickhouse }}
|
37
|
-
uses:
|
39
|
+
uses: hoverkraft-tech/compose-action@v2.1.0
|
38
40
|
env:
|
39
41
|
CLICKHOUSE_VERSION: ${{ matrix.clickhouse }}
|
40
42
|
with:
|
@@ -72,14 +74,16 @@ jobs:
|
|
72
74
|
- ruby: 3.2
|
73
75
|
rails: 7.1.3
|
74
76
|
- ruby: 3.2
|
75
|
-
rails: 7.2.
|
76
|
-
|
77
|
+
rails: 7.2.1
|
78
|
+
- ruby: 3.2
|
79
|
+
rails: 8.0.1
|
80
|
+
clickhouse: [ '22.1', '24.9' ]
|
77
81
|
|
78
82
|
steps:
|
79
83
|
- uses: actions/checkout@v4
|
80
84
|
|
81
85
|
- name: Start ClickHouse Cluster ${{ matrix.clickhouse }}
|
82
|
-
uses:
|
86
|
+
uses: hoverkraft-tech/compose-action@v2.1.0
|
83
87
|
env:
|
84
88
|
CLICKHOUSE_VERSION: ${{ matrix.clickhouse }}
|
85
89
|
with:
|
data/README.md
CHANGED
@@ -184,7 +184,11 @@ Action.settings(optimize_read_in_order: 1).where(date: Date.current).limit(10)
|
|
184
184
|
|
185
185
|
User.joins(:actions).using(:group_id)
|
186
186
|
# Clickhouse User Load (10.3ms) SELECT users.* FROM users INNER JOIN actions USING group_id
|
187
|
-
#=> #<ActiveRecord::Relation [#<
|
187
|
+
#=> #<ActiveRecord::Relation [#<User *** >]>
|
188
|
+
|
189
|
+
User.window('x', order: 'date', partition: 'name', rows: 'UNBOUNDED PRECEDING').select('sum(value) OVER x')
|
190
|
+
# SELECT sum(value) OVER x FROM users WINDOW x AS (PARTITION BY name ORDER BY date ROWS UNBOUNDED PRECEDING)
|
191
|
+
#=> #<ActiveRecord::Relation [#<User *** >]>
|
188
192
|
```
|
189
193
|
|
190
194
|
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
|
26
26
|
spec.add_runtime_dependency 'bundler', '>= 1.13.4'
|
27
|
-
spec.add_runtime_dependency 'activerecord', '
|
27
|
+
spec.add_runtime_dependency 'activerecord', '>= 7.1', '< 9.0'
|
28
28
|
|
29
29
|
spec.add_development_dependency 'rake', '~> 13.0'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
@@ -178,10 +178,12 @@ module ActiveRecord
|
|
178
178
|
def request(sql, format = nil, settings = {})
|
179
179
|
formatted_sql = apply_format(sql, format)
|
180
180
|
request_params = @connection_config || {}
|
181
|
-
@
|
182
|
-
|
183
|
-
|
184
|
-
|
181
|
+
@lock.synchronize do
|
182
|
+
@connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql, {
|
183
|
+
'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}",
|
184
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
185
|
+
})
|
186
|
+
end
|
185
187
|
end
|
186
188
|
|
187
189
|
def apply_format(sql, format)
|
@@ -300,9 +300,11 @@ module ActiveRecord
|
|
300
300
|
end
|
301
301
|
|
302
302
|
# @param [String] table
|
303
|
+
# @option [Boolean] single_line
|
303
304
|
# @return [String]
|
304
|
-
def show_create_table(table)
|
305
|
-
do_system_execute("SHOW CREATE TABLE `#{table}`")['data'].try(:first).try(:first).gsub(
|
305
|
+
def show_create_table(table, single_line: true)
|
306
|
+
sql = do_system_execute("SHOW CREATE TABLE `#{table}`")['data'].try(:first).try(:first).gsub("#{@config[:database]}.", '')
|
307
|
+
single_line ? sql.squish : sql
|
306
308
|
end
|
307
309
|
|
308
310
|
# Create a new ClickHouse database.
|
@@ -4,6 +4,11 @@ module Arel
|
|
4
4
|
module Visitors
|
5
5
|
class Clickhouse < ::Arel::Visitors::ToSql
|
6
6
|
|
7
|
+
def compile(node, collector = Arel::Collectors::SQLString.new)
|
8
|
+
@delete_or_update = false
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
7
12
|
def aggregate(name, o, collector)
|
8
13
|
# replacing function name for materialized view
|
9
14
|
if o.expressions.first && o.expressions.first != '*' && !o.expressions.first.is_a?(String) && o.expressions.first.relation&.is_view
|
@@ -16,12 +21,11 @@ module Arel
|
|
16
21
|
# https://clickhouse.com/docs/en/sql-reference/statements/delete
|
17
22
|
# DELETE and UPDATE in ClickHouse working only without table name
|
18
23
|
def visit_Arel_Attributes_Attribute(o, collector)
|
19
|
-
|
20
|
-
|
21
|
-
collector <<
|
22
|
-
else
|
23
|
-
super
|
24
|
+
unless @delete_or_update
|
25
|
+
join_name = o.relation.table_alias || o.relation.name
|
26
|
+
collector << quote_table_name(join_name) << '.'
|
24
27
|
end
|
28
|
+
collector << quote_column_name(o.name)
|
25
29
|
end
|
26
30
|
|
27
31
|
def visit_Arel_Nodes_SelectOptions(o, collector)
|
@@ -30,6 +34,7 @@ module Arel
|
|
30
34
|
end
|
31
35
|
|
32
36
|
def visit_Arel_Nodes_UpdateStatement(o, collector)
|
37
|
+
@delete_or_update = true
|
33
38
|
o = prepare_update_statement(o)
|
34
39
|
|
35
40
|
collector << 'ALTER TABLE '
|
@@ -40,6 +45,11 @@ module Arel
|
|
40
45
|
maybe_visit o.limit, collector
|
41
46
|
end
|
42
47
|
|
48
|
+
def visit_Arel_Nodes_DeleteStatement(o, collector)
|
49
|
+
@delete_or_update = true
|
50
|
+
super
|
51
|
+
end
|
52
|
+
|
43
53
|
def visit_Arel_Nodes_Final(o, collector)
|
44
54
|
visit o.expr, collector
|
45
55
|
collector << ' FINAL'
|
@@ -64,7 +74,7 @@ module Arel
|
|
64
74
|
collector
|
65
75
|
end
|
66
76
|
|
67
|
-
def visit_Arel_Nodes_Using
|
77
|
+
def visit_Arel_Nodes_Using(o, collector)
|
68
78
|
collector << "USING "
|
69
79
|
visit o.expr, collector
|
70
80
|
collector
|
@@ -40,7 +40,7 @@ module ClickhouseActiverecord
|
|
40
40
|
# get all tables
|
41
41
|
tables = connection.execute("SHOW TABLES FROM #{@configuration.database} WHERE name NOT LIKE '.inner_id.%'")['data'].flatten.map do |table|
|
42
42
|
next if %w[schema_migrations ar_internal_metadata].include?(table)
|
43
|
-
connection.show_create_table(table).gsub("#{@configuration.database}.", '')
|
43
|
+
connection.show_create_table(table, single_line: false).gsub("#{@configuration.database}.", '')
|
44
44
|
end.compact
|
45
45
|
|
46
46
|
# sort view to last
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clickhouse-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Odintsov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,22 @@ dependencies:
|
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '7.1'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '9.0'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '7.1'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '9.0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: rake
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -160,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
166
|
- !ruby/object:Gem::Version
|
161
167
|
version: '0'
|
162
168
|
requirements: []
|
163
|
-
rubygems_version: 3.
|
169
|
+
rubygems_version: 3.3.7
|
164
170
|
signing_key:
|
165
171
|
specification_version: 4
|
166
172
|
summary: ClickHouse ActiveRecord
|