@@ -1118,6 +1118,52 @@ using TBaseComputation = TStatefulWideFlowCodegeneratorNode<TBlockExpandChunkedW
1118
1118
const size_t WideFieldsIndex_;
1119
1119
};
1120
1120
1121
+ class TBlockExpandChunkedStreamWrapper : public TMutableComputationNode <TBlockExpandChunkedStreamWrapper> {
1122
+ using TBaseComputation = TMutableComputationNode<TBlockExpandChunkedStreamWrapper>;
1123
+ class TExpanderState : public TComputationValue <TExpanderState> {
1124
+ using TBase = TComputationValue<TExpanderState>;
1125
+ public:
1126
+ TExpanderState (TMemoryUsageInfo* memInfo, TComputationContext& ctx, NUdf::TUnboxedValue&& stream, size_t width)
1127
+ : TBase(memInfo), HolderFactory_(ctx.HolderFactory), State_(ctx.HolderFactory.Create<TBlockState>(width)), Stream_(stream) {}
1128
+
1129
+ NUdf::EFetchStatus WideFetch (NUdf::TUnboxedValue* output, ui32 width) {
1130
+ auto & s = *static_cast <TBlockState*>(State_.AsBoxed ().Get ());
1131
+ if (!s.Count ) {
1132
+ s.ClearValues ();
1133
+ auto result = Stream_.WideFetch (s.Values .data (), width);
1134
+ if (NUdf::EFetchStatus::Ok != result) {
1135
+ return result;
1136
+ }
1137
+ s.FillArrays ();
1138
+ }
1139
+
1140
+ const auto sliceSize = s.Slice ();
1141
+ for (size_t i = 0 ; i < width; ++i) {
1142
+ output[i] = s.Get (sliceSize, HolderFactory_, i);
1143
+ }
1144
+ return NUdf::EFetchStatus::Ok;
1145
+ }
1146
+
1147
+ private:
1148
+ const THolderFactory& HolderFactory_;
1149
+ NUdf::TUnboxedValue State_;
1150
+ NUdf::TUnboxedValue Stream_;
1151
+ };
1152
+ public:
1153
+ TBlockExpandChunkedStreamWrapper (TComputationMutables& mutables, IComputationNode* stream, size_t width)
1154
+ : TBaseComputation(mutables, EValueRepresentation::Boxed)
1155
+ , Stream_(stream)
1156
+ , Width_(width) {}
1157
+
1158
+ NUdf::TUnboxedValuePod DoCalculate (TComputationContext& ctx) const {
1159
+ return ctx.HolderFactory .Create <TExpanderState>(ctx, std::move (Stream_->GetValue (ctx)), Width_);
1160
+ }
1161
+ void RegisterDependencies () const override {}
1162
+ private:
1163
+ IComputationNode* const Stream_;
1164
+ const size_t Width_;
1165
+ };
1166
+
1121
1167
} // namespace
1122
1168
1123
1169
IComputationNode* WrapToBlocks (TCallable& callable, const TComputationNodeFactoryContext& ctx) {
@@ -1182,13 +1228,21 @@ IComputationNode* WrapReplicateScalar(TCallable& callable, const TComputationNod
1182
1228
1183
1229
IComputationNode* WrapBlockExpandChunked (TCallable& callable, const TComputationNodeFactoryContext& ctx) {
1184
1230
MKQL_ENSURE (callable.GetInputsCount () == 1 , " Expected 1 args, got " << callable.GetInputsCount ());
1185
-
1186
- const auto flowType = AS_TYPE (TFlowType, callable.GetInput (0 ).GetStaticType ());
1187
- const auto wideComponents = GetWideComponents (flowType);
1188
-
1189
- const auto wideFlow = dynamic_cast <IComputationWideFlowNode*>(LocateNode (ctx.NodeLocator , callable, 0 ));
1190
- MKQL_ENSURE (wideFlow != nullptr , " Expected wide flow node" );
1191
- return new TBlockExpandChunkedWrapper (ctx.Mutables , wideFlow, wideComponents.size ());
1231
+ if (callable.GetInput (0 ).GetStaticType ()->IsStream ()) {
1232
+ const auto streamType = AS_TYPE (TStreamType, callable.GetInput (0 ).GetStaticType ());
1233
+ const auto wideComponents = GetWideComponents (streamType);
1234
+ const auto computation = dynamic_cast <IComputationNode*>(LocateNode (ctx.NodeLocator , callable, 0 ));
1235
+
1236
+ MKQL_ENSURE (computation != nullptr , " Expected computation node" );
1237
+ return new TBlockExpandChunkedStreamWrapper (ctx.Mutables , computation, wideComponents.size ());
1238
+ } else {
1239
+ const auto flowType = AS_TYPE (TFlowType, callable.GetInput (0 ).GetStaticType ());
1240
+ const auto wideComponents = GetWideComponents (flowType);
1241
+
1242
+ const auto wideFlow = dynamic_cast <IComputationWideFlowNode*>(LocateNode (ctx.NodeLocator , callable, 0 ));
1243
+ MKQL_ENSURE (wideFlow != nullptr , " Expected wide flow node" );
1244
+ return new TBlockExpandChunkedWrapper (ctx.Mutables , wideFlow, wideComponents.size ());
1245
+ }
1192
1246
}
1193
1247
1194
1248
}
0 commit comments