Skip to content

Commit

Permalink
Fix optimizer and return back KQP peephole type check. (#842)
Browse files Browse the repository at this point in the history
* Fix optimizer and return back KQP peephole type check.

* A little fix.

* Canonize test.
  • Loading branch information
Tony-Romanov authored Jan 29, 2024
1 parent 14521dd commit 93067e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
10 changes: 3 additions & 7 deletions ydb/core/kqp/opt/peephole/kqp_opt_peephole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ TStatus ReplaceNonDetFunctionsWithParams(TExprNode::TPtr& input, TExprContext& c
class TKqpPeepholeTransformer : public TOptimizeTransformerBase {
public:
TKqpPeepholeTransformer(TTypeAnnotationContext& typesCtx)
: TOptimizeTransformerBase(nullptr, NYql::NLog::EComponent::ProviderKqp, {})
, TypesCtx(typesCtx)
: TOptimizeTransformerBase(&typesCtx, NYql::NLog::EComponent::ProviderKqp, {})
{
#define HNDL(name) "KqpPeephole-"#name, Hndl(&TKqpPeepholeTransformer::name)
AddHandler(0, &TDqReplicate::Match, HNDL(RewriteReplicate));
Expand Down Expand Up @@ -134,13 +133,13 @@ class TKqpPeepholeTransformer : public TOptimizeTransformerBase {
}

TMaybeNode<TExprBase> BuildWideReadTable(TExprBase node, TExprContext& ctx) {
TExprBase output = KqpBuildWideReadTable(node, ctx, TypesCtx);
TExprBase output = KqpBuildWideReadTable(node, ctx, *Types);
DumpAppliedRule("BuildWideReadTable", node.Ptr(), output.Ptr(), ctx);
return output;
}

TMaybeNode<TExprBase> RewriteLength(TExprBase node, TExprContext& ctx) {
TExprBase output = DqPeepholeRewriteLength(node, ctx, TypesCtx);
TExprBase output = DqPeepholeRewriteLength(node, ctx, *Types);
DumpAppliedRule("RewriteLength", node.Ptr(), output.Ptr(), ctx);
return output;
}
Expand All @@ -150,9 +149,6 @@ class TKqpPeepholeTransformer : public TOptimizeTransformerBase {
DumpAppliedRule("RewriteKqpWriteConstraint", node.Ptr(), output.Ptr(), ctx);
return output;
}

private:
TTypeAnnotationContext& TypesCtx;
};

struct TKqpPeepholePipelineConfigurator : IPipelineConfigurator {
Expand Down
10 changes: 5 additions & 5 deletions ydb/library/yql/dq/opt/dq_opt_peephole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,18 +511,18 @@ NNodes::TExprBase DqPeepholeRewriteJoinDict(const NNodes::TExprBase& node, TExpr
rightKeySelector = BuildDictKeySelector(ctx, joinDict.Pos(), rightKeys, keyTypeItems, castKeyRight);
}

auto streamToDict = [&ctx](const TExprBase& input, const TExprNode::TPtr& keySelector) {
const auto streamToDict = [&ctx](const TExprBase& input, const TExprNode::TPtr& keySelector) {
return Build<TCoSqueezeToDict>(ctx, input.Pos())
.Stream(input)
.Stream(TCoIterator::Match(input.Raw()) ? TExprBase(ctx.RenameNode(input.Ref(), TCoToFlow::CallableName())) : input)
.KeySelector(keySelector)
.PayloadSelector()
.Args({"item"})
.Body("item")
.Build()
.Settings()
.Add<TCoAtom>().Build("Hashed")
.Add<TCoAtom>().Build("Many")
.Add<TCoAtom>().Build("Compact")
.Add<TCoAtom>().Build("Hashed", TNodeFlags::Default)
.Add<TCoAtom>().Build("Many", TNodeFlags::Default)
.Add<TCoAtom>().Build("Compact", TNodeFlags::Default)
.Build()
.Done();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,18 @@
"PlanNodeType": "Connection",
"Plans": [
{
"Node Type": "FullJoin (JoinDict)-ConstantExpr",
"Node Type": "FullJoin (JoinDict)",
"Operators": [
{
"Inputs": [
{
"ExternalPlanNodeId": 4
},
{
"InternalOperatorId": 1
"Other": "ConstantExpression"
}
],
"Name": "FullJoin (JoinDict)"
},
{
"Inputs": [],
"Iterator": "[{id: 1}]",
"Name": "Iterator"
}
],
"PlanNodeId": 5,
Expand Down

0 comments on commit 93067e7

Please sign in to comment.