1 /* Copyright (C) 2014 InfiniDB, Inc.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 MA 02110-1301, USA. */
17
18 #include <stdio.h>
19 #include <string>
20 #include <stdexcept>
21 using namespace std;
22
23 #include <cppunit/extensions/HelperMacros.h>
24
25 #include <sstream>
26 #include <exception>
27 #include <iostream>
28 #include <unistd.h>
29 #include <sys/types.h>
30 #include <sys/ipc.h>
31 #include <sys/sem.h>
32 #include <sys/shm.h>
33 #include <errno.h>
34
35 #include "messagequeue.h"
36 #include "bytestream.h"
37 using namespace messageqcpp;
38
39 #include "ddlpkg.h"
40 #include "sqlparser.h"
41 using namespace ddlpackage;
42
43 #include "createtableprocessor.h"
44 #include "createindexprocessor.h"
45 #include "altertableprocessor.h"
46 #include "dropindexprocessor.h"
47 #include "droptableprocessor.h"
48
49 using namespace ddlpackageprocessor;
50
51 #include "writeengine.h"
52 #include "we_colop.h"
53 using namespace WriteEngine;
54
55 #include "messagelog.h"
56 class SystemCatalogBuilder
57 {
58 public:
build()59 static void build()
60 {
61 ColumnOp colOp;
62 Column curCol;
63 WriteEngine::WriteEngineWrapper fWriteEngine;
64 WriteEngine::TxnID txnID = 0;
65 int rc;
66
67 remove();
68
69 colOp.initColumn( curCol );
70 // SYSTABLE
71
72 cout << "Creating System Catalog..." << endl;
73
74 // TableName
75 rc = colOp.createColumn( curCol, 0, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1001 );
76 CPPUNIT_ASSERT( rc == NO_ERROR );
77
78 cout << "Creating Dictionary..." << endl;
79 //Dictionary files
80 rc = fWriteEngine.createStore (txnID, 2001, 2002, 2003);
81 // Schema
82 rc = colOp.createColumn( curCol, 1, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1002 );
83 CPPUNIT_ASSERT( rc == NO_ERROR );
84
85 cout << "Creating Dictionary..." << endl;
86 //Dictionary files
87 rc = fWriteEngine.createStore (txnID, 2004, 2005, 2006);
88 // CreateDate
89 rc = colOp.createColumn( curCol, 2, 8, WriteEngine::DATE, WriteEngine::WR_CHAR, 1003 );
90 CPPUNIT_ASSERT( rc == NO_ERROR );
91
92 // LastUpdateDate
93 rc = colOp.createColumn( curCol, 3, 8, WriteEngine::DATE, WriteEngine::WR_CHAR, 1004 );
94 CPPUNIT_ASSERT( rc == NO_ERROR );
95
96 // INIT
97 rc = colOp.createColumn( curCol, 4, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1005 );
98 CPPUNIT_ASSERT( rc == NO_ERROR );
99
100 // NEXT
101 rc = colOp.createColumn( curCol, 5, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1006 );
102 CPPUNIT_ASSERT( rc == NO_ERROR );
103
104 //SYSCOLUMN
105 // Shema
106 rc = colOp.createColumn( curCol, 0, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1007 );
107 CPPUNIT_ASSERT( rc == NO_ERROR );
108
109 cout << "Creating Dictionary..." << endl;
110 //Dictionary files
111 rc = fWriteEngine.createStore (txnID, 2007, 2008, 2009);
112
113 // TableName
114 rc = colOp.createColumn( curCol, 1, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1008 );
115 CPPUNIT_ASSERT( rc == NO_ERROR );
116
117 cout << "Creating Dictionary..." << endl;
118 //Dictionary files
119 rc = fWriteEngine.createStore (txnID, 2010, 2011, 2012);
120
121 // ColumnName
122 rc = colOp.createColumn( curCol, 2, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1009 );
123 CPPUNIT_ASSERT( rc == NO_ERROR );
124
125 //Dictionary files
126 rc = fWriteEngine.createStore (txnID, 2013, 2014, 2015);
127 // ObjectID
128 rc = colOp.createColumn( curCol, 3, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1010 );
129 CPPUNIT_ASSERT( rc == NO_ERROR );
130
131 // DictOID
132 rc = colOp.createColumn( curCol, 4, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1011 );
133 CPPUNIT_ASSERT( rc == NO_ERROR );
134
135 // ListOID
136 rc = colOp.createColumn( curCol, 5, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1012 );
137 CPPUNIT_ASSERT( rc == NO_ERROR );
138
139 // TreeOID
140 rc = colOp.createColumn( curCol, 6, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1013 );
141 CPPUNIT_ASSERT( rc == NO_ERROR );
142
143 // DataType
144 rc = colOp.createColumn( curCol, 7, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1014 );
145 CPPUNIT_ASSERT( rc == NO_ERROR );
146
147 // ColumnLength
148 rc = colOp.createColumn( curCol, 8, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1015 );
149 CPPUNIT_ASSERT( rc == NO_ERROR );
150
151 // ColumnPos
152 rc = colOp.createColumn( curCol, 9, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1016 );
153 CPPUNIT_ASSERT( rc == NO_ERROR );
154
155 // LastUpdate
156 rc = colOp.createColumn( curCol, 10, 8, WriteEngine::DATE, WriteEngine::WR_CHAR, 1017 );
157 CPPUNIT_ASSERT( rc == NO_ERROR );
158
159 // DefaultValue
160 rc = colOp.createColumn( curCol, 11, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1018 );
161 CPPUNIT_ASSERT( rc == NO_ERROR );
162
163 cout << "Creating Dictionary..." << endl;
164 //Dictionary files
165 rc = fWriteEngine.createStore (txnID, 2016, 2017, 2018);
166 // Nullable
167 rc = colOp.createColumn( curCol, 12, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1019 );
168 CPPUNIT_ASSERT( rc == NO_ERROR );
169
170 // Scale
171 rc = colOp.createColumn( curCol, 13, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1020 );
172 CPPUNIT_ASSERT( rc == NO_ERROR );
173
174 // Precision
175 rc = colOp.createColumn( curCol, 14, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1021 );
176 CPPUNIT_ASSERT( rc == NO_ERROR );
177
178 // AutoInc
179 rc = colOp.createColumn( curCol, 15, 1, WriteEngine::CHAR, WriteEngine::WR_CHAR, 1022 );
180 CPPUNIT_ASSERT( rc == NO_ERROR );
181
182 // SYSCONSTRAINT
183
184 // ConstraintName
185 rc = colOp.createColumn( curCol, 0, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1023 );
186 CPPUNIT_ASSERT( rc == NO_ERROR );
187
188 cout << "Creating Dictionary..." << endl;
189 //Dictionary files
190 rc = fWriteEngine.createStore (txnID, 2019, 2020, 2021);
191 // Schema
192 rc = colOp.createColumn( curCol, 1, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1024 );
193 CPPUNIT_ASSERT( rc == NO_ERROR );
194
195 cout << "Creating Dictionary..." << endl;
196 //Dictionary files
197 rc = fWriteEngine.createStore (txnID, 2022, 2023, 2024);
198 // TableName
199 rc = colOp.createColumn( curCol, 2, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1025 );
200 CPPUNIT_ASSERT( rc == NO_ERROR );
201
202 cout << "Creating Dictionary..." << endl;
203 //Dictionary files
204 rc = fWriteEngine.createStore (txnID, 2025, 2026, 2027);
205
206 // ConstraintType
207 rc = colOp.createColumn( curCol, 3, 1, WriteEngine::CHAR, WriteEngine::WR_CHAR, 1026 );
208 CPPUNIT_ASSERT( rc == NO_ERROR );
209
210 // ConstraintPrim
211 rc = colOp.createColumn( curCol, 4, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1027 );
212 CPPUNIT_ASSERT( rc == NO_ERROR );
213
214 cout << "Creating Dictionary..." << endl;
215 //Dictionary files
216 rc = fWriteEngine.createStore (txnID, 2028, 2029, 2030);
217
218 // ConstraintText
219 rc = colOp.createColumn( curCol, 5, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1028 );
220 CPPUNIT_ASSERT( rc == NO_ERROR );
221
222 cout << "Creating Dictionary..." << endl;
223 //Dictionary files
224 rc = fWriteEngine.createStore (txnID, 2031, 2032, 2033);
225
226 // ConstraintStatus
227 rc = colOp.createColumn( curCol, 6, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1029 );
228 CPPUNIT_ASSERT( rc == NO_ERROR );
229
230 cout << "Creating Dictionary..." << endl;
231 //Dictionary files
232 rc = fWriteEngine.createStore (txnID, 2034, 2035, 2036);
233
234 // IndexName
235 rc = colOp.createColumn( curCol, 7, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1030 );
236 CPPUNIT_ASSERT( rc == NO_ERROR );
237
238 cout << "Creating Dictionary..." << endl;
239 //Dictionary files
240 rc = fWriteEngine.createStore (txnID, 2037, 2038, 2039);
241
242 //SYSCONSTRAINTCOL
243 // Schema
244 rc = colOp.createColumn( curCol, 0, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1031 );
245 CPPUNIT_ASSERT( rc == NO_ERROR );
246
247 cout << "Creating Dictionary..." << endl;
248 //Dictionary files
249 rc = fWriteEngine.createStore (txnID, 2040, 2041, 2042);
250
251 // TableName
252 rc = colOp.createColumn( curCol, 1, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1032 );
253 CPPUNIT_ASSERT( rc == NO_ERROR );
254
255 //Dictionary files
256 rc = fWriteEngine.createStore (txnID, 2043, 2044, 2045);
257
258 // ColumnName
259 rc = colOp.createColumn( curCol, 2, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1033 );
260 CPPUNIT_ASSERT( rc == NO_ERROR );
261
262 cout << "Creating Dictionary..." << endl;
263 //Dictionary files
264 rc = fWriteEngine.createStore (txnID, 2046, 2047, 2048);
265
266 // ConstraintName
267 rc = colOp.createColumn( curCol, 3, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1034 );
268 CPPUNIT_ASSERT( rc == NO_ERROR );
269
270 cout << "Creating Dictionary..." << endl;
271 //Dictionary files
272 rc = fWriteEngine.createStore (txnID, 2049, 2050, 2051);
273
274 // SYSINDEX
275 // Schema
276 rc = colOp.createColumn( curCol, 4, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1035 );
277 CPPUNIT_ASSERT( rc == NO_ERROR );
278
279 cout << "Creating Dictionary..." << endl;
280 //Dictionary files
281 rc = fWriteEngine.createStore (txnID, 2052, 2053, 2054);
282
283 //TableName
284 rc = colOp.createColumn( curCol, 5, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1036 );
285 CPPUNIT_ASSERT( rc == NO_ERROR );
286
287 cout << "Creating Dictionary..." << endl;
288 //Dictionary files
289 rc = fWriteEngine.createStore (txnID, 2055, 2056, 2057);
290
291 // IndexName
292 rc = colOp.createColumn( curCol, 6, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1037 );
293 CPPUNIT_ASSERT( rc == NO_ERROR );
294
295 cout << "Creating Dictionary..." << endl;
296 //Dictionary files
297 rc = fWriteEngine.createStore (txnID, 2058, 2059, 2060);
298
299 // ListOID
300 rc = colOp.createColumn( curCol, 7, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1038 );
301 CPPUNIT_ASSERT( rc == NO_ERROR );
302
303 // TreeOID
304 rc = colOp.createColumn( curCol, 8, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1039 );
305 CPPUNIT_ASSERT( rc == NO_ERROR );
306
307 // IndexType
308 rc = colOp.createColumn( curCol, 9, 1, WriteEngine::CHAR, WriteEngine::WR_CHAR, 1040 );
309 CPPUNIT_ASSERT( rc == NO_ERROR );
310
311 // CreateDate
312 rc = colOp.createColumn( curCol, 10, 8, WriteEngine::DATE, WriteEngine::WR_CHAR, 1041 );
313 CPPUNIT_ASSERT( rc == NO_ERROR );
314
315 // LastUpdateDate
316 rc = colOp.createColumn( curCol, 11, 8, WriteEngine::DATE, WriteEngine::WR_CHAR, 1042 );
317 CPPUNIT_ASSERT( rc == NO_ERROR );
318
319 // RecordCount
320 rc = colOp.createColumn( curCol, 12, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1043 );
321 CPPUNIT_ASSERT( rc == NO_ERROR );
322
323 // TreeLevel
324 rc = colOp.createColumn( curCol, 13, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1044 );
325 CPPUNIT_ASSERT( rc == NO_ERROR );
326
327 // LeafCount
328 rc = colOp.createColumn( curCol, 14, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1045 );
329 CPPUNIT_ASSERT( rc == NO_ERROR );
330
331 // DistinctKeys
332 rc = colOp.createColumn( curCol, 15, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1046 );
333 CPPUNIT_ASSERT( rc == NO_ERROR );
334
335 // LeafBlocks
336 rc = colOp.createColumn( curCol, 16, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1047 );
337 CPPUNIT_ASSERT( rc == NO_ERROR );
338
339 // AvgLeafCount
340 rc = colOp.createColumn( curCol, 17, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1048 );
341 CPPUNIT_ASSERT( rc == NO_ERROR );
342
343 // AvgDataBlock
344 rc = colOp.createColumn( curCol, 18, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1049 );
345 CPPUNIT_ASSERT( rc == NO_ERROR );
346
347 // SampleSize
348 rc = colOp.createColumn( curCol, 19, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1050 );
349 CPPUNIT_ASSERT( rc == NO_ERROR );
350
351 // ClusterFactor
352 rc = colOp.createColumn( curCol, 20, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1051 );
353 CPPUNIT_ASSERT( rc == NO_ERROR );
354
355 // LastAnalysisDate
356 rc = colOp.createColumn( curCol, 21, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1052 );
357 CPPUNIT_ASSERT( rc == NO_ERROR );
358
359 // SYSINDEXCOL
360 // Schema
361 rc = colOp.createColumn( curCol, 0, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1053 );
362 CPPUNIT_ASSERT( rc == NO_ERROR );
363
364 cout << "Creating Dictionary..." << endl;
365 //Dictionary files
366 rc = fWriteEngine.createStore (txnID, 2061, 2062, 2063);
367
368 // TableName
369 rc = colOp.createColumn( curCol, 1, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1054 );
370 CPPUNIT_ASSERT( rc == NO_ERROR );
371
372 cout << "Creating Dictionary..." << endl;
373 //Dictionary files
374 rc = fWriteEngine.createStore (txnID, 2064, 2065, 2066);
375
376 // ColumnName
377 rc = colOp.createColumn( curCol, 2, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1055 );
378 CPPUNIT_ASSERT( rc == NO_ERROR );
379
380 cout << "Creating Dictionary..." << endl;
381 //Dictionary files
382 rc = fWriteEngine.createStore (txnID, 2067, 2068, 2069);
383
384 // IndexName
385 rc = colOp.createColumn( curCol, 3, 8, WriteEngine::VARCHAR, WriteEngine::WR_CHAR, 1056 );
386 CPPUNIT_ASSERT( rc == NO_ERROR );
387
388 cout << "Creating Dictionary..." << endl;
389 //Dictionary files
390 rc = fWriteEngine.createStore (txnID, 2070, 2071, 2072);
391
392 // ColumnPos
393 rc = colOp.createColumn( curCol, 4, 4, WriteEngine::INT, WriteEngine::WR_CHAR, 1057 );
394 CPPUNIT_ASSERT( rc == NO_ERROR );
395 }
396
remove()397 static void remove()
398 {
399 ColumnOp colOp;
400
401 for ( int i = 1001; i <= 1057; i++ )
402 colOp.deleteFile( i );
403 }
404
405 };
406
destroySemaphores()407 void destroySemaphores()
408 {
409 key_t semkey;
410 int sems, err;
411
412 semkey = 0x2149bdd2;
413 sems = semget(semkey, 2, 0666);
414
415 if (sems != -1)
416 {
417 err = semctl(sems, 0, IPC_RMID);
418
419 if (err == -1)
420 perror("tdriver: semctl");
421 }
422 }
423
424
425
destroyShmseg()426 void destroyShmseg()
427 {
428 key_t shmkey;
429 int shms, err;
430
431 shmkey = 0x2149bdd2;
432 shms = shmget(shmkey, 0, 0666);
433
434 if (shms != -1)
435 {
436 err = shmctl(shms, IPC_RMID, NULL);
437
438 if (err == -1 && errno != EINVAL)
439 {
440 perror("tdriver: shmctl");
441 return;
442 }
443 }
444 }
445
setUp()446 void setUp()
447 {
448 destroySemaphores();
449 destroyShmseg();
450 unlink("/tmp/oidbitmap");
451 SystemCatalogBuilder::build();
452 }
453
tearDown()454 void tearDown()
455 {
456 destroySemaphores();
457 destroyShmseg();
458 unlink("/tmp/oidbitmap");
459 }
460
461 class DDLPackageProcessorTest : public CppUnit::TestFixture
462 {
463 CPPUNIT_TEST_SUITE(DDLPackageProcessorTest);
464
465 /*
466 CPPUNIT_TEST( test_createtable );
467 CPPUNIT_TEST( test_createtable_region );
468 CPPUNIT_TEST( test_createindex );
469 CPPUNIT_TEST( test_createuniqueindex );
470
471 CPPUNIT_TEST( test_altertable_renamecolumn );
472 CPPUNIT_TEST( test_altertable_renamecolumnwithcons );
473
474 CPPUNIT_TEST( test_altertable_addacolumn );
475 CPPUNIT_TEST( test_altertable_addacolumnconstrain );
476 CPPUNIT_TEST( test_altertable_addacolumnunique );
477 CPPUNIT_TEST( test_altertable_dropacolumn );
478 CPPUNIT_TEST( test_altertable_dropcolumns );
479 CPPUNIT_TEST( test_altertable_addcolumns );
480 CPPUNIT_TEST( test_altertable_addtableconstraint );
481 CPPUNIT_TEST( test_altertable_droptableconstraint );
482 CPPUNIT_TEST( test_altertable_setcolumndefault );
483 CPPUNIT_TEST( test_altertable_dropcolumndefault );
484 CPPUNIT_TEST( test_altertable_renametable );
485 CPPUNIT_TEST( test_dropindex );
486 CPPUNIT_TEST( test_droptable ); */
487
488 CPPUNIT_TEST_SUITE_END();
489 private:
490
491 public:
492
493 /*
494 * destroySemaphores() and destroyShmseg() will print error messages
495 * if there are no objects to destroy. That's OK.
496 */
test_createtable_region()497 void test_createtable_region()
498 {
499 cout << "Begining create region table testing..." << endl;
500 std::string sqlbuf = "create table region( r_regionkey integer NOT NULL, r_name char(25) ,r_comment varchar(152));";
501 SqlParser parser;
502 parser.Parse(sqlbuf.c_str());
503
504 if (parser.Good())
505 {
506 const ParseTree& ptree = parser.GetParseTree();
507
508 try
509 {
510 CreateTableProcessor processor;
511 processor.setDebugLevel(CreateTableProcessor::VERBOSE);
512
513 SqlStatement& stmt = *ptree.fList[0];
514 CreateTableProcessor::DDLResult result;
515
516 result = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt));
517 std::cout << "return: " << result.result << std::endl;
518 }
519 catch (...)
520 {
521 tearDown();
522 throw;
523 }
524 }
525
526 tearDown();
527 }
528
test_createtable()529 void test_createtable()
530 {
531 //setUp();
532 //removeSystemCatalog();
533 //createSystemCatalog();
534 cout << "Begining create table testing..." << endl;
535 std::string sqlbuf = "create table tpch.part( p_partkey integer NOT NULL ,p_name varchar(55) default 'helloworld', p_mfgr char(6), p_brand char(10) , p_type varchar(25) default 'foobar' , p_size integer , p_container char(10) ,p_retailprice integer , p_comment varchar(23), CONSTRAINT PK_PART PRIMARY KEY(p_partkey) )";
536 SqlParser parser;
537 parser.Parse(sqlbuf.c_str());
538
539 if (parser.Good())
540 {
541 const ParseTree& ptree = parser.GetParseTree();
542
543 try
544 {
545 CreateTableProcessor processor;
546 processor.setDebugLevel(CreateTableProcessor::VERBOSE);
547
548 SqlStatement& stmt = *ptree.fList[0];
549
550 CreateTableStatement& ct = dynamic_cast<CreateTableStatement&>(stmt);
551
552 cout << "Parsed CreateTable:" << endl;
553 cout << ct << endl;
554
555 CreateTableProcessor::DDLResult result;
556
557 result = processor.processPackage(ct);
558 std::cout << "return: " << result.result << std::endl;
559 }
560 catch (...)
561 {
562 tearDown();
563 throw;
564 }
565 }
566
567 tearDown();
568 }
569
test_createindex()570 void test_createindex()
571 {
572 cout << "Begining create index test ... " << endl;
573 std::string sqlbuf = "CREATE INDEX test_idx ON tpch.part (p_size)";
574 SqlParser parser;
575 parser.Parse(sqlbuf.c_str());
576
577 if (parser.Good())
578 {
579 const ParseTree& ptree = parser.GetParseTree();
580
581 try
582 {
583 CreateIndexProcessor processor;
584 processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
585
586 SqlStatement& stmt = *ptree.fList[0];
587 CreateIndexProcessor::DDLResult result;
588
589 result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
590 std::cout << "return: " << result.result << std::endl;
591 }
592 catch (...)
593 {
594 tearDown();
595 throw;
596 }
597 }
598
599 tearDown();
600 }
601
test_createuniqueindex()602 void test_createuniqueindex()
603 {
604 cout << "Begining create unique index test ..." << endl;
605 std::string sqlbuf = "CREATE UNIQUE INDEX test_idx ON tpch.part (p_mfgr)";
606 SqlParser parser;
607 parser.Parse(sqlbuf.c_str());
608
609 if (parser.Good())
610 {
611 const ParseTree& ptree = parser.GetParseTree();
612
613 try
614 {
615 CreateIndexProcessor processor;
616 processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
617
618 SqlStatement& stmt = *ptree.fList[0];
619 CreateIndexProcessor::DDLResult result;
620
621 result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
622 std::cout << "return: " << result.result << std::endl;
623 }
624 catch (...)
625 {
626 tearDown();
627 throw;
628 }
629 }
630
631 tearDown();
632 }
test_altertable_addacolumn()633 void test_altertable_addacolumn()
634 {
635 cout << "Begoning Alter Table Add column test ..." << endl;
636 std::string sqlbuf = "ALTER TABLE tpch.part ADD COLUMN c3 char(50)";
637
638 SqlParser parser;
639 parser.Parse(sqlbuf.c_str());
640
641 if (parser.Good())
642 {
643 const ParseTree& ptree = parser.GetParseTree();
644
645 try
646 {
647 AlterTableProcessor processor;
648 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
649
650 SqlStatement& stmt = *ptree.fList[0];
651 AlterTableProcessor::DDLResult result;
652
653 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
654 std::cout << "return: " << result.result << std::endl;
655 }
656 catch (...)
657 {
658 tearDown();
659 throw;
660 }
661 }
662
663 tearDown();
664 }
665
test_altertable_addacolumnconstrain()666 void test_altertable_addacolumnconstrain()
667 {
668 cout << "Begining Alter Table add column constraint test ..." << endl;
669 std::string sqlbuf = "ALTER TABLE tpch.part ADD COLUMN c3 char(50) NOT NULL";
670
671 SqlParser parser;
672 parser.Parse(sqlbuf.c_str());
673
674 if (parser.Good())
675 {
676 const ParseTree& ptree = parser.GetParseTree();
677
678 try
679 {
680 AlterTableProcessor processor;
681 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
682
683 SqlStatement& stmt = *ptree.fList[0];
684 AlterTableProcessor::DDLResult result;
685
686 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
687 std::cout << "return: " << result.result << std::endl;
688 }
689 catch (...)
690 {
691 tearDown();
692 throw;
693 }
694 }
695
696 tearDown();
697 }
698
test_altertable_addacolumnunique()699 void test_altertable_addacolumnunique()
700 {
701 cout << "Begining Alter Table add column with constraint test ..." << endl;
702 std::string sqlbuf = "ALTER TABLE tpch.part ADD COLUMN c3 char(50) UNIQUE";
703
704 SqlParser parser;
705 parser.Parse(sqlbuf.c_str());
706
707 if (parser.Good())
708 {
709 const ParseTree& ptree = parser.GetParseTree();
710
711 try
712 {
713 AlterTableProcessor processor;
714 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
715
716 SqlStatement& stmt = *ptree.fList[0];
717 AlterTableProcessor::DDLResult result;
718
719 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
720 std::cout << "return: " << result.result << std::endl;
721 }
722 catch (...)
723 {
724 tearDown();
725 throw;
726 }
727 }
728
729 tearDown();
730 }
test_altertable_dropacolumn()731 void test_altertable_dropacolumn()
732 {
733 cout << "Begining Alter Table drop a column test ..." << endl;
734 std::string sqlbuf = "ALTER TABLE tpch.part DROP p_size ";
735
736 SqlParser parser;
737 parser.Parse(sqlbuf.c_str());
738
739 if (parser.Good())
740 {
741 const ParseTree& ptree = parser.GetParseTree();
742
743 try
744 {
745 AlterTableProcessor processor;
746 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
747
748 SqlStatement& stmt = *ptree.fList[0];
749 AlterTableProcessor::DDLResult result;
750
751 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
752 std::cout << "return: " << result.result << std::endl;
753 }
754 catch (...)
755 {
756 tearDown();
757 throw;
758 }
759 }
760
761 tearDown();
762 }
763
test_altertable_dropcolumns()764 void test_altertable_dropcolumns()
765 {
766 cout << "Begining Alter Table drop columns test ..." << endl;
767 std::string sqlbuf = "ALTER TABLE tpch.part DROP p_size, DROP p_type ";
768
769 SqlParser parser;
770 parser.Parse(sqlbuf.c_str());
771
772 if (parser.Good())
773 {
774 const ParseTree& ptree = parser.GetParseTree();
775
776 try
777 {
778 AlterTableProcessor processor;
779 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
780
781 SqlStatement& stmt = *ptree.fList[0];
782 AlterTableProcessor::DDLResult result;
783
784 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
785 std::cout << "return: " << result.result << std::endl;
786 }
787 catch (...)
788 {
789 tearDown();
790 throw;
791 }
792 }
793
794 tearDown();
795 }
796
test_altertable_addcolumns()797 void test_altertable_addcolumns()
798 {
799 cout << "Begining Alter Table add columns test ..." << endl;
800 std::string sqlbuf = "ALTER TABLE test ADD COLUMN c3 char(50), ADD COLUMN c4 char(10), ADD COLUMN C5 int;";
801
802 SqlParser parser;
803 parser.Parse(sqlbuf.c_str());
804
805 if (parser.Good())
806 {
807 const ParseTree& ptree = parser.GetParseTree();
808
809 try
810 {
811 AlterTableProcessor processor;
812 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
813
814 SqlStatement& stmt = *ptree.fList[0];
815 AlterTableProcessor::DDLResult result;
816
817 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
818 std::cout << "return: " << result.result << std::endl;
819 }
820 catch (...)
821 {
822 tearDown();
823 throw;
824 }
825 }
826
827 tearDown();
828 }
test_dropindex()829 void test_dropindex()
830 {
831 cout << "Begining Alter Table drop index test ..." << endl;
832 std::string sqlbuf = "drop index tpch.test_idx";
833
834 SqlParser parser;
835 parser.Parse(sqlbuf.c_str());
836
837 if (parser.Good())
838 {
839 const ParseTree& ptree = parser.GetParseTree();
840
841 try
842 {
843 DropIndexProcessor processor;
844 processor.setDebugLevel(DropIndexProcessor::VERBOSE);
845
846 SqlStatement& stmt = *ptree.fList[0];
847 DropIndexProcessor::DDLResult result;
848
849 result = processor.processPackage(dynamic_cast<DropIndexStatement&>(stmt));
850 std::cout << "return: " << result.result << std::endl;
851 }
852 catch (...)
853 {
854 tearDown();
855 throw;
856 }
857 }
858
859 tearDown();
860 }
test_altertable_renamecolumn()861 void test_altertable_renamecolumn()
862 {
863 cout << "Begining Alter Table rename a column ..." << endl;
864 std::string sqlbuf = "ALTER TABLE tpch.part RENAME COLUMN p_size TO size;";
865
866 SqlParser parser;
867 parser.Parse(sqlbuf.c_str());
868
869 if (parser.Good())
870 {
871 const ParseTree& ptree = parser.GetParseTree();
872
873 try
874 {
875 AlterTableProcessor processor;
876 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
877
878 SqlStatement& stmt = *ptree.fList[0];
879 AlterTableProcessor::DDLResult result;
880
881 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
882 std::cout << "return: " << result.result << std::endl;
883 }
884 catch (...)
885 {
886 tearDown();
887 throw;
888 }
889 }
890
891 tearDown();
892 }
893
894
test_altertable_renamecolumnwithcons()895 void test_altertable_renamecolumnwithcons()
896 {
897 cout << "Begining Alter Table rename a column with constraints ..." << endl;
898 std::string sqlbuf = "ALTER TABLE tpch.part RENAME COLUMN p_partkey TO partlkey;";
899
900 SqlParser parser;
901 parser.Parse(sqlbuf.c_str());
902
903 if (parser.Good())
904 {
905 const ParseTree& ptree = parser.GetParseTree();
906
907 try
908 {
909 AlterTableProcessor processor;
910 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
911
912 SqlStatement& stmt = *ptree.fList[0];
913 AlterTableProcessor::DDLResult result;
914
915 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
916 std::cout << "return: " << result.result << std::endl;
917 }
918 catch (...)
919 {
920 tearDown();
921 throw;
922 }
923 }
924
925 tearDown();
926 }
test_altertable_addtableconstraint()927 void test_altertable_addtableconstraint()
928 {
929 cout << "Begining Alter Table add table constraint test ... " << endl;
930 std::string sqlbuf = "ALTER TABLE tpch.part add CONSTRAINT unique(p_type);";
931
932 SqlParser parser;
933 parser.Parse(sqlbuf.c_str());
934
935 if (parser.Good())
936 {
937 const ParseTree& ptree = parser.GetParseTree();
938
939 try
940 {
941 AlterTableProcessor processor;
942 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
943
944 SqlStatement& stmt = *ptree.fList[0];
945 AlterTableProcessor::DDLResult result;
946
947 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
948 std::cout << "return: " << result.result << std::endl;
949 }
950 catch (...)
951 {
952 tearDown();
953 throw;
954 }
955 }
956
957 tearDown();
958 }
959
test_altertable_droptableconstraint()960 void test_altertable_droptableconstraint()
961 {
962 cout << "Begining Alter Table drop table constraint test ..." << endl;
963 std::string sqlbuf = "ALTER TABLE tpch.part drop constraint pk_tpch cascade;";
964
965 SqlParser parser;
966 parser.Parse(sqlbuf.c_str());
967
968 if (parser.Good())
969 {
970 const ParseTree& ptree = parser.GetParseTree();
971
972 try
973 {
974 AlterTableProcessor processor;
975 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
976
977 SqlStatement& stmt = *ptree.fList[0];
978 AlterTableProcessor::DDLResult result;
979
980 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
981 std::cout << "return: " << result.result << std::endl;
982 }
983 catch (...)
984 {
985 tearDown();
986 throw;
987 }
988 }
989
990 tearDown();
991 }
992
test_altertable_setcolumndefault()993 void test_altertable_setcolumndefault()
994 {
995 cout << "Begining Alter Table set column default test ..." << endl;
996 std::string sqlbuf = "ALTER TABLE tpch.part alter p_partkey set default 3 ;";
997
998 SqlParser parser;
999 parser.Parse(sqlbuf.c_str());
1000
1001 if (parser.Good())
1002 {
1003 const ParseTree& ptree = parser.GetParseTree();
1004
1005 try
1006 {
1007 AlterTableProcessor processor;
1008 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
1009
1010 SqlStatement& stmt = *ptree.fList[0];
1011 AlterTableProcessor::DDLResult result;
1012
1013 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
1014 std::cout << "return: " << result.result << std::endl;
1015 }
1016 catch (...)
1017 {
1018 tearDown();
1019 throw;
1020 }
1021 }
1022
1023 tearDown();
1024 }
test_altertable_dropcolumndefault()1025 void test_altertable_dropcolumndefault()
1026 {
1027 cout << "Begining Alter Table drop column default test ..." << endl;
1028 std::string sqlbuf = "ALTER TABLE tpch.part ALTER COLUMN p_type DROP DEFAULT; ;";
1029
1030 SqlParser parser;
1031 parser.Parse(sqlbuf.c_str());
1032
1033 if (parser.Good())
1034 {
1035 const ParseTree& ptree = parser.GetParseTree();
1036
1037 try
1038 {
1039 AlterTableProcessor processor;
1040 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
1041
1042 SqlStatement& stmt = *ptree.fList[0];
1043 AlterTableProcessor::DDLResult result;
1044
1045 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
1046 std::cout << "return: " << result.result << std::endl;
1047 }
1048 catch (...)
1049 {
1050 tearDown();
1051 throw;
1052 }
1053 }
1054
1055 tearDown();
1056 }
1057
test_altertable_renametable()1058 void test_altertable_renametable()
1059 {
1060 cout << "Begining Alter Table rename a table test ..." << endl;
1061 std::string sqlbuf = "ALTER TABLE tpch.region rename to tpch.ready ;";
1062
1063 SqlParser parser;
1064 parser.Parse(sqlbuf.c_str());
1065
1066 if (parser.Good())
1067 {
1068 const ParseTree& ptree = parser.GetParseTree();
1069
1070 try
1071 {
1072 AlterTableProcessor processor;
1073 processor.setDebugLevel(AlterTableProcessor::VERBOSE);
1074
1075 SqlStatement& stmt = *ptree.fList[0];
1076 AlterTableProcessor::DDLResult result;
1077
1078 result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
1079 std::cout << "return: " << result.result << std::endl;
1080 }
1081 catch (...)
1082 {
1083 tearDown();
1084 throw;
1085 }
1086 }
1087
1088 tearDown();
1089 }
1090
test_droptable()1091 void test_droptable()
1092 {
1093 cout << "Begining drop table test ..." << endl;
1094 std::string sqlbuf = "drop table tpch.part";
1095
1096 SqlParser parser;
1097 parser.Parse(sqlbuf.c_str());
1098
1099 if (parser.Good())
1100 {
1101 const ParseTree& ptree = parser.GetParseTree();
1102
1103 try
1104 {
1105 DropTableProcessor processor;
1106 processor.setDebugLevel(DropTableProcessor::VERBOSE);
1107
1108 SqlStatement& stmt = *ptree.fList[0];
1109 DropTableProcessor::DDLResult result;
1110
1111 result = processor.processPackage(dynamic_cast<DropTableStatement&>(stmt));
1112 std::cout << "return: " << result.result << std::endl;
1113 }
1114 catch (...)
1115 {
1116 tearDown();
1117 throw;
1118 }
1119 }
1120
1121 tearDown();
1122 }
1123
1124 };
1125
1126 CPPUNIT_TEST_SUITE_REGISTRATION( DDLPackageProcessorTest );
1127
1128 #include <cppunit/extensions/TestFactoryRegistry.h>
1129 #include <cppunit/ui/text/TestRunner.h>
1130
main(int argc,char ** argv)1131 int main( int argc, char** argv)
1132 {
1133 // Uncomment before running tests
1134 //setUp();
1135 CppUnit::TextUi::TestRunner runner;
1136 CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
1137 runner.addTest( registry.makeTest() );
1138 bool wasSuccessful = runner.run( "", false );
1139 return (wasSuccessful ? 0 : 1);
1140 }
1141