Skip to content

Commit

Permalink
Preserve statistics for S3Settings node
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed May 30, 2024
1 parent f507540 commit 2a30389
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions ydb/library/yql/providers/dq/provider/yql_dq_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,16 @@ class TDqsStatisticsTransformer : public NDq::TDqStatisticsTransformerBase {

bool BeforeLambdasSpecific(const TExprNode::TPtr& input, TExprContext& ctx) override {
bool matched = true;
bool hasDqSource = false;

if (TDqReadWrapBase::Match(input.Get()) || (hasDqSource = TDqSourceWrapBase::Match(input.Get()))) {
auto node = hasDqSource
? input
: input->Child(TDqReadWrapBase::idx_Input);
auto dataSourceChildIndex = 1;
YQL_ENSURE(node->ChildrenSize() > 1);
YQL_ENSURE(node->Child(dataSourceChildIndex)->IsCallable("DataSource"));
auto dataSourceName = node->Child(dataSourceChildIndex)->Child(0)->Content();
auto datasource = State->TypeCtx->DataSourceMap.FindPtr(dataSourceName);
YQL_ENSURE(datasource);
if (auto dqIntegration = (*datasource)->GetDqIntegration()) {
auto stat = dqIntegration->ReadStatistics(node, ctx);
if (stat) {
State->TypeCtx->SetStats(input.Get(), std::make_shared<TOptimizerStatistics>(std::move(*stat)));
}

if (TDqReadWrapBase::Match(input.Get())) {
if (auto stat = GetStats(input->Child(TDqReadWrapBase::idx_Input), ctx)) {
State->TypeCtx->SetStats(input.Get(), stat);
}
} else if (TDqSourceWrapBase::Match(input.Get())) {
if (auto stat = GetStats(input, ctx)) {
State->TypeCtx->SetStats(input.Get(), stat);
// This node can be split, so to preserve the statistics, we also expose it to settings
State->TypeCtx->SetStats(input->Child(TDqSourceWrapBase::idx_Settings), stat);
}
} else {
matched = false;
Expand All @@ -52,6 +45,21 @@ class TDqsStatisticsTransformer : public NDq::TDqStatisticsTransformerBase {
}

private:
std::shared_ptr<TOptimizerStatistics> GetStats(const TExprNode::TPtr& node, TExprContext& ctx) {
auto dataSourceChildIndex = 1;
YQL_ENSURE(node->ChildrenSize() > 1);
YQL_ENSURE(node->Child(dataSourceChildIndex)->IsCallable("DataSource"));
auto dataSourceName = node->Child(dataSourceChildIndex)->Child(0)->Content();
auto datasource = State->TypeCtx->DataSourceMap.FindPtr(dataSourceName);
if (auto dqIntegration = (*datasource)->GetDqIntegration()) {
auto stat = dqIntegration->ReadStatistics(node, ctx);
if (stat) {
return std::make_shared<TOptimizerStatistics>(std::move(*stat));
}
}
return {};
}

TDqStatePtr State;
};

Expand Down

0 comments on commit 2a30389

Please sign in to comment.