clickhouse 0.1.2 → 0.1.3
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 +4 -0
- data/README.md +34 -0
- data/VERSION +1 -1
- data/lib/clickhouse/cluster.rb +1 -1
- data/lib/clickhouse/error.rb +4 -4
- data/lib/clickhouse/version.rb +1 -1
- data/test/unit/connection/test_cluster.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9430c069f56f33af1e4e54bcad89cf33fd836051
|
4
|
+
data.tar.gz: a708443dd04408661f84e897e0cec49777188330
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b99166f3cbe200af3337764a0db939432094168d52cd2ba0f6526ef43fc5778e60030bbb49e7e877def07b5c0670df71a2c548488135a5a7613a2e7510884c8
|
7
|
+
data.tar.gz: a71ad741943715b618bfae02fa34874074b4a72c3b9814c2a38c48bb5fae184b77a9367aa6976d6ca68312397112db11a28bbf3fee4573443839bec5c05fafca
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -141,6 +141,40 @@ GROUP BY year, date;
|
|
141
141
|
=> [2, 2016, #<Date: 2016-10-17 ((2457679j,0s,0n),+0s,2299161j)>, 0.1915000081062317]
|
142
142
|
```
|
143
143
|
|
144
|
+
### Connecting to a cluster
|
145
|
+
|
146
|
+
To connect to a cluster you only need to specify the URLs of the cluster servers in `:urls` of the configuration and that is it! The API of using Clickhouse stays the same.
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
Clickhouse.establish_connection urls: %w(http://192.168.99.100:32809 http://192.168.99.100:32812 http://192.168.99.100:32815)
|
150
|
+
=> true
|
151
|
+
|
152
|
+
Clickhouse.connection.tables
|
153
|
+
I, [2016-10-21T11:56:47.375772 #63374] INFO -- :
|
154
|
+
SQL (6.2ms) SHOW TABLES;
|
155
|
+
=> ["events"]
|
156
|
+
```
|
157
|
+
|
158
|
+
In case of a connection dropping out, Clickhouse will retry the request with another connection. The failed connection will also be removed from the connection pool.
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
Clickhouse.establish_connection urls: %w(http://192.168.99.100:32809 http://192.168.99.100:1 http://192.168.99.100:32815)
|
162
|
+
=> true
|
163
|
+
|
164
|
+
Clickhouse.connection.pond.available.collect(&:url)
|
165
|
+
=> ["http://192.168.99.100:1", "http://192.168.99.100:32815", "http://192.168.99.100:32809"]
|
166
|
+
|
167
|
+
Clickhouse.connection.tables
|
168
|
+
I, [2016-10-21T12:11:55.974573 #63527] INFO -- :
|
169
|
+
SQL (7.1ms) SHOW TABLES;
|
170
|
+
=> ["events"]
|
171
|
+
|
172
|
+
Clickhouse.connection.pond.available.collect(&:url)
|
173
|
+
=> ["http://192.168.99.100:32809", "http://192.168.99.100:32815"]
|
174
|
+
```
|
175
|
+
|
176
|
+
If all the connections failed, it will just return `nil`.
|
177
|
+
|
144
178
|
### Check out the tests
|
145
179
|
|
146
180
|
To see what more the `Clickhouse` gem has to offer, please take a look at the unit tests ( [test/unit/connection/test_query.rb](https://github.com/archan937/clickhouse/blob/master/test/unit/connection/test_query.rb) for instance).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/clickhouse/cluster.rb
CHANGED
data/lib/clickhouse/error.rb
CHANGED
@@ -3,16 +3,16 @@ module Clickhouse
|
|
3
3
|
class Error < StandardError
|
4
4
|
end
|
5
5
|
|
6
|
-
class InvalidConnectionError < Error
|
7
|
-
end
|
8
|
-
|
9
6
|
class ConnectionError < Error
|
10
7
|
end
|
11
8
|
|
12
|
-
class
|
9
|
+
class InvalidConnectionError < ConnectionError
|
13
10
|
end
|
14
11
|
|
15
12
|
class QueryError < Error
|
16
13
|
end
|
17
14
|
|
15
|
+
class InvalidQueryError < QueryError
|
16
|
+
end
|
17
|
+
|
18
18
|
end
|
data/lib/clickhouse/version.rb
CHANGED
@@ -34,6 +34,7 @@ module Unit
|
|
34
34
|
describe "when connection fails" do
|
35
35
|
it "removes invalid connections from the pond" do
|
36
36
|
cluster = Clickhouse::Cluster.new :urls => %w(http://localhost:1234 http://localhost:1235 http://localhost:1236)
|
37
|
+
|
37
38
|
assert_equal %w(
|
38
39
|
http://localhost:1234
|
39
40
|
http://localhost:1235
|
@@ -44,6 +45,29 @@ module Unit
|
|
44
45
|
assert_equal [], cluster.pond.available.collect(&:url)
|
45
46
|
end
|
46
47
|
end
|
48
|
+
|
49
|
+
describe "when error gets raised other than Clickhouse::ConnectionError" do
|
50
|
+
it "does not remove the connection from the pond" do
|
51
|
+
Clickhouse::Connection.any_instance.expects(:ping!)
|
52
|
+
|
53
|
+
cluster = Clickhouse::Cluster.new :urls => %w(http://localhost:1234 http://localhost:1235 http://localhost:1236)
|
54
|
+
assert_equal %w(
|
55
|
+
http://localhost:1234
|
56
|
+
http://localhost:1235
|
57
|
+
http://localhost:1236
|
58
|
+
), cluster.pond.available.collect(&:url)
|
59
|
+
|
60
|
+
assert_raises NoMethodError do
|
61
|
+
cluster.select_rows ""
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_equal %w(
|
65
|
+
http://localhost:1235
|
66
|
+
http://localhost:1236
|
67
|
+
http://localhost:1234
|
68
|
+
), cluster.pond.available.collect(&:url)
|
69
|
+
end
|
70
|
+
end
|
47
71
|
end
|
48
72
|
|
49
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clickhouse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Engel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|