-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.php
332 lines (281 loc) · 8.66 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<?php
/**
* @author [email protected]
* Date: 19/02/6 8:23
*/
$br = (php_sapi_name() == "cli")? "":"<br>";
if(!extension_loaded('SeasClick')) {
dl('SeasClick.' . PHP_SHLIB_SUFFIX);
}
$config = [
"host" => "clickhouse",
"port" => "9000",
"compression" => true
];
clientTest($config);
function clientTest($config)
{
$deleteTable = true;
$client = new SeasClick($config);
$client->execute("CREATE DATABASE IF NOT EXISTS test");
testArray($client, $deleteTable);
testEnum($client, $deleteTable);
testString($client, $deleteTable);
testNullAble($client, $deleteTable);
testUInt($client, $deleteTable);
testFloat($client, $deleteTable);
testUUID($client, $deleteTable);
testDate($client, $deleteTable);
testMulInstance($config, $deleteTable);
testTuple($client, $deleteTable);
}
function testMulInstance($config, $deleteTable = false) {
$client1 = new SeasClick($config);
testArray($client1, $deleteTable);
$client2 = new SeasClick($config);
testArray($client2, $deleteTable);
$client3 = new SeasClick($config);
testArray($client3, $deleteTable);
$client4 = new SeasClick($config);
testArray($client4, $deleteTable);
unset($client1);
unset($client2);
unset($client3);
unset($client4);
}
function testTuple($client, $deleteTable = false) {
$client->execute("CREATE TABLE IF NOT EXISTS test.tuple_test (tuple_c Tuple(id UInt64, name String), int_c UInt64, string_c String) ENGINE = Memory");
$client->insert("test.tuple_test", [
'tuple_c', 'int_c', 'string_c'
], [
[[1, 'one'], 1, 'one'],
[[2, 'two'], 2, 'two'],
]);
$result = $client->select("SELECT {select} FROM {table}", [
'select' => 'tuple_c, int_c, string_c',
'table' => 'test.tuple_test'
]);
var_dump($result);
if ($deleteTable) {
$client->execute("DROP TABLE {table}", [
'table' => 'test.tuple_test'
]);
}
}
function testArray($client, $deleteTable = false) {
$client->execute("CREATE TABLE IF NOT EXISTS test.array_test (string_c String, array_c Array(Int8), arraynull_c Array(Nullable(String))) ENGINE = Memory");
$client->writeStart("test.array_test", [
'string_c', 'arraynull_c'
]);
$client->write([
[
'string_c2', ["string"]
]
]);
$client->writeEnd();
$client->insert("test.array_test", [
'string_c'
], [
[
'string_c1'
],
[
'string_c2'
]
]);
$client->insert("test.array_test", [
'array_c'
], [
[
[1, 2, 3]
],
[
[4, 5, 6]
]
]);
$result = $client->select("SELECT {select} FROM {table}", [
'select' => 'string_c, array_c, arraynull_c',
'table' => 'test.array_test'
]);
var_dump($result);
if ($deleteTable) {
$client->execute("DROP TABLE {table}", [
'table' => 'test.array_test'
]);
}
}
function testEnum($client, $deleteTable = false) {
$client->execute("CREATE TABLE IF NOT EXISTS test.enum_test (enum8_c Enum8('One8' = 1, 'Two8' = 2), enum16_c Enum16('One16' = 1, 'Two16' = 2)) ENGINE = Memory");
$client->insert("test.enum_test", [
'enum8_c', 'enum16_c'
],[
[1, 'Two16'],
['Two8', 1]
]);
$result = $client->select("SELECT {select} FROM {table}", [
'select' => 'enum8_c, enum16_c',
'table' => 'test.enum_test'
]);
var_dump($result);
if ($deleteTable) {
$client->execute("DROP TABLE {table}", [
'table' => 'test.enum_test'
]);
}
}
function testString($client, $deleteTable = false) {
$client->execute("CREATE TABLE IF NOT EXISTS test.string_test (string_c String, fixedstring_c FixedString(50)) ENGINE = Memory");
$client->insert("test.string_test", [
'string_c', 'fixedstring_c'
], [
[
'string_c1',
'fixedstring_c1'
],
[
'string_c2',
'fixedstring_c2'
]
]);
$result = $client->select("SELECT {select} FROM {table}", [
'select' => 'string_c, fixedstring_c',
'table' => 'test.string_test'
]);
var_dump($result);
if ($deleteTable) {
$client->execute("DROP TABLE {table}", [
'table' => 'test.string_test'
]);
}
}
function testNullAble($client, $deleteTable = false) {
$client->execute("CREATE TABLE IF NOT EXISTS test.nullable_test (int8null_c Nullable(Int8), stringnull_c Nullable(String), enumnull_c Nullable(Enum8('One8' = 1, 'Two8' = 2)), float32null_c Nullable(Float32), uuidnull_c Nullable(UUID)) ENGINE = Memory");
$client->insert("test.nullable_test",[
'int8null_c',
'stringnull_c',
'enumnull_c',
'float32null_c',
'uuidnull_c'
], [
[8, 'string', 'One8', 32, '31249a1b7b0542709f37c609b48a9bb2'],
[null, null, null, null, null],
]);
$result = $client->select("SELECT {select} FROM {table}", [
'select' => 'int8null_c, stringnull_c, enumnull_c, float32null_c, uuidnull_c',
'table' => 'test.nullable_test'
]);
var_dump($result);
if ($deleteTable) {
$client->execute("DROP TABLE {table}", [
'table' => 'test.nullable_test'
]);
}
}
function testUInt($client, $deleteTable = false) {
$client->execute("CREATE TABLE IF NOT EXISTS test.int_test (int8_c Int8, int16_c Int16, uint8_c UInt8, uint16_c UInt16) ENGINE = Memory");
$client->insert("test.int_test",[
'int8_c','int16_c','uint8_c','uint16_c'
], [
[8, 8, 8, 8],
[9, 9, 9, 9],
]);
$client->writeStart("test.int_test", [
'int8_c','int16_c','uint8_c'
]);
$client->write([
[8, 8, 8],
[9, 9, 9],
]);
$client->writeEnd();
$result = $client->select("SELECT {select} FROM {table}", [
'select' => 'int8_c, int16_c, uint8_c, uint16_c',
'table' => 'test.int_test'
]);
var_dump($result);
if ($deleteTable) {
$client->execute("DROP TABLE {table}", [
'table' => 'test.int_test'
]);
}
}
function testFloat($client, $deleteTable = false) {
$client->execute("CREATE TABLE IF NOT EXISTS test.float_test (float32_c Float32, float64_c Float64) ENGINE = Memory");
$client->insert("test.float_test",[
'float32_c', 'float64_c'
], [
[32.32, 64.64],
[32.31, 64.68]
]);
$client->writeStart("test.float_test", [
'float32_c'
]);
$client->write([
[32.32],
[32.31]
]);
$client->writeEnd();
$result = $client->select("SELECT {select} FROM {table}", [
'select' => 'float32_c, float64_c',
'table' => 'test.float_test'
]);
var_dump($result);
if ($deleteTable) {
$client->execute("DROP TABLE {table}", [
'table' => 'test.float_test'
]);
}
}
/**
* testUUID
* You can insert a UUID with -, but the query is definitely not -
*/
function testUUID($client, $deleteTable = false) {
$client->execute("CREATE TABLE IF NOT EXISTS test.uuid_test (uuid_c UUID, uuid2_c UUID) ENGINE = Memory");
$client->insert("test.uuid_test",[
'uuid_c', 'uuid2_c'
], [
['31249a1b-7b05-4270-9f37-c609b48a9bb2', '31249a1b7b0542709f37c609b48a9bb2'],
['31249a1b-7b05-4270-9f37-c609b48a9bb2', null],
]);
$client->writeStart("test.uuid_test", [
'uuid_c'
]);
$client->write([
['00000000-0000-0000-9f37-c609b48a9bb2'],
['31249a1b-7b05-4270-9f37-c609b48a9bb2'],
]);
$client->writeEnd();
$result = $client->select("SELECT {select} FROM {table}", [
'select' => 'uuid_c, uuid2_c',
'table' => 'test.uuid_test'
]);
var_dump($result);
if ($deleteTable) {
$client->execute("DROP TABLE {table}", [
'table' => 'test.uuid_test'
]);
}
}
/**
* testDate
* Regardless of whether the type is date or datetime is inserted as a timestamp, the query is also a timestamp.
*/
function testDate($client, $deleteTable = false) {
$client->execute("CREATE TABLE IF NOT EXISTS test.date_test (date_c Date, datetime_c DateTime) ENGINE = Memory");
$client->insert("test.date_test", [
'date_c', 'datetime_c'
], [
[time(), time()],
[time(), time()]
]);
$result = $client->select("SELECT {select} FROM {table}", [
'select' => 'date_c, datetime_c',
'table' => 'test.date_test'
]);
var_dump($result);
if ($deleteTable) {
$client->execute("DROP TABLE {table}", [
'table' => 'test.date_test'
]);
}
}