Skip to content

Commit 24d3e91

Browse files
Merge 6111922 into 8a523e2
2 parents 8a523e2 + 6111922 commit 24d3e91

File tree

12 files changed

+65
-52
lines changed

12 files changed

+65
-52
lines changed

ydb/core/kqp/provider/yql_kikimr_exec.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ class TKiSourceCallableExecutionTransformer : public TAsyncCallbackTransformer<T
764764
lambda = NDq::BuildProgram(
765765
programLambda, *paramsType, compiler, SessionCtx->Query().QueryData->GetAllocState()->TypeEnv,
766766
*SessionCtx->Query().QueryData->GetAllocState()->HolderFactory.GetFunctionRegistry(),
767-
ctx, fakeReads);
767+
ctx, fakeReads, {});
768768

769769
NKikimr::NMiniKQL::TProgramBuilder programBuilder(SessionCtx->Query().QueryData->GetAllocState()->TypeEnv,
770770
*SessionCtx->Query().QueryData->GetAllocState()->HolderFactory.GetFunctionRegistry());

ydb/core/kqp/query_compiler/kqp_query_compiler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ class TKqpQueryCompiler : public IKqpQueryCompiler {
778778

779779
auto paramsType = CollectParameters(stage, ctx);
780780
auto programBytecode = NDq::BuildProgram(stage.Program(), *paramsType, *KqlCompiler, TypeEnv, FuncRegistry,
781-
ctx, {});
781+
ctx, {}, {});
782782

783783
auto& programProto = *stageProto.MutableProgram();
784784
programProto.SetRuntimeVersion(NYql::NDqProto::ERuntimeVersion::RUNTIME_VERSION_YQL_1_0);

ydb/library/yql/dq/tasks/dq_task_program.cpp

+34-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,41 @@
22

33
#include <ydb/library/yql/core/yql_expr_optimize.h>
44
#include <ydb/library/yql/minikql/mkql_node_serialization.h>
5+
#include <ydb/library/yql/minikql/mkql_runtime_version.h>
56
#include <ydb/library/yql/providers/common/mkql/yql_type_mkql.h>
67

78
namespace NYql::NDq {
89

910
using namespace NKikimr::NMiniKQL;
1011
using namespace NYql::NNodes;
1112

13+
14+
class TSpillingTransformProvider {
15+
public:
16+
17+
TSpillingTransformProvider(const TSpillingSettings& spillingSettings): SpillingSettings(spillingSettings){};
18+
19+
TCallableVisitFunc operator()(TInternName name) {
20+
if (RuntimeVersion >= 50U && SpillingSettings.EnableSpillingInGraceJoin && (name == "GraceJoin" || name == "GraceSelfJoin")) {
21+
return [name](NKikimr::NMiniKQL::TCallable& callable, const TTypeEnvironment& env) {
22+
TCallableBuilder callableBuilder(env,
23+
TStringBuilder() << callable.GetType()->GetName() << "WithSpilling",
24+
callable.GetType()->GetReturnType(), false);
25+
for (ui32 i = 0; i < callable.GetInputsCount(); ++i) {
26+
callableBuilder.Add(callable.GetInput(i));
27+
}
28+
return TRuntimeNode(callableBuilder.Build(), false);
29+
};
30+
}
31+
32+
return TCallableVisitFunc();
33+
}
34+
35+
private:
36+
37+
TSpillingSettings SpillingSettings;
38+
};
39+
1240
const TStructExprType* CollectParameters(NNodes::TCoLambda program, TExprContext& ctx) {
1341
TVector<const TItemExprType*> memberTypes;
1442

@@ -27,7 +55,7 @@ const TStructExprType* CollectParameters(NNodes::TCoLambda program, TExprContext
2755

2856
TString BuildProgram(NNodes::TCoLambda program, const TStructExprType& paramsType,
2957
const NCommon::IMkqlCallableCompiler& compiler, const TTypeEnvironment& typeEnv,
30-
const IFunctionRegistry& funcRegistry, TExprContext& exprCtx, const TVector<TExprBase>& reads)
58+
const IFunctionRegistry& funcRegistry, TExprContext& exprCtx, const TVector<TExprBase>& reads, const TSpillingSettings& spillingSettings)
3159
{
3260
TProgramBuilder pgmBuilder(typeEnv, funcRegistry);
3361

@@ -49,6 +77,11 @@ TString BuildProgram(NNodes::TCoLambda program, const TStructExprType& paramsTyp
4977

5078
TRuntimeNode rootNode = MkqlBuildExpr(program.Body().Ref(), ctx);
5179

80+
TExploringNodeVisitor explorer;
81+
explorer.Walk(rootNode.GetNode(), typeEnv);
82+
bool wereChanges = false;
83+
rootNode = SinglePassVisitCallables(rootNode, explorer, TSpillingTransformProvider(spillingSettings), typeEnv, true, wereChanges);
84+
5285
TStructLiteralBuilder structBuilder(typeEnv);
5386
structBuilder.Add("Program", rootNode);
5487
structBuilder.Add("Inputs", pgmBuilder.NewTuple(inputNodes));
@@ -64,7 +97,6 @@ TString BuildProgram(NNodes::TCoLambda program, const TStructExprType& paramsTyp
6497

6598
auto programNode = structBuilder.Build();
6699

67-
TExploringNodeVisitor explorer;
68100
explorer.Walk(programNode, typeEnv);
69101
ui32 uniqueId = 0;
70102
for (auto& node : explorer.GetNodes()) {

ydb/library/yql/dq/tasks/dq_task_program.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99

1010
namespace NYql::NDq {
1111

12+
struct TSpillingSettings {
13+
bool EnableSpillingInGraceJoin = false;
14+
};
15+
1216
const TStructExprType* CollectParameters(NNodes::TCoLambda program, TExprContext& ctx);
1317

1418
TString BuildProgram(NNodes::TCoLambda program, const TStructExprType& paramsType,
1519
const NCommon::IMkqlCallableCompiler& compiler, const NKikimr::NMiniKQL::TTypeEnvironment& typeEnv,
1620
const NKikimr::NMiniKQL::IFunctionRegistry& funcRegistry, TExprContext& exprCtx,
17-
const TVector<NNodes::TExprBase>& reads);
21+
const TVector<NNodes::TExprBase>& reads, const TSpillingSettings& spillingSettings);
1822

1923
} // namespace NYql::NDq

ydb/library/yql/minikql/comp_nodes/mkql_factory.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ struct TCallableComputationNodeBuilderFuncMapFiller {
234234
{"JoinDict", &WrapJoinDict},
235235
{"GraceJoin", &WrapGraceJoin},
236236
{"GraceSelfJoin", &WrapGraceSelfJoin},
237-
{"GraceJoinWithSpilling", &WrapGraceJoinWithSpilling},
238-
{"GraceSelfJoinWithSpilling", &WrapGraceSelfJoinWithSpilling},
237+
{"GraceJoinWithSpilling", &WrapGraceJoin},
238+
{"GraceSelfJoinWithSpilling", &WrapGraceSelfJoin},
239239
{"MapJoinCore", &WrapMapJoinCore},
240240
{"CommonJoinCore", &WrapCommonJoinCore},
241241
{"CombineCore", &WrapCombineCore},

ydb/library/yql/minikql/comp_nodes/mkql_grace_join.cpp

+10-14
Original file line numberDiff line numberDiff line change
@@ -1170,29 +1170,25 @@ IComputationNode* WrapGraceJoinCommon(TCallable& callable, const TComputationNod
11701170

11711171
IComputationNode* WrapGraceJoin(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
11721172
MKQL_ENSURE(callable.GetInputsCount() == 8, "Expected 8 args");
1173+
bool isSpillingAllowed = false;
1174+
if (callable.GetType()->GetName() == "GraceJoinWithSpilling") {
1175+
isSpillingAllowed = true;
1176+
}
11731177

1174-
return WrapGraceJoinCommon(callable, ctx, false, false);
1178+
return WrapGraceJoinCommon(callable, ctx, false, isSpillingAllowed);
11751179
}
11761180

11771181
IComputationNode* WrapGraceSelfJoin(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
11781182
MKQL_ENSURE(callable.GetInputsCount() == 7, "Expected 7 args");
1179-
1180-
return WrapGraceJoinCommon(callable, ctx, true, false);
1181-
}
1182-
1183-
IComputationNode* WrapGraceJoinWithSpilling(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
1184-
MKQL_ENSURE(callable.GetInputsCount() == 8, "Expected 8 args");
11851183

1186-
return WrapGraceJoinCommon(callable, ctx, false, true);
1187-
}
1188-
1189-
IComputationNode* WrapGraceSelfJoinWithSpilling(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
1190-
MKQL_ENSURE(callable.GetInputsCount() == 7, "Expected 7 args");
1184+
bool isSpillingAllowed = false;
1185+
if (callable.GetType()->GetName() == "GraceSelfJoinWithSpilling") {
1186+
isSpillingAllowed = true;
1187+
}
11911188

1192-
return WrapGraceJoinCommon(callable, ctx, true, true);
1189+
return WrapGraceJoinCommon(callable, ctx, true, isSpillingAllowed);
11931190
}
11941191

1195-
11961192
}
11971193

11981194
}

ydb/library/yql/minikql/mkql_program_builder.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -2160,28 +2160,6 @@ TRuntimeNode TProgramBuilder::GraceSelfJoin(TRuntimeNode flowLeft, EJoinKind jo
21602160
return GraceJoinCommon(__func__, flowLeft, {}, joinKind, leftKeyColumns, rightKeyColumns, leftRenames, rightRenames, returnType, anyJoinSettings);
21612161
}
21622162

2163-
TRuntimeNode TProgramBuilder::GraceJoinWithSpilling(TRuntimeNode flowLeft, TRuntimeNode flowRight, EJoinKind joinKind,
2164-
const TArrayRef<const ui32>& leftKeyColumns, const TArrayRef<const ui32>& rightKeyColumns,
2165-
const TArrayRef<const ui32>& leftRenames, const TArrayRef<const ui32>& rightRenames, TType* returnType, EAnyJoinSettings anyJoinSettings ) {
2166-
2167-
if constexpr (RuntimeVersion < 50U) {
2168-
THROW yexception() << "Runtime version (" << RuntimeVersion << ") too old for " << __func__;
2169-
}
2170-
2171-
return GraceJoinCommon(__func__, flowLeft, flowRight, joinKind, leftKeyColumns, rightKeyColumns, leftRenames, rightRenames, returnType, anyJoinSettings);
2172-
}
2173-
2174-
TRuntimeNode TProgramBuilder::GraceSelfJoinWithSpilling(TRuntimeNode flowLeft, EJoinKind joinKind,
2175-
const TArrayRef<const ui32>& leftKeyColumns, const TArrayRef<const ui32>& rightKeyColumns,
2176-
const TArrayRef<const ui32>& leftRenames, const TArrayRef<const ui32>& rightRenames, TType* returnType, EAnyJoinSettings anyJoinSettings ) {
2177-
2178-
if constexpr (RuntimeVersion < 50U) {
2179-
THROW yexception() << "Runtime version (" << RuntimeVersion << ") too old for " << __func__;
2180-
}
2181-
2182-
return GraceJoinCommon(__func__, flowLeft, {}, joinKind, leftKeyColumns, rightKeyColumns, leftRenames, rightRenames, returnType, anyJoinSettings);
2183-
}
2184-
21852163
TRuntimeNode TProgramBuilder::ToSortedDict(TRuntimeNode list, bool all, const TUnaryLambda& keySelector,
21862164
const TUnaryLambda& payloadSelector, bool isCompact, ui64 itemsCountHint) {
21872165
return ToDict(list, all, keySelector, payloadSelector, __func__, isCompact, itemsCountHint);

ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -1704,13 +1704,6 @@ TMkqlCommonCallableCompiler::TShared::TShared() {
17041704

17051705
const auto returnType = BuildType(node, *node.GetTypeAnn(), ctx.ProgramBuilder);
17061706

1707-
// TODO: use PRAGMA
1708-
bool IsSpillingAllowed = false;
1709-
if (RuntimeVersion >= 50U && IsSpillingAllowed) {
1710-
return selfJoin
1711-
? ctx.ProgramBuilder.GraceSelfJoinWithSpilling(flowLeft, joinKind, leftKeyColumns, rightKeyColumns, leftRenames, rightRenames, returnType, anyJoinSettings)
1712-
: ctx.ProgramBuilder.GraceJoinWithSpilling(flowLeft, flowRight, joinKind, leftKeyColumns, rightKeyColumns, leftRenames, rightRenames, returnType, anyJoinSettings);
1713-
}
17141707
return selfJoin
17151708
? ctx.ProgramBuilder.GraceSelfJoin(flowLeft, joinKind, leftKeyColumns, rightKeyColumns, leftRenames, rightRenames, returnType, anyJoinSettings)
17161709
: ctx.ProgramBuilder.GraceJoin(flowLeft, flowRight, joinKind, leftKeyColumns, rightKeyColumns, leftRenames, rightRenames, returnType, anyJoinSettings);

ydb/library/yql/providers/dq/common/yql_dq_settings.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ TDqConfiguration::TDqConfiguration() {
9898

9999
REGISTER_SETTING(*this, _MaxAttachmentsSize);
100100
REGISTER_SETTING(*this, DisableCheckpoints);
101+
REGISTER_SETTING(*this, EnableSpillingInGraceJoin);
101102
}
102103

103104
} // namespace NYql

ydb/library/yql/providers/dq/common/yql_dq_settings.h

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct TDqSettings {
6060
static constexpr ui32 MaxDPccpDPTableSize = 16400U;
6161
static constexpr ui64 MaxAttachmentsSize = 2_GB;
6262
static constexpr bool SplitStageOnDqReplicate = true;
63+
static constexpr bool EnableSpillingInGraceJoin = false;
6364
};
6465

6566
using TPtr = std::shared_ptr<TDqSettings>;
@@ -131,6 +132,8 @@ struct TDqSettings {
131132
NCommon::TConfSetting<bool, false> DisableLLVMForBlockStages;
132133
NCommon::TConfSetting<bool, false> SplitStageOnDqReplicate;
133134

135+
NCommon::TConfSetting<bool, false> EnableSpillingInGraceJoin;
136+
134137
NCommon::TConfSetting<ui64, false> _MaxAttachmentsSize;
135138
NCommon::TConfSetting<bool, false> DisableCheckpoints;
136139

@@ -215,6 +218,10 @@ struct TDqSettings {
215218
return SpillingEngine.Get().GetOrElse(TDqSettings::TDefault::SpillingEngine) != ESpillingEngine::Disable;
216219
}
217220

221+
bool IsSpillingInGraceJoinEnabled() const {
222+
return IsSpillingEnabled() && EnableSpillingInGraceJoin.Get().GetOrElse(false);
223+
}
224+
218225
bool IsDqReplicateEnabled(const TTypeAnnotationContext& typesCtx) const {
219226
return EnableDqReplicate.Get().GetOrElse(
220227
typesCtx.BlockEngineMode != EBlockEngineMode::Disable || TDqSettings::TDefault::EnableDqReplicate);

ydb/library/yql/providers/dq/planner/execution_planner.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,11 @@ namespace NYql::NDqs {
676676
Y_ABORT_UNLESS(false);
677677
}
678678
*/
679+
TSpillingSettings spillingSettings{Settings->IsSpillingInGraceJoinEnabled()};
679680
StagePrograms[stageInfo.first] = std::make_tuple(
680681
NDq::BuildProgram(
681682
stage.Program(), *paramsType, compiler, typeEnv, *FunctionRegistry,
682-
ExprContext, fakeReads),
683+
ExprContext, fakeReads, spillingSettings),
683684
stageId, publicId);
684685
}
685686
}

ydb/library/yql/providers/dq/provider/exec/yql_dq_exectransformer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,10 @@ class TDqExecTransformer: public TExecTransformerBase, TCounters
760760

761761
TVector<TExprBase> fakeReads;
762762
auto paramsType = NDq::CollectParameters(programLambda, ctx);
763+
NDq::TSpillingSettings spillingSettings{State->Settings->IsSpillingInGraceJoinEnabled()};
763764
*lambda = NDq::BuildProgram(
764765
programLambda, *paramsType, compiler, typeEnv, *State->FunctionRegistry,
765-
ctx, fakeReads);
766+
ctx, fakeReads, spillingSettings);
766767
}
767768

768769
auto block = MeasureBlock("RuntimeNodeVisitor");

0 commit comments

Comments
 (0)