You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Client works with alone server and cluster. Also, client can make async select and insert (from local files) queries.
22
22
23
23
## Alone server
24
24
25
25
```php
26
26
$server = new Tinderbox\Clickhouse\Server('127.0.0.1', '8123', 'default', 'user', 'pass');
27
-
$client = new Tinderbox\Clickhouse\Client($server);
27
+
$serverProvider = (new Tinderbox\Clickhouse\ServerProvider())->addServer($server);
28
+
29
+
$client = new Tinderbox\Clickhouse\Client($serverProvider);
28
30
```
29
31
30
32
## Cluster
31
33
32
34
```php
33
-
$cluster = new Tinderbox\Clickhouse\Cluster([
35
+
$testCluster = new Tinderbox\Clickhouse\Cluster('cluster-name', [
34
36
'server-1' => [
35
37
'host' => '127.0.0.1',
36
38
'port' => '8123',
@@ -40,11 +42,31 @@ $cluster = new Tinderbox\Clickhouse\Cluster([
40
42
],
41
43
'server-2' => new Tinderbox\Clickhouse\Server('127.0.0.1', '8124', 'default', 'user', 'pass')
42
44
]);
43
-
$client = new Tinderbox\Clickhouse\Client($cluster);
45
+
46
+
$anotherCluster = new Tinderbox\Clickhouse\Cluster('cluster-name', [
47
+
[
48
+
'host' => '127.0.0.1',
49
+
'port' => '8125',
50
+
'database' => 'default',
51
+
'user' => 'user',
52
+
'password' => 'pass'
53
+
],
54
+
new Tinderbox\Clickhouse\Server('127.0.0.1', '8126', 'default', 'user', 'pass')
55
+
]);
56
+
57
+
$serverProvider = (new Tinderbox\Clickhouse\ServerProvider())->addCluster($testCluster)->addCluster($anotherCluster);
58
+
59
+
$client = (new Tinderbox\Clickhouse\Client($serverProvider));
60
+
```
61
+
62
+
Before execute any query on cluster, you should provide cluster name and client will run all queries on specified cluster.
63
+
64
+
```
65
+
$client->onCluster('test-cluster');
44
66
```
45
67
46
-
By default client will use first server in given list. If you want to perform request on another server you should use
47
-
`using($hostname)` method on client and then run query;
68
+
By default client will use random server in given list of servers or in specified cluster. If you want to perform request on specified server you should use
69
+
`using($hostname)` method on client and then run query. Client will remember hostname for next queries:
48
70
49
71
```php
50
72
$client->using('server-2')->select('select * from table');
@@ -91,7 +113,7 @@ $client->select('select * from table where column = :column', [
91
113
92
114
## Select queries
93
115
94
-
Any SELECT query will return instance of `Result`. This class implements interfaces `\ArrayAccess`, `\Countable` и `\Iterator`,
116
+
Any SELECT query will return instance of `Result`. This class implements interfaces `\ArrayAccess`, `\Countable` и `\Iterator`,
95
117
which means that it can be used as an array.
96
118
97
119
Array with result rows can be obtained via `rows` property
@@ -104,8 +126,9 @@ $rows = $result->getRows();
104
126
Also you can get some statistic of your query execution:
105
127
106
128
1. Number of read rows
107
-
2. Number of read bytes
129
+
2. Number of read bytes
108
130
3. Time of query execution
131
+
4. Rows before limit at least
109
132
110
133
Statistic can be obtained via `statistic` property
['select * from clicks where date = ? and userId in _users', ['2017-01-01'], new TempTable('_users', 'users.csv', ['number' => 'UInt64'])],
191
-
['select * from visits where date = ?', ['2017-01-01']],
192
-
['select * from views where date = ?', ['2017-01-01']],
217
+
list($clicks, $visits, $views) = $client->read([
218
+
['query' => 'select * from clicks where date = ? and userId in _users', 'bindings' => ['2017-01-01'], new TempTable('_users', 'users.csv', ['number' => 'UInt64'])],
219
+
['query' => 'select * from visits where date = ?', 'bindings' => ['2017-01-01']],
220
+
['query' => 'select * from views where date = ?', 'bindings' => ['2017-01-01']],
193
221
]);
194
222
195
223
foreach ($clicks as $click) {
@@ -207,29 +235,47 @@ Insert queries always returns true or throws exceptions in case of error.
207
235
Data can be written row by row or from local CSV or TSV files.
0 commit comments