|
9 | 9 | #include <ydb/core/tx/schemeshard/schemeshard_private.h>
|
10 | 10 | #include <ydb/core/tx/schemeshard/schemeshard_billing_helpers.h>
|
11 | 11 | #include <ydb/core/tx/datashard/datashard.h>
|
12 |
| -#include <ydb/core/tx/datashard/datashard_ut_common_kqp.h> |
13 | 12 | #include <ydb/core/wrappers/ut_helpers/s3_mock.h>
|
14 | 13 | #include <ydb/core/metering/metering.h>
|
15 | 14 | #include <ydb/core/ydb_convert/table_description.h>
|
@@ -374,6 +373,39 @@ Y_UNIT_TEST_SUITE(TRestoreTests) {
|
374 | 373 | NKqp::CompareYson(data.YsonStr, content);
|
375 | 374 | }
|
376 | 375 |
|
| 376 | + bool CheckDefaultFromLiteral(const NKikimrSchemeOp::TTableDescription& desc) { |
| 377 | + for (const auto& column: desc.GetColumns()) { |
| 378 | + if (column.GetName() == "value") { |
| 379 | + switch (column.GetDefaultValueCase()) { |
| 380 | + case NKikimrSchemeOp::TColumnDescription::kDefaultFromLiteral: { |
| 381 | + const auto& fromLiteral = column.GetDefaultFromLiteral(); |
| 382 | + |
| 383 | + TString str; |
| 384 | + google::protobuf::TextFormat::PrintToString(fromLiteral, &str); |
| 385 | + |
| 386 | + TString result = R"(type { |
| 387 | + optional_type { |
| 388 | + item { |
| 389 | + type_id: UTF8 |
| 390 | + } |
| 391 | + } |
| 392 | +} |
| 393 | +value { |
| 394 | + items { |
| 395 | + text_value: "value1" |
| 396 | + } |
| 397 | +} |
| 398 | +)"; |
| 399 | + return str == result; |
| 400 | + } |
| 401 | + default: break; |
| 402 | + } |
| 403 | + break; |
| 404 | + } |
| 405 | + } |
| 406 | + return false; |
| 407 | + } |
| 408 | + |
377 | 409 | Y_UNIT_TEST_WITH_COMPRESSION(ShouldSucceedWithDefaultFromLiteral) {
|
378 | 410 | TTestBasicRuntime runtime;
|
379 | 411 |
|
@@ -411,36 +443,7 @@ Y_UNIT_TEST_SUITE(TRestoreTests) {
|
411 | 443 |
|
412 | 444 | const auto& table = desc.GetPathDescription().GetTable();
|
413 | 445 |
|
414 |
| - for (const auto& column: table.GetColumns()) { |
415 |
| - if (column.GetName() == "value") { |
416 |
| - switch (column.GetDefaultValueCase()) { |
417 |
| - case NKikimrSchemeOp::TColumnDescription::kDefaultFromLiteral: { |
418 |
| - const auto& fromLiteral = column.GetDefaultFromLiteral(); |
419 |
| - |
420 |
| - TString str; |
421 |
| - google::protobuf::TextFormat::PrintToString(fromLiteral, &str); |
422 |
| - |
423 |
| - TString result = R"(type { |
424 |
| - optional_type { |
425 |
| - item { |
426 |
| - type_id: UTF8 |
427 |
| - } |
428 |
| - } |
429 |
| -} |
430 |
| -value { |
431 |
| - items { |
432 |
| - text_value: "value1" |
433 |
| - } |
434 |
| -} |
435 |
| -)"; |
436 |
| - UNIT_ASSERT_VALUES_EQUAL_C(str, result, "Invalid default value"); |
437 |
| - return; |
438 |
| - } |
439 |
| - default: break; |
440 |
| - } |
441 |
| - } |
442 |
| - } |
443 |
| - UNIT_ASSERT_C(false, "Invalid default value"); |
| 446 | + UNIT_ASSERT_C(CheckDefaultFromLiteral(table), "Invalid default value"); |
444 | 447 | }
|
445 | 448 |
|
446 | 449 | Y_UNIT_TEST_WITH_COMPRESSION(ShouldSucceedOnMultiShardTable) {
|
@@ -799,6 +802,81 @@ value {
|
799 | 802 | TestGetImport(runtime, txId, "/MyRoot");
|
800 | 803 | }
|
801 | 804 |
|
| 805 | + Y_UNIT_TEST(ShouldRestoreDefaultValuesFromLiteral) { |
| 806 | + TPortManager portManager; |
| 807 | + const ui16 port = portManager.GetPort(); |
| 808 | + |
| 809 | + TS3Mock s3Mock({}, TS3Mock::TSettings(port)); |
| 810 | + UNIT_ASSERT(s3Mock.Start()); |
| 811 | + |
| 812 | + TTestBasicRuntime runtime; |
| 813 | + TTestEnv env(runtime); |
| 814 | + ui64 txId = 100; |
| 815 | + |
| 816 | + runtime.SetLogPriority(NKikimrServices::DATASHARD_BACKUP, NActors::NLog::PRI_TRACE); |
| 817 | + runtime.SetLogPriority(NKikimrServices::DATASHARD_RESTORE, NActors::NLog::PRI_TRACE); |
| 818 | + runtime.SetLogPriority(NKikimrServices::EXPORT, NActors::NLog::PRI_TRACE); |
| 819 | + runtime.SetLogPriority(NKikimrServices::IMPORT, NActors::NLog::PRI_TRACE); |
| 820 | + |
| 821 | + TestCreateTable(runtime, ++txId, "/MyRoot", R"( |
| 822 | + Name: "Original" |
| 823 | + Columns { Name: "key" Type: "Utf8" } |
| 824 | + Columns { |
| 825 | + Name: "value" |
| 826 | + Type: "Utf8" |
| 827 | + DefaultFromLiteral { |
| 828 | + type { |
| 829 | + optional_type { |
| 830 | + item { |
| 831 | + type_id: UTF8 |
| 832 | + } |
| 833 | + } |
| 834 | + } |
| 835 | + value { |
| 836 | + items { |
| 837 | + text_value: "value1" |
| 838 | + } |
| 839 | + } |
| 840 | + } |
| 841 | + } |
| 842 | + KeyColumnNames: ["key"] |
| 843 | + )"); |
| 844 | + env.TestWaitNotification(runtime, txId); |
| 845 | + |
| 846 | + TestExport(runtime, ++txId, "/MyRoot", Sprintf(R"( |
| 847 | + ExportToS3Settings { |
| 848 | + endpoint: "localhost:%d" |
| 849 | + scheme: HTTP |
| 850 | + items { |
| 851 | + source_path: "/MyRoot/Original" |
| 852 | + destination_prefix: "" |
| 853 | + } |
| 854 | + } |
| 855 | + )", port)); |
| 856 | + env.TestWaitNotification(runtime, txId); |
| 857 | + TestGetExport(runtime, txId, "/MyRoot"); |
| 858 | + |
| 859 | + TestImport(runtime, ++txId, "/MyRoot", Sprintf(R"( |
| 860 | + ImportFromS3Settings { |
| 861 | + endpoint: "localhost:%d" |
| 862 | + scheme: HTTP |
| 863 | + items { |
| 864 | + source_prefix: "" |
| 865 | + destination_path: "/MyRoot/Restored" |
| 866 | + } |
| 867 | + } |
| 868 | + )", port)); |
| 869 | + env.TestWaitNotification(runtime, txId); |
| 870 | + TestGetImport(runtime, txId, "/MyRoot"); |
| 871 | + |
| 872 | + const auto desc = DescribePath(runtime, "/MyRoot/Restored", true, true); |
| 873 | + UNIT_ASSERT_VALUES_EQUAL(desc.GetStatus(), NKikimrScheme::StatusSuccess); |
| 874 | + |
| 875 | + const auto& table = desc.GetPathDescription().GetTable(); |
| 876 | + |
| 877 | + UNIT_ASSERT_C(CheckDefaultFromLiteral(table), "Invalid default value"); |
| 878 | + } |
| 879 | + |
802 | 880 | Y_UNIT_TEST(ExportImportPg) {
|
803 | 881 | TTestBasicRuntime runtime;
|
804 | 882 | TTestEnv env(runtime, TTestEnvOptions().EnableTablePgTypes(true));
|
|
0 commit comments