@@ -63,10 +63,12 @@ void CreateAndLoadTable4() {
63
63
" i CHAR, j VARCHAR, k VARBINARY, l BOOLEAN);" );
64
64
65
65
// Insert tuples into table
66
- TestingSQLUtil::ExecuteSQLQuery (" INSERT INTO test4 VALUES "
66
+ TestingSQLUtil::ExecuteSQLQuery (
67
+ " INSERT INTO test4 VALUES "
67
68
" (1, 2, 3, 4, 5.1, 6.1, '2017-10-10 00:00:00-00', "
68
69
" 'A', 'a', '1', 'true');" );
69
- TestingSQLUtil::ExecuteSQLQuery (" INSERT INTO test4 VALUES "
70
+ TestingSQLUtil::ExecuteSQLQuery (
71
+ " INSERT INTO test4 VALUES "
70
72
" (11, 12, 13, 14, 15.1, 16.1, '2017-10-11 00:00:00-00', "
71
73
" 'B', 'b', '2', 'false');" );
72
74
}
@@ -81,8 +83,7 @@ void CreateAndLoadTable5() {
81
83
82
84
void CreateAndLoadTable6 () {
83
85
// Create a table first
84
- TestingSQLUtil::ExecuteSQLQuery (
85
- " CREATE TABLE test6(a INT, b INT, c INT);" );
86
+ TestingSQLUtil::ExecuteSQLQuery (" CREATE TABLE test6(a INT, b INT, c INT);" );
86
87
87
88
// Insert tuples into table
88
89
TestingSQLUtil::ExecuteSQLQuery (" INSERT INTO test6 VALUES (1, 22, 333);" );
@@ -93,8 +94,7 @@ void CreateAndLoadTable6() {
93
94
94
95
void CreateAndLoadTable7 () {
95
96
// Create a table first
96
- TestingSQLUtil::ExecuteSQLQuery (
97
- " CREATE TABLE test7(a INT, b INT, c INT);" );
97
+ TestingSQLUtil::ExecuteSQLQuery (" CREATE TABLE test7(a INT, b INT, c INT);" );
98
98
99
99
// Insert tuples into table
100
100
TestingSQLUtil::ExecuteSQLQuery (" INSERT INTO test7 VALUES (99, 5, 888);" );
@@ -103,7 +103,6 @@ void CreateAndLoadTable7() {
103
103
TestingSQLUtil::ExecuteSQLQuery (" INSERT INTO test7 VALUES (55, 8, 999);" );
104
104
}
105
105
106
-
107
106
TEST_F (InsertSQLTests, InsertOneValue) {
108
107
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
109
108
auto txn = txn_manager.BeginTransaction ();
@@ -258,12 +257,12 @@ TEST_F(InsertSQLTests, InsertTooLargeVarchar) {
258
257
new optimizer::Optimizer ());
259
258
260
259
std::string query (" INSERT INTO test3 VALUES(1, 'abcd', 'abcdefghij');" );
261
- // std::string query("INSERT INTO test3 VALUES(1, 'abcd', 'abcdefghijk');");
260
+ // std::string query("INSERT INTO test3 VALUES(1, 'abcd', 'abcdefghijk');");
262
261
263
262
txn = txn_manager.BeginTransaction ();
264
- // This should be re-enabled when the check is properly done in catalog
263
+ // This should be re-enabled when the check is properly done in catalog
265
264
// It used to be done at the insert query level
266
- // EXPECT_THROW(TestingSQLUtil::GeneratePlanWithOptimizer(optimizer, query,
265
+ // EXPECT_THROW(TestingSQLUtil::GeneratePlanWithOptimizer(optimizer, query,
267
266
// txn, peloton::Exception);
268
267
auto plan = TestingSQLUtil::GeneratePlanWithOptimizer (optimizer, query, txn);
269
268
EXPECT_EQ (plan->GetPlanNodeType (), PlanNodeType::INSERT);
@@ -402,7 +401,7 @@ TEST_F(InsertSQLTests, InsertIntoSelectSimpleAllType) {
402
401
EXPECT_EQ (" 5.1" , TestingSQLUtil::GetResultValueAsString (result, 4 ));
403
402
EXPECT_EQ (" 6.1" , TestingSQLUtil::GetResultValueAsString (result, 5 ));
404
403
EXPECT_EQ (" 2017-10-10 00:00:00.000000+00" ,
405
- TestingSQLUtil::GetResultValueAsString (result, 6 ));
404
+ TestingSQLUtil::GetResultValueAsString (result, 6 ));
406
405
EXPECT_EQ (" A" , TestingSQLUtil::GetResultValueAsString (result, 7 ));
407
406
EXPECT_EQ (" a" , TestingSQLUtil::GetResultValueAsString (result, 8 ));
408
407
EXPECT_EQ (' 1' , TestingSQLUtil::GetResultValueAsString (result, 9 ).at (0 ));
@@ -419,7 +418,7 @@ TEST_F(InsertSQLTests, InsertIntoSelectSimpleAllType) {
419
418
EXPECT_EQ (" 5.1" , TestingSQLUtil::GetResultValueAsString (result, 4 ));
420
419
EXPECT_EQ (" 6.1" , TestingSQLUtil::GetResultValueAsString (result, 5 ));
421
420
EXPECT_EQ (" 2017-10-10 00:00:00.000000+00" ,
422
- TestingSQLUtil::GetResultValueAsString (result, 6 ));
421
+ TestingSQLUtil::GetResultValueAsString (result, 6 ));
423
422
EXPECT_EQ (" A" , TestingSQLUtil::GetResultValueAsString (result, 7 ));
424
423
EXPECT_EQ (" a" , TestingSQLUtil::GetResultValueAsString (result, 8 ));
425
424
EXPECT_EQ (' 1' , TestingSQLUtil::GetResultValueAsString (result, 9 ).at (0 ));
@@ -436,7 +435,7 @@ TEST_F(InsertSQLTests, InsertIntoSelectSimpleAllType) {
436
435
EXPECT_EQ (" 15.1" , TestingSQLUtil::GetResultValueAsString (result, 4 ));
437
436
EXPECT_EQ (" 16.1" , TestingSQLUtil::GetResultValueAsString (result, 5 ));
438
437
EXPECT_EQ (" 2017-10-11 00:00:00.000000+00" ,
439
- TestingSQLUtil::GetResultValueAsString (result, 6 ));
438
+ TestingSQLUtil::GetResultValueAsString (result, 6 ));
440
439
EXPECT_EQ (" B" , TestingSQLUtil::GetResultValueAsString (result, 7 ));
441
440
EXPECT_EQ (" b" , TestingSQLUtil::GetResultValueAsString (result, 8 ));
442
441
EXPECT_EQ (' 2' , TestingSQLUtil::GetResultValueAsString (result, 9 ).at (0 ));
@@ -529,8 +528,9 @@ TEST_F(InsertSQLTests, UniqueColumn) {
529
528
catalog::Catalog::GetInstance ()->CreateDatabase (DEFAULT_DB_NAME, txn);
530
529
txn_manager.CommitTransaction (txn);
531
530
532
- std::string create_table (" CREATE TABLE t (id INTEGER NOT NULL PRIMARY KEY,"
533
- " st VARCHAR(15) NOT NULL UNIQUE);" );
531
+ std::string create_table (
532
+ " CREATE TABLE t (id INTEGER NOT NULL PRIMARY KEY,"
533
+ " st VARCHAR(15) NOT NULL UNIQUE);" );
534
534
TestingSQLUtil::ExecuteSQLQuery (create_table);
535
535
536
536
ResultType result;
@@ -542,26 +542,23 @@ TEST_F(InsertSQLTests, UniqueColumn) {
542
542
result = TestingSQLUtil::ExecuteSQLQuery (ins_query_1);
543
543
EXPECT_EQ (result, ResultType::SUCCESS);
544
544
ref_result.push_back (" abc" );
545
- TestingSQLUtil::ExecuteSQLQueryAndCheckResult (result_query,
546
- ref_result,
545
+ TestingSQLUtil::ExecuteSQLQueryAndCheckResult (result_query, ref_result,
547
546
false );
548
547
549
548
// Second row, distinct from first, should succeed
550
549
std::string ins_query_2 (" INSERT INTO t VALUES (2, 'def');" );
551
550
result = TestingSQLUtil::ExecuteSQLQuery (ins_query_2);
552
551
EXPECT_EQ (result, ResultType::SUCCESS);
553
552
ref_result.push_back (" def" );
554
- TestingSQLUtil::ExecuteSQLQueryAndCheckResult (result_query,
555
- ref_result,
553
+ TestingSQLUtil::ExecuteSQLQueryAndCheckResult (result_query, ref_result,
556
554
false );
557
555
558
556
// Third row, non-unique value for string, should fail
559
557
std::string ins_query_3 (" INSERT INTO t VALUES (3, 'abc');" );
560
558
result = TestingSQLUtil::ExecuteSQLQuery (ins_query_3);
561
559
EXPECT_EQ (result, ResultType::ABORTED);
562
560
// and the results returned should not include failed insert
563
- TestingSQLUtil::ExecuteSQLQueryAndCheckResult (result_query,
564
- ref_result,
561
+ TestingSQLUtil::ExecuteSQLQueryAndCheckResult (result_query, ref_result,
565
562
false );
566
563
567
564
// free the database just created
@@ -570,33 +567,33 @@ TEST_F(InsertSQLTests, UniqueColumn) {
570
567
txn_manager.CommitTransaction (txn);
571
568
}
572
569
573
- TEST_F (InsertSQLTests, NonExistentTable){
574
- auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
575
- auto txn = txn_manager.BeginTransaction ();
576
- catalog::Catalog::GetInstance ()->CreateDatabase (DEFAULT_DB_NAME, txn);
577
- txn_manager.CommitTransaction (txn);
578
- std::string error_message;
579
- int rows_changed;
580
- std::unique_ptr<optimizer::AbstractOptimizer> optimizer (
581
- new optimizer::Optimizer ());
582
-
583
- rows_changed = 0 ;
584
- EXPECT_THROW ({
585
- try {
586
- // Insert an int into a non-existent table.
587
- std::string query (" INSERT INTO NotExistTestTable VALUES(3);" );
588
- txn = txn_manager.BeginTransaction ();
589
- auto plan = TestingSQLUtil::GeneratePlanWithOptimizer (optimizer, query, txn);
590
- EXPECT_EQ (plan-> GetPlanNodeType (), PlanNodeType::INSERT );
591
- txn_manager. CommitTransaction (txn );
592
- } catch (peloton::Exception &ex) {
593
- EXPECT_EQ (ExceptionType::CATALOG, ex. GetType ());
594
- EXPECT_STREQ ( " Table NotExistTestTable is not found " ,
595
- ex.what ());
596
- throw peloton::CatalogException (ex.what ());
597
- }
598
- }, peloton::CatalogException);
599
- EXPECT_EQ (0 , rows_changed);
570
+ TEST_F (InsertSQLTests, NonExistentTable) {
571
+ auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
572
+ auto txn = txn_manager.BeginTransaction ();
573
+ catalog::Catalog::GetInstance ()->CreateDatabase (DEFAULT_DB_NAME, txn);
574
+ txn_manager.CommitTransaction (txn);
575
+ std::string error_message;
576
+ int rows_changed;
577
+ std::unique_ptr<optimizer::AbstractOptimizer> optimizer (
578
+ new optimizer::Optimizer ());
579
+
580
+ rows_changed = 0 ;
581
+ EXPECT_THROW ({
582
+ try {
583
+ // Insert an int into a non-existent table.
584
+ std::string query (" INSERT INTO NotExistTestTable VALUES(3);" );
585
+ txn = txn_manager.BeginTransaction ();
586
+ auto plan =
587
+ TestingSQLUtil::GeneratePlanWithOptimizer (optimizer, query, txn );
588
+ EXPECT_EQ (plan-> GetPlanNodeType (), PlanNodeType::INSERT );
589
+ txn_manager. CommitTransaction (txn);
590
+ } catch (peloton::Exception &ex) {
591
+ EXPECT_EQ (ExceptionType::CATALOG, ex. GetType ());
592
+ EXPECT_STREQ ( " Table NotExistTestTable is not found " , ex.what ());
593
+ throw peloton::CatalogException (ex.what ());
594
+ }
595
+ }, peloton::CatalogException);
596
+ EXPECT_EQ (0 , rows_changed);
600
597
}
601
598
602
599
} // namespace test
0 commit comments