Skip to content

Commit 1277454

Browse files
authored
[YQ-1997] Extra tests
1 parent 5f6a40a commit 1277454

File tree

3 files changed

+171
-2
lines changed

3 files changed

+171
-2
lines changed

ydb/core/tx/schemeshard/schemeshard__operation_alter_external_table.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class TAlterExternalTable: public TSubOperation {
348348
/// Extract old data source end
349349

350350
const auto oldExternalTableInfo =
351-
context.SS->ExternalTables.Value(dstPath->PathId, nullptr);
351+
context.SS->ExternalTables.Value(dstPath->PathId, nullptr);
352352
Y_ABORT_UNLESS(oldExternalTableInfo);
353353
auto [externalTableInfo, maybeError] =
354354
NExternalTable::CreateExternalTable(externalDataSource->SourceType,

ydb/core/tx/schemeshard/ut_external_data_source/ut_external_data_source.cpp

+81
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,87 @@ Y_UNIT_TEST_SUITE(TExternalDataSourceTest) {
459459
}
460460
}
461461

462+
Y_UNIT_TEST(CreateExternalDataSourceShouldFailIfSuchEntityAlreadyExists) {
463+
TTestBasicRuntime runtime;
464+
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExistsForExternalEntities(true));
465+
ui64 txId = 100;
466+
467+
TestCreateExternalDataSource(runtime, ++txId, "/MyRoot",R"(
468+
Name: "MyExternalDataSource"
469+
SourceType: "ObjectStorage"
470+
Location: "https://s3.cloud.net/my_bucket"
471+
Auth {
472+
None {
473+
}
474+
}
475+
)",{NKikimrScheme::StatusAccepted});
476+
477+
env.TestWaitNotification(runtime, txId);
478+
479+
{
480+
auto describeResult = DescribePath(runtime, "/MyRoot/MyExternalDataSource");
481+
TestDescribeResult(describeResult, {NLs::PathExist});
482+
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalDataSourceDescription());
483+
const auto& externalDataSourceDescription = describeResult.GetPathDescription().GetExternalDataSourceDescription();
484+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetName(), "MyExternalDataSource");
485+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetSourceType(), "ObjectStorage");
486+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetVersion(), 1);
487+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetLocation(), "https://s3.cloud.net/my_bucket");
488+
UNIT_ASSERT_EQUAL(externalDataSourceDescription.GetAuth().identity_case(), NKikimrSchemeOp::TAuth::kNone);
489+
}
490+
491+
TestCreateExternalDataSource(runtime, ++txId, "/MyRoot",R"(
492+
Name: "MyExternalDataSource"
493+
SourceType: "ObjectStorage"
494+
Location: "https://s3.cloud.net/my_new_bucket"
495+
Auth {
496+
None {
497+
}
498+
}
499+
)",{NKikimrScheme::StatusAlreadyExists});
500+
env.TestWaitNotification(runtime, txId);
501+
502+
{
503+
auto describeResult = DescribePath(runtime, "/MyRoot/MyExternalDataSource");
504+
TestDescribeResult(describeResult, {NLs::PathExist});
505+
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalDataSourceDescription());
506+
const auto& externalDataSourceDescription = describeResult.GetPathDescription().GetExternalDataSourceDescription();
507+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetName(), "MyExternalDataSource");
508+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetSourceType(), "ObjectStorage");
509+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetVersion(), 1);
510+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetLocation(), "https://s3.cloud.net/my_bucket");
511+
UNIT_ASSERT_EQUAL(externalDataSourceDescription.GetAuth().identity_case(), NKikimrSchemeOp::TAuth::kNone);
512+
}
513+
}
514+
515+
Y_UNIT_TEST(ReplaceExternalDataStoreShouldFailIfEntityOfAnotherTypeWithSameNameExists) {
516+
TTestBasicRuntime runtime;
517+
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExistsForExternalEntities(true));
518+
ui64 txId = 100;
519+
520+
TestCreateView(runtime, ++txId, "/MyRoot", R"(
521+
Name: "UniqueName"
522+
QueryText: "Some query"
523+
)", {NKikimrScheme::StatusAccepted}
524+
);
525+
env.TestWaitNotification(runtime, txId);
526+
527+
TestLs(runtime, "/MyRoot/UniqueName", false, NLs::PathExist);
528+
529+
TestCreateExternalDataSource(runtime, ++txId, "/MyRoot",R"(
530+
Name: "UniqueName"
531+
SourceType: "ObjectStorage"
532+
Location: "https://s3.cloud.net/my_bucket"
533+
Auth {
534+
None {
535+
}
536+
}
537+
ReplaceIfExists: true
538+
)",{{NKikimrScheme::StatusNameConflict, "error: unexpected path type"}});
539+
540+
env.TestWaitNotification(runtime, txId);
541+
}
542+
462543
Y_UNIT_TEST(ReplaceExternalDataSourceIfNotExistsShouldFailIfFeatureFlagIsNotSet) {
463544
TTestBasicRuntime runtime;
464545
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExistsForExternalEntities(false));

ydb/core/tx/schemeshard/ut_external_table/ut_external_table.cpp

+89-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ Y_UNIT_TEST_SUITE(TExternalTableTest) {
331331
env.TestWaitNotification(runtime, txId);
332332

333333
{
334-
auto describeResult = DescribePath(runtime, "/MyRoot/ExternalTable");
334+
auto describeResult = DescribePath(runtime, "/MyRoot/ExternalTable");
335335
TestDescribeResult(describeResult, {NLs::PathExist});
336336
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalTableDescription());
337337
const auto& externalTableDescription = describeResult.GetPathDescription().GetExternalTableDescription();
@@ -379,6 +379,94 @@ Y_UNIT_TEST_SUITE(TExternalTableTest) {
379379
}
380380
}
381381

382+
Y_UNIT_TEST(CreateExternalTableShouldFailIfSuchEntityAlreadyExists) {
383+
TTestBasicRuntime runtime;
384+
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExistsForExternalEntities(true));
385+
ui64 txId = 100;
386+
387+
CreateExternalDataSource(runtime, env, ++txId);
388+
TestCreateExternalTable(runtime, ++txId, "/MyRoot", R"(
389+
Name: "ExternalTable"
390+
SourceType: "General"
391+
DataSourcePath: "/MyRoot/ExternalDataSource"
392+
Location: "/"
393+
Columns { Name: "key" Type: "Uint64" }
394+
)", {NKikimrScheme::StatusAccepted});
395+
396+
env.TestWaitNotification(runtime, txId);
397+
398+
{
399+
auto describeResult = DescribePath(runtime, "/MyRoot/ExternalTable");
400+
TestDescribeResult(describeResult, {NLs::PathExist});
401+
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalTableDescription());
402+
const auto& externalTableDescription = describeResult.GetPathDescription().GetExternalTableDescription();
403+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetName(), "ExternalTable");
404+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetDataSourcePath(), "/MyRoot/ExternalDataSource");
405+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetLocation(), "/");
406+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetSourceType(), "ObjectStorage");
407+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetVersion(), 1);
408+
auto& columns = externalTableDescription.GetColumns();
409+
UNIT_ASSERT_VALUES_EQUAL(columns.size(), 1);
410+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetName(), "key");
411+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetType(), "Uint64");
412+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetNotNull(), false);
413+
}
414+
415+
TestCreateExternalTable(runtime, ++txId, "/MyRoot", R"(
416+
Name: "ExternalTable"
417+
SourceType: "General"
418+
DataSourcePath: "/MyRoot/ExternalDataSource"
419+
Location: "/new_location"
420+
Columns { Name: "key" Type: "Uint64" }
421+
Columns { Name: "value" Type: "Uint64" }
422+
)", {NKikimrScheme::StatusAlreadyExists});
423+
env.TestWaitNotification(runtime, txId);
424+
425+
{
426+
auto describeResult = DescribePath(runtime, "/MyRoot/ExternalTable");
427+
TestDescribeResult(describeResult, {NLs::PathExist});
428+
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalTableDescription());
429+
const auto& externalTableDescription = describeResult.GetPathDescription().GetExternalTableDescription();
430+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetName(), "ExternalTable");
431+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetDataSourcePath(), "/MyRoot/ExternalDataSource");
432+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetLocation(), "/");
433+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetSourceType(), "ObjectStorage");
434+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetVersion(), 1);
435+
auto& columns = externalTableDescription.GetColumns();
436+
UNIT_ASSERT_VALUES_EQUAL(columns.size(), 1);
437+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetName(), "key");
438+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetType(), "Uint64");
439+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetNotNull(), false);
440+
}
441+
}
442+
443+
Y_UNIT_TEST(ReplaceExternalTableShouldFailIfEntityOfAnotherTypeWithSameNameExists) {
444+
TTestBasicRuntime runtime;
445+
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExistsForExternalEntities(true));
446+
ui64 txId = 100;
447+
448+
TestCreateView(runtime, ++txId, "/MyRoot", R"(
449+
Name: "UniqueName"
450+
QueryText: "Some query"
451+
)", {NKikimrScheme::StatusAccepted}
452+
);
453+
env.TestWaitNotification(runtime, txId);
454+
455+
TestLs(runtime, "/MyRoot/UniqueName", false, NLs::PathExist);
456+
457+
CreateExternalDataSource(runtime, env, ++txId);
458+
TestCreateExternalTable(runtime, ++txId, "/MyRoot", R"(
459+
Name: "UniqueName"
460+
SourceType: "General"
461+
DataSourcePath: "/MyRoot/ExternalDataSource"
462+
Location: "/"
463+
Columns { Name: "key" Type: "Uint64" }
464+
ReplaceIfExists: true
465+
)", {{NKikimrScheme::StatusNameConflict, "error: unexpected path type"}});
466+
467+
env.TestWaitNotification(runtime, txId);
468+
}
469+
382470
Y_UNIT_TEST(ReplaceExternalTableIfNotExistsShouldFailIfFeatureFlagIsNotSet) {
383471
TTestBasicRuntime runtime;
384472
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExistsForExternalEntities(false));

0 commit comments

Comments
 (0)