@@ -524,6 +524,168 @@ Y_UNIT_TEST_SUITE(KqpEffects) {
524
524
UNIT_ASSERT_VALUES_EQUAL (reads[0 ][" type" ], " Scan" );
525
525
UNIT_ASSERT_VALUES_EQUAL (reads[0 ][" columns" ].GetArraySafe ().size (), 3 );
526
526
}
527
+
528
+ Y_UNIT_TEST_TWIN (AlterDuringUpsertTransaction, UseSink) {
529
+ NKikimrConfig::TAppConfig appConfig;
530
+ appConfig.MutableTableServiceConfig ()->SetEnableOltpSink (UseSink);
531
+ auto kikimr = DefaultKikimrRunner ({}, appConfig);
532
+ auto db = kikimr.GetTableClient ();
533
+ auto session1 = db.CreateSession ().GetValueSync ().GetSession ();
534
+ auto session2 = db.CreateSession ().GetValueSync ().GetSession ();
535
+
536
+ auto ret = session1.ExecuteSchemeQuery (R"(
537
+ CREATE TABLE `TestTable` (
538
+ Key Uint32,
539
+ Value1 String,
540
+ PRIMARY KEY (Key)
541
+ )
542
+ )" ).ExtractValueSync ();
543
+ UNIT_ASSERT_C (ret.IsSuccess (), ret.GetIssues ().ToString ());
544
+
545
+ auto txControl = TTxControl::BeginTx ();
546
+ auto upsertResult = session1.ExecuteDataQuery (R"(
547
+ UPSERT INTO `TestTable` (Key, Value1) VALUES
548
+ (1u, "First"),
549
+ (2u, "Second")
550
+ )" , txControl).ExtractValueSync ();
551
+ UNIT_ASSERT_C (upsertResult.IsSuccess (), upsertResult.GetIssues ().ToString ());
552
+ auto tx1 = upsertResult.GetTransaction ();
553
+ UNIT_ASSERT (tx1);
554
+
555
+ auto alterResult = session2.ExecuteSchemeQuery (R"(
556
+ ALTER TABLE `TestTable` ADD COLUMN Value2 Int32
557
+ )" ).ExtractValueSync ();
558
+ UNIT_ASSERT_C (alterResult.IsSuccess (), alterResult.GetIssues ().ToString ());
559
+
560
+ auto commitResult = tx1->Commit ().GetValueSync ();
561
+ UNIT_ASSERT_VALUES_EQUAL_C (commitResult.GetStatus (), EStatus::ABORTED, commitResult.GetIssues ().ToString ());
562
+ UNIT_ASSERT_C (commitResult.GetIssues ().ToString ().contains (" Scheme changed. Table: `/Root/TestTable`." )
563
+ || commitResult.GetIssues ().ToString ().contains (" Table '/Root/TestTable' scheme changed." ),
564
+ commitResult.GetIssues ().ToString ());
565
+ }
566
+
567
+ Y_UNIT_TEST_TWIN (AlterAfterUpsertTransaction, UseSink) {
568
+ NKikimrConfig::TAppConfig appConfig;
569
+ appConfig.MutableTableServiceConfig ()->SetEnableOltpSink (UseSink);
570
+ auto kikimr = DefaultKikimrRunner ({}, appConfig);
571
+ auto db = kikimr.GetTableClient ();
572
+ auto session1 = db.CreateSession ().GetValueSync ().GetSession ();
573
+ auto session2 = db.CreateSession ().GetValueSync ().GetSession ();
574
+
575
+ auto ret = session1.ExecuteSchemeQuery (R"(
576
+ CREATE TABLE `TestTable` (
577
+ Key Uint32,
578
+ Value1 String,
579
+ PRIMARY KEY (Key)
580
+ )
581
+ )" ).ExtractValueSync ();
582
+ UNIT_ASSERT_C (ret.IsSuccess (), ret.GetIssues ().ToString ());
583
+
584
+ auto txControl = TTxControl::BeginTx ();
585
+ auto upsertResult = session1.ExecuteDataQuery (R"(
586
+ UPSERT INTO `TestTable` (Key, Value1) VALUES
587
+ (1u, "First"),
588
+ (2u, "Second");
589
+ SELECT * FROM `TestTable`;
590
+ )" , txControl).ExtractValueSync ();
591
+ UNIT_ASSERT_C (upsertResult.IsSuccess (), upsertResult.GetIssues ().ToString ());
592
+ auto tx1 = upsertResult.GetTransaction ();
593
+ UNIT_ASSERT (tx1);
594
+
595
+ auto alterResult = session2.ExecuteSchemeQuery (R"(
596
+ ALTER TABLE `TestTable` ADD COLUMN Value2 Int32
597
+ )" ).ExtractValueSync ();
598
+ UNIT_ASSERT_C (alterResult.IsSuccess (), alterResult.GetIssues ().ToString ());
599
+
600
+ auto commitResult = tx1->Commit ().GetValueSync ();
601
+ UNIT_ASSERT_VALUES_EQUAL_C (commitResult.GetStatus (), EStatus::ABORTED, commitResult.GetIssues ().ToString ());
602
+ }
603
+
604
+ Y_UNIT_TEST_TWIN (AlterAfterUpsertBeforeUpsertTransaction, UseSink) {
605
+ NKikimrConfig::TAppConfig appConfig;
606
+ appConfig.MutableTableServiceConfig ()->SetEnableOltpSink (UseSink);
607
+ auto kikimr = DefaultKikimrRunner ({}, appConfig);
608
+ auto db = kikimr.GetTableClient ();
609
+ auto session1 = db.CreateSession ().GetValueSync ().GetSession ();
610
+ auto session2 = db.CreateSession ().GetValueSync ().GetSession ();
611
+
612
+ auto ret = session1.ExecuteSchemeQuery (R"(
613
+ CREATE TABLE `TestTable` (
614
+ Key Uint32,
615
+ Value1 String,
616
+ PRIMARY KEY (Key)
617
+ )
618
+ )" ).ExtractValueSync ();
619
+ UNIT_ASSERT_C (ret.IsSuccess (), ret.GetIssues ().ToString ());
620
+
621
+ auto txControl = TTxControl::BeginTx ();
622
+ auto upsertResult = session1.ExecuteDataQuery (R"(
623
+ UPSERT INTO `TestTable` (Key, Value1) VALUES
624
+ (1u, "First"),
625
+ (2u, "Second");
626
+ SELECT * FROM `TestTable` WHERE Key = 1u;
627
+ )" , txControl).ExtractValueSync ();
628
+ UNIT_ASSERT_C (upsertResult.IsSuccess (), upsertResult.GetIssues ().ToString ());
629
+ auto tx1 = upsertResult.GetTransaction ();
630
+ UNIT_ASSERT (tx1);
631
+
632
+ auto alterResult = session2.ExecuteSchemeQuery (R"(
633
+ ALTER TABLE `TestTable` ADD COLUMN Value2 Int32
634
+ )" ).ExtractValueSync ();
635
+ UNIT_ASSERT_C (alterResult.IsSuccess (), alterResult.GetIssues ().ToString ());
636
+
637
+ auto upsertResult2 = session1.ExecuteDataQuery (R"(
638
+ UPSERT INTO `TestTable` (Key, Value1) VALUES
639
+ (1u, "First"),
640
+ (2u, "Second");
641
+ )" , TTxControl::Tx (*tx1)).ExtractValueSync ();
642
+ UNIT_ASSERT_C (upsertResult2.IsSuccess (), upsertResult2.GetIssues ().ToString ());
643
+
644
+ auto commitResult = tx1->Commit ().GetValueSync ();
645
+ UNIT_ASSERT_VALUES_EQUAL_C (commitResult.GetStatus (), EStatus::ABORTED, commitResult.GetIssues ().ToString ());
646
+ }
647
+
648
+ Y_UNIT_TEST_TWIN (AlterAfterUpsertBeforeUpsertSelectTransaction, UseSink) {
649
+ NKikimrConfig::TAppConfig appConfig;
650
+ appConfig.MutableTableServiceConfig ()->SetEnableOltpSink (UseSink);
651
+ auto kikimr = DefaultKikimrRunner ({}, appConfig);
652
+ auto db = kikimr.GetTableClient ();
653
+ auto session1 = db.CreateSession ().GetValueSync ().GetSession ();
654
+ auto session2 = db.CreateSession ().GetValueSync ().GetSession ();
655
+
656
+ auto ret = session1.ExecuteSchemeQuery (R"(
657
+ CREATE TABLE `TestTable` (
658
+ Key Uint32,
659
+ Value1 String,
660
+ PRIMARY KEY (Key)
661
+ )
662
+ )" ).ExtractValueSync ();
663
+ UNIT_ASSERT_C (ret.IsSuccess (), ret.GetIssues ().ToString ());
664
+
665
+ auto txControl = TTxControl::BeginTx ();
666
+ auto upsertResult = session1.ExecuteDataQuery (R"(
667
+ UPSERT INTO `TestTable` (Key, Value1) VALUES
668
+ (1u, "First"),
669
+ (2u, "Second");
670
+ SELECT * FROM `TestTable` WHERE Key = 1u;
671
+ )" , txControl).ExtractValueSync ();
672
+ UNIT_ASSERT_C (upsertResult.IsSuccess (), upsertResult.GetIssues ().ToString ());
673
+ auto tx1 = upsertResult.GetTransaction ();
674
+ UNIT_ASSERT (tx1);
675
+
676
+ auto alterResult = session2.ExecuteSchemeQuery (R"(
677
+ ALTER TABLE `TestTable` ADD COLUMN Value2 Int32
678
+ )" ).ExtractValueSync ();
679
+ UNIT_ASSERT_C (alterResult.IsSuccess (), alterResult.GetIssues ().ToString ());
680
+
681
+ auto upsertResult2 = session1.ExecuteDataQuery (R"(
682
+ UPSERT INTO `TestTable` (Key, Value1) VALUES
683
+ (1u, "First"),
684
+ (2u, "Second");
685
+ SELECT * FROM `TestTable` WHERE Key = 1u;
686
+ )" , TTxControl::Tx (*tx1)).ExtractValueSync ();
687
+ UNIT_ASSERT_VALUES_EQUAL_C (upsertResult2.GetStatus (), EStatus::ABORTED, upsertResult2.GetIssues ().ToString ());
688
+ }
527
689
}
528
690
529
691
} // namespace NKqp
0 commit comments