Skip to content

Commit c74b1ff

Browse files
Merge 69259bd into 8a523e2
2 parents 8a523e2 + 69259bd commit c74b1ff

File tree

12 files changed

+71
-52
lines changed

12 files changed

+71
-52
lines changed

ydb/core/kqp/provider/yql_kikimr_exec.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,43 @@
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+
20+
TCallableVisitFunc operator()(TInternName name) {
21+
if (RuntimeVersion >= 50U && SpillingSettings.EnableSpillingInGraceJoin && (name == "GraceJoin" || name == "GraceSelfJoin")) {
22+
return [name](NKikimr::NMiniKQL::TCallable& callable, const TTypeEnvironment& env) {
23+
TCallableBuilder callableBuilder(env,
24+
TStringBuilder() << callable.GetType()->GetName() << "WithSpilling",
25+
callable.GetType()->GetReturnType(), false);
26+
for (ui32 i = 0; i < callable.GetInputsCount(); ++i) {
27+
callableBuilder.Add(callable.GetInput(i));
28+
}
29+
return TRuntimeNode(callableBuilder.Build(), false);
30+
};
31+
}
32+
33+
34+
return TCallableVisitFunc();
35+
}
36+
37+
private:
38+
39+
TSpillingSettings SpillingSettings;
40+
};
41+
1242
const TStructExprType* CollectParameters(NNodes::TCoLambda program, TExprContext& ctx) {
1343
TVector<const TItemExprType*> memberTypes;
1444

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

2858
TString BuildProgram(NNodes::TCoLambda program, const TStructExprType& paramsType,
2959
const NCommon::IMkqlCallableCompiler& compiler, const TTypeEnvironment& typeEnv,
30-
const IFunctionRegistry& funcRegistry, TExprContext& exprCtx, const TVector<TExprBase>& reads)
60+
const IFunctionRegistry& funcRegistry, TExprContext& exprCtx, const TVector<TExprBase>& reads, const TSpillingSettings& spillingSettings)
3161
{
3262
TProgramBuilder pgmBuilder(typeEnv, funcRegistry);
3363

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

5080
TRuntimeNode rootNode = MkqlBuildExpr(program.Body().Ref(), ctx);
5181

82+
TExploringNodeVisitor explorer;
83+
explorer.Walk(rootNode.GetNode(), typeEnv);
84+
bool wereChanges = false;
85+
rootNode = SinglePassVisitCallables(rootNode, explorer, TSpillingTransformProvider(spillingSettings), typeEnv, true, wereChanges);
86+
5287
TStructLiteralBuilder structBuilder(typeEnv);
5388
structBuilder.Add("Program", rootNode);
5489
structBuilder.Add("Inputs", pgmBuilder.NewTuple(inputNodes));
@@ -64,7 +99,6 @@ TString BuildProgram(NNodes::TCoLambda program, const TStructExprType& paramsTyp
6499

65100
auto programNode = structBuilder.Build();
66101

67-
TExploringNodeVisitor explorer;
68102
explorer.Walk(programNode, typeEnv);
69103
ui32 uniqueId = 0;
70104
for (auto& node : explorer.GetNodes()) {

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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,29 +1170,27 @@ 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+
}
1177+
1178+
std::cerr << "MISHA " << callable.GetType()->GetName() << std::endl;
11731179

1174-
return WrapGraceJoinCommon(callable, ctx, false, false);
1180+
return WrapGraceJoinCommon(callable, ctx, false, isSpillingAllowed);
11751181
}
11761182

11771183
IComputationNode* WrapGraceSelfJoin(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
11781184
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");
11851185

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");
1186+
bool isSpillingAllowed = false;
1187+
if (callable.GetType()->GetName() == "GraceSelfJoinWithSpilling") {
1188+
isSpillingAllowed = true;
1189+
}
11911190

1192-
return WrapGraceJoinCommon(callable, ctx, true, true);
1191+
return WrapGraceJoinCommon(callable, ctx, true, isSpillingAllowed);
11931192
}
11941193

1195-
11961194
}
11971195

11981196
}

ydb/library/yql/minikql/mkql_program_builder.cpp

Lines changed: 0 additions & 22 deletions
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

Lines changed: 0 additions & 7 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "execution_planner.h"
22

33
#include <ydb/library/yql/dq/integration/yql_dq_integration.h>
4+
#include <ydb/library/yql/minikql/mkql_runtime_version.h>
45
#include <ydb/library/yql/providers/dq/expr_nodes/dqs_expr_nodes.h>
56
#include <ydb/library/yql/providers/dq/opt/dqs_opt.h>
67
#include <ydb/library/yql/providers/dq/opt/logical_optimize.h>
@@ -676,10 +677,12 @@ namespace NYql::NDqs {
676677
Y_ABORT_UNLESS(false);
677678
}
678679
*/
680+
681+
TSpillingSettings spillingSettings{Settings->IsSpillingInGraceJoinEnabled()};
679682
StagePrograms[stageInfo.first] = std::make_tuple(
680683
NDq::BuildProgram(
681684
stage.Program(), *paramsType, compiler, typeEnv, *FunctionRegistry,
682-
ExprContext, fakeReads),
685+
ExprContext, fakeReads, spillingSettings),
683686
stageId, publicId);
684687
}
685688
}

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

Lines changed: 2 additions & 1 deletion
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)