Skip to content

Commit 420ffcf

Browse files
authored
Optimize attribute fetch loop for source tables in YT (#11073)
1 parent e17223e commit 420ffcf

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

ydb/library/yql/providers/yt/gateway/native/yql_yt_native.cpp

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,38 +2580,22 @@ class TYtNativeGateway : public IYtGateway {
25802580
TTableInfoResult& result)
25812581
{
25822582
TVector<NYT::TNode> attributes(tables.size());
2583+
TVector<TMaybe<NYT::TNode>> linkAttributes(tables.size());
2584+
std::atomic<bool> linksPresent = false;
25832585
{
25842586
auto batchGet = tx->CreateBatchRequest();
25852587
TVector<TFuture<void>> batchRes(Reserve(idxs.size()));
25862588
for (auto& idx: idxs) {
2587-
batchRes.push_back(batchGet->Get(idx.second + "/@").Apply([&attributes, idx] (const TFuture<NYT::TNode>& res) {
2588-
attributes[idx.first] = res.GetValue();
2589-
}));
2590-
}
2591-
batchGet->ExecuteBatch();
2592-
WaitExceptionOrAll(batchRes).GetValue();
2593-
}
2594-
{
2595-
auto batchGet = tx->CreateBatchRequest();
2596-
TVector<TFuture<void>> batchRes;
2597-
auto getOpts = TGetOptions()
2598-
.AttributeFilter(TAttributeFilter()
2599-
.AddAttribute("type")
2600-
.AddAttribute(TString{QB2Premapper})
2601-
.AddAttribute(TString{YqlRowSpecAttribute})
2602-
);
2603-
for (auto& idx: idxs) {
2604-
batchRes.push_back(batchGet->Get(tables[idx.first].Table() + "&/@", getOpts).Apply([idx, &attributes](const TFuture<NYT::TNode>& f) {
2589+
batchRes.push_back(batchGet->Get(tables[idx.first].Table() + "&/@").Apply(
2590+
[&attributes, &linkAttributes, &linksPresent, idx] (const TFuture<NYT::TNode>& res) {
26052591
try {
2606-
NYT::TNode attrs = f.GetValue();
2607-
if (GetTypeFromAttributes(attrs, false) == "link") {
2608-
// override some attributes by the link ones
2609-
if (attrs.HasKey(QB2Premapper)) {
2610-
attributes[idx.first][QB2Premapper] = attrs[QB2Premapper];
2611-
}
2612-
if (attrs.HasKey(YqlRowSpecAttribute)) {
2613-
attributes[idx.first][YqlRowSpecAttribute] = attrs[YqlRowSpecAttribute];
2614-
}
2592+
NYT::TNode attrs = res.GetValue();
2593+
auto type = GetTypeFromAttributes(attrs, false);
2594+
if (type == "link") {
2595+
linkAttributes[idx.first] = attrs;
2596+
linksPresent.store(true);
2597+
} else {
2598+
attributes[idx.first] = attrs;
26152599
}
26162600
} catch (const TErrorResponse& e) {
26172601
// Yt returns NoSuchTransaction as inner issue for ResolveError
@@ -2625,7 +2609,30 @@ class TYtNativeGateway : public IYtGateway {
26252609
batchGet->ExecuteBatch();
26262610
WaitExceptionOrAll(batchRes).GetValue();
26272611
}
2628-
2612+
if (linksPresent.load()) {
2613+
auto batchGet = tx->CreateBatchRequest();
2614+
TVector<TFuture<void>> batchRes;
2615+
for (auto& idx : idxs) {
2616+
if (!linkAttributes[idx.first]) {
2617+
continue;
2618+
}
2619+
const auto& linkAttr = *linkAttributes[idx.first];
2620+
batchRes.push_back(batchGet->Get(idx.second + "/@").Apply(
2621+
[idx, &linkAttr, &attributes](const TFuture<NYT::TNode>& f) {
2622+
NYT::TNode attrs = f.GetValue();
2623+
attributes[idx.first] = attrs;
2624+
// override some attributes by the link ones
2625+
if (linkAttr.HasKey(QB2Premapper)) {
2626+
attributes[idx.first][QB2Premapper] = linkAttr[QB2Premapper];
2627+
}
2628+
if (linkAttr.HasKey(YqlRowSpecAttribute)) {
2629+
attributes[idx.first][YqlRowSpecAttribute] = linkAttr[YqlRowSpecAttribute];
2630+
}
2631+
}));
2632+
}
2633+
batchGet->ExecuteBatch();
2634+
WaitExceptionOrAll(batchRes).GetValue();
2635+
}
26292636
auto batchGet = tx->CreateBatchRequest();
26302637
TVector<TFuture<void>> batchRes;
26312638

0 commit comments

Comments
 (0)