|
27 | 27 | #include <ydb/library/yql/minikql/mkql_program_builder.h> |
28 | 28 |
|
29 | 29 | #include <ydb/core/kqp/provider/yql_kikimr_results.h> |
| 30 | +#include <ydb/core/kqp/gateway/utils/scheme_helpers.h> |
30 | 31 |
|
31 | 32 | namespace NYql { |
32 | 33 | namespace { |
@@ -505,6 +506,96 @@ namespace { |
505 | 506 | } |
506 | 507 | } |
507 | 508 | } |
| 509 | + |
| 510 | + bool IsPartitioningSetting(TStringBuf name) { |
| 511 | + return name == "autoPartitioningBySize" |
| 512 | + || name == "partitionSizeMb" |
| 513 | + || name == "autoPartitioningByLoad" |
| 514 | + || name == "minPartitions" |
| 515 | + || name == "maxPartitions"; |
| 516 | + } |
| 517 | + |
| 518 | + [[nodiscard]] bool ParsePartitioningSettings( |
| 519 | + Ydb::Table::PartitioningSettings& partitioningSettings, |
| 520 | + const TCoNameValueTuple& setting, |
| 521 | + TExprContext& ctx |
| 522 | + ) { |
| 523 | + auto name = setting.Name().Value(); |
| 524 | + if (name == "autoPartitioningBySize") { |
| 525 | + auto val = to_lower(setting.Value().Cast<TCoAtom>().StringValue()); |
| 526 | + if (val == "enabled") { |
| 527 | + partitioningSettings.set_partitioning_by_size(Ydb::FeatureFlag::ENABLED); |
| 528 | + } else if (val == "disabled") { |
| 529 | + partitioningSettings.set_partitioning_by_size(Ydb::FeatureFlag::DISABLED); |
| 530 | + } else { |
| 531 | + ctx.AddError( |
| 532 | + TIssue(ctx.GetPosition(setting.Value().Cast<TCoAtom>().Pos()), |
| 533 | + TStringBuilder() << "Unknown feature flag '" << val << "' for auto partitioning by size" |
| 534 | + ) |
| 535 | + ); |
| 536 | + return false; |
| 537 | + } |
| 538 | + } else if (name == "partitionSizeMb") { |
| 539 | + ui64 value = FromString<ui64>( |
| 540 | + setting.Value().Cast<TCoDataCtor>().Literal().Cast<TCoAtom>().Value() |
| 541 | + ); |
| 542 | + if (value) { |
| 543 | + partitioningSettings.set_partition_size_mb(value); |
| 544 | + } else { |
| 545 | + ctx.AddError( |
| 546 | + TIssue(ctx.GetPosition(setting.Name().Pos()), |
| 547 | + "Can't set preferred partition size to 0. " |
| 548 | + "To disable auto partitioning by size use 'SET AUTO_PARTITIONING_BY_SIZE DISABLED'" |
| 549 | + ) |
| 550 | + ); |
| 551 | + return false; |
| 552 | + } |
| 553 | + } else if (name == "autoPartitioningByLoad") { |
| 554 | + auto val = to_lower(setting.Value().Cast<TCoAtom>().StringValue()); |
| 555 | + if (val == "enabled") { |
| 556 | + partitioningSettings.set_partitioning_by_load(Ydb::FeatureFlag::ENABLED); |
| 557 | + } else if (val == "disabled") { |
| 558 | + partitioningSettings.set_partitioning_by_load(Ydb::FeatureFlag::DISABLED); |
| 559 | + } else { |
| 560 | + ctx.AddError( |
| 561 | + TIssue(ctx.GetPosition(setting.Value().Cast<TCoAtom>().Pos()), |
| 562 | + TStringBuilder() << "Unknown feature flag '" << val << "' for auto partitioning by load" |
| 563 | + ) |
| 564 | + ); |
| 565 | + return false; |
| 566 | + } |
| 567 | + } else if (name == "minPartitions") { |
| 568 | + ui64 value = FromString<ui64>( |
| 569 | + setting.Value().Cast<TCoDataCtor>().Literal().Cast<TCoAtom>().Value() |
| 570 | + ); |
| 571 | + if (value) { |
| 572 | + partitioningSettings.set_min_partitions_count(value); |
| 573 | + } else { |
| 574 | + ctx.AddError( |
| 575 | + TIssue(ctx.GetPosition(setting.Name().Pos()), |
| 576 | + "Can't set min partition count to 0" |
| 577 | + ) |
| 578 | + ); |
| 579 | + return false; |
| 580 | + } |
| 581 | + } else if (name == "maxPartitions") { |
| 582 | + ui64 value = FromString<ui64>( |
| 583 | + setting.Value().Cast<TCoDataCtor>().Literal().Cast<TCoAtom>().Value() |
| 584 | + ); |
| 585 | + if (value) { |
| 586 | + partitioningSettings.set_max_partitions_count(value); |
| 587 | + } else { |
| 588 | + ctx.AddError( |
| 589 | + TIssue(ctx.GetPosition(setting.Name().Pos()), |
| 590 | + "Can't set max partition count to 0" |
| 591 | + ) |
| 592 | + ); |
| 593 | + return false; |
| 594 | + } |
| 595 | + } |
| 596 | + |
| 597 | + return true; |
| 598 | + } |
508 | 599 | } |
509 | 600 |
|
510 | 601 | class TKiSinkPlanInfoTransformer : public TGraphTransformerBase { |
@@ -1290,71 +1381,10 @@ class TKiSinkCallableExecutionTransformer : public TAsyncCallbackTransformer<TKi |
1290 | 1381 | alterTableRequest.set_set_compaction_policy(TString( |
1291 | 1382 | setting.Value().Cast<TCoDataCtor>().Literal().Cast<TCoAtom>().Value() |
1292 | 1383 | )); |
1293 | | - } else if (name == "autoPartitioningBySize") { |
1294 | | - auto partitioningSettings = alterTableRequest.mutable_alter_partitioning_settings(); |
1295 | | - auto val = to_lower(TString(setting.Value().Cast<TCoAtom>().Value())); |
1296 | | - if (val == "enabled") { |
1297 | | - partitioningSettings->set_partitioning_by_size(Ydb::FeatureFlag::ENABLED); |
1298 | | - } else if (val == "disabled") { |
1299 | | - partitioningSettings->set_partitioning_by_size(Ydb::FeatureFlag::DISABLED); |
1300 | | - } else { |
1301 | | - auto errText = TStringBuilder() << "Unknown feature flag '" |
1302 | | - << val |
1303 | | - << "' for auto partitioning by size"; |
1304 | | - ctx.AddError(TIssue(ctx.GetPosition(setting.Value().Cast<TCoAtom>().Pos()), |
1305 | | - errText)); |
1306 | | - return SyncError(); |
1307 | | - } |
1308 | | - } else if (name == "partitionSizeMb") { |
1309 | | - ui64 value = FromString<ui64>( |
1310 | | - setting.Value().Cast<TCoDataCtor>().Literal().Cast<TCoAtom>().Value() |
1311 | | - ); |
1312 | | - if (value) { |
1313 | | - auto partitioningSettings = alterTableRequest.mutable_alter_partitioning_settings(); |
1314 | | - partitioningSettings->set_partition_size_mb(value); |
1315 | | - } else { |
1316 | | - ctx.AddError(TIssue(ctx.GetPosition(setting.Name().Pos()), |
1317 | | - "Can't set preferred partition size to 0. " |
1318 | | - "To disable auto partitioning by size use 'SET AUTO_PARTITIONING_BY_SIZE DISABLED'")); |
1319 | | - return SyncError(); |
1320 | | - } |
1321 | | - } else if (name == "autoPartitioningByLoad") { |
1322 | | - auto partitioningSettings = alterTableRequest.mutable_alter_partitioning_settings(); |
1323 | | - TString val = to_lower(TString(setting.Value().Cast<TCoAtom>().Value())); |
1324 | | - if (val == "enabled") { |
1325 | | - partitioningSettings->set_partitioning_by_load(Ydb::FeatureFlag::ENABLED); |
1326 | | - } else if (val == "disabled") { |
1327 | | - partitioningSettings->set_partitioning_by_load(Ydb::FeatureFlag::DISABLED); |
1328 | | - } else { |
1329 | | - auto errText = TStringBuilder() << "Unknown feature flag '" |
1330 | | - << val |
1331 | | - << "' for auto partitioning by load"; |
1332 | | - ctx.AddError(TIssue(ctx.GetPosition(setting.Value().Cast<TCoAtom>().Pos()), |
1333 | | - errText)); |
1334 | | - return SyncError(); |
1335 | | - } |
1336 | | - } else if (name == "minPartitions") { |
1337 | | - ui64 value = FromString<ui64>( |
1338 | | - setting.Value().Cast<TCoDataCtor>().Literal().Cast<TCoAtom>().Value() |
1339 | | - ); |
1340 | | - if (value) { |
1341 | | - auto partitioningSettings = alterTableRequest.mutable_alter_partitioning_settings(); |
1342 | | - partitioningSettings->set_min_partitions_count(value); |
1343 | | - } else { |
1344 | | - ctx.AddError(TIssue(ctx.GetPosition(setting.Name().Pos()), |
1345 | | - "Can't set min partition count to 0")); |
1346 | | - return SyncError(); |
1347 | | - } |
1348 | | - } else if (name == "maxPartitions") { |
1349 | | - ui64 value = FromString<ui64>( |
1350 | | - setting.Value().Cast<TCoDataCtor>().Literal().Cast<TCoAtom>().Value() |
1351 | | - ); |
1352 | | - if (value) { |
1353 | | - auto partitioningSettings = alterTableRequest.mutable_alter_partitioning_settings(); |
1354 | | - partitioningSettings->set_max_partitions_count(value); |
1355 | | - } else { |
1356 | | - ctx.AddError(TIssue(ctx.GetPosition(setting.Name().Pos()), |
1357 | | - "Can't set max partition count to 0")); |
| 1384 | + } else if (IsPartitioningSetting(name)) { |
| 1385 | + if (!ParsePartitioningSettings( |
| 1386 | + *alterTableRequest.mutable_alter_partitioning_settings(), setting, ctx |
| 1387 | + )) { |
1358 | 1388 | return SyncError(); |
1359 | 1389 | } |
1360 | 1390 | } else if (name == "keyBloomFilter") { |
@@ -1476,6 +1506,49 @@ class TKiSinkCallableExecutionTransformer : public TAsyncCallbackTransformer<TKi |
1476 | 1506 | default: |
1477 | 1507 | YQL_ENSURE(false, "Unknown index type: " << (ui32)add_index->type_case()); |
1478 | 1508 | } |
| 1509 | + } else if (name == "alterIndex") { |
| 1510 | + if (maybeAlter.Cast().Actions().Size() > 1) { |
| 1511 | + ctx.AddError( |
| 1512 | + TIssue(ctx.GetPosition(action.Name().Pos()), |
| 1513 | + "ALTER INDEX action cannot be combined with any other ALTER TABLE action" |
| 1514 | + ) |
| 1515 | + ); |
| 1516 | + return SyncError(); |
| 1517 | + } |
| 1518 | + auto listNode = action.Value().Cast<TCoNameValueTupleList>(); |
| 1519 | + for (const auto& indexSetting : listNode) { |
| 1520 | + auto settingName = indexSetting.Name().Value(); |
| 1521 | + if (settingName == "indexName") { |
| 1522 | + auto indexName = indexSetting.Value().Cast<TCoAtom>().StringValue(); |
| 1523 | + auto indexTablePath = NKikimr::NKqp::NSchemeHelpers::CreateIndexTablePath(table.Metadata->Name, indexName); |
| 1524 | + alterTableRequest.set_path(std::move(indexTablePath)); |
| 1525 | + } else if (settingName == "tableSettings") { |
| 1526 | + auto tableSettings = indexSetting.Value().Cast<TCoNameValueTupleList>(); |
| 1527 | + for (const auto& tableSetting : tableSettings) { |
| 1528 | + if (IsPartitioningSetting(tableSetting.Name().Value())) { |
| 1529 | + if (!ParsePartitioningSettings( |
| 1530 | + *alterTableRequest.mutable_alter_partitioning_settings(), tableSetting, ctx |
| 1531 | + )) { |
| 1532 | + return SyncError(); |
| 1533 | + } |
| 1534 | + } else { |
| 1535 | + ctx.AddError( |
| 1536 | + TIssue(ctx.GetPosition(tableSetting.Name().Pos()), |
| 1537 | + TStringBuilder() << "Unknown index table setting: " << name |
| 1538 | + ) |
| 1539 | + ); |
| 1540 | + return SyncError(); |
| 1541 | + } |
| 1542 | + } |
| 1543 | + } else { |
| 1544 | + ctx.AddError( |
| 1545 | + TIssue(ctx.GetPosition(indexSetting.Name().Pos()), |
| 1546 | + TStringBuilder() << "Unknown alter index setting: " << settingName |
| 1547 | + ) |
| 1548 | + ); |
| 1549 | + return SyncError(); |
| 1550 | + } |
| 1551 | + } |
1479 | 1552 | } else if (name == "dropIndex") { |
1480 | 1553 | auto nameNode = action.Value().Cast<TCoAtom>(); |
1481 | 1554 | alterTableRequest.add_drop_indexes(TString(nameNode.Value())); |
|
0 commit comments