MCPcopy Create free account
hub / github.com/apache/datafusion / add_partial_result

Method add_partial_result

datafusion/physical-expr/src/expressions/case.rs:553–602  ·  view source on GitHub ↗

Adds a partial result array. This method adds the given array data as a partial result and updates the index mapping to indicate that the specified rows should take their values from this array. The partial results will be merged into a single array when finish() is called.

(
        &mut self,
        row_indices: &ArrayRef,
        row_values: ArrayRef,
    )

Source from the content-addressed store, hash-verified

551 /// to indicate that the specified rows should take their values from this array.
552 /// The partial results will be merged into a single array when finish() is called.
553 fn add_partial_result(
554 &mut self,
555 row_indices: &ArrayRef,
556 row_values: ArrayRef,
557 ) -> Result<()> {
558 assert_or_internal_err!(
559 row_indices.null_count() == 0,
560 "Row indices must not contain nulls"
561 );
562
563 match &mut self.state {
564 ResultState::Empty => {
565 let array_index = PartialResultIndex::zero();
566 let mut indices = vec![PartialResultIndex::none(); self.row_count];
567 for row_ix in row_indices.as_primitive::<UInt32Type>().values().iter() {
568 indices[*row_ix as usize] = array_index;
569 }
570
571 self.state = ResultState::Partial {
572 arrays: vec![row_values],
573 indices,
574 };
575
576 Ok(())
577 }
578 ResultState::Partial { arrays, indices } => {
579 let array_index = PartialResultIndex::try_new(arrays.len())?;
580
581 arrays.push(row_values);
582
583 for row_ix in row_indices.as_primitive::<UInt32Type>().values().iter() {
584 // This is check is only active for debug config because the callers of this method,
585 // `case_when_with_expr` and `case_when_no_expr`, already ensure that
586 // they only calculate a value for each row at most once.
587 #[cfg(debug_assertions)]
588 assert_or_internal_err!(
589 indices[*row_ix as usize].is_none(),
590 "Duplicate value for row {}",
591 *row_ix
592 );
593
594 indices[*row_ix as usize] = array_index;
595 }
596 Ok(())
597 }
598 ResultState::Complete(_) => internal_err!(
599 "Cannot add a partial result when complete result is already set"
600 ),
601 }
602 }
603
604 /// Sets a result that applies to all rows.
605 ///

Callers 1

add_branch_resultMethod · 0.80

Calls 4

iterMethod · 0.45
valuesMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected