Skip to content

Commit 438ee8d

Browse files
authored
Preserve statistics for S3Settings node (#5012)
1 parent df9ee81 commit 438ee8d

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

ydb/library/yql/providers/dq/provider/yql_dq_statistics.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,16 @@ class TDqsStatisticsTransformer : public NDq::TDqStatisticsTransformerBase {
2121

2222
bool BeforeLambdasSpecific(const TExprNode::TPtr& input, TExprContext& ctx) override {
2323
bool matched = true;
24-
bool hasDqSource = false;
25-
26-
if (TDqReadWrapBase::Match(input.Get()) || (hasDqSource = TDqSourceWrapBase::Match(input.Get()))) {
27-
auto node = hasDqSource
28-
? input
29-
: input->Child(TDqReadWrapBase::idx_Input);
30-
auto dataSourceChildIndex = 1;
31-
YQL_ENSURE(node->ChildrenSize() > 1);
32-
YQL_ENSURE(node->Child(dataSourceChildIndex)->IsCallable("DataSource"));
33-
auto dataSourceName = node->Child(dataSourceChildIndex)->Child(0)->Content();
34-
auto datasource = State->TypeCtx->DataSourceMap.FindPtr(dataSourceName);
35-
YQL_ENSURE(datasource);
36-
if (auto dqIntegration = (*datasource)->GetDqIntegration()) {
37-
auto stat = dqIntegration->ReadStatistics(node, ctx);
38-
if (stat) {
39-
State->TypeCtx->SetStats(input.Get(), std::make_shared<TOptimizerStatistics>(std::move(*stat)));
40-
}
24+
25+
if (TDqReadWrapBase::Match(input.Get())) {
26+
if (auto stat = GetStats(input->Child(TDqReadWrapBase::idx_Input), ctx)) {
27+
State->TypeCtx->SetStats(input.Get(), stat);
28+
}
29+
} else if (TDqSourceWrapBase::Match(input.Get())) {
30+
if (auto stat = GetStats(input, ctx)) {
31+
State->TypeCtx->SetStats(input.Get(), stat);
32+
// This node can be split, so to preserve the statistics, we also expose it to settings
33+
State->TypeCtx->SetStats(input->Child(TDqSourceWrapBase::idx_Settings), stat);
4134
}
4235
} else {
4336
matched = false;
@@ -52,6 +45,21 @@ class TDqsStatisticsTransformer : public NDq::TDqStatisticsTransformerBase {
5245
}
5346

5447
private:
48+
std::shared_ptr<TOptimizerStatistics> GetStats(const TExprNode::TPtr& node, TExprContext& ctx) {
49+
auto dataSourceChildIndex = 1;
50+
YQL_ENSURE(node->ChildrenSize() > 1);
51+
YQL_ENSURE(node->Child(dataSourceChildIndex)->IsCallable("DataSource"));
52+
auto dataSourceName = node->Child(dataSourceChildIndex)->Child(0)->Content();
53+
auto datasource = State->TypeCtx->DataSourceMap.FindPtr(dataSourceName);
54+
if (auto dqIntegration = (*datasource)->GetDqIntegration()) {
55+
auto stat = dqIntegration->ReadStatistics(node, ctx);
56+
if (stat) {
57+
return std::make_shared<TOptimizerStatistics>(std::move(*stat));
58+
}
59+
}
60+
return {};
61+
}
62+
5563
TDqStatePtr State;
5664
};
5765

0 commit comments

Comments
 (0)