click_house 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -21
- data/lib/click_house/extend/connection_inserting.rb +6 -2
- data/lib/click_house/type/array_type.rb +3 -16
- data/lib/click_house/version.rb +1 -1
- 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: 7cc9a21cc317327e783b02a5fd86dc4af9a8996cc9be80244074b5350db7de45
|
4
|
+
data.tar.gz: 69d8e8827f4c3cad0a5a05f0dbfddccc021a6f149905185406de3af671d989a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 996d33f947b213b6c710275dc9b422fe2b46c0051ff08ea941f496bbbbf00dec6652c6c3310c059968219e35a4f2137386c41a194984ca83ea770ace158fdf8e
|
7
|
+
data.tar.gz: 0ab36517fb80d6ad07e34ff26a85469bd50f9c86d889e96ccc245a26de9980c72d45b9b6e59aef273a14c6314318a34820840d0d2c04821a6ca617b05100183f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,8 +3,11 @@
|
|
3
3
|
# ClickHouse Ruby driver
|
4
4
|
|
5
5
|
[![pipeline status](https://travis-ci.com/shlima/click_house.svg?branch=master)](https://travis-ci.com/shlima/click_house)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/shlima/click_house/badges/gpa.svg)](https://codeclimate.com/github/shlima/click_house)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/click_house.svg)](https://badge.fury.io/rb/click_house)
|
6
8
|
|
7
9
|
```bash
|
10
|
+
# Requires modern Ruby (>= 2.5), tested with Yandex.Clickhouse v 19.16.2.2
|
8
11
|
gem install click_house
|
9
12
|
```
|
10
13
|
|
@@ -13,7 +16,7 @@ is a high-performance column-oriented database management system developed by
|
|
13
16
|
[Yandex](https://yandex.com/company) which operates Russia's most popular search engine.
|
14
17
|
|
15
18
|
> This development was inspired by currently [unmaintainable alternative](https://github.com/archan937/clickhouse)
|
16
|
-
> but rewritten and well tested
|
19
|
+
> but rewritten and well tested
|
17
20
|
|
18
21
|
### Why use the HTTP interface and not the TCP interface?
|
19
22
|
|
@@ -22,13 +25,14 @@ Well, the developers of ClickHouse themselves [discourage](https://github.com/ya
|
|
22
25
|
> TCP transport is more specific, we don't want to expose details.
|
23
26
|
Despite we have full compatibility of protocol of different versions of client and server, we want to keep the ability to "break" it for very old clients. And that protocol is not too clean to make a specification.
|
24
27
|
|
28
|
+
Yandex uses HTTP interface for working from Java and Perl, Python and Go as well as shell scripts.
|
29
|
+
|
25
30
|
# TOC
|
26
31
|
|
27
32
|
* [Configuration](#configuration)
|
28
33
|
* [Usage](#usage)
|
29
34
|
* [Queries](#queries)
|
30
35
|
* [Insert](#insert)
|
31
|
-
* [Insert an Array](#insert-an-array)
|
32
36
|
* [Create a table](#create-a-table)
|
33
37
|
* [Alter table](#alter-table)
|
34
38
|
* [Type casting](#type-casting)
|
@@ -181,24 +185,6 @@ ClickHouse.connection.insert('table', columns: %i[id name], values: [[1, 'Mercur
|
|
181
185
|
#=> true
|
182
186
|
```
|
183
187
|
|
184
|
-
## Insert an Array
|
185
|
-
|
186
|
-
Serializing an Array of strings is pretty low level at the moment but it works (and thanks for that).
|
187
|
-
Array of numeric types works as expected without pre-serialization
|
188
|
-
|
189
|
-
```ruby
|
190
|
-
string_type = ClickHouse::Type::StringType.new
|
191
|
-
array_of_string = ClickHouse::Type::ArrayType.new(string_type)
|
192
|
-
|
193
|
-
data = [
|
194
|
-
{ id: 1, tags: array_of_string.serialize(%w[ruby redis rails node]) }
|
195
|
-
]
|
196
|
-
|
197
|
-
subject.insert('rspec', columns: data.first.keys) do |buffer|
|
198
|
-
buffer.concat(data.map(&:values))
|
199
|
-
end
|
200
|
-
```
|
201
|
-
|
202
188
|
## Create a table
|
203
189
|
### Create table using DSL
|
204
190
|
|
@@ -296,7 +282,7 @@ ClickHouse.connection.alter_table('table', 'DROP COLUMN user_id', cluster: nil)
|
|
296
282
|
# By SQL in a block
|
297
283
|
ClickHouse.connection.alter_table('table', cluster: nil) do
|
298
284
|
<<~SQL
|
299
|
-
|
285
|
+
MOVE PART '20190301_14343_16206_438' TO VOLUME 'slow'
|
300
286
|
SQL
|
301
287
|
end
|
302
288
|
```
|
@@ -5,8 +5,12 @@ module ClickHouse
|
|
5
5
|
module ConnectionInserting
|
6
6
|
def insert(table, columns:, values: [])
|
7
7
|
yield(values) if block_given?
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
body = values.map do |value_row|
|
10
|
+
columns.zip(value_row).to_h.to_json
|
11
|
+
end
|
12
|
+
|
13
|
+
execute("INSERT INTO #{table} FORMAT JSONEachRow", body.join("\n")).success?
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
@@ -5,8 +5,6 @@ module ClickHouse
|
|
5
5
|
class ArrayType < BaseType
|
6
6
|
attr_reader :subtype
|
7
7
|
|
8
|
-
STRING_QUOTE = "'"
|
9
|
-
|
10
8
|
def initialize(subtype)
|
11
9
|
@subtype = subtype
|
12
10
|
end
|
@@ -16,22 +14,11 @@ module ClickHouse
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def serialize(array, *argv)
|
19
|
-
return
|
17
|
+
return unless array.is_a?(Array)
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
format("%<quote>s#{escaped}%<quote>s", quote: STRING_QUOTE)
|
19
|
+
array.map do |value|
|
20
|
+
subtype.serialize(value, *argv)
|
24
21
|
end
|
25
|
-
|
26
|
-
"[#{serialized.join(',')}]"
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def string?
|
32
|
-
return @is_string if defined?(@is_string)
|
33
|
-
|
34
|
-
@is_string = subtype.is_a?(StringType) || subtype.is_a?(FixedStringType)
|
35
22
|
end
|
36
23
|
end
|
37
24
|
end
|
data/lib/click_house/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: click_house
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aliaksandr Shylau
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|