Skip to content

Commit 5c509d3

Browse files
authored
YQ-2068 refactoring, get rid of macro in BuildConnections (#883)
1 parent 319d074 commit 5c509d3

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

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

+18-15
Original file line numberDiff line numberDiff line change
@@ -571,24 +571,27 @@ namespace NYql::NDqs {
571571
return !parts.empty();
572572
}
573573

574-
#define BUILD_CONNECTION(TYPE, BUILDER) \
575-
if (auto conn = input.Maybe<TYPE>()) { \
576-
BUILDER(TasksGraph, stage, inputIndex, logFunc); \
577-
continue; \
578-
}
579-
580-
void TDqsExecutionPlanner::BuildConnections( const NNodes::TDqPhyStage& stage) {
574+
const static std::unordered_map<
575+
std::string_view,
576+
void(*)(TDqsTasksGraph&, const NNodes::TDqPhyStage&, ui32, const TChannelLogFunc&)
577+
> ConnectionBuilders = {
578+
{TDqCnUnionAll::CallableName(), &BuildUnionAllChannels},
579+
{TDqCnHashShuffle::CallableName(), &BuildHashShuffleChannels},
580+
{TDqCnBroadcast::CallableName(), &BuildBroadcastChannels},
581+
{TDqCnMap::CallableName(), BuildMapChannels},
582+
{TDqCnMerge::CallableName(), BuildMergeChannels},
583+
};
584+
585+
void TDqsExecutionPlanner::BuildConnections(const NNodes::TDqPhyStage& stage) {
581586
NDq::TChannelLogFunc logFunc = [](ui64, ui64, ui64, TStringBuf, bool) {};
582-
583587
for (ui32 inputIndex = 0; inputIndex < stage.Inputs().Size(); ++inputIndex) {
584-
const auto& input = stage.Inputs().Item(inputIndex);
588+
const auto &input = stage.Inputs().Item(inputIndex);
585589
if (input.Maybe<TDqConnection>()) {
586-
BUILD_CONNECTION(TDqCnUnionAll, BuildUnionAllChannels);
587-
BUILD_CONNECTION(TDqCnHashShuffle, BuildHashShuffleChannels);
588-
BUILD_CONNECTION(TDqCnBroadcast, BuildBroadcastChannels);
589-
BUILD_CONNECTION(TDqCnMap, BuildMapChannels);
590-
BUILD_CONNECTION(TDqCnMerge, BuildMergeChannels);
591-
YQL_ENSURE(false, "Unknown stage connection type: " << input.Cast<NNodes::TCallable>().CallableName());
590+
if (const auto it = ConnectionBuilders.find(input.Cast<NNodes::TCallable>().CallableName()); it != ConnectionBuilders.cend()) {
591+
it->second(TasksGraph, stage, inputIndex, logFunc);
592+
} else {
593+
YQL_ENSURE(false, "Unknown stage connection type: " << input.Cast<NNodes::TCallable>().CallableName());
594+
}
592595
} else {
593596
YQL_ENSURE(input.Maybe<TDqSource>(), "Unknown stage input: " << input.Cast<NNodes::TCallable>().CallableName());
594597
}

0 commit comments

Comments
 (0)