Skip to content

Commit 73b8d3c

Browse files
committed
1 parent 84f575d commit 73b8d3c

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,80 @@ Y_UNIT_TEST_SUITE(TExternalDataSourceTest) {
403403

404404
TestLs(runtime, "/MyRoot/ExternalDataSource", false, NLs::PathNotExist);
405405
}
406+
407+
Y_UNIT_TEST(CreateExternalDataSourceWithOrReplace) {
408+
TTestBasicRuntime runtime;
409+
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExists(true));
410+
ui64 txId = 100;
411+
412+
TestCreateExternalDataSource(runtime, ++txId, "/MyRoot",R"(
413+
Name: "MyExternalDataSource"
414+
SourceType: "ObjectStorage"
415+
Location: "https://s3.cloud.net/my_bucket"
416+
Auth {
417+
None {
418+
}
419+
}
420+
ReplaceIfExists: true
421+
)",{NKikimrScheme::StatusAccepted});
422+
423+
env.TestWaitNotification(runtime, txId);
424+
425+
{
426+
auto describeResult = DescribePath(runtime, "/MyRoot/MyExternalDataSource");
427+
TestDescribeResult(describeResult, {NLs::PathExist});
428+
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalDataSourceDescription());
429+
const auto& externalDataSourceDescription = describeResult.GetPathDescription().GetExternalDataSourceDescription();
430+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetName(), "MyExternalDataSource");
431+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetSourceType(), "ObjectStorage");
432+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetVersion(), 1);
433+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetLocation(), "https://s3.cloud.net/my_bucket");
434+
UNIT_ASSERT_EQUAL(externalDataSourceDescription.GetAuth().identity_case(), NKikimrSchemeOp::TAuth::kNone);
435+
}
436+
437+
TestCreateExternalDataSource(runtime, ++txId, "/MyRoot",R"(
438+
Name: "MyExternalDataSource"
439+
SourceType: "ObjectStorage"
440+
Location: "https://s3.cloud.net/my_new_bucket"
441+
Auth {
442+
None {
443+
}
444+
}
445+
ReplaceIfExists: true
446+
)",{NKikimrScheme::StatusAccepted});
447+
env.TestWaitNotification(runtime, txId);
448+
449+
{
450+
auto describeResult = DescribePath(runtime, "/MyRoot/MyExternalDataSource");
451+
TestDescribeResult(describeResult, {NLs::PathExist});
452+
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalDataSourceDescription());
453+
const auto& externalDataSourceDescription = describeResult.GetPathDescription().GetExternalDataSourceDescription();
454+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetName(), "MyExternalDataSource");
455+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetSourceType(), "ObjectStorage");
456+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetVersion(), 2);
457+
UNIT_ASSERT_VALUES_EQUAL(externalDataSourceDescription.GetLocation(), "https://s3.cloud.net/my_new_bucket");
458+
UNIT_ASSERT_EQUAL(externalDataSourceDescription.GetAuth().identity_case(), NKikimrSchemeOp::TAuth::kNone);
459+
}
460+
}
461+
462+
Y_UNIT_TEST(CreateExternalDataSourceWithOrReplaceShouldFailIfFeatureFlagIsNotSet) {
463+
TTestBasicRuntime runtime;
464+
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExists(false));
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+
ReplaceIfExists: true
476+
)",{{NKikimrScheme::StatusPreconditionFailed, "Unsupported: feature flag EnableReplaceIfExists is off"}});
477+
478+
env.TestWaitNotification(runtime, txId);
479+
480+
TestLs(runtime, "/MyRoot/MyExternalDataSource", false, NLs::PathNotExist);
481+
}
406482
}

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,90 @@ Y_UNIT_TEST_SUITE(TExternalTableTest) {
312312
Columns { Name: "Value" Type: "Utf8"}
313313
)", {{NKikimrScheme::StatusPathDoesNotExist, "Check failed: path: '/MyRoot/ExternalDataSource1'"}});
314314
}
315+
316+
Y_UNIT_TEST(CreateExternalTableWithOrReplace) {
317+
TTestBasicRuntime runtime;
318+
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExists(true));
319+
ui64 txId = 100;
320+
321+
CreateExternalDataSource(runtime, env, ++txId);
322+
TestCreateExternalTable(runtime, ++txId, "/MyRoot", R"(
323+
Name: "ExternalTable"
324+
SourceType: "General"
325+
DataSourcePath: "/MyRoot/ExternalDataSource"
326+
Location: "/"
327+
Columns { Name: "key" Type: "Uint64" }
328+
ReplaceIfExists: true
329+
)", {NKikimrScheme::StatusAccepted});
330+
331+
env.TestWaitNotification(runtime, txId);
332+
333+
{
334+
auto describeResult = DescribePath(runtime, "/MyRoot/ExternalTable");
335+
TestDescribeResult(describeResult, {NLs::PathExist});
336+
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalTableDescription());
337+
const auto& externalTableDescription = describeResult.GetPathDescription().GetExternalTableDescription();
338+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetName(), "ExternalTable");
339+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetDataSourcePath(), "/MyRoot/ExternalDataSource");
340+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetLocation(), "/");
341+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetSourceType(), "ObjectStorage");
342+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetVersion(), 1);
343+
auto& columns = externalTableDescription.GetColumns();
344+
UNIT_ASSERT_VALUES_EQUAL(columns.size(), 1);
345+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetName(), "key");
346+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetType(), "Uint64");
347+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetNotNull(), false);
348+
}
349+
350+
TestCreateExternalTable(runtime, ++txId, "/MyRoot", R"(
351+
Name: "ExternalTable"
352+
SourceType: "General"
353+
DataSourcePath: "/MyRoot/ExternalDataSource"
354+
Location: "/new_location"
355+
Columns { Name: "key" Type: "Uint64" }
356+
Columns { Name: "value" Type: "Uint64" }
357+
ReplaceIfExists: true
358+
)", {NKikimrScheme::StatusAccepted});
359+
env.TestWaitNotification(runtime, txId);
360+
361+
{
362+
auto describeResult = DescribePath(runtime, "/MyRoot/ExternalTable");
363+
TestDescribeResult(describeResult, {NLs::PathExist});
364+
UNIT_ASSERT(describeResult.GetPathDescription().HasExternalTableDescription());
365+
const auto& externalTableDescription = describeResult.GetPathDescription().GetExternalTableDescription();
366+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetName(), "ExternalTable");
367+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetDataSourcePath(), "/MyRoot/ExternalDataSource");
368+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetLocation(), "/new_location");
369+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetSourceType(), "ObjectStorage");
370+
UNIT_ASSERT_VALUES_EQUAL(externalTableDescription.GetVersion(), 2);
371+
auto& columns = externalTableDescription.GetColumns();
372+
UNIT_ASSERT_VALUES_EQUAL(columns.size(), 2);
373+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetName(), "key");
374+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetType(), "Uint64");
375+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(0).GetNotNull(), false);
376+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(1).GetName(), "value");
377+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(1).GetType(), "Uint64");
378+
UNIT_ASSERT_VALUES_EQUAL(columns.Get(1).GetNotNull(), false);
379+
}
380+
}
381+
382+
Y_UNIT_TEST(CreateExternalTableWithOrReplaceShouldFailIfFeatureFlagIsNotSet) {
383+
TTestBasicRuntime runtime;
384+
TTestEnv env(runtime, TTestEnvOptions().EnableReplaceIfExists(false));
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+
ReplaceIfExists: true
395+
)", {{NKikimrScheme::StatusPreconditionFailed, "Unsupported: feature flag EnableReplaceIfExists is off"}});
396+
397+
env.TestWaitNotification(runtime, txId);
398+
399+
TestLs(runtime, "/MyRoot/ExternalTable", false, NLs::PathNotExist);
400+
}
315401
}

0 commit comments

Comments
 (0)