clickhouse-activerecord 1.1.1 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/active_record/connection_adapters/clickhouse/quoting.rb +2 -2
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +14 -4
- data/lib/arel/visitors/clickhouse.rb +8 -0
- data/lib/clickhouse-activerecord/schema_dumper.rb +4 -9
- data/lib/clickhouse-activerecord/version.rb +1 -1
- data/lib/core_extensions/active_record/relation.rb +18 -0
- data/lib/core_extensions/arel/select_manager.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 419c50a4b99b183f729939034e8f6b671bf899fb0ef93fc97f105798fa437aa1
|
4
|
+
data.tar.gz: 7508a2ed443d64565ca6b1f5af48bf076cf40d2eae91fd3c3187cae05371a864
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e8607fa219f6e17e22a3029ba564e6d3d6d2bd39cf86f639d277a6e83fe2ffb1a47e93fceb8d20c4de6a7e9679f8a15b40ee744bfa445be14e6e0693dde4a0e
|
7
|
+
data.tar.gz: 5e58b79aab91a64387dc74821a75710c70738791227084a3a6ce29e72827a40e0458d48643a99c14b6d2dc6c94bbed8672d31051d7501084aa3a7e0bc27ef6a1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
### Version 1.1.2 (Aug 27, 2024)
|
2
|
+
* 🎉 Support for rails 7.2 #156
|
3
|
+
* Add method `views` for getting table `View` list in #152
|
4
|
+
* Add support for Map datatype in #144
|
5
|
+
* Add support window named functions
|
6
|
+
* Fix schema dumper default values for number
|
7
|
+
* Normalize table name in schema dump in #148
|
8
|
+
* Noop savepoint functionality in #150
|
9
|
+
* Fix `#find_by` in #153
|
10
|
+
* Add RSpec configure
|
11
|
+
* Fix detect model primary key
|
12
|
+
|
1
13
|
### Version 1.0.7 (Apr 27, 2024)
|
2
14
|
|
3
15
|
* Support table indexes
|
@@ -47,7 +47,7 @@ module ActiveRecord
|
|
47
47
|
|
48
48
|
module ModelSchema
|
49
49
|
module ClassMethods
|
50
|
-
delegate :final, :final!, :settings, :settings!, to: :all
|
50
|
+
delegate :final, :final!, :settings, :settings!, :window, :window!, to: :all
|
51
51
|
|
52
52
|
def is_view
|
53
53
|
@is_view || false
|
@@ -142,6 +142,11 @@ module ActiveRecord
|
|
142
142
|
connect
|
143
143
|
end
|
144
144
|
|
145
|
+
# Return ClickHouse server version
|
146
|
+
def server_version
|
147
|
+
@server_version ||= do_system_execute('SELECT version()')['data'][0][0]
|
148
|
+
end
|
149
|
+
|
145
150
|
# Savepoints are not supported, noop
|
146
151
|
def create_savepoint(name)
|
147
152
|
end
|
@@ -276,10 +281,15 @@ module ActiveRecord
|
|
276
281
|
|
277
282
|
# SCHEMA STATEMENTS ========================================
|
278
283
|
|
279
|
-
def
|
284
|
+
def primary_keys(table_name)
|
285
|
+
if server_version.to_f >= 23.4
|
286
|
+
structure = do_system_execute("SHOW COLUMNS FROM `#{table_name}`")
|
287
|
+
return structure['data'].select {|m| m[3]&.include?('PRI') }.pluck(0)
|
288
|
+
end
|
289
|
+
|
280
290
|
pk = table_structure(table_name).first
|
281
|
-
return 'id' if pk.present? && pk[0] == 'id'
|
282
|
-
|
291
|
+
return ['id'] if pk.present? && pk[0] == 'id'
|
292
|
+
[]
|
283
293
|
end
|
284
294
|
|
285
295
|
def create_schema_dumper(options) # :nodoc:
|
@@ -74,6 +74,14 @@ module Arel
|
|
74
74
|
infix_value o, collector, op
|
75
75
|
end
|
76
76
|
|
77
|
+
def visit_Arel_Nodes_Rows(o, collector)
|
78
|
+
if o.expr.is_a?(String)
|
79
|
+
collector << "ROWS #{o.expr}"
|
80
|
+
else
|
81
|
+
super
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
77
85
|
def sanitize_as_setting_value(value)
|
78
86
|
if value == :default
|
79
87
|
'DEFAULT'
|
@@ -54,16 +54,11 @@ module ClickhouseActiverecord
|
|
54
54
|
tbl.print ', materialized: true' if match && match[1].presence
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
pkcolspec = column_spec_for_primary_key(pkcol)
|
62
|
-
if pkcolspec.present?
|
63
|
-
tbl.print ", #{format_colspec(pkcolspec)}"
|
57
|
+
if (id = columns.detect { |c| c.name == 'id' })
|
58
|
+
spec = column_spec_for_primary_key(id)
|
59
|
+
if spec.present?
|
60
|
+
tbl.print ", #{format_colspec(spec)}"
|
64
61
|
end
|
65
|
-
when Array
|
66
|
-
tbl.print ", primary_key: #{pk.inspect}"
|
67
62
|
else
|
68
63
|
tbl.print ", id: false"
|
69
64
|
end
|
@@ -64,6 +64,23 @@ module CoreExtensions
|
|
64
64
|
self
|
65
65
|
end
|
66
66
|
|
67
|
+
# Windows functions let you perform calculations across a set of rows that are related to the current row. For example:
|
68
|
+
#
|
69
|
+
# users = User.window('x', order: 'date', partition: 'name', rows: 'UNBOUNDED PRECEDING').select('sum(value) OVER x')
|
70
|
+
# # SELECT sum(value) OVER x FROM users WINDOW x AS (PARTITION BY name ORDER BY date ROWS UNBOUNDED PRECEDING)
|
71
|
+
#
|
72
|
+
# @param [String] name
|
73
|
+
# @param [Hash] opts
|
74
|
+
def window(name, **opts)
|
75
|
+
spawn.window!(name, **opts)
|
76
|
+
end
|
77
|
+
|
78
|
+
def window!(name, **opts)
|
79
|
+
@values[:windows] = [] unless @values[:windows]
|
80
|
+
@values[:windows] << [name, opts]
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
67
84
|
private
|
68
85
|
|
69
86
|
def check_command(cmd)
|
@@ -80,6 +97,7 @@ module CoreExtensions
|
|
80
97
|
arel.final! if @values[:final].present?
|
81
98
|
arel.settings(@values[:settings]) if @values[:settings].present?
|
82
99
|
arel.using(@values[:using]) if @values[:using].present?
|
100
|
+
arel.windows(@values[:windows]) if @values[:windows].present?
|
83
101
|
|
84
102
|
arel
|
85
103
|
end
|
@@ -13,6 +13,18 @@ module CoreExtensions
|
|
13
13
|
self
|
14
14
|
end
|
15
15
|
|
16
|
+
# @param [Array] windows
|
17
|
+
def windows(windows)
|
18
|
+
@ctx.windows = windows.map do |name, opts|
|
19
|
+
# https://github.com/rails/rails/blob/main/activerecord/test/cases/arel/select_manager_test.rb#L790
|
20
|
+
window = ::Arel::Nodes::NamedWindow.new(name)
|
21
|
+
opts.each do |key, value|
|
22
|
+
window.send(key, value)
|
23
|
+
end
|
24
|
+
window
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
16
28
|
def using(*exprs)
|
17
29
|
@ctx.source.right.last.right = ::Arel::Nodes::Using.new(::Arel.sql(exprs.join(',')))
|
18
30
|
self
|
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.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Odintsov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|