Skip to content

Commit 69211f5

Browse files
committed
Add more and better checks
1 parent c1733e7 commit 69211f5

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

ydb/core/kqp/opt/kqp_query_plan.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@ class TxPlanSerializer {
467467
if (!TryFromString(wideColumnName, idx)) {
468468
return wideColumnName;
469469
}
470+
471+
YQL_ENSURE(idx < settings.OutputNarrowType->GetSize(),
472+
"Failed to lookup column name for index " << idx << " in type " << settings.OutputNarrowType->ToString());
473+
470474
return TString(settings.OutputNarrowType->GetItems()[idx]->GetName());
471475
};
472476

ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,6 @@ bool CanPropagateWideBlockThroughChannel(
287287
return false;
288288
}
289289

290-
auto outputItemType = program.Lambda().Ref().GetTypeAnn()->Cast<TStreamExprType>()->GetItemType();
291-
if (IsWideBlockType(*outputItemType)) {
292-
// output is already wide block
293-
return false;
294-
}
295-
296290
YQL_ENSURE(stageSettings.OutputNarrowType);
297291

298292
if (!IsCompatibleWithBlocks(program.Pos(), *stageSettings.OutputNarrowType, ctx, typesCtx)) {
@@ -306,6 +300,15 @@ bool CanPropagateWideBlockThroughChannel(
306300
return false;
307301
}
308302

303+
auto typeAnnotation = program.Lambda().Ref().GetTypeAnn();
304+
305+
YQL_ENSURE(typeAnnotation, "Program for stage " << output.Stage().Ref().UniqueId() << " doesn't have type annotation");
306+
307+
if (IsWideBlockType(*typeAnnotation->Cast<TStreamExprType>()->GetItemType())) {
308+
// output is already wide block
309+
return false;
310+
}
311+
309312
return true;
310313
}
311314

@@ -445,8 +448,6 @@ TMaybeNode<TKqpPhysicalTx> PeepholeOptimize(const TKqpPhysicalTx& tx, TExprConte
445448
.ArgsType(ExpandType(stage.Pos(), *ctx.MakeType<TTupleExprType>(argTypes), ctx))
446449
.Done();
447450

448-
YQL_ENSURE(programs.emplace(stage.Ref().UniqueId(), program).second);
449-
450451
const bool allowNonDeterministicFunctions = !program.Lambda().Body().Maybe<TKqpEffects>();
451452

452453
TExprNode::TPtr newProgram;
@@ -468,7 +469,7 @@ TMaybeNode<TKqpPhysicalTx> PeepholeOptimize(const TKqpPhysicalTx& tx, TExprConte
468469
}
469470

470471
optimizedStages.emplace(stage.Ref().UniqueId());
471-
programs.at(stage.Ref().UniqueId()) = TKqpProgram(newProgram);
472+
YQL_ENSURE(programs.emplace(stage.Ref().UniqueId(), TKqpProgram(newProgram)).second);
472473
}
473474

474475
TVector<TKqpParamBinding> bindings(tx.ParamBindings().begin(), tx.ParamBindings().end());

0 commit comments

Comments
 (0)