Skip to content

Commit c75b688

Browse files
committed
Switch to temporary tables usage
1 parent c42876b commit c75b688

File tree

4 files changed

+100
-112
lines changed

4 files changed

+100
-112
lines changed

tests/simple/main.cpp

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ inline void ArrayExample(Client& client) {
3535
Block b;
3636

3737
/// 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))");
3939

4040
auto arr = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());
4141

@@ -53,9 +53,9 @@ inline void ArrayExample(Client& client) {
5353
arr->AppendAsColumn(id);
5454

5555
b.AppendColumn("arr", arr);
56-
client.Insert("test.array", b);
56+
client.Insert("test_array", b);
5757

58-
client.Select("SELECT arr FROM test.array", [](const Block& block)
58+
client.Select("SELECT arr FROM test_array", [](const Block& block)
5959
{
6060
for (size_t c = 0; c < block.GetRowCount(); ++c) {
6161
auto col = block[0]->As<ColumnArray>()->GetAsColumn(c);
@@ -68,14 +68,14 @@ inline void ArrayExample(Client& client) {
6868
);
6969

7070
/// Delete table.
71-
client.Execute("DROP TABLE test.array");
71+
client.Execute("DROP TEMPORARY TABLE test_array");
7272
}
7373

7474
inline void MultiArrayExample(Client& client) {
7575
Block b;
7676

7777
/// 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)))");
7979

8080
auto arr = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());
8181

@@ -86,9 +86,9 @@ inline void MultiArrayExample(Client& client) {
8686
auto a2 = std::make_shared<ColumnArray>(std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>()));
8787
a2->AppendAsColumn(arr);
8888
b.AppendColumn("arr", a2);
89-
client.Insert("test.multiarray", b);
89+
client.Insert("test_multiarray", b);
9090

91-
client.Select("SELECT arr FROM test.multiarray", [](const Block& block)
91+
client.Select("SELECT arr FROM test_multiarray", [](const Block& block)
9292
{
9393
for (size_t c = 0; c < block.GetRowCount(); ++c) {
9494
auto col = block[0]->As<ColumnArray>()->GetAsColumn(c);
@@ -108,24 +108,24 @@ inline void MultiArrayExample(Client& client) {
108108
);
109109

110110
/// Delete table.
111-
client.Execute("DROP TABLE test.multiarray");
111+
client.Execute("DROP TEMPORARY TABLE test_multiarray");
112112
}
113113

114114
inline void DateExample(Client& client) {
115115
Block b;
116116

117117
/// 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'))");
119119

120120
auto d = std::make_shared<ColumnDateTime>();
121121
auto dz = std::make_shared<ColumnDateTime>();
122122
d->Append(std::time(nullptr));
123123
dz->Append(std::time(nullptr));
124124
b.AppendColumn("d", d);
125125
b.AppendColumn("dz", dz);
126-
client.Insert("test.date", b);
126+
client.Insert("test_date", b);
127127

128-
client.Select("SELECT d, dz FROM test.date", [](const Block& block)
128+
client.Select("SELECT d, dz FROM test_date", [](const Block& block)
129129
{
130130
for (size_t c = 0; c < block.GetRowCount(); ++c) {
131131

@@ -142,21 +142,22 @@ inline void DateExample(Client& client) {
142142
);
143143

144144
/// Delete table.
145-
client.Execute("DROP TABLE test.date");
145+
client.Execute("DROP TEMPORARY TABLE test_date");
146146
}
147147

148148
inline void DateTime64Example(Client& client) {
149149
Block b;
150150

151151
/// 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))");
153153

154154
auto d = std::make_shared<ColumnDateTime64>(6);
155155
d->Append(std::time(nullptr) * 1000000 + 123456);
156-
b.AppendColumn("d", d);
157-
client.Insert("test.datetime64", b);
158156

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)
160161
{
161162
for (size_t c = 0; c < block.GetRowCount(); ++c) {
162163
auto col = block[0]->As<ColumnDateTime64>();
@@ -171,21 +172,21 @@ inline void DateTime64Example(Client& client) {
171172
);
172173

173174
/// Delete table.
174-
client.Execute("DROP TABLE test.datetime64");
175+
client.Execute("DROP TEMPORARY TABLE test_datetime64");
175176
}
176177

177178
inline void DecimalExample(Client& client) {
178179
Block b;
179180

180181
/// 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))");
182183

183184
auto d = std::make_shared<ColumnDecimal>(18, 4);
184185
d->Append(21111);
185186
b.AppendColumn("d", d);
186-
client.Insert("test.decimal", b);
187+
client.Insert("test_decimal", b);
187188

188-
client.Select("SELECT d FROM test.decimal", [](const Block& block)
189+
client.Select("SELECT d FROM test_decimal", [](const Block& block)
189190
{
190191
for (size_t c = 0; c < block.GetRowCount(); ++c) {
191192
auto col = block[0]->As<ColumnDecimal>();
@@ -204,12 +205,12 @@ inline void DecimalExample(Client& client) {
204205
);
205206

206207
/// Delete table.
207-
client.Execute("DROP TABLE test.decimal");
208+
client.Execute("DROP TEMPORARY TABLE test_decimal");
208209
}
209210

210211
inline void GenericExample(Client& client) {
211212
/// 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)");
213214

214215
/// Insert some values.
215216
{
@@ -226,23 +227,23 @@ inline void GenericExample(Client& client) {
226227
block.AppendColumn("id" , id);
227228
block.AppendColumn("name", name);
228229

229-
client.Insert("test.client", block);
230+
client.Insert("test_client", block);
230231
}
231232

232233
/// 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)
234235
{
235236
PrintBlock(block);
236237
}
237238
);
238239

239240
/// Delete table.
240-
client.Execute("DROP TABLE test.client");
241+
client.Execute("DROP TEMPORARY TABLE test_client");
241242
}
242243

243244
inline void NullableExample(Client& client) {
244245
/// 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))");
246247

247248
/// Insert some values.
248249
{
@@ -272,11 +273,11 @@ inline void NullableExample(Client& client) {
272273
block.AppendColumn("date", std::make_shared<ColumnNullable>(date, nulls));
273274
}
274275

275-
client.Insert("test.client", block);
276+
client.Insert("test_client", block);
276277
}
277278

278279
/// 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)
280281
{
281282
for (size_t c = 0; c < block.GetRowCount(); ++c) {
282283
auto col_id = block[0]->As<ColumnNullable>();
@@ -301,7 +302,7 @@ inline void NullableExample(Client& client) {
301302
);
302303

303304
/// Delete table.
304-
client.Execute("DROP TABLE test.client");
305+
client.Execute("DROP TEMPORARY TABLE test_client");
305306
}
306307

307308
inline void NumbersExample(Client& client) {
@@ -326,7 +327,7 @@ inline void NumbersExample(Client& client) {
326327

327328
inline void CancelableExample(Client& client) {
328329
/// 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)");
330331

331332
/// Insert a few blocks.
332333
for (unsigned j = 0; j < 10; j++) {
@@ -338,28 +339,28 @@ inline void CancelableExample(Client& client) {
338339
}
339340

340341
b.AppendColumn("x", x);
341-
client.Insert("test.client", b);
342+
client.Insert("test_client", b);
342343
}
343344

344345
/// Send a query which is canceled after receiving the first block (note:
345346
/// due to the low number of rows in this test, this will not actually have
346347
/// 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&)
348349
{
349350
return false;
350351
}
351352
);
352353

353354
/// Delete table.
354-
client.Execute("DROP TABLE test.client");
355+
client.Execute("DROP TEMPORARY TABLE test_client");
355356
}
356357

357358
inline void ExecptionExample(Client& client) {
358359
/// 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)");
360361
/// Expect failing on table creation.
361362
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)");
363364
} catch (const ServerException& e) {
364365
if (e.GetCode() == ErrorCodes::TABLE_ALREADY_EXISTS) {
365366
// OK
@@ -369,12 +370,12 @@ inline void ExecptionExample(Client& client) {
369370
}
370371

371372
/// Delete table.
372-
client.Execute("DROP TABLE test.exceptions");
373+
client.Execute("DROP TEMPORARY TABLE test_exceptions");
373374
}
374375

375376
inline void EnumExample(Client& client) {
376377
/// 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))");
378379

379380
/// Insert some values.
380381
{
@@ -391,11 +392,11 @@ inline void EnumExample(Client& client) {
391392
block.AppendColumn("id", id);
392393
block.AppendColumn("e", e);
393394

394-
client.Insert("test.enums", block);
395+
client.Insert("test_enums", block);
395396
}
396397

397398
/// 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)
399400
{
400401
for (Block::Iterator bi(block); bi.IsValid(); bi.Next()) {
401402
std::cout << bi.Name() << " ";
@@ -410,7 +411,7 @@ inline void EnumExample(Client& client) {
410411
);
411412

412413
/// Delete table.
413-
client.Execute("DROP TABLE test.enums");
414+
client.Execute("DROP TEMPORARY TABLE test_enums");
414415
}
415416

416417
inline void SelectNull(Client& client) {
@@ -435,7 +436,7 @@ inline void ShowTables(Client& client) {
435436

436437
inline void IPExample(Client &client) {
437438
/// 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)");
439440

440441
/// Insert some values.
441442
{
@@ -460,11 +461,11 @@ inline void IPExample(Client &client) {
460461
block.AppendColumn("v4", v4);
461462
block.AppendColumn("v6", v6);
462463

463-
client.Insert("test.ips", block);
464+
client.Insert("test_ips", block);
464465
}
465466

466467
/// 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)
468469
{
469470
for (Block::Iterator bi(block); bi.IsValid(); bi.Next()) {
470471
std::cout << bi.Name() << " ";
@@ -480,7 +481,7 @@ inline void IPExample(Client &client) {
480481
);
481482

482483
/// Delete table.
483-
client.Execute("DROP TABLE test.ips");
484+
client.Execute("DROP TEMPORARY TABLE test_ips");
484485
}
485486

486487
static void RunTests(Client& client) {

0 commit comments

Comments
 (0)