1515#include < yql/essentials/core/yql_opt_normalize_depends_on.h>
1616#include < yql/essentials/core/yql_opt_proposed_by_data.h>
1717#include < yql/essentials/core/yql_opt_rewrite_io.h>
18+ #include < yql/essentials/utils/log/log.h>
1819
1920#include < yql/essentials/providers/common/provider/yql_provider_names.h>
2021
@@ -166,8 +167,42 @@ TTransformationPipeline& TTransformationPipeline::AddFinalCommonOptimization(EYq
166167 return *this ;
167168}
168169
169- TTransformationPipeline& TTransformationPipeline::AddOptimization (bool checkWorld, bool withFinalOptimization, EYqlIssueCode issueCode) {
170+ TTransformationPipeline& TTransformationPipeline::AddOptimizationWithLineage (bool checkWorld, bool withFinalOptimization, EYqlIssueCode issueCode) {
170171 AddCommonOptimization (false , issueCode);
172+ Transformers_.push_back (TTransformStage (
173+ CreateChoiceGraphTransformer (
174+ [&typesCtx = std::as_const (*TypeAnnotationContext_)](const TExprNode::TPtr&, TExprContext&) {
175+ return typesCtx.EnableLineage ;
176+ },
177+ TTransformStage (
178+ CreateFunctorTransformer (
179+ [typeCtx = TypeAnnotationContext_](const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) {
180+ output = input;
181+ try {
182+ CalculateLineage (*input, *typeCtx, ctx, false );
183+ } catch (const std::exception& e) {
184+ YQL_LOG (ERROR) << " CalculateLineage error: " << e.what ();
185+ typeCtx->CorrectLineage = false ;
186+ }
187+ return IGraphTransformer::TStatus::Ok;
188+ }),
189+ " Lineage" ,
190+ issueCode),
191+ TTransformStage (
192+ new TNullTransformer (),
193+ " SkipLineage" ,
194+ issueCode)),
195+ " LineageCalculation" ,
196+ issueCode));
197+ AddProviderOptimization (issueCode);
198+ if (withFinalOptimization) {
199+ AddFinalCommonOptimization (issueCode);
200+ }
201+ AddCheckExecution (checkWorld, issueCode);
202+ return *this ;
203+ }
204+
205+ TTransformationPipeline& TTransformationPipeline::AddProviderOptimization (EYqlIssueCode issueCode) {
171206 Transformers_.push_back (TTransformStage (
172207 CreateChoiceGraphTransformer (
173208 [&typesCtx = std::as_const (*TypeAnnotationContext_)](const TExprNode::TPtr&, TExprContext&) {
@@ -210,6 +245,12 @@ TTransformationPipeline& TTransformationPipeline::AddOptimization(bool checkWorl
210245 CreatePhysicalFinalizers (*TypeAnnotationContext_),
211246 " PhysicalFinalizers" ,
212247 issueCode));
248+ return *this ;
249+ }
250+
251+ TTransformationPipeline& TTransformationPipeline::AddOptimization (bool checkWorld, bool withFinalOptimization, EYqlIssueCode issueCode) {
252+ AddCommonOptimization (false , issueCode);
253+ AddProviderOptimization (issueCode);
213254 if (withFinalOptimization) {
214255 AddFinalCommonOptimization (issueCode);
215256 }
@@ -223,7 +264,7 @@ TTransformationPipeline& TTransformationPipeline::AddLineageOptimization(TMaybe<
223264 CreateFunctorTransformer (
224265 [typeCtx = TypeAnnotationContext_, &lineageOut](const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) {
225266 output = input;
226- lineageOut = CalculateLineage (*input, *typeCtx, ctx);
267+ lineageOut = CalculateLineage (*input, *typeCtx, ctx, true );
227268 return IGraphTransformer::TStatus::Ok;
228269 }),
229270 " LineageScanner" ,
0 commit comments