@@ -27,12 +27,12 @@ using TExec = arrow::Status(*)(arrow::compute::KernelContext*, const arrow::comp
27
27
28
28
class TUdfKernelState : public arrow ::compute::KernelState {
29
29
public:
30
- TUdfKernelState (const TVector<const TType*>& argTypes, const TType* outputType, bool onlyScalars, const ITypeInfoHelper* typeInfoHelper, const IPgBuilder& pgBuilder )
30
+ TUdfKernelState (const TVector<const TType*>& argTypes, const TType* outputType, bool onlyScalars, const ITypeInfoHelper* typeInfoHelper, const IValueBuilder* valueBuilder )
31
31
: ArgTypes_(argTypes)
32
32
, OutputType_(outputType)
33
33
, OnlyScalars_(onlyScalars)
34
34
, TypeInfoHelper_(typeInfoHelper)
35
- , PgBuilder_(pgBuilder )
35
+ , ValueBuilder_(valueBuilder )
36
36
{
37
37
Readers_.resize (ArgTypes_.size ());
38
38
}
@@ -48,7 +48,7 @@ class TUdfKernelState : public arrow::compute::KernelState {
48
48
IArrayBuilder& GetArrayBuilder () {
49
49
Y_ENSURE (!OnlyScalars_);
50
50
if (!ArrayBuilder_) {
51
- ArrayBuilder_ = MakeArrayBuilder (*TypeInfoHelper_, OutputType_, *GetYqlMemoryPool (), TypeInfoHelper_->GetMaxBlockLength (OutputType_), &PgBuilder_ );
51
+ ArrayBuilder_ = MakeArrayBuilder (*TypeInfoHelper_, OutputType_, *GetYqlMemoryPool (), TypeInfoHelper_->GetMaxBlockLength (OutputType_), &ValueBuilder_-> GetPgBuilder () );
52
52
}
53
53
54
54
return *ArrayBuilder_;
@@ -62,13 +62,18 @@ class TUdfKernelState : public arrow::compute::KernelState {
62
62
63
63
return *ScalarBuilder_;
64
64
}
65
+
66
+ const IValueBuilder& GetValueBuilder () {
67
+ Y_ENSURE (ValueBuilder_);
68
+ return *ValueBuilder_;
69
+ }
65
70
66
71
private:
67
72
const TVector<const TType*> ArgTypes_;
68
73
const TType* OutputType_;
69
74
const bool OnlyScalars_;
70
75
const ITypeInfoHelper* TypeInfoHelper_;
71
- const IPgBuilder& PgBuilder_;
76
+ const IValueBuilder* ValueBuilder_;
72
77
TVector<std::unique_ptr<IBlockReader>> Readers_;
73
78
std::unique_ptr<IArrayBuilder> ArrayBuilder_;
74
79
std::unique_ptr<IScalarBuilder> ScalarBuilder_;
@@ -157,7 +162,7 @@ class TSimpleArrowUdfImpl : public TBoxedValue {
157
162
}
158
163
}
159
164
160
- TUdfKernelState kernelState (ArgTypes_, OutputType_, OnlyScalars_, TypeInfoHelper_.Get (), valueBuilder-> GetPgBuilder () );
165
+ TUdfKernelState kernelState (ArgTypes_, OutputType_, OnlyScalars_, TypeInfoHelper_.Get (), valueBuilder);
161
166
arrow::compute::ExecContext execContext (GetYqlMemoryPool ());
162
167
arrow::compute::KernelContext kernelContext (&execContext);
163
168
kernelContext.SetState (&kernelState);
@@ -351,6 +356,7 @@ TReader* CastToBlockReaderImpl(IBlockReader& reader) {
351
356
352
357
template <typename TDerived, typename TReader = IBlockReader, typename TArrayBuilderImpl = IArrayBuilder, typename TScalarBuilderImpl = IScalarBuilder>
353
358
struct TUnaryKernelExec {
359
+
354
360
static arrow::Status Do (arrow::compute::KernelContext* ctx, const arrow::compute::ExecBatch& batch, arrow::Datum* res) {
355
361
auto & state = dynamic_cast <TUdfKernelState&>(*ctx->state ());
356
362
auto & reader = state.GetReader (0 );
@@ -362,7 +368,7 @@ struct TUnaryKernelExec {
362
368
auto * builderImpl = CastToScalarBuilderImpl<TScalarBuilderImpl>(builder);
363
369
364
370
auto item = readerImpl->GetScalarItem (*arg.scalar ());
365
- TDerived::Process (item, [&](TBlockItem out) {
371
+ TDerived::Process (&state. GetValueBuilder (), item, [&](TBlockItem out) {
366
372
*res = builderImpl->Build (out);
367
373
});
368
374
}
@@ -377,7 +383,7 @@ struct TUnaryKernelExec {
377
383
for (int64_t i = 0 ; i < array.length ;) {
378
384
for (size_t j = 0 ; j < maxBlockLength && i < array.length ; ++j, ++i) {
379
385
auto item = readerImpl->GetItem (array, i);
380
- TDerived::Process (item, [&](TBlockItem out) {
386
+ TDerived::Process (&state. GetValueBuilder (), item, [&](TBlockItem out) {
381
387
builderImpl->Add (out);
382
388
});
383
389
}
@@ -411,7 +417,8 @@ struct TBinaryKernelExec {
411
417
412
418
auto item1 = reader1Impl->GetScalarItem (*arg1.scalar ());
413
419
auto item2 = reader2Impl->GetScalarItem (*arg2.scalar ());
414
- TDerived::Process (item1, item2, [&](TBlockItem out) {
420
+
421
+ TDerived::Process (&state.GetValueBuilder (), item1, item2, [&](TBlockItem out) {
415
422
*res = builderImpl->Build (out);
416
423
});
417
424
}
@@ -427,7 +434,7 @@ struct TBinaryKernelExec {
427
434
for (int64_t i = 0 ; i < array2.length ;) {
428
435
for (size_t j = 0 ; j < maxBlockLength && i < array2.length ; ++j, ++i) {
429
436
auto item2 = reader2Impl->GetItem (array2, i);
430
- TDerived::Process (item1, item2, [&](TBlockItem out) {
437
+ TDerived::Process (&state. GetValueBuilder (), item1, item2, [&](TBlockItem out) {
431
438
builderImpl->Add (out);
432
439
});
433
440
}
@@ -448,7 +455,7 @@ struct TBinaryKernelExec {
448
455
for (int64_t i = 0 ; i < array1.length ;) {
449
456
for (size_t j = 0 ; j < maxBlockLength && i < array1.length ; ++j, ++i) {
450
457
auto item1 = reader1Impl->GetItem (array1, i);
451
- TDerived::Process (item1, item2, [&](TBlockItem out) {
458
+ TDerived::Process (&state. GetValueBuilder (), item1, item2, [&](TBlockItem out) {
452
459
builderImpl->Add (out);
453
460
});
454
461
}
@@ -470,9 +477,9 @@ struct TBinaryKernelExec {
470
477
Y_ENSURE (array1.length == array2.length );
471
478
for (int64_t i = 0 ; i < array1.length ;) {
472
479
for (size_t j = 0 ; j < maxBlockLength && i < array1.length ; ++j, ++i) {
473
- auto item1 = reader1. GetItem (array1, i);
474
- auto item2 = reader2. GetItem (array2, i);
475
- TDerived::Process (item1, item2, [&](TBlockItem out) {
480
+ auto item1 = reader1Impl-> GetItem (array1, i);
481
+ auto item2 = reader2Impl-> GetItem (array2, i);
482
+ TDerived::Process (&state. GetValueBuilder (), item1, item2, [&](TBlockItem out) {
476
483
builderImpl->Add (out);
477
484
});
478
485
}
@@ -529,7 +536,7 @@ struct TGenericKernelExec {
529
536
auto & reader = state.GetReader (k);
530
537
args[k] = reader.GetScalarItem (*batch[k].scalar ());
531
538
}
532
- TDerived::Process (items, [&](TBlockItem out) {
539
+ TDerived::Process (&state. GetValueBuilder (), items, [&](TBlockItem out) {
533
540
*res = builderImpl->Build (out);
534
541
});
535
542
} else {
@@ -559,7 +566,7 @@ struct TGenericKernelExec {
559
566
560
567
args[k] = reader.GetItem (*batch[k].array (), i);
561
568
}
562
- TDerived::Process (items, [&](TBlockItem out) {
569
+ TDerived::Process (&state. GetValueBuilder (), items, [&](TBlockItem out) {
563
570
builderImpl->Add (out);
564
571
});
565
572
}
0 commit comments