@@ -35,7 +35,7 @@ inline void ArrayExample(Client& client) {
35
35
Block b;
36
36
37
37
// / Create a table.
38
- client.Execute (" CREATE TABLE IF NOT EXISTS test.array (arr Array(UInt64)) ENGINE = Memory " );
38
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_array (arr Array(UInt64))" );
39
39
40
40
auto arr = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());
41
41
@@ -53,9 +53,9 @@ inline void ArrayExample(Client& client) {
53
53
arr->AppendAsColumn (id);
54
54
55
55
b.AppendColumn (" arr" , arr);
56
- client.Insert (" test.array " , b);
56
+ client.Insert (" test_array " , b);
57
57
58
- client.Select (" SELECT arr FROM test.array " , [](const Block& block)
58
+ client.Select (" SELECT arr FROM test_array " , [](const Block& block)
59
59
{
60
60
for (size_t c = 0 ; c < block.GetRowCount (); ++c) {
61
61
auto col = block[0 ]->As <ColumnArray>()->GetAsColumn (c);
@@ -68,14 +68,14 @@ inline void ArrayExample(Client& client) {
68
68
);
69
69
70
70
// / Delete table.
71
- client.Execute (" DROP TABLE test.array " );
71
+ client.Execute (" DROP TEMPORARY TABLE test_array " );
72
72
}
73
73
74
74
inline void MultiArrayExample (Client& client) {
75
75
Block b;
76
76
77
77
// / Create a table.
78
- client.Execute (" CREATE TABLE IF NOT EXISTS test.multiarray (arr Array(Array(UInt64))) ENGINE = Memory " );
78
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_multiarray (arr Array(Array(UInt64)))" );
79
79
80
80
auto arr = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());
81
81
@@ -86,9 +86,9 @@ inline void MultiArrayExample(Client& client) {
86
86
auto a2 = std::make_shared<ColumnArray>(std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>()));
87
87
a2->AppendAsColumn (arr);
88
88
b.AppendColumn (" arr" , a2);
89
- client.Insert (" test.multiarray " , b);
89
+ client.Insert (" test_multiarray " , b);
90
90
91
- client.Select (" SELECT arr FROM test.multiarray " , [](const Block& block)
91
+ client.Select (" SELECT arr FROM test_multiarray " , [](const Block& block)
92
92
{
93
93
for (size_t c = 0 ; c < block.GetRowCount (); ++c) {
94
94
auto col = block[0 ]->As <ColumnArray>()->GetAsColumn (c);
@@ -108,24 +108,24 @@ inline void MultiArrayExample(Client& client) {
108
108
);
109
109
110
110
// / Delete table.
111
- client.Execute (" DROP TABLE test.multiarray " );
111
+ client.Execute (" DROP TEMPORARY TABLE test_multiarray " );
112
112
}
113
113
114
114
inline void DateExample (Client& client) {
115
115
Block b;
116
116
117
117
// / Create a table.
118
- client.Execute (" CREATE TABLE IF NOT EXISTS test.date (d DateTime, dz DateTime('Europe/Moscow')) ENGINE = Memory " );
118
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_date (d DateTime, dz DateTime('Europe/Moscow'))" );
119
119
120
120
auto d = std::make_shared<ColumnDateTime>();
121
121
auto dz = std::make_shared<ColumnDateTime>();
122
122
d->Append (std::time (nullptr ));
123
123
dz->Append (std::time (nullptr ));
124
124
b.AppendColumn (" d" , d);
125
125
b.AppendColumn (" dz" , dz);
126
- client.Insert (" test.date " , b);
126
+ client.Insert (" test_date " , b);
127
127
128
- client.Select (" SELECT d, dz FROM test.date " , [](const Block& block)
128
+ client.Select (" SELECT d, dz FROM test_date " , [](const Block& block)
129
129
{
130
130
for (size_t c = 0 ; c < block.GetRowCount (); ++c) {
131
131
@@ -142,21 +142,22 @@ inline void DateExample(Client& client) {
142
142
);
143
143
144
144
// / Delete table.
145
- client.Execute (" DROP TABLE test.date " );
145
+ client.Execute (" DROP TEMPORARY TABLE test_date " );
146
146
}
147
147
148
148
inline void DateTime64Example (Client& client) {
149
149
Block b;
150
150
151
151
// / Create a table.
152
- client.Execute (" CREATE TABLE IF NOT EXISTS test.datetime64 (dt64 DateTime64(6)) ENGINE = Memory " );
152
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_datetime64 (dt64 DateTime64(6))" );
153
153
154
154
auto d = std::make_shared<ColumnDateTime64>(6 );
155
155
d->Append (std::time (nullptr ) * 1000000 + 123456 );
156
- b.AppendColumn (" d" , d);
157
- client.Insert (" test.datetime64" , b);
158
156
159
- client.Select (" SELECT d FROM test.date" , [](const Block& block)
157
+ b.AppendColumn (" dt64" , d);
158
+ client.Insert (" test_datetime64" , b);
159
+
160
+ client.Select (" SELECT dt64 FROM test_datetime64" , [](const Block& block)
160
161
{
161
162
for (size_t c = 0 ; c < block.GetRowCount (); ++c) {
162
163
auto col = block[0 ]->As <ColumnDateTime64>();
@@ -171,21 +172,21 @@ inline void DateTime64Example(Client& client) {
171
172
);
172
173
173
174
// / Delete table.
174
- client.Execute (" DROP TABLE test.datetime64 " );
175
+ client.Execute (" DROP TEMPORARY TABLE test_datetime64 " );
175
176
}
176
177
177
178
inline void DecimalExample (Client& client) {
178
179
Block b;
179
180
180
181
// / Create a table.
181
- client.Execute (" CREATE TABLE IF NOT EXISTS test.decimal (d Decimal64(4)) ENGINE = Memory " );
182
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_decimal (d Decimal64(4))" );
182
183
183
184
auto d = std::make_shared<ColumnDecimal>(18 , 4 );
184
185
d->Append (21111 );
185
186
b.AppendColumn (" d" , d);
186
- client.Insert (" test.decimal " , b);
187
+ client.Insert (" test_decimal " , b);
187
188
188
- client.Select (" SELECT d FROM test.decimal " , [](const Block& block)
189
+ client.Select (" SELECT d FROM test_decimal " , [](const Block& block)
189
190
{
190
191
for (size_t c = 0 ; c < block.GetRowCount (); ++c) {
191
192
auto col = block[0 ]->As <ColumnDecimal>();
@@ -204,12 +205,12 @@ inline void DecimalExample(Client& client) {
204
205
);
205
206
206
207
// / Delete table.
207
- client.Execute (" DROP TABLE test.decimal " );
208
+ client.Execute (" DROP TEMPORARY TABLE test_decimal " );
208
209
}
209
210
210
211
inline void GenericExample (Client& client) {
211
212
// / Create a table.
212
- client.Execute (" CREATE TABLE IF NOT EXISTS test.client (id UInt64, name String) ENGINE = Memory " );
213
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_client (id UInt64, name String)" );
213
214
214
215
// / Insert some values.
215
216
{
@@ -226,23 +227,23 @@ inline void GenericExample(Client& client) {
226
227
block.AppendColumn (" id" , id);
227
228
block.AppendColumn (" name" , name);
228
229
229
- client.Insert (" test.client " , block);
230
+ client.Insert (" test_client " , block);
230
231
}
231
232
232
233
// / Select values inserted in the previous step.
233
- client.Select (" SELECT id, name FROM test.client " , [](const Block& block)
234
+ client.Select (" SELECT id, name FROM test_client " , [](const Block& block)
234
235
{
235
236
PrintBlock (block);
236
237
}
237
238
);
238
239
239
240
// / Delete table.
240
- client.Execute (" DROP TABLE test.client " );
241
+ client.Execute (" DROP TEMPORARY TABLE test_client " );
241
242
}
242
243
243
244
inline void NullableExample (Client& client) {
244
245
// / Create a table.
245
- client.Execute (" CREATE TABLE IF NOT EXISTS test.client (id Nullable(UInt64), date Nullable(Date)) ENGINE = Memory " );
246
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_client (id Nullable(UInt64), date Nullable(Date))" );
246
247
247
248
// / Insert some values.
248
249
{
@@ -272,11 +273,11 @@ inline void NullableExample(Client& client) {
272
273
block.AppendColumn (" date" , std::make_shared<ColumnNullable>(date, nulls));
273
274
}
274
275
275
- client.Insert (" test.client " , block);
276
+ client.Insert (" test_client " , block);
276
277
}
277
278
278
279
// / Select values inserted in the previous step.
279
- client.Select (" SELECT id, date FROM test.client " , [](const Block& block)
280
+ client.Select (" SELECT id, date FROM test_client " , [](const Block& block)
280
281
{
281
282
for (size_t c = 0 ; c < block.GetRowCount (); ++c) {
282
283
auto col_id = block[0 ]->As <ColumnNullable>();
@@ -301,7 +302,7 @@ inline void NullableExample(Client& client) {
301
302
);
302
303
303
304
// / Delete table.
304
- client.Execute (" DROP TABLE test.client " );
305
+ client.Execute (" DROP TEMPORARY TABLE test_client " );
305
306
}
306
307
307
308
inline void NumbersExample (Client& client) {
@@ -326,7 +327,7 @@ inline void NumbersExample(Client& client) {
326
327
327
328
inline void CancelableExample (Client& client) {
328
329
// / Create a table.
329
- client.Execute (" CREATE TABLE IF NOT EXISTS test.client (x UInt64) ENGINE = Memory " );
330
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_client (x UInt64)" );
330
331
331
332
// / Insert a few blocks.
332
333
for (unsigned j = 0 ; j < 10 ; j++) {
@@ -338,28 +339,28 @@ inline void CancelableExample(Client& client) {
338
339
}
339
340
340
341
b.AppendColumn (" x" , x);
341
- client.Insert (" test.client " , b);
342
+ client.Insert (" test_client " , b);
342
343
}
343
344
344
345
// / Send a query which is canceled after receiving the first block (note:
345
346
// / due to the low number of rows in this test, this will not actually have
346
347
// / any effect, it just tests for errors)
347
- client.SelectCancelable (" SELECT * FROM test.client " , [](const Block&)
348
+ client.SelectCancelable (" SELECT * FROM test_client " , [](const Block&)
348
349
{
349
350
return false ;
350
351
}
351
352
);
352
353
353
354
// / Delete table.
354
- client.Execute (" DROP TABLE test.client " );
355
+ client.Execute (" DROP TEMPORARY TABLE test_client " );
355
356
}
356
357
357
358
inline void ExecptionExample (Client& client) {
358
359
// / Create a table.
359
- client.Execute (" CREATE TABLE IF NOT EXISTS test.exceptions (id UInt64, name String) ENGINE = Memory " );
360
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_exceptions (id UInt64, name String)" );
360
361
// / Expect failing on table creation.
361
362
try {
362
- client.Execute (" CREATE TABLE test.exceptions (id UInt64, name String) ENGINE = Memory " );
363
+ client.Execute (" CREATE TEMPORARY TABLE test_exceptions (id UInt64, name String)" );
363
364
} catch (const ServerException& e) {
364
365
if (e.GetCode () == ErrorCodes::TABLE_ALREADY_EXISTS) {
365
366
// OK
@@ -369,12 +370,12 @@ inline void ExecptionExample(Client& client) {
369
370
}
370
371
371
372
// / Delete table.
372
- client.Execute (" DROP TABLE test.exceptions " );
373
+ client.Execute (" DROP TEMPORARY TABLE test_exceptions " );
373
374
}
374
375
375
376
inline void EnumExample (Client& client) {
376
377
// / Create a table.
377
- client.Execute (" CREATE TABLE IF NOT EXISTS test.enums (id UInt64, e Enum8('One' = 1, 'Two' = 2)) ENGINE = Memory " );
378
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_enums (id UInt64, e Enum8('One' = 1, 'Two' = 2))" );
378
379
379
380
// / Insert some values.
380
381
{
@@ -391,11 +392,11 @@ inline void EnumExample(Client& client) {
391
392
block.AppendColumn (" id" , id);
392
393
block.AppendColumn (" e" , e);
393
394
394
- client.Insert (" test.enums " , block);
395
+ client.Insert (" test_enums " , block);
395
396
}
396
397
397
398
// / Select values inserted in the previous step.
398
- client.Select (" SELECT id, e FROM test.enums " , [](const Block& block)
399
+ client.Select (" SELECT id, e FROM test_enums " , [](const Block& block)
399
400
{
400
401
for (Block::Iterator bi (block); bi.IsValid (); bi.Next ()) {
401
402
std::cout << bi.Name () << " " ;
@@ -410,7 +411,7 @@ inline void EnumExample(Client& client) {
410
411
);
411
412
412
413
// / Delete table.
413
- client.Execute (" DROP TABLE test.enums " );
414
+ client.Execute (" DROP TEMPORARY TABLE test_enums " );
414
415
}
415
416
416
417
inline void SelectNull (Client& client) {
@@ -435,7 +436,7 @@ inline void ShowTables(Client& client) {
435
436
436
437
inline void IPExample (Client &client) {
437
438
// / Create a table.
438
- client.Execute (" CREATE TABLE IF NOT EXISTS test.ips (id UInt64, v4 IPv4, v6 IPv6) ENGINE = Memory " );
439
+ client.Execute (" CREATE TEMPORARY TABLE IF NOT EXISTS test_ips (id UInt64, v4 IPv4, v6 IPv6)" );
439
440
440
441
// / Insert some values.
441
442
{
@@ -460,11 +461,11 @@ inline void IPExample(Client &client) {
460
461
block.AppendColumn (" v4" , v4);
461
462
block.AppendColumn (" v6" , v6);
462
463
463
- client.Insert (" test.ips " , block);
464
+ client.Insert (" test_ips " , block);
464
465
}
465
466
466
467
// / Select values inserted in the previous step.
467
- client.Select (" SELECT id, v4, v6 FROM test.ips " , [](const Block& block)
468
+ client.Select (" SELECT id, v4, v6 FROM test_ips " , [](const Block& block)
468
469
{
469
470
for (Block::Iterator bi (block); bi.IsValid (); bi.Next ()) {
470
471
std::cout << bi.Name () << " " ;
@@ -480,7 +481,7 @@ inline void IPExample(Client &client) {
480
481
);
481
482
482
483
// / Delete table.
483
- client.Execute (" DROP TABLE test.ips " );
484
+ client.Execute (" DROP TEMPORARY TABLE test_ips " );
484
485
}
485
486
486
487
static void RunTests (Client& client) {
0 commit comments