Skip to content

Commit fadeabf

Browse files
committed
YQL-18053: Implement node emitting phase for BlockAsStruct
1 parent de3584a commit fadeabf

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ struct TCallableComputationNodeBuilderFuncMapFiller {
298298
{"BlockJust", &WrapBlockJust},
299299
{"BlockCompress", &WrapBlockCompress},
300300
{"BlockAsTuple", &WrapBlockAsContainer},
301+
{"BlockAsStruct", &WrapBlockAsContainer},
301302
{"BlockMember", &WrapBlockMember},
302303
{"BlockNth", &WrapBlockNth},
303304
{"BlockExpandChunked", &WrapBlockExpandChunked},

ydb/library/yql/minikql/mkql_program_builder.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,28 @@ TRuntimeNode TProgramBuilder::BlockNth(TRuntimeNode tuple, ui32 index) {
16571657
return TRuntimeNode(callableBuilder.Build(), false);
16581658
}
16591659

1660+
TRuntimeNode TProgramBuilder::BlockAsStruct(const TArrayRef<std::pair<std::string_view, TRuntimeNode>>& args) {
1661+
MKQL_ENSURE(!args.empty(), "Expected at least one argument");
1662+
1663+
TBlockType::EShape resultShape = TBlockType::EShape::Scalar;
1664+
TVector<std::pair<std::string_view, TType*>> members;
1665+
for (const auto& x : args) {
1666+
auto blockType = AS_TYPE(TBlockType, x.second.GetStaticType());
1667+
members.emplace_back(x.first, blockType->GetItemType());
1668+
if (blockType->GetShape() == TBlockType::EShape::Many) {
1669+
resultShape = TBlockType::EShape::Many;
1670+
}
1671+
}
1672+
1673+
auto returnType = NewBlockType(NewStructType(members), resultShape);
1674+
TCallableBuilder callableBuilder(Env, __func__, returnType);
1675+
for (const auto& x : args) {
1676+
callableBuilder.Add(x.second);
1677+
}
1678+
1679+
return TRuntimeNode(callableBuilder.Build(), false);
1680+
}
1681+
16601682
TRuntimeNode TProgramBuilder::BlockAsTuple(const TArrayRef<const TRuntimeNode>& args) {
16611683
MKQL_ENSURE(!args.empty(), "Expected at least one argument");
16621684

ydb/library/yql/minikql/mkql_program_builder.h

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class TProgramBuilder : public TTypeBuilder {
239239
TRuntimeNode BlockExists(TRuntimeNode data);
240240
TRuntimeNode BlockMember(TRuntimeNode structure, const std::string_view& memberName);
241241
TRuntimeNode BlockNth(TRuntimeNode tuple, ui32 index);
242+
TRuntimeNode BlockAsStruct(const TArrayRef<std::pair<std::string_view, TRuntimeNode>>& args);
242243
TRuntimeNode BlockAsTuple(const TArrayRef<const TRuntimeNode>& args);
243244
TRuntimeNode BlockToPg(TRuntimeNode input, TType* returnType);
244245
TRuntimeNode BlockFromPg(TRuntimeNode input, TType* returnType);

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

+8
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,14 @@ TMkqlCommonCallableCompiler::TShared::TShared() {
27372737
return ctx.ProgramBuilder.BlockNth(tupleObj, index);
27382738
});
27392739

2740+
AddCallable("BlockAsStruct", [](const TExprNode& node, TMkqlBuildContext& ctx) {
2741+
std::vector<std::pair<std::string_view, TRuntimeNode>> members;
2742+
for (const auto& x : node.Children()) {
2743+
members.emplace_back(x->Head().Content(), MkqlBuildExpr(x->Tail(), ctx));
2744+
}
2745+
return ctx.ProgramBuilder.BlockAsStruct(members);
2746+
});
2747+
27402748
AddCallable("BlockAsTuple", [](const TExprNode& node, TMkqlBuildContext& ctx) {
27412749
TVector<TRuntimeNode> args;
27422750
for (const auto& x : node.Children()) {

0 commit comments

Comments
 (0)