11#include " arrow_filter.h"
22#include " switch_type.h"
3+ #include " common/container.h"
4+ #include " common/adapter.h"
5+
36#include < contrib/libs/apache/arrow/cpp/src/arrow/array/builder_primitive.h>
47#include < contrib/libs/apache/arrow/cpp/src/arrow/chunked_array.h>
58#include < contrib/libs/apache/arrow/cpp/src/arrow/compute/api_vector.h>
@@ -307,7 +310,7 @@ NKikimr::NArrow::TColumnFilter TColumnFilter::MakePredicateFilter(const arrow::D
307310 return NArrow::TColumnFilter (std::move (bits));
308311}
309312
310- template <arrow::Datum::Kind kindExpected, class TData >
313+ template <class TData >
311314bool ApplyImpl (const TColumnFilter& filter, std::shared_ptr<TData>& batch, const std::optional<ui32> startPos, const std::optional<ui32> count) {
312315 if (!batch || !batch->num_rows ()) {
313316 return false ;
@@ -322,33 +325,26 @@ bool ApplyImpl(const TColumnFilter& filter, std::shared_ptr<TData>& batch, const
322325 }
323326 }
324327 if (filter.IsTotalDenyFilter ()) {
325- batch = batch-> Slice ( 0 , 0 );
328+ batch = NAdapter::TDataBuilderPolicy<TData>:: GetEmptySame (batch );
326329 return true ;
327330 }
328331 if (filter.IsTotalAllowFilter ()) {
329332 return true ;
330333 }
331- auto res = arrow::compute::Filter (batch, filter.BuildArrowFilter (batch->num_rows (), startPos, count));
332- Y_VERIFY_S (res.ok (), res.status ().message ());
333- Y_ABORT_UNLESS ((*res).kind () == kindExpected);
334- if constexpr (kindExpected == arrow::Datum::TABLE) {
335- batch = (*res).table ();
336- return batch->num_rows ();
337- }
338- if constexpr (kindExpected == arrow::Datum::RECORD_BATCH) {
339- batch = (*res).record_batch ();
340- return batch->num_rows ();
341- }
342- AFL_VERIFY (false );
343- return false ;
334+ batch = NAdapter::TDataBuilderPolicy<TData>::ApplyArrowFilter (batch, filter.BuildArrowFilter (batch->num_rows (), startPos, count));
335+ return batch->num_rows ();
336+ }
337+
338+ bool TColumnFilter::Apply (std::shared_ptr<TGeneralContainer>& batch, const std::optional<ui32> startPos, const std::optional<ui32> count) const {
339+ return ApplyImpl (*this , batch, startPos, count);
344340}
345341
346342bool TColumnFilter::Apply (std::shared_ptr<arrow::Table>& batch, const std::optional<ui32> startPos, const std::optional<ui32> count) const {
347- return ApplyImpl<arrow::Datum::TABLE> (*this , batch, startPos, count);
343+ return ApplyImpl (*this , batch, startPos, count);
348344}
349345
350346bool TColumnFilter::Apply (std::shared_ptr<arrow::RecordBatch>& batch, const std::optional<ui32> startPos, const std::optional<ui32> count) const {
351- return ApplyImpl<arrow::Datum::RECORD_BATCH> (*this , batch, startPos, count);
347+ return ApplyImpl (*this , batch, startPos, count);
352348}
353349
354350void TColumnFilter::Apply (const ui32 expectedRecordsCount, std::vector<arrow::Datum*>& datums) const {
0 commit comments