clickhouse-activerecord 0.1.3 → 0.1.4
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/CHANGELOG.md +13 -0
- data/README.md +18 -2
- data/clickhouse-activerecord.gemspec +4 -3
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +17 -1
- data/lib/clickhouse-activerecord.rb +4 -1
- data/lib/clickhouse-activerecord/arel/visitors/to_sql.rb +20 -0
- data/lib/{clickhouse → clickhouse-activerecord}/railtie.rb +1 -1
- data/lib/clickhouse-activerecord/schema_dumper.rb +10 -0
- data/lib/clickhouse-activerecord/version.rb +3 -0
- data/lib/tasks/clickhouse.rake +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 526a938e8ee69d1c9ed717405c965e7995d497f5
|
4
|
+
data.tar.gz: 0e073d0606e1dd2c0f96504d571e2fcdbb2df041
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17718b1dbe7a43fa085fbd87b8f81640eaaae219217d2256bfd6743e61b5b1990fc2a93cb65dc3da007c7970a67e5f17a48f496aeabb9bbf8e5818be284ce6cd
|
7
|
+
data.tar.gz: 202af70214fab7c2816f9b45dad1557d1fba71087ab6940e8919c9995fd2312573bbea554473aab429f41ddf68d12cef21f7a49638f7ed873df97e7cd26de65f
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
### Version 0.1.4 (Nov 29, 2017)
|
2
|
+
|
3
|
+
* Support materialized view
|
4
|
+
* Aggregated functions for view
|
5
|
+
* Schema dumper with SQL create table
|
6
|
+
|
7
|
+
### Version 0.1.2 (Sep 27, 2017)
|
8
|
+
|
9
|
+
* Fix Big Int type
|
10
|
+
|
11
|
+
### Version 0.1.0 (Aug 31, 2017)
|
12
|
+
|
13
|
+
* Initial release
|
data/README.md
CHANGED
@@ -39,6 +39,14 @@ class Action < ActiveRecord::Base
|
|
39
39
|
end
|
40
40
|
```
|
41
41
|
|
42
|
+
For materialized view model add:
|
43
|
+
```ruby
|
44
|
+
class ActionView < ActiveRecord::Base
|
45
|
+
establish_connection "#{Rails.env}_clickhouse".to_sym
|
46
|
+
self.is_view = true
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
42
50
|
Or global connection, but schema dump don't works:
|
43
51
|
|
44
52
|
```yml
|
@@ -54,14 +62,22 @@ Schema dump:
|
|
54
62
|
|
55
63
|
$ rake clickhouse:schema:dump
|
56
64
|
|
65
|
+
We use schema for emulate development or tests environment on PostgreSQL adapter.
|
66
|
+
|
57
67
|
### Insert and select data
|
58
68
|
|
59
69
|
```ruby
|
60
70
|
Action.where(url: 'http://example.com', date: Date.current).where.not(name: nil).order(created_at: :desc).limit(10)
|
61
|
-
|
71
|
+
# Clickhouse Action Load (10.3ms) SELECT actions.* FROM actions WHERE actions.date = '2017-11-29' AND actions.url = 'http://example.com' AND (actions.name IS NOT NULL) ORDER BY actions.created_at DESC LIMIT 10
|
72
|
+
#=> #<ActiveRecord::Relation [#<Action *** >]>
|
62
73
|
|
63
74
|
Action.create(url: 'http://example.com', date: Date.yesterday)
|
64
|
-
|
75
|
+
# Clickhouse Action Load (10.8ms) INSERT INTO actions (url, date) VALUES ('http://example.com', '2017-11-28')
|
76
|
+
#=> true
|
77
|
+
|
78
|
+
ActionView.maximum(:date)
|
79
|
+
# Clickhouse (10.3ms) SELECT maxMerge(actions.date) FROM actions
|
80
|
+
#=> 'Wed, 29 Nov 2017'
|
65
81
|
```
|
66
82
|
|
67
83
|
NOTE: Creating tables in developing.
|
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
lib = File.expand_path('../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require File.expand_path('../lib/clickhouse-activerecord/version', __FILE__)
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
8
|
spec.name = 'clickhouse-activerecord'
|
8
|
-
spec.version =
|
9
|
+
spec.version = ClickhouseActiverecord::VERSION
|
9
10
|
spec.authors = ['Sergey Odintsov']
|
10
11
|
spec.email = ['nixx.dj@gmail.com']
|
11
12
|
|
@@ -21,8 +22,8 @@ Gem::Specification.new do |spec|
|
|
21
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
23
|
spec.require_paths = ['lib']
|
23
24
|
|
24
|
-
spec.
|
25
|
-
spec.
|
25
|
+
spec.add_runtime_dependency 'bundler', '~> 1.13', '>= 1.13.4'
|
26
|
+
spec.add_runtime_dependency 'rails', '>= 4.1.8', '< 5'
|
26
27
|
|
27
28
|
spec.add_development_dependency 'bundler', '~> 1.15'
|
28
29
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'clickhouse-activerecord/arel/visitors/to_sql'
|
1
2
|
require 'active_record/connection_adapters/abstract_adapter'
|
2
3
|
require 'active_record/connection_adapters/clickhouse/oid/date'
|
3
4
|
require 'active_record/connection_adapters/clickhouse/oid/date_time'
|
@@ -23,6 +24,21 @@ module ActiveRecord
|
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
27
|
+
module ModelSchema
|
28
|
+
|
29
|
+
module ClassMethods
|
30
|
+
def is_view
|
31
|
+
@is_view || false
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param [Boolean] value
|
35
|
+
def is_view=(value)
|
36
|
+
@is_view = value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
26
42
|
module ConnectionAdapters
|
27
43
|
|
28
44
|
class ClickhouseColumn < Column
|
@@ -89,7 +105,7 @@ module ActiveRecord
|
|
89
105
|
@connection_parameters = connection_parameters
|
90
106
|
@config = config
|
91
107
|
|
92
|
-
@visitor = Arel::Visitors::ToSql.new self
|
108
|
+
@visitor = ClickhouseActiverecord::Arel::Visitors::ToSql.new self
|
93
109
|
|
94
110
|
connect
|
95
111
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'active_record/connection_adapters/clickhouse_adapter'
|
2
2
|
|
3
|
-
|
3
|
+
if defined?(Rails::Railtie)
|
4
|
+
require 'clickhouse-activerecord/railtie'
|
5
|
+
require 'clickhouse-activerecord/schema_dumper'
|
6
|
+
end
|
4
7
|
|
5
8
|
module ClickhouseActiverecord
|
6
9
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'arel/visitors/to_sql'
|
2
|
+
|
3
|
+
module ClickhouseActiverecord
|
4
|
+
module Arel
|
5
|
+
module Visitors
|
6
|
+
class ToSql < ::Arel::Visitors::ToSql
|
7
|
+
|
8
|
+
def aggregate(name, o, collector)
|
9
|
+
# replacing function name for materialized view
|
10
|
+
if o.expressions.first.relation.engine.is_view
|
11
|
+
super("#{name.downcase}Merge", o, collector)
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class ClickhouseActiverecord::SchemaDumper < ActiveRecord::SchemaDumper
|
2
|
+
|
3
|
+
def table(table, stream)
|
4
|
+
|
5
|
+
stream.puts " # TABLE: #{table}"
|
6
|
+
stream.puts " # SQL: #{@connection.query("SHOW CREATE TABLE #{table.gsub(/^\.inner\./, '')}")['data'].try(:first).try(:first)}"
|
7
|
+
super(table.gsub(/^\.inner\./, ''), stream)
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
data/lib/tasks/clickhouse.rake
CHANGED
@@ -14,7 +14,7 @@ namespace :clickhouse do
|
|
14
14
|
filename = "#{Rails.root}/db/clickhouse_schema.rb"
|
15
15
|
File.open(filename, 'w:utf-8') do |file|
|
16
16
|
ActiveRecord::Base.establish_connection(:"#{Rails.env}_clickhouse")
|
17
|
-
|
17
|
+
ClickhouseActiverecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
metadata
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clickhouse-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Odintsov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 1.13.4
|
@@ -21,6 +24,9 @@ dependencies:
|
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.13'
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 1.13.4
|
@@ -31,6 +37,9 @@ dependencies:
|
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
39
|
version: 4.1.8
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '5'
|
34
43
|
type: :runtime
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,6 +47,9 @@ dependencies:
|
|
38
47
|
- - ">="
|
39
48
|
- !ruby/object:Gem::Version
|
40
49
|
version: 4.1.8
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '5'
|
41
53
|
- !ruby/object:Gem::Dependency
|
42
54
|
name: bundler
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,6 +86,7 @@ extensions: []
|
|
74
86
|
extra_rdoc_files: []
|
75
87
|
files:
|
76
88
|
- ".gitignore"
|
89
|
+
- CHANGELOG.md
|
77
90
|
- CODE_OF_CONDUCT.md
|
78
91
|
- Gemfile
|
79
92
|
- LICENSE.txt
|
@@ -87,7 +100,10 @@ files:
|
|
87
100
|
- lib/active_record/connection_adapters/clickhouse/oid/date_time.rb
|
88
101
|
- lib/active_record/connection_adapters/clickhouse_adapter.rb
|
89
102
|
- lib/clickhouse-activerecord.rb
|
90
|
-
- lib/clickhouse/
|
103
|
+
- lib/clickhouse-activerecord/arel/visitors/to_sql.rb
|
104
|
+
- lib/clickhouse-activerecord/railtie.rb
|
105
|
+
- lib/clickhouse-activerecord/schema_dumper.rb
|
106
|
+
- lib/clickhouse-activerecord/version.rb
|
91
107
|
- lib/tasks/clickhouse.rake
|
92
108
|
homepage: https://github.com/pnixx/clickhouse-activerecord
|
93
109
|
licenses:
|