@@ -527,5 +527,111 @@ TEST_F(UpdateSQLTests, MultiTileGroupUpdateSQLTest) {
527
527
txn_manager.CommitTransaction (txn);
528
528
}
529
529
530
+ TEST_F (UpdateSQLTests, AttributeOrderUpdateSQLTest) {
531
+ // This test updates the attributes of the table in different orders.
532
+ // It ensure that the updates in the data_table are in the correct
533
+ // order irrespective of the order of attributes in the update statement.
534
+
535
+ LOG_DEBUG (" Bootstrapping..." );
536
+
537
+ auto catalog = catalog::Catalog::GetInstance ();
538
+ auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
539
+ auto txn = txn_manager.BeginTransaction ();
540
+ catalog->CreateDatabase (DEFAULT_DB_NAME, txn);
541
+ txn_manager.CommitTransaction (txn);
542
+
543
+ LOG_DEBUG (" Bootstrapping completed!" );
544
+
545
+ txn = txn_manager.BeginTransaction ();
546
+ // Create a table first
547
+ LOG_DEBUG (" Creating a table..." );
548
+ LOG_DEBUG (" Query: CREATE TABLE test(a INT, b INT)" );
549
+
550
+ TestingSQLUtil::ExecuteSQLQuery (" CREATE TABLE test(a INT, b INT);" );
551
+ txn_manager.CommitTransaction (txn);
552
+
553
+ LOG_DEBUG (" Table created!" );
554
+
555
+ txn = txn_manager.BeginTransaction ();
556
+ // Insert a tuple into table
557
+ LOG_DEBUG (" Inserting a tuple..." );
558
+
559
+ LOG_DEBUG (" Query: INSERT INTO test VALUES (1, 100)" );
560
+ TestingSQLUtil::ExecuteSQLQuery (" INSERT INTO test VALUES (1, 100);" );
561
+
562
+ txn_manager.CommitTransaction (txn);
563
+ LOG_DEBUG (" Tuple inserted!" );
564
+
565
+ txn = txn_manager.BeginTransaction ();
566
+ // Update a tuple in the table in the order (b, a)
567
+ LOG_DEBUG (" Updating a tuple..." );
568
+ LOG_DEBUG (" Query: UPDATE test SET b = b * 2, a = a * 2" );
569
+
570
+ std::vector<ResultValue> result;
571
+ std::vector<FieldInfo> tuple_descriptor;
572
+ std::string error_message;
573
+ int rows_affected;
574
+
575
+ TestingSQLUtil::ExecuteSQLQuery (" UPDATE test SET b = b * 2, a = a * 2;" ,
576
+ result, tuple_descriptor, rows_affected,
577
+ error_message);
578
+
579
+ txn_manager.CommitTransaction (txn);
580
+ // Check the return value
581
+ EXPECT_EQ (1 , rows_affected);
582
+ LOG_DEBUG (" Tuple Update successful!" );
583
+
584
+ // Check the updated values.
585
+ txn = txn_manager.BeginTransaction ();
586
+ // Update a tuple in the table in the order (b, a)
587
+ LOG_DEBUG (" Selecting the updated tuple..." );
588
+ LOG_DEBUG (" Query: SELECT a, b FROM test;" );
589
+
590
+ TestingSQLUtil::ExecuteSQLQuery (" SELECT a, b FROM test;" , result,
591
+ tuple_descriptor, rows_affected,
592
+ error_message);
593
+
594
+ txn_manager.CommitTransaction (txn);
595
+ // Check the return value
596
+ EXPECT_EQ (TestingSQLUtil::GetResultValueAsString (result, 0 ), " 2" );
597
+ EXPECT_EQ (TestingSQLUtil::GetResultValueAsString (result, 1 ), " 200" );
598
+ LOG_DEBUG (" Attributes updated in the correct order!" );
599
+
600
+ txn = txn_manager.BeginTransaction ();
601
+ // Update a tuple in the table in the order (a, b)
602
+ LOG_DEBUG (" Updating a tuple again..." );
603
+ LOG_DEBUG (" Query: UPDATE test SET a = a * 2, b = b * 2" );
604
+
605
+ TestingSQLUtil::ExecuteSQLQuery (" UPDATE test SET a = a * 2, b = b * 2;" ,
606
+ result, tuple_descriptor, rows_affected,
607
+ error_message);
608
+
609
+ txn_manager.CommitTransaction (txn);
610
+ // Check the return value
611
+ EXPECT_EQ (1 , rows_affected);
612
+ LOG_DEBUG (" Tuple Update successful, agin!" );
613
+
614
+ // Check the updated values.
615
+ txn = txn_manager.BeginTransaction ();
616
+ // Update a tuple in the table in the order (b, a)
617
+ LOG_DEBUG (" Selecting the updated tuple..." );
618
+ LOG_DEBUG (" Query: SELECT a, b FROM test;" );
619
+
620
+ TestingSQLUtil::ExecuteSQLQuery (" SELECT a, b FROM test;" , result,
621
+ tuple_descriptor, rows_affected,
622
+ error_message);
623
+
624
+ txn_manager.CommitTransaction (txn);
625
+ // Check the return value
626
+ EXPECT_EQ (TestingSQLUtil::GetResultValueAsString (result, 0 ), " 4" );
627
+ EXPECT_EQ (TestingSQLUtil::GetResultValueAsString (result, 1 ), " 400" );
628
+ LOG_DEBUG (" Attributes updated in the correct order, again!" );
629
+
630
+ // free the database just created
631
+ txn = txn_manager.BeginTransaction ();
632
+ catalog::Catalog::GetInstance ()->DropDatabaseWithName (DEFAULT_DB_NAME, txn);
633
+ txn_manager.CommitTransaction (txn);
634
+ }
635
+
530
636
} // namespace test
531
637
} // namespace peloton
0 commit comments