Skip to content

Commit 7a3076c

Browse files
Merge 870b68e into bfbba84
2 parents bfbba84 + 870b68e commit 7a3076c

File tree

7 files changed

+51
-45
lines changed

7 files changed

+51
-45
lines changed

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

+33
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,37 @@
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

8+
#include <util/generic/xrange.h>
9+
710
namespace NYql::NDq {
811

912
using namespace NKikimr::NMiniKQL;
1013
using namespace NYql::NNodes;
1114

15+
16+
class TSpillingTransformProvider {
17+
public:
18+
TCallableVisitFunc operator()(TInternName name) {
19+
if (name == "GraceJoin" || name == "GraceSelfJoin") {
20+
return [name](NKikimr::NMiniKQL::TCallable& callable, const TTypeEnvironment& env) {
21+
TCallableBuilder callableBuilder(env,
22+
TStringBuilder() << callable.GetType()->GetName() << "WithSpilling",
23+
callable.GetType()->GetReturnType(), false);
24+
for (ui32 i: xrange(callable.GetInputsCount())) {
25+
callableBuilder.Add(callable.GetInput(i));
26+
}
27+
return TRuntimeNode(callableBuilder.Build(), false);
28+
};
29+
}
30+
31+
32+
return TCallableVisitFunc();
33+
}
34+
};
35+
1236
const TStructExprType* CollectParameters(NNodes::TCoLambda program, TExprContext& ctx) {
1337
TVector<const TItemExprType*> memberTypes;
1438

@@ -49,6 +73,15 @@ TString BuildProgram(NNodes::TCoLambda program, const TStructExprType& paramsTyp
4973

5074
TRuntimeNode rootNode = MkqlBuildExpr(program.Body().Ref(), ctx);
5175

76+
if (RuntimeVersion >= 50U) {
77+
TExploringNodeVisitor explorer;
78+
explorer.Walk(rootNode.GetNode(), typeEnv);
79+
bool wereChanges = false;
80+
rootNode = SinglePassVisitCallables(rootNode, explorer, TSpillingTransformProvider(), typeEnv, true, wereChanges);
81+
82+
std::cerr << "MISHA " << wereChanges << std::endl;
83+
}
84+
5285
TStructLiteralBuilder structBuilder(typeEnv);
5386
structBuilder.Add("Program", rootNode);
5487
structBuilder.Add("Inputs", pgmBuilder.NewTuple(inputNodes));

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

+12-14
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

-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

+3
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

0 commit comments

Comments
 (0)