@@ -278,5 +278,141 @@ TEST_F(UpdateSQLTests, UpdateSQLCastTest) {
278
278
txn_manager.CommitTransaction (txn);
279
279
}
280
280
281
+ TEST_F (UpdateSQLTests, HalloweenTest) {
282
+ LOG_DEBUG (" Bootstrapping..." );
283
+
284
+ auto catalog = catalog::Catalog::GetInstance ();
285
+ auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
286
+ auto txn = txn_manager.BeginTransaction ();
287
+ catalog->CreateDatabase (DEFAULT_DB_NAME, txn);
288
+ txn_manager.CommitTransaction (txn);
289
+
290
+ LOG_DEBUG (" Bootstrapping completed!" );
291
+
292
+ size_t active_tilegroup_count = 3 ;
293
+ storage::DataTable::SetActiveTileGroupCount (active_tilegroup_count);
294
+
295
+ LOG_DEBUG (" Active tile group count = %zu" ,
296
+ storage::DataTable::GetActiveTileGroupCount ());
297
+ // Create a table first
298
+ LOG_DEBUG (" Creating a table..." );
299
+ LOG_DEBUG (" Query: CREATE TABLE test(a INT, b INT)" );
300
+
301
+ TestingSQLUtil::ExecuteSQLQuery (" CREATE TABLE test(a INT, b INT);" );
302
+
303
+ LOG_DEBUG (" Table created!" );
304
+
305
+ txn = txn_manager.BeginTransaction ();
306
+ // Insert a tuple into table
307
+ LOG_DEBUG (" Inserting a tuple..." );
308
+
309
+ LOG_DEBUG (" Query: INSERT INTO test VALUES (10, 100)" );
310
+ TestingSQLUtil::ExecuteSQLQuery (" INSERT INTO test VALUES (10, 1000);" );
311
+ LOG_DEBUG (" Tuple inserted!" );
312
+
313
+ txn_manager.CommitTransaction (txn);
314
+
315
+ // Update a tuple into table
316
+ LOG_DEBUG (" Updating a tuple..." );
317
+ LOG_DEBUG (" Query: UPDATE test SET a = a/2" );
318
+
319
+ std::vector<ResultValue> result;
320
+ std::vector<FieldInfo> tuple_descriptor;
321
+ std::string error_message;
322
+ int rows_affected;
323
+
324
+ txn = txn_manager.BeginTransaction ();
325
+ TestingSQLUtil::ExecuteSQLQuery (" UPDATE test SET a = a/2;" , result,
326
+ tuple_descriptor, rows_affected,
327
+ error_message);
328
+
329
+ // Check the return value
330
+ EXPECT_EQ (1 , rows_affected);
331
+ LOG_DEBUG (" Tuple Updated!" );
332
+ txn_manager.CommitTransaction (txn);
333
+
334
+ LOG_DEBUG (" Selecting updated value." );
335
+ txn = txn_manager.BeginTransaction ();
336
+ // Check value of column salary after updating
337
+ TestingSQLUtil::ExecuteSQLQuery (" SELECT a from test" , result,
338
+ tuple_descriptor, rows_affected,
339
+ error_message);
340
+ // Check the return value
341
+ txn_manager.CommitTransaction (txn);
342
+
343
+ EXPECT_EQ (TestingSQLUtil::GetResultValueAsString (result, 0 ), " 5" );
344
+ LOG_DEBUG (" Successfully updated tuple." );
345
+
346
+ // free the database just created
347
+ txn = txn_manager.BeginTransaction ();
348
+ catalog::Catalog::GetInstance ()->DropDatabaseWithName (DEFAULT_DB_NAME, txn);
349
+ txn_manager.CommitTransaction (txn);
350
+ }
351
+
352
+ TEST_F (UpdateSQLTests, MultiTileGroupUpdateSQLTest) {
353
+ LOG_DEBUG (" Bootstrapping..." );
354
+
355
+ auto catalog = catalog::Catalog::GetInstance ();
356
+ auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
357
+ auto txn = txn_manager.BeginTransaction ();
358
+ catalog->CreateDatabase (DEFAULT_DB_NAME, txn);
359
+ txn_manager.CommitTransaction (txn);
360
+
361
+ LOG_DEBUG (" Bootstrapping completed!" );
362
+
363
+ size_t active_tilegroup_count = 3 ;
364
+ storage::DataTable::SetActiveTileGroupCount (active_tilegroup_count);
365
+
366
+ LOG_DEBUG (" Active tile group count = %zu" ,
367
+ storage::DataTable::GetActiveTileGroupCount ());
368
+ // Create a table first
369
+ LOG_DEBUG (" Creating a table..." );
370
+ LOG_DEBUG (" Query: CREATE TABLE test(a INT PRIMARY KEY, b INT)" );
371
+
372
+ TestingSQLUtil::ExecuteSQLQuery (
373
+ " CREATE TABLE test(a INT PRIMARY KEY, b INT);" );
374
+
375
+ LOG_DEBUG (" Table created!" );
376
+
377
+ // Insert a tuple into table
378
+ LOG_DEBUG (" Inserting a tuple..." );
379
+
380
+ LOG_DEBUG (" Query: INSERT INTO test VALUES (1, 100)" );
381
+ TestingSQLUtil::ExecuteSQLQuery (" INSERT INTO test VALUES (1, 100);" );
382
+
383
+ LOG_DEBUG (" Tuple inserted!" );
384
+
385
+ // Update a tuple into table
386
+ LOG_DEBUG (" Updating a tuple..." );
387
+ LOG_DEBUG (" Query: UPDATE test SET a = 10 WHERE b = 100" );
388
+
389
+ std::vector<ResultValue> result;
390
+ std::vector<FieldInfo> tuple_descriptor;
391
+ std::string error_message;
392
+ int rows_affected;
393
+
394
+ TestingSQLUtil::ExecuteSQLQuery (" UPDATE test SET a = 10 WHERE b = 100;" ,
395
+ result, tuple_descriptor, rows_affected,
396
+ error_message);
397
+
398
+ LOG_DEBUG (" Query: UPDATE test SET a = 1 WHERE b = 100" );
399
+ // Check the return value
400
+ EXPECT_EQ (1 , rows_affected);
401
+ LOG_DEBUG (" Tuple Updated!" );
402
+
403
+ TestingSQLUtil::ExecuteSQLQuery (" UPDATE test SET a = 1 WHERE b = 100;" ,
404
+ result, tuple_descriptor, rows_affected,
405
+ error_message);
406
+
407
+ // Check the return value
408
+ EXPECT_EQ (1 , rows_affected);
409
+ LOG_DEBUG (" Tuple Updated!" );
410
+
411
+ // free the database just created
412
+ txn = txn_manager.BeginTransaction ();
413
+ catalog::Catalog::GetInstance ()->DropDatabaseWithName (DEFAULT_DB_NAME, txn);
414
+ txn_manager.CommitTransaction (txn);
415
+ }
416
+
281
417
} // namespace test
282
418
} // namespace peloton
0 commit comments