@@ -312,4 +312,90 @@ Y_UNIT_TEST_SUITE(TExternalTableTest) {
312
312
Columns { Name: "Value" Type: "Utf8"}
313
313
)" , {{NKikimrScheme::StatusPathDoesNotExist, " Check failed: path: '/MyRoot/ExternalDataSource1'" }});
314
314
}
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
+ }
315
401
}
0 commit comments