@@ -477,9 +477,8 @@ bool ExecSpanIterator::Next(ExecSpan* span, SelectionSpan* selection_span) {
477477 // Then the selection span
478478 if (selection_vector_) {
479479 DCHECK_NE (selection_span, nullptr );
480- const uint64_t chunk_start = static_cast <uint64_t >(position_);
481- const uint64_t chunk_end =
482- static_cast <uint64_t >(position_) + static_cast <uint64_t >(iteration_size);
480+ const int64_t chunk_start = position_;
481+ const int64_t chunk_end = position_ + iteration_size;
483482
484483 const int64_t consumed = selection_vector_->GetSpanForChunk (
485484 chunk_start, chunk_end, selection_position_, selection_span);
@@ -892,12 +891,6 @@ class ScalarExecutor : public KernelExecutorImpl<ScalarKernel> {
892891 return EmitResult (result->data (), listener);
893892 }
894893
895- if (batch.selection_vector && !kernel_->selective_exec ) {
896- // If the batch contains a selection vector but the kernel does not support
897- // selective execution, we need to execute the batch in a "dense" manner.
898- return ExecuteSelectiveDense (batch, listener);
899- }
900-
901894 return ExecuteBatch (batch, listener);
902895 }
903896
@@ -940,39 +933,6 @@ class ScalarExecutor : public KernelExecutorImpl<ScalarKernel> {
940933 }
941934 }
942935
943- // Execute a single batch with a selection vector "densely" for a kernel that doesn't
944- // support selective execution. "Densely" here means that we first gather the rows
945- // indicated by the selection vector into a contiguous ExecBatch, execute that, and
946- // then scatter the result back to the original row positions in the output.
947- Status ExecuteSelectiveDense (const ExecBatch& batch, ExecListener* listener) {
948- DCHECK (batch.selection_vector && !kernel_->selective_exec );
949-
950- if (CheckIfAllScalar (batch)) {
951- // For all-scalar batch, we can skip the gather/scatter steps as if there is no
952- // selection vector - the result is a scalar anyway.
953- ExecBatch input = batch;
954- input.selection_vector = nullptr ;
955- return ExecuteBatch (input, listener);
956- }
957-
958- ARROW_ASSIGN_OR_RAISE (
959- std::vector<Datum> values,
960- batch.selection_vector ->MakeDenseValues (batch.values , exec_context ()));
961- ARROW_ASSIGN_OR_RAISE (
962- ExecBatch input,
963- ExecBatch::Make (std::move (values), batch.selection_vector ->length ()));
964-
965- DatumAccumulator dense_listener;
966- RETURN_NOT_OK (ExecuteBatch (input, &dense_listener));
967- Datum dense_result = WrapResults (input.values , dense_listener.values ());
968-
969- ARROW_ASSIGN_OR_RAISE (
970- auto result,
971- batch.selection_vector ->ScatterDenseResult (dense_result, batch.length ,
972- exec_context ()));
973- return listener->OnResult (std::move (result));
974- }
975-
976936 Status EmitResult (std::shared_ptr<ArrayData> out, ExecListener* listener) {
977937 if (span_iterator_.have_all_scalars ()) {
978938 // ARROW-16757 We boxed scalar inputs as ArraySpan, so now we have to
@@ -1569,7 +1529,7 @@ void PropagateNullsSpans(const ExecSpan& batch, ArraySpan* out) {
15691529}
15701530
15711531std::unique_ptr<KernelExecutor> KernelExecutor::MakeScalar () {
1572- return std::make_unique<detail::ScalarExecutor>();
1532+ return MakeDenseSelectionExecutor ( std::make_unique<detail::ScalarExecutor>() );
15731533}
15741534
15751535std::unique_ptr<KernelExecutor> KernelExecutor::MakeVector () {
@@ -1708,26 +1668,27 @@ class IndexSelectionVector final : public SelectionVector {
17081668 return Scatter (dense_result, indices, ScatterOptions{/* max_index=*/ output_length - 1 });
17091669 }
17101670
1711- int64_t GetSpanForChunk (uint64_t chunk_start, uint64_t chunk_end,
1671+ int64_t GetSpanForChunk (int64_t chunk_start, int64_t chunk_end,
17121672 int64_t selection_position,
17131673 SelectionSpan* out) const override {
17141674 DCHECK_NE (out, nullptr );
1675+ DCHECK_GE (chunk_start, 0 );
17151676 DCHECK_LE (chunk_start, chunk_end);
17161677
17171678 const int32_t * indices_begin = indices_ + selection_position;
17181679 const int32_t * indices_end = indices_ + length ();
17191680 DCHECK_LE (indices_begin, indices_end);
17201681
1721- const int32_t chunk_end_i32 = static_cast < int32_t >(chunk_end);
1722- const int32_t * indices_limit =
1723- std::lower_bound (indices_begin, indices_end, chunk_end_i32 );
1682+ const int32_t * indices_limit = std::lower_bound (
1683+ indices_begin, indices_end, chunk_end,
1684+ []( int32_t index, int64_t end) { return static_cast < int64_t >(index) < end; } );
17241685 const int64_t num_indices = indices_limit - indices_begin;
17251686
17261687 if (num_indices > 0 ) {
17271688 const int32_t first = indices_begin[0 ];
17281689 const int32_t last = indices_begin[num_indices - 1 ];
1729- DCHECK_GE (static_cast <uint64_t >(first), chunk_start);
1730- DCHECK_LT (static_cast <uint64_t >(last), chunk_end);
1690+ DCHECK_GE (static_cast <int64_t >(first), chunk_start);
1691+ DCHECK_LT (static_cast <int64_t >(last), chunk_end);
17311692
17321693 // If the discrete indices form a contiguous run, represent them as such.
17331694 // Since Validate enforces strict increasing order, checking
@@ -1737,10 +1698,10 @@ class IndexSelectionVector final : public SelectionVector {
17371698 static_cast <int64_t >(chunk_start),
17381699 num_indices};
17391700 } else {
1740- *out = DiscreteSpan{indices_begin, num_indices, static_cast < int32_t >( chunk_start) };
1701+ *out = DiscreteSpan{indices_begin, num_indices, chunk_start};
17411702 }
17421703 } else {
1743- *out = DiscreteSpan{indices_begin, /* length=*/ 0 , static_cast < int32_t >( chunk_start) };
1704+ *out = DiscreteSpan{indices_begin, /* length=*/ 0 , chunk_start};
17441705 }
17451706
17461707 return num_indices;
0 commit comments