2
2
#include " actors/kqp_ic_gateway_actors.h"
3
3
4
4
#include < ydb/core/base/path.h>
5
+ #include < ydb/core/base/table_index.h>
5
6
#include < ydb/core/external_sources/external_source_factory.h>
6
7
#include < ydb/core/kqp/federated_query/kqp_federated_query_actors.h>
7
8
#include < ydb/core/kqp/gateway/utils/scheme_helpers.h>
@@ -175,7 +176,7 @@ TTableMetadataResult GetTableMetadataResult(const NSchemeCache::TSchemeCacheNavi
175
176
THashMap<TString, NYql::TKikimrPathId> sequences;
176
177
177
178
for (const auto & sequenceDesc : entry.Sequences ) {
178
- sequences[sequenceDesc.GetName ()] =
179
+ sequences[sequenceDesc.GetName ()] =
179
180
NYql::TKikimrPathId (sequenceDesc.GetPathId ().GetOwnerId (), sequenceDesc.GetPathId ().GetLocalId ());
180
181
}
181
182
@@ -187,7 +188,7 @@ TTableMetadataResult GetTableMetadataResult(const NSchemeCache::TSchemeCacheNavi
187
188
const TString typeName = GetTypeName (NScheme::TTypeInfoMod{columnDesc.PType , columnDesc.PTypeMod });
188
189
auto defaultKind = NKikimrKqp::TKqpColumnMetadataProto::DEFAULT_KIND_UNSPECIFIED;
189
190
NYql::TKikimrPathId defaultFromSequencePathId = {};
190
-
191
+
191
192
if (columnDesc.IsDefaultFromSequence ()) {
192
193
defaultKind = NKikimrKqp::TKqpColumnMetadataProto::DEFAULT_KIND_SEQUENCE;
193
194
auto sequenceIt = sequences.find (columnDesc.DefaultFromSequence );
@@ -196,7 +197,7 @@ TTableMetadataResult GetTableMetadataResult(const NSchemeCache::TSchemeCacheNavi
196
197
} else if (columnDesc.IsDefaultFromLiteral ()) {
197
198
defaultKind = NKikimrKqp::TKqpColumnMetadataProto::DEFAULT_KIND_LITERAL;
198
199
}
199
-
200
+
200
201
tableMeta->Columns .emplace (
201
202
columnDesc.Name ,
202
203
NYql::TKikimrColumnMetadata (
@@ -400,11 +401,15 @@ TString GetDebugString(const std::pair<NKikimr::TIndexId, TString>& id) {
400
401
return TStringBuilder () << " Path: " << id.second << " TableId: " << id.first ;
401
402
}
402
403
403
- void UpdateMetadataIfSuccess (NYql::TKikimrTableMetadataPtr ptr, size_t idx, const TTableMetadataResult& value) {
404
- if (value.Success ()) {
405
- ptr->SecondaryGlobalIndexMetadata [idx] = value.Metadata ;
404
+ void UpdateMetadataIfSuccess (NYql::TKikimrTableMetadataPtr& implTable, TTableMetadataResult& value) {
405
+ YQL_ENSURE (value.Success ());
406
+ if (!implTable) {
407
+ implTable = std::move (value.Metadata );
408
+ return ;
406
409
}
407
-
410
+ YQL_ENSURE (!implTable->Next );
411
+ YQL_ENSURE (implTable->Name < value.Metadata ->Name );
412
+ implTable->Next = std::move (value.Metadata );
408
413
}
409
414
410
415
void SetError (TTableMetadataResult& externalDataSourceMetadata, const TString& error) {
@@ -618,28 +623,21 @@ NThreading::TFuture<TTableMetadataResult> TKqpTableMetadataLoader::LoadIndexMeta
618
623
const auto & tableName = tableMetadata->Name ;
619
624
const size_t indexesCount = tableMetadata->Indexes .size ();
620
625
621
- TVector<NThreading::TFuture<TGenericResult >> children;
626
+ TVector<NThreading::TFuture<TTableMetadataResult >> children;
622
627
children.reserve (indexesCount);
623
628
624
- tableMetadata->SecondaryGlobalIndexMetadata .resize (indexesCount);
625
629
const ui64 tableOwnerId = tableMetadata->PathId .OwnerId ();
626
630
627
631
for (size_t i = 0 ; i < indexesCount; i++) {
628
632
const auto & index = tableMetadata->Indexes [i];
629
- const auto indexTablePaths = NSchemeHelpers::CreateIndexTablePath (tableName, index.Type , index.Name );
630
- for (const auto & indexTablePath : indexTablePaths ) {
633
+ const auto implTablePaths = NSchemeHelpers::CreateIndexTablePath (tableName, index.Type , index.Name );
634
+ for (const auto & implTablePath : implTablePaths ) {
631
635
if (!index.SchemaVersion ) {
632
636
LOG_DEBUG_S (*ActorSystem, NKikimrServices::KQP_GATEWAY, " Load index metadata without schema version check index: " << index.Name );
633
637
children.push_back (
634
- LoadTableMetadata (cluster, indexTablePath ,
638
+ LoadTableMetadata (cluster, implTablePath ,
635
639
TLoadTableMetadataSettings ().WithPrivateTables (true ), database, userToken)
636
- .Apply ([i, tableMetadata](const TFuture<TTableMetadataResult>& result) {
637
- auto value = result.GetValue ();
638
- UpdateMetadataIfSuccess (tableMetadata, i, value);
639
- return static_cast <TGenericResult>(value);
640
- })
641
640
);
642
-
643
641
} else {
644
642
LOG_DEBUG_S (*ActorSystem, NKikimrServices::KQP_GATEWAY, " Load index metadata with schema version check"
645
643
<< " index: " << index.Name
@@ -650,12 +648,7 @@ NThreading::TFuture<TTableMetadataResult> TKqpTableMetadataLoader::LoadIndexMeta
650
648
auto ownerId = index.PathOwnerId ? index.PathOwnerId : tableOwnerId; // for compat with 20-2
651
649
children.push_back (
652
650
LoadIndexMetadataByPathId (cluster,
653
- NKikimr::TIndexId (ownerId, index.LocalPathId , index.SchemaVersion ), indexTablePath, database, userToken)
654
- .Apply ([i, tableMetadata](const TFuture<TTableMetadataResult>& result) {
655
- auto value = result.GetValue ();
656
- UpdateMetadataIfSuccess (tableMetadata, i, value);
657
- return static_cast <TGenericResult>(value);
658
- })
651
+ NKikimr::TIndexId (ownerId, index.LocalPathId , index.SchemaVersion ), implTablePath, database, userToken)
659
652
);
660
653
661
654
}
@@ -666,14 +659,26 @@ NThreading::TFuture<TTableMetadataResult> TKqpTableMetadataLoader::LoadIndexMeta
666
659
auto loadIndexMetadataChecker =
667
660
[ptr, result{std::move (loadTableMetadataResult)}, children](const NThreading::TFuture<void >) mutable {
668
661
bool loadOk = true ;
669
- for (const auto & child : children) {
670
- result.AddIssues (child.GetValue ().Issues ());
671
- if (!child.GetValue ().Success ()) {
672
- loadOk = false ;
662
+
663
+ const auto indexesCount = result.Metadata ->Indexes .size ();
664
+ result.Metadata ->ImplTables .resize (indexesCount);
665
+ auto it = children.begin ();
666
+ for (size_t i = 0 ; i < indexesCount; i++) {
667
+ for (const auto & _ : NTableIndex::GetImplTables (NYql::TIndexDescription::ConvertIndexType (
668
+ result.Metadata ->Indexes [i].Type ))) {
669
+ YQL_ENSURE (it != children.end ());
670
+ auto value = it++->ExtractValue ();
671
+ result.AddIssues (value.Issues ());
672
+ if (loadOk && (loadOk = value.Success ())) {
673
+ UpdateMetadataIfSuccess (result.Metadata ->ImplTables [i], value);
674
+ }
673
675
}
674
676
}
677
+ YQL_ENSURE (it == children.end ());
678
+
675
679
auto locked = ptr.lock ();
676
680
if (!loadOk || !locked) {
681
+ result.Metadata ->ImplTables .clear ();
677
682
result.SetStatus (TIssuesIds::KIKIMR_INDEX_METADATA_LOAD_FAILED);
678
683
} else {
679
684
locked->OnLoadedTableMetadata (result);
@@ -909,13 +914,17 @@ NThreading::TFuture<TTableMetadataResult> TKqpTableMetadataLoader::LoadTableMeta
909
914
case EKind::KindIndex: {
910
915
Y_ENSURE (entry.ListNodeEntry , " expected children list" );
911
916
for (const auto & child : entry.ListNodeEntry ->Children ) {
917
+ if (!table.EndsWith (child.Name )) {
918
+ continue ;
919
+ }
912
920
TIndexId pathId = TIndexId (child.PathId , child.SchemaVersion );
913
921
914
922
LoadTableMetadataCache (cluster, std::make_pair (pathId, table), settings, database, userToken)
915
923
.Apply ([promise](const TFuture<TTableMetadataResult>& result) mutable
916
924
{
917
925
promise.SetValue (result.GetValue ());
918
926
});
927
+ break ;
919
928
}
920
929
break ;
921
930
}
0 commit comments