5
5
#include < ydb/public/api/protos/draft/ydb_replication.pb.h>
6
6
#include < ydb/public/api/protos/draft/ydb_view.pb.h>
7
7
#include < ydb/public/api/protos/ydb_rate_limiter.pb.h>
8
+ #include < ydb/public/api/protos/ydb_table.pb.h>
8
9
#include < ydb/public/lib/ydb_cli/common/recursive_list.h>
9
10
#include < ydb/public/lib/ydb_cli/dump/dump.h>
10
11
#include < ydb/public/lib/yson_value/ydb_yson_value.h>
14
15
#include < ydb-cpp-sdk/client/export/export.h>
15
16
#include < ydb-cpp-sdk/client/import/import.h>
16
17
#include < ydb-cpp-sdk/client/operation/operation.h>
18
+ #include < ydb-cpp-sdk/client/proto/accessor.h>
17
19
#include < ydb-cpp-sdk/client/query/client.h>
18
20
#include < ydb-cpp-sdk/client/rate_limiter/rate_limiter.h>
19
21
#include < ydb-cpp-sdk/client/table/table.h>
@@ -35,6 +37,34 @@ using namespace NYdb::NScheme;
35
37
using namespace NYdb ::NTable;
36
38
using namespace NYdb ::NView;
37
39
40
+ namespace Ydb ::Table {
41
+
42
+ bool operator ==(const DescribeExternalDataSourceResult& lhs, const DescribeExternalDataSourceResult& rhs) {
43
+ google::protobuf::util::MessageDifferencer differencer;
44
+ differencer.IgnoreField (DescribeExternalDataSourceResult::GetDescriptor ()->FindFieldByName (" self" ));
45
+ return differencer.Compare (lhs, rhs);
46
+ }
47
+
48
+ bool operator ==(const DescribeExternalTableResult& lhs, const DescribeExternalTableResult& rhs) {
49
+ google::protobuf::util::MessageDifferencer differencer;
50
+ differencer.IgnoreField (DescribeExternalTableResult::GetDescriptor ()->FindFieldByName (" self" ));
51
+ return differencer.Compare (lhs, rhs);
52
+ }
53
+
54
+ }
55
+
56
+ namespace Ydb ::RateLimiter {
57
+
58
+ bool operator ==(const HierarchicalDrrSettings& lhs, const HierarchicalDrrSettings& rhs) {
59
+ return google::protobuf::util::MessageDifferencer::Equals (lhs, rhs);
60
+ }
61
+
62
+ bool operator ==(const MeteringConfig& lhs, const MeteringConfig& rhs) {
63
+ return google::protobuf::util::MessageDifferencer::Equals (lhs, rhs);
64
+ }
65
+
66
+ }
67
+
38
68
namespace NYdb ::NTable {
39
69
40
70
bool operator ==(const TValue& lhs, const TValue& rhs) {
@@ -53,13 +83,6 @@ bool operator==(const TKeyRange& lhs, const TKeyRange& rhs) {
53
83
54
84
namespace NYdb ::NRateLimiter {
55
85
56
- bool operator ==(
57
- const Ydb::RateLimiter::HierarchicalDrrSettings& lhs,
58
- const Ydb::RateLimiter::HierarchicalDrrSettings& rhs
59
- ) {
60
- return google::protobuf::util::MessageDifferencer::Equals (lhs, rhs);
61
- }
62
-
63
86
bool operator ==(
64
87
const TDescribeResourceResult::THierarchicalDrrProps& lhs,
65
88
const TDescribeResourceResult::THierarchicalDrrProps& rhs
@@ -71,13 +94,6 @@ bool operator==(
71
94
return left == right;
72
95
}
73
96
74
- bool operator ==(
75
- const Ydb::RateLimiter::MeteringConfig& lhs,
76
- const Ydb::RateLimiter::MeteringConfig& rhs
77
- ) {
78
- return google::protobuf::util::MessageDifferencer::Equals (lhs, rhs);
79
- }
80
-
81
97
bool operator ==(const TMeteringConfig& lhs, const TMeteringConfig& rhs) {
82
98
Ydb::RateLimiter::MeteringConfig left;
83
99
lhs.SerializeTo (left);
@@ -990,6 +1006,87 @@ void TestReplicationSettingsArePreserved(
990
1006
checkDescription ();
991
1007
}
992
1008
1009
+ Ydb::Table::DescribeExternalDataSourceResult DescribeExternalDataSource (TSession& session, const TString& path) {
1010
+ auto result = session.DescribeExternalDataSource (path).ExtractValueSync ();
1011
+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
1012
+ return TProtoAccessor::GetProto (result.GetExternalDataSourceDescription ());;
1013
+ }
1014
+
1015
+ void TestExternalDataSourceSettingsArePreserved (
1016
+ const char * path, TSession& tableSession, NQuery::TSession& querySession, TBackupFunction&& backup, TRestoreFunction&& restore
1017
+ ) {
1018
+ ExecuteQuery (querySession, Sprintf (R"(
1019
+ CREATE EXTERNAL DATA SOURCE `%s` WITH (
1020
+ SOURCE_TYPE = "ObjectStorage",
1021
+ LOCATION = "192.168.1.1:8123",
1022
+ AUTH_METHOD = "NONE"
1023
+ );
1024
+ )" , path
1025
+ ), true
1026
+ );
1027
+ const auto originalDescription = DescribeExternalDataSource (tableSession, path);
1028
+
1029
+ backup ();
1030
+
1031
+ ExecuteQuery (querySession, Sprintf (R"(
1032
+ DROP EXTERNAL DATA SOURCE `%s`;
1033
+ )" , path
1034
+ ), true
1035
+ );
1036
+
1037
+ restore ();
1038
+ UNIT_ASSERT_VALUES_EQUAL (
1039
+ DescribeExternalDataSource (tableSession, path),
1040
+ originalDescription
1041
+ );
1042
+ }
1043
+
1044
+ Ydb::Table::DescribeExternalTableResult DescribeExternalTable (TSession& session, const TString& path) {
1045
+ auto result = session.DescribeExternalTable (path).ExtractValueSync ();
1046
+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
1047
+ return TProtoAccessor::GetProto (result.GetExternalTableDescription ());;
1048
+ }
1049
+
1050
+ void TestExternalTableSettingsArePreserved (
1051
+ const char * path, const char * externalDataSource, TSession& tableSession, NQuery::TSession& querySession, TBackupFunction&& backup, TRestoreFunction&& restore
1052
+ ) {
1053
+ ExecuteQuery (querySession, Sprintf (R"(
1054
+ CREATE EXTERNAL DATA SOURCE `%s` WITH (
1055
+ SOURCE_TYPE = "ObjectStorage",
1056
+ LOCATION = "192.168.1.1:8123",
1057
+ AUTH_METHOD = "NONE"
1058
+ );
1059
+
1060
+ CREATE EXTERNAL TABLE `%s` (
1061
+ key Utf8 NOT NULL,
1062
+ value Utf8 NOT NULL
1063
+ ) WITH (
1064
+ DATA_SOURCE = "%s",
1065
+ LOCATION = "folder",
1066
+ FORMAT = "csv_with_names",
1067
+ COMPRESSION = "gzip"
1068
+ );
1069
+ )" , externalDataSource, path, externalDataSource
1070
+ ), true
1071
+ );
1072
+ const auto originalDescription = DescribeExternalTable (tableSession, path);
1073
+
1074
+ backup ();
1075
+
1076
+ ExecuteQuery (querySession, Sprintf (R"(
1077
+ DROP EXTERNAL TABLE `%s`;
1078
+ DROP EXTERNAL DATA SOURCE `%s`;
1079
+ )" , path, externalDataSource
1080
+ ), true
1081
+ );
1082
+
1083
+ restore ();
1084
+ UNIT_ASSERT_VALUES_EQUAL (
1085
+ DescribeExternalTable (tableSession, path),
1086
+ originalDescription
1087
+ );
1088
+ }
1089
+
993
1090
}
994
1091
995
1092
Y_UNIT_TEST_SUITE (BackupRestore) {
@@ -1398,6 +1495,52 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
1398
1495
);
1399
1496
}
1400
1497
1498
+ void TestExternalDataSourceBackupRestore () {
1499
+ TKikimrWithGrpcAndRootSchema server;
1500
+ server.GetRuntime ()->GetAppData ().FeatureFlags .SetEnableExternalDataSources (true );
1501
+ auto driver = TDriver (TDriverConfig ().SetEndpoint (Sprintf (" localhost:%u" , server.GetPort ())));
1502
+ TTableClient tableClient (driver);
1503
+ auto tableSession = tableClient.CreateSession ().ExtractValueSync ().GetSession ();
1504
+ NQuery::TQueryClient queryClient (driver);
1505
+ auto querySession = queryClient.GetSession ().ExtractValueSync ().GetSession ();
1506
+ TTempDir tempDir;
1507
+ const auto & pathToBackup = tempDir.Path ();
1508
+
1509
+ constexpr const char * path = " /Root/externalDataSource" ;
1510
+
1511
+ TestExternalDataSourceSettingsArePreserved (
1512
+ path,
1513
+ tableSession,
1514
+ querySession,
1515
+ CreateBackupLambda (driver, pathToBackup),
1516
+ CreateRestoreLambda (driver, pathToBackup)
1517
+ );
1518
+ }
1519
+
1520
+ void TestExternalTableBackupRestore () {
1521
+ TKikimrWithGrpcAndRootSchema server;
1522
+ server.GetRuntime ()->GetAppData ().FeatureFlags .SetEnableExternalDataSources (true );
1523
+ auto driver = TDriver (TDriverConfig ().SetEndpoint (Sprintf (" localhost:%u" , server.GetPort ())));
1524
+ TTableClient tableClient (driver);
1525
+ auto tableSession = tableClient.CreateSession ().ExtractValueSync ().GetSession ();
1526
+ NQuery::TQueryClient queryClient (driver);
1527
+ auto querySession = queryClient.GetSession ().ExtractValueSync ().GetSession ();
1528
+ TTempDir tempDir;
1529
+ const auto & pathToBackup = tempDir.Path ();
1530
+
1531
+ constexpr const char * path = " /Root/externalTable" ;
1532
+ constexpr const char * externalDataSource = " /Root/externalDataSource" ;
1533
+
1534
+ TestExternalTableSettingsArePreserved (
1535
+ path,
1536
+ externalDataSource,
1537
+ tableSession,
1538
+ querySession,
1539
+ CreateBackupLambda (driver, pathToBackup),
1540
+ CreateRestoreLambda (driver, pathToBackup)
1541
+ );
1542
+ }
1543
+
1401
1544
Y_UNIT_TEST_ALL_PROTO_ENUM_VALUES (TestAllSchemeObjectTypes, NKikimrSchemeOp::EPathType) {
1402
1545
using namespace NKikimrSchemeOp ;
1403
1546
@@ -1424,9 +1567,9 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
1424
1567
case EPathTypeTransfer:
1425
1568
break ; // https://github.com/ydb-platform/ydb/issues/10436
1426
1569
case EPathTypeExternalTable:
1427
- break ; // https://github.com/ydb-platform/ydb/issues/10438
1570
+ return TestExternalTableBackupRestore ();
1428
1571
case EPathTypeExternalDataSource:
1429
- break ; // https://github.com/ydb-platform/ydb/issues/10439
1572
+ return TestExternalDataSourceBackupRestore ();
1430
1573
case EPathTypeResourcePool:
1431
1574
break ; // https://github.com/ydb-platform/ydb/issues/10440
1432
1575
case EPathTypeKesus:
0 commit comments