Skip to content

Commit

Permalink
remove general conversion
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
  • Loading branch information
jayzhan211 committed Nov 17, 2023
1 parent 7f6e6e7 commit 6b56441
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 40 deletions.
37 changes: 0 additions & 37 deletions datafusion/common/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,43 +2110,6 @@ impl ScalarValue {
}
}

/// Retrieve ScalarValue for each row in `array`
///
/// Example
/// ```
/// use datafusion_common::ScalarValue;
/// use arrow::array::ListArray;
/// use arrow::datatypes::{DataType, Int32Type};
///
/// let list_arr = ListArray::from_iter_primitive::<Int32Type, _, _>(vec![
/// Some(vec![Some(1), Some(2), Some(3)]),
/// None,
/// Some(vec![Some(4), Some(5)])
/// ]);
///
/// let scalar_vec = ScalarValue::convert_array_to_scalar_vec(&list_arr).unwrap();
///
/// let expected = vec![
/// vec![
/// ScalarValue::Int32(Some(1)),
/// ScalarValue::Int32(Some(2)),
/// ScalarValue::Int32(Some(3)),
/// ],
/// vec![],
/// vec![ScalarValue::Int32(Some(4)), ScalarValue::Int32(Some(5))]
/// ];
///
/// assert_eq!(scalar_vec, expected);
/// ```
pub fn convert_array_to_scalar_vec(array: &dyn Array) -> Result<Vec<Vec<Self>>> {
let data_type = array.data_type().to_owned();

match data_type {
DataType::List(_) => Self::convert_list_array_to_scalar_vec(array),
_ => Ok(vec![Self::convert_non_list_array_to_scalars(array)?]),
}
}

// TODO: Support more types after other ScalarValue is wrapped with ArrayRef
/// Get raw data (inner array) inside ScalarValue
pub fn raw_data(&self) -> Result<ArrayRef> {
Expand Down
14 changes: 11 additions & 3 deletions datafusion/physical-expr/src/aggregate/array_agg_distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,17 @@ impl Accumulator for DistinctArrayAggAccumulator {
assert_eq!(values.len(), 1, "batch input should only include 1 column!");

let array = &values[0];
let scalars = ScalarValue::convert_array_to_scalar_vec(array)?;
for scalar in scalars {
self.values.extend(scalar)
match array.data_type() {
DataType::List(_) => {
let scalar_vec = ScalarValue::convert_list_array_to_scalar_vec(array)?;
for scalars in scalar_vec {
self.values.extend(scalars);
}
}
_ => {
let scalars = ScalarValue::convert_non_list_array_to_scalars(array)?;
self.values.extend(scalars);
}
}
Ok(())
}
Expand Down

0 comments on commit 6b56441

Please sign in to comment.