Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Alnen committed Jan 31, 2024
1 parent 84f575d commit 73b8d3c
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,80 @@ Y_UNIT_TEST_SUITE(TExternalDataSourceTest) {

TestLs(runtime, "/MyRoot/ExternalDataSource", false, NLs::PathNotExist);
}

Y_UNIT_TEST(CreateExternalDataSourceWithOrReplace) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExists(true));
ui64 txId = 100;

TestCreateExternalDataSource(runtime, ++txId, "/MyRoot",R"(
Name: "MyExternalDataSource"
SourceType: "ObjectStorage"
Location: "https://s3.cloud.net/my_bucket"
Auth {
None {
}
}
ReplaceIfExists: true
)",{NKikimrScheme::StatusAccepted});

env.TestWaitNotification(runtime, txId);

{
auto describeResult = DescribePath(runtime, "/MyRoot/MyExternalDataSource");
TestDescribeResult(describeResult, {NLs::PathExist});
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalDataSourceDescription());
const auto& externalDataSourceDescription = describeResult.GetPathDescription().GetExternalDataSourceDescription();
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetName(), "MyExternalDataSource");
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetSourceType(), "ObjectStorage");
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetVersion(), 1);
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetLocation(), "https://s3.cloud.net/my_bucket");
UNIT_ASSERT_EQUAL(externalDataSourceDescription.GetAuth().identity_case(), NKikimrSchemeOp::TAuth::kNone);
}

TestCreateExternalDataSource(runtime, ++txId, "/MyRoot",R"(
Name: "MyExternalDataSource"
SourceType: "ObjectStorage"
Location: "https://s3.cloud.net/my_new_bucket"
Auth {
None {
}
}
ReplaceIfExists: true
)",{NKikimrScheme::StatusAccepted});
env.TestWaitNotification(runtime, txId);

{
auto describeResult = DescribePath(runtime, "/MyRoot/MyExternalDataSource");
TestDescribeResult(describeResult, {NLs::PathExist});
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalDataSourceDescription());
const auto& externalDataSourceDescription = describeResult.GetPathDescription().GetExternalDataSourceDescription();
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetName(), "MyExternalDataSource");
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetSourceType(), "ObjectStorage");
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetVersion(), 2);
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetLocation(), "https://s3.cloud.net/my_new_bucket");
UNIT_ASSERT_EQUAL(externalDataSourceDescription.GetAuth().identity_case(), NKikimrSchemeOp::TAuth::kNone);
}
}

Y_UNIT_TEST(CreateExternalDataSourceWithOrReplaceShouldFailIfFeatureFlagIsNotSet) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExists(false));
ui64 txId = 100;

TestCreateExternalDataSource(runtime, ++txId, "/MyRoot",R"(
Name: "MyExternalDataSource"
SourceType: "ObjectStorage"
Location: "https://s3.cloud.net/my_bucket"
Auth {
None {
}
}
ReplaceIfExists: true
)",{{NKikimrScheme::StatusPreconditionFailed, "Unsupported: feature flag EnableReplaceIfExists is off"}});

env.TestWaitNotification(runtime, txId);

TestLs(runtime, "/MyRoot/MyExternalDataSource", false, NLs::PathNotExist);
}
}
86 changes: 86 additions & 0 deletions ydb/core/tx/schemeshard/ut_external_table/ut_external_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,90 @@ Y_UNIT_TEST_SUITE(TExternalTableTest) {
Columns { Name: "Value" Type: "Utf8"}
)", {{NKikimrScheme::StatusPathDoesNotExist, "Check failed: path: '/MyRoot/ExternalDataSource1'"}});
}

Y_UNIT_TEST(CreateExternalTableWithOrReplace) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExists(true));
ui64 txId = 100;

CreateExternalDataSource(runtime, env, ++txId);
TestCreateExternalTable(runtime, ++txId, "/MyRoot", R"(
Name: "ExternalTable"
SourceType: "General"
DataSourcePath: "/MyRoot/ExternalDataSource"
Location: "/"
Columns { Name: "key" Type: "Uint64" }
ReplaceIfExists: true
)", {NKikimrScheme::StatusAccepted});

env.TestWaitNotification(runtime, txId);

{
auto describeResult = DescribePath(runtime, "/MyRoot/ExternalTable");
TestDescribeResult(describeResult, {NLs::PathExist});
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalTableDescription());
const auto& externalTableDescription = describeResult.GetPathDescription().GetExternalTableDescription();
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetName(), "ExternalTable");
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetDataSourcePath(), "/MyRoot/ExternalDataSource");
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetLocation(), "/");
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetSourceType(), "ObjectStorage");
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetVersion(), 1);
auto& columns = externalTableDescription.GetColumns();
UNIT_ASSERT_VALUES_EQUAL(columns.size(), 1);
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetName(), "key");
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetType(), "Uint64");
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetNotNull(), false);
}

TestCreateExternalTable(runtime, ++txId, "/MyRoot", R"(
Name: "ExternalTable"
SourceType: "General"
DataSourcePath: "/MyRoot/ExternalDataSource"
Location: "/new_location"
Columns { Name: "key" Type: "Uint64" }
Columns { Name: "value" Type: "Uint64" }
ReplaceIfExists: true
)", {NKikimrScheme::StatusAccepted});
env.TestWaitNotification(runtime, txId);

{
auto describeResult = DescribePath(runtime, "/MyRoot/ExternalTable");
TestDescribeResult(describeResult, {NLs::PathExist});
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalTableDescription());
const auto& externalTableDescription = describeResult.GetPathDescription().GetExternalTableDescription();
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetName(), "ExternalTable");
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetDataSourcePath(), "/MyRoot/ExternalDataSource");
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetLocation(), "/new_location");
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetSourceType(), "ObjectStorage");
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetVersion(), 2);
auto& columns = externalTableDescription.GetColumns();
UNIT_ASSERT_VALUES_EQUAL(columns.size(), 2);
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetName(), "key");
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetType(), "Uint64");
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetNotNull(), false);
UNIT_ASSERT_VALUES_EQUAL(columns.Get(1).GetName(), "value");
UNIT_ASSERT_VALUES_EQUAL(columns.Get(1).GetType(), "Uint64");
UNIT_ASSERT_VALUES_EQUAL(columns.Get(1).GetNotNull(), false);
}
}

Y_UNIT_TEST(CreateExternalTableWithOrReplaceShouldFailIfFeatureFlagIsNotSet) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExists(false));
ui64 txId = 100;

CreateExternalDataSource(runtime, env, ++txId);
TestCreateExternalTable(runtime, ++txId, "/MyRoot", R"(
Name: "ExternalTable"
SourceType: "General"
DataSourcePath: "/MyRoot/ExternalDataSource"
Location: "/"
Columns { Name: "key" Type: "Uint64" }
ReplaceIfExists: true
)", {{NKikimrScheme::StatusPreconditionFailed, "Unsupported: feature flag EnableReplaceIfExists is off"}});

env.TestWaitNotification(runtime, txId);

TestLs(runtime, "/MyRoot/ExternalTable", false, NLs::PathNotExist);
}
}

0 comments on commit 73b8d3c

Please sign in to comment.