@@ -331,7 +331,7 @@ Y_UNIT_TEST_SUITE(TExternalTableTest) {
331
331
env.TestWaitNotification (runtime, txId);
332
332
333
333
{
334
- auto describeResult = DescribePath (runtime, " /MyRoot/ExternalTable" );
334
+ auto describeResult = DescribePath (runtime, " /MyRoot/ExternalTable" );
335
335
TestDescribeResult (describeResult, {NLs::PathExist});
336
336
UNIT_ASSERT (describeResult.GetPathDescription ().HasExternalTableDescription ());
337
337
const auto & externalTableDescription = describeResult.GetPathDescription ().GetExternalTableDescription ();
@@ -379,6 +379,94 @@ Y_UNIT_TEST_SUITE(TExternalTableTest) {
379
379
}
380
380
}
381
381
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
+
382
470
Y_UNIT_TEST (ReplaceExternalTableIfNotExistsShouldFailIfFeatureFlagIsNotSet) {
383
471
TTestBasicRuntime runtime;
384
472
TTestEnv env (runtime, TTestEnvOptions ().EnableReplaceIfExistsForExternalEntities (false ));
0 commit comments