@@ -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
5447private:
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