clickhouse-rails 0.1.4 → 0.1.5
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/.rubocop.yml +8 -0
- data/Gemfile.lock +2 -2
- data/lib/clickhouse/rails/migrations/base.rb +13 -4
- data/lib/clickhouse/rails/version.rb +1 -1
- data/lib/clickhouse/table.rb +27 -3
- data/spec/table_spec.rb +21 -10
- 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: 718aac003d13c2483b97702f3f9f3e03bd2e10416c6bec748c7571a189c630f1
|
4
|
+
data.tar.gz: 60761d44e0f1c8b2e235212812cf3aabdd36212a8ff99a2d47ba60688f162f06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b29b6bd85c036c8daf286c994c2881c79e1a3765b0c742646f0fcc1e3a64bf84ff39777468d3c2c81ec342d26580867491ab821479f69cf9f13fe2c17ff2dd13
|
7
|
+
data.tar.gz: da05288e90ba6c12eeecb43ac196c48dcd711981b7e5c0cd46b600925c13f9ddbdc94a04158df98787e35be54de2d15737b8a61128c179a308d84bacc2e7d5b9
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
clickhouse-rails (0.1.
|
4
|
+
clickhouse-rails (0.1.5)
|
5
5
|
clickhouse
|
6
6
|
railties
|
7
7
|
|
@@ -80,7 +80,7 @@ GEM
|
|
80
80
|
coderay (~> 1.1.0)
|
81
81
|
method_source (~> 0.9.0)
|
82
82
|
psych (3.1.0)
|
83
|
-
public_suffix (3.1.
|
83
|
+
public_suffix (3.1.1)
|
84
84
|
rack (2.0.7)
|
85
85
|
rack-protection (2.0.5)
|
86
86
|
rack
|
@@ -55,8 +55,15 @@ module Clickhouse
|
|
55
55
|
drop_table(table_name)
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
def create_table(table_name, &block)
|
59
|
+
logger.info "# >======= Create #{table_name} ========"
|
60
|
+
connection.create_table(table_name, &block)
|
61
|
+
end
|
62
|
+
|
63
|
+
def drop_table(table_name, &block)
|
64
|
+
logger.info "# >======= Drop #{table_name} ========"
|
65
|
+
connection.drop_table(table_name, &block)
|
66
|
+
end
|
60
67
|
|
61
68
|
def alter_table(table_name)
|
62
69
|
@table_info = connection.describe_table(table_name)
|
@@ -73,7 +80,9 @@ module Clickhouse
|
|
73
80
|
end
|
74
81
|
type = type.gsub('Uint', 'UInt').delete('_')
|
75
82
|
|
76
|
-
|
83
|
+
query = "ALTER TABLE #{@table_name} ADD COLUMN #{column} #{type}"
|
84
|
+
logger.info(query)
|
85
|
+
connection.execute(query)
|
77
86
|
end
|
78
87
|
|
79
88
|
def run_migration(migration)
|
@@ -92,7 +101,7 @@ module Clickhouse
|
|
92
101
|
end
|
93
102
|
|
94
103
|
def logger
|
95
|
-
|
104
|
+
Logger.new(STDOUT)
|
96
105
|
end
|
97
106
|
end
|
98
107
|
end
|
data/lib/clickhouse/table.rb
CHANGED
@@ -20,7 +20,7 @@ module Clickhouse
|
|
20
20
|
[complete_row]
|
21
21
|
end
|
22
22
|
end
|
23
|
-
alias
|
23
|
+
alias create insert_row
|
24
24
|
|
25
25
|
def insert_rows(batch_rows)
|
26
26
|
connection.insert_rows(table_name) do |table_rows|
|
@@ -64,14 +64,38 @@ module Clickhouse
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def prepare_row(row)
|
67
|
-
|
67
|
+
validate_row(row)
|
68
68
|
|
69
|
-
|
69
|
+
row.stringify_keys!
|
70
|
+
crop_row(row)
|
71
|
+
|
72
|
+
empty_row.merge(row)
|
70
73
|
end
|
71
74
|
|
72
75
|
def connection
|
73
76
|
::Clickhouse.connection
|
74
77
|
end
|
78
|
+
|
79
|
+
def logger
|
80
|
+
::Rails.logger
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def validate_row(row)
|
86
|
+
return if row.is_a?(Hash)
|
87
|
+
|
88
|
+
raise WrongTypeRowError, "#{row.inspect} has wrong type"
|
89
|
+
end
|
90
|
+
|
91
|
+
def crop_row(row)
|
92
|
+
undefined_columns = row.keys - empty_row.keys
|
93
|
+
|
94
|
+
return if undefined_columns.empty?
|
95
|
+
|
96
|
+
logger.warn("Clickhouse: Undefined columns for #{table_name}: #{undefined_columns}")
|
97
|
+
row.except!(*undefined_columns)
|
98
|
+
end
|
75
99
|
end
|
76
100
|
end
|
77
101
|
end
|
data/spec/table_spec.rb
CHANGED
@@ -45,16 +45,6 @@ describe Clickhouse::Table do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
context 'when row is an array' do
|
49
|
-
# TODO: implement array logic
|
50
|
-
let(:rows) { [['a'], ['2']] }
|
51
|
-
|
52
|
-
it 'raises an error' do
|
53
|
-
expect { CustomTable.insert_rows(rows) }
|
54
|
-
.to raise_error(Clickhouse::Table::WrongTypeRowError)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
48
|
context 'when row has empty attributes' do
|
59
49
|
let(:rows) { [{}] }
|
60
50
|
|
@@ -65,4 +55,25 @@ describe Clickhouse::Table do
|
|
65
55
|
end
|
66
56
|
end
|
67
57
|
end
|
58
|
+
|
59
|
+
describe '#prepare_row' do
|
60
|
+
subject(:method) { CustomTable.prepare_row(row) }
|
61
|
+
|
62
|
+
context 'when row has wrong type' do
|
63
|
+
# TODO: implement array logic
|
64
|
+
let(:row) { ['a'] }
|
65
|
+
|
66
|
+
it 'raises an error' do
|
67
|
+
expect { method }.to raise_error(Clickhouse::Table::WrongTypeRowError)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when row has extra fields' do
|
72
|
+
let(:row) { { 'field' => 'a', 'extra_field' => 'b' } }
|
73
|
+
|
74
|
+
it 'leaves only existing fields' do
|
75
|
+
is_expected.to eq('field' => 'a')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
68
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clickhouse-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vsevolod Avramov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clickhouse
|