Skip to content

Commit 1ed4119

Browse files
committed
Fixes
1 parent b028a93 commit 1ed4119

File tree

3 files changed

+111
-34
lines changed

3 files changed

+111
-34
lines changed

ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp

+109-31
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <ydb/core/tx/schemeshard/schemeshard_private.h>
1010
#include <ydb/core/tx/schemeshard/schemeshard_billing_helpers.h>
1111
#include <ydb/core/tx/datashard/datashard.h>
12-
#include <ydb/core/tx/datashard/datashard_ut_common_kqp.h>
1312
#include <ydb/core/wrappers/ut_helpers/s3_mock.h>
1413
#include <ydb/core/metering/metering.h>
1514
#include <ydb/core/ydb_convert/table_description.h>
@@ -374,6 +373,39 @@ Y_UNIT_TEST_SUITE(TRestoreTests) {
374373
NKqp::CompareYson(data.YsonStr, content);
375374
}
376375

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+
377409
Y_UNIT_TEST_WITH_COMPRESSION(ShouldSucceedWithDefaultFromLiteral) {
378410
TTestBasicRuntime runtime;
379411

@@ -411,36 +443,7 @@ Y_UNIT_TEST_SUITE(TRestoreTests) {
411443

412444
const auto& table = desc.GetPathDescription().GetTable();
413445

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");
444447
}
445448

446449
Y_UNIT_TEST_WITH_COMPRESSION(ShouldSucceedOnMultiShardTable) {
@@ -799,6 +802,81 @@ value {
799802
TestGetImport(runtime, txId, "/MyRoot");
800803
}
801804

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+
802880
Y_UNIT_TEST(ExportImportPg) {
803881
TTestBasicRuntime runtime;
804882
TTestEnv env(runtime, TTestEnvOptions().EnableTablePgTypes(true));

ydb/core/ydb_convert/table_description.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ bool FillColumnDescription(NKikimrSchemeOp::TTableDescription& out,
656656
cd->SetFamilyName(column.family());
657657
}
658658

659-
switch (column.default_policy_case()) {
659+
switch (column.default_value_policy_case()) {
660660
case Ydb::Table::ColumnMeta::kFromLiteral: {
661661
auto fromLiteral = cd->MutableDefaultFromLiteral();
662662
*fromLiteral = column.from_literal();

ydb/public/api/protos/ydb_table.proto

+1-2
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ message ColumnMeta {
342342
string family = 3;
343343
// Column nullability
344344
optional bool not_null = 4;
345-
// Default value policy
346-
oneof default_policy {
345+
oneof default_value_policy {
347346
TypedValue from_literal = 6;
348347
}
349348
}

0 commit comments

Comments
 (0)