Skip to content

Commit

Permalink
Adjust BlockMapJoinCore program builder with key column drops
Browse files Browse the repository at this point in the history
  • Loading branch information
igormunkin committed Sep 10, 2024
1 parent 9e26730 commit f48070e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 15 additions & 1 deletion ydb/library/yql/minikql/mkql_program_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5855,7 +5855,8 @@ TRuntimeNode TProgramBuilder::ScalarApply(const TArrayRef<const TRuntimeNode>& a
}

TRuntimeNode TProgramBuilder::BlockMapJoinCore(TRuntimeNode flow, TRuntimeNode dict,
EJoinKind joinKind, const TArrayRef<const ui32>& leftKeyColumns
EJoinKind joinKind, const TArrayRef<const ui32>& leftKeyColumns,
const TArrayRef<const ui32>& leftKeyDrops
) {
if constexpr (RuntimeVersion < 51U) {
THROW yexception() << "Runtime version (" << RuntimeVersion << ") too old for " << __func__;
Expand All @@ -5864,6 +5865,11 @@ TRuntimeNode TProgramBuilder::BlockMapJoinCore(TRuntimeNode flow, TRuntimeNode d
joinKind == EJoinKind::LeftSemi || joinKind == EJoinKind::LeftOnly,
"Unsupported join kind");
MKQL_ENSURE(!leftKeyColumns.empty(), "At least one key column must be specified");
const TSet<ui32> leftKeySet(leftKeyColumns.cbegin(), leftKeyColumns.cend());
for (const auto& drop : leftKeyDrops) {
MKQL_ENSURE(leftKeySet.contains(drop),
"Only key columns has to be specified in drop column set");
}

TRuntimeNode::TList leftKeyColumnsNodes;
leftKeyColumnsNodes.reserve(leftKeyColumns.size());
Expand All @@ -5872,6 +5878,13 @@ TRuntimeNode TProgramBuilder::BlockMapJoinCore(TRuntimeNode flow, TRuntimeNode d
return NewDataLiteral(idx);
});

TRuntimeNode::TList leftKeyDropsNodes;
leftKeyDropsNodes.reserve(leftKeyDrops.size());
std::transform(leftKeyDrops.cbegin(), leftKeyDrops.cend(),
std::back_inserter(leftKeyDropsNodes), [this](const ui32 idx) {
return NewDataLiteral(idx);
});

auto returnJoinItems = ValidateBlockFlowType(flow.GetStaticType(), false);
const auto payloadType = AS_TYPE(TDictType, dict.GetStaticType())->GetPayloadType();
const auto payloadItemType = payloadType->IsList()
Expand Down Expand Up @@ -5907,6 +5920,7 @@ TRuntimeNode TProgramBuilder::BlockMapJoinCore(TRuntimeNode flow, TRuntimeNode d
callableBuilder.Add(dict);
callableBuilder.Add(NewDataLiteral((ui32)joinKind));
callableBuilder.Add(NewTuple(leftKeyColumnsNodes));
callableBuilder.Add(NewTuple(leftKeyDropsNodes));

return TRuntimeNode(callableBuilder.Build(), false);
}
Expand Down
3 changes: 2 additions & 1 deletion ydb/library/yql/minikql/mkql_program_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ class TProgramBuilder : public TTypeBuilder {
TRuntimeNode BlockPgResolvedCall(const std::string_view& name, ui32 id,
const TArrayRef<const TRuntimeNode>& args, TType* returnType);
TRuntimeNode BlockMapJoinCore(TRuntimeNode flow, TRuntimeNode dict,
EJoinKind joinKind, const TArrayRef<const ui32>& leftKeyColumns);
EJoinKind joinKind, const TArrayRef<const ui32>& leftKeyColumns,
const TArrayRef<const ui32>& leftKeyDrops = {});

//-- logical functions
TRuntimeNode BlockNot(TRuntimeNode data);
Expand Down

0 comments on commit f48070e

Please sign in to comment.