@@ -24,11 +24,11 @@ template<bool IsWide>
24
24
class TDqInputUnionStreamValue : public TComputationValue <TDqInputUnionStreamValue<IsWide>> {
25
25
using TBase = TComputationValue<TDqInputUnionStreamValue<IsWide>>;
26
26
public:
27
- TDqInputUnionStreamValue (TMemoryUsageInfo* memInfo, TVector<IDqInput::TPtr>&& inputs, TDqMeteringStats::TInputStatsMeter stats)
27
+ TDqInputUnionStreamValue (TMemoryUsageInfo* memInfo, const NKikimr::NMiniKQL::TType* type, TVector<IDqInput::TPtr>&& inputs, TDqMeteringStats::TInputStatsMeter stats)
28
28
: TBase(memInfo)
29
29
, Inputs(std::move(inputs))
30
30
, Alive(Inputs.size())
31
- , Batch(Inputs.empty() ? nullptr : Inputs.front()-> GetInputType () )
31
+ , Batch(type )
32
32
, Stats(stats)
33
33
{}
34
34
@@ -114,13 +114,15 @@ template<bool IsWide>
114
114
class TDqInputMergeStreamValue : public TComputationValue <TDqInputMergeStreamValue<IsWide>> {
115
115
using TBase = TComputationValue<TDqInputMergeStreamValue<IsWide>>;
116
116
public:
117
- TDqInputMergeStreamValue (TMemoryUsageInfo* memInfo, TVector<IDqInput::TPtr>&& inputs,
117
+ TDqInputMergeStreamValue (TMemoryUsageInfo* memInfo, const NKikimr::NMiniKQL::TType* type, TVector<IDqInput::TPtr>&& inputs,
118
118
TVector<TSortColumnInfo>&& sortCols, TDqMeteringStats::TInputStatsMeter stats)
119
119
: TBase(memInfo)
120
120
, Inputs(std::move(inputs))
121
+ , Width(type->IsMulti () ? static_cast<const NMiniKQL::TMultiType*>(type)->GetElementsCount() : TMaybe<ui32>())
121
122
, SortCols(std::move(sortCols))
122
123
, Stats(stats)
123
124
{
125
+ YQL_ENSURE (!IsWide ^ Width.Defined ());
124
126
CurrentBuffers.reserve (Inputs.size ());
125
127
CurrentItemIndexes.reserve (Inputs.size ());
126
128
for (ui32 idx = 0 ; idx < Inputs.size (); ++idx) {
@@ -216,7 +218,7 @@ class TDqInputMergeStreamValue : public TComputationValue<TDqInputMergeStreamVal
216
218
return status;
217
219
}
218
220
219
- YQL_ENSURE (!Inputs. empty () && *Inputs. front ()-> GetInputWidth () == width);
221
+ YQL_ENSURE (*Width == width);
220
222
CopyResult (result, width);
221
223
if (Stats) {
222
224
Stats.Add (result, width);
@@ -300,6 +302,7 @@ class TDqInputMergeStreamValue : public TComputationValue<TDqInputMergeStreamVal
300
302
301
303
private:
302
304
TVector<IDqInput::TPtr> Inputs;
305
+ const TMaybe<ui32> Width;
303
306
TVector<TSortColumnInfo> SortCols;
304
307
TVector<TUnboxedValueBatch> CurrentBuffers;
305
308
TVector<TUnboxedValuesIterator<IsWide>> CurrentItemIndexes;
@@ -308,20 +311,6 @@ class TDqInputMergeStreamValue : public TComputationValue<TDqInputMergeStreamVal
308
311
TDqMeteringStats::TInputStatsMeter Stats;
309
312
};
310
313
311
- bool IsWideInputs (const TVector<IDqInput::TPtr>& inputs) {
312
- NKikimr::NMiniKQL::TType* type = nullptr ;
313
- bool isWide = false ;
314
- for (auto & input : inputs) {
315
- if (!type) {
316
- type = input->GetInputType ();
317
- isWide = input->GetInputWidth ().Defined ();
318
- } else {
319
- YQL_ENSURE (type->IsSameType (*input->GetInputType ()));
320
- }
321
- }
322
- return isWide;
323
- }
324
-
325
314
TVector<NKikimr::NMiniKQL::TType*> ExtractBlockItemTypes (const NKikimr::NMiniKQL::TType* type) {
326
315
TVector<NKikimr::NMiniKQL::TType*> result;
327
316
@@ -390,18 +379,17 @@ TVector<IBlockItemComparator::TPtr> MakeComparators(const TVector<TSortColumnInf
390
379
class TDqInputMergeBlockStreamValue : public TComputationValue <TDqInputMergeBlockStreamValue> {
391
380
using TBase = TComputationValue<TDqInputMergeBlockStreamValue>;
392
381
public:
393
- TDqInputMergeBlockStreamValue (TMemoryUsageInfo* memInfo, TVector<IDqInput::TPtr>&& inputs,
382
+ TDqInputMergeBlockStreamValue (TMemoryUsageInfo* memInfo, const NKikimr::NMiniKQL::TType* type, TVector<IDqInput::TPtr>&& inputs,
394
383
TVector<TSortColumnInfo>&& sortCols, const NKikimr::NMiniKQL::THolderFactory& factory, TDqMeteringStats::TInputStatsMeter stats)
395
384
: TBase(memInfo)
396
385
, SortCols_(std::move(sortCols))
397
- , ItemTypes_(ExtractBlockItemTypes(inputs.front()-> GetInputType () ))
386
+ , ItemTypes_(ExtractBlockItemTypes(type ))
398
387
, MaxOutputBlockLen_(CalcMaxBlockLength(ItemTypes_.begin(), ItemTypes_.end(), TTypeInfoHelper()))
399
388
, Comparators_(MakeComparators(SortCols_, ItemTypes_))
400
389
, Builders_(MakeBuilders(MaxOutputBlockLen_, ItemTypes_))
401
390
, Factory_(factory)
402
391
, Stats_(stats)
403
392
{
404
- YQL_ENSURE (!inputs.empty ());
405
393
YQL_ENSURE (MaxOutputBlockLen_ > 0 );
406
394
InputData_.reserve (inputs.size ());
407
395
for (auto & input : inputs) {
@@ -697,6 +685,15 @@ class TDqInputMergeBlockStreamValue : public TComputationValue<TDqInputMergeBloc
697
685
bool IsFinished_ = false ;
698
686
};
699
687
688
+ void ValidateInputTypes (const NKikimr::NMiniKQL::TType* type, const TVector<IDqInput::TPtr>& inputs) {
689
+ YQL_ENSURE (type);
690
+ for (size_t i = 0 ; i < inputs.size (); ++i) {
691
+ auto inputType = inputs[i]->GetInputType ();
692
+ YQL_ENSURE (inputType);
693
+ YQL_ENSURE (type->IsSameType (*inputType), " Unexpected type for input #" << i << " : expected " << *type << " , got " << *inputType);
694
+ }
695
+ }
696
+
700
697
} // namespace
701
698
702
699
void TDqMeteringStats::TInputStatsMeter::Add (const NKikimr::NUdf::TUnboxedValue& val) {
@@ -737,31 +734,33 @@ void TDqMeteringStats::TInputStatsMeter::Add(const NKikimr::NUdf::TUnboxedValue*
737
734
}
738
735
}
739
736
740
- NUdf::TUnboxedValue CreateInputUnionValue (TVector<IDqInput::TPtr>&& inputs,
737
+ NUdf::TUnboxedValue CreateInputUnionValue (const NKikimr::NMiniKQL::TType* type, TVector<IDqInput::TPtr>&& inputs,
741
738
const NMiniKQL::THolderFactory& factory, TDqMeteringStats::TInputStatsMeter stats)
742
739
{
743
- if (IsWideInputs (inputs)) {
744
- return factory.Create <TDqInputUnionStreamValue<true >>(std::move (inputs), stats);
740
+ ValidateInputTypes (type, inputs);
741
+ if (type->IsMulti ()) {
742
+ return factory.Create <TDqInputUnionStreamValue<true >>(type, std::move (inputs), stats);
745
743
}
746
- return factory.Create <TDqInputUnionStreamValue<false >>(std::move (inputs), stats);
744
+ return factory.Create <TDqInputUnionStreamValue<false >>(type, std::move (inputs), stats);
747
745
}
748
746
749
- NKikimr::NUdf::TUnboxedValue CreateInputMergeValue (TVector<IDqInput::TPtr>&& inputs,
747
+ NKikimr::NUdf::TUnboxedValue CreateInputMergeValue (const NKikimr::NMiniKQL::TType* type, TVector<IDqInput::TPtr>&& inputs,
750
748
TVector<TSortColumnInfo>&& sortCols, const NKikimr::NMiniKQL::THolderFactory& factory, TDqMeteringStats::TInputStatsMeter stats)
751
749
{
750
+ ValidateInputTypes (type, inputs);
752
751
YQL_ENSURE (!inputs.empty ());
753
- if (IsWideInputs (inputs )) {
752
+ if (type-> IsMulti ( )) {
754
753
if (AnyOf (sortCols, [](const auto & sortCol) { return sortCol.IsBlockOrScalar (); })) {
755
754
// we can ignore scalar columns, since all they have exactly the same value in all inputs
756
755
EraseIf (sortCols, [](const auto & sortCol) { return *sortCol.IsScalar ; });
757
756
if (sortCols.empty ()) {
758
- return factory.Create <TDqInputUnionStreamValue<true >>(std::move (inputs), stats);
757
+ return factory.Create <TDqInputUnionStreamValue<true >>(type, std::move (inputs), stats);
759
758
}
760
- return factory.Create <TDqInputMergeBlockStreamValue>(std::move (inputs), std::move (sortCols), factory, stats);
759
+ return factory.Create <TDqInputMergeBlockStreamValue>(type, std::move (inputs), std::move (sortCols), factory, stats);
761
760
}
762
- return factory.Create <TDqInputMergeStreamValue<true >>(std::move (inputs), std::move (sortCols), stats);
761
+ return factory.Create <TDqInputMergeStreamValue<true >>(type, std::move (inputs), std::move (sortCols), stats);
763
762
}
764
- return factory.Create <TDqInputMergeStreamValue<false >>(std::move (inputs), std::move (sortCols), stats);
763
+ return factory.Create <TDqInputMergeStreamValue<false >>(type, std::move (inputs), std::move (sortCols), stats);
765
764
}
766
765
767
766
} // namespace NYql::NDq
0 commit comments