Skip to content

Commit

Permalink
remove convert-list/non-list
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <[email protected]>
  • Loading branch information
jayzhan211 committed Dec 18, 2023
1 parent d19fdf0 commit 1c82d51
Showing 1 changed file with 0 additions and 85 deletions.
85 changes: 0 additions & 85 deletions datafusion/common/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2080,60 +2080,6 @@ impl ScalarValue {
}
}

/// Retrieve ScalarValue for each row in `array`
///
/// Convert ListArray to `Vec<Vec<ScalarValue>>`, first `Vec` is for rows, second `Vec` is for elements in the list
///
/// 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_list_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_list_array_to_scalar_vec(array: &dyn Array) -> Result<Vec<Vec<Self>>> {
let mut scalars_vec = Vec::with_capacity(array.len());

if let Some(list_arr) = array.as_list_opt::<i32>() {
for index in 0..list_arr.len() {
let scalars = match list_arr.is_null(index) {
true => Vec::new(),
false => {
let nested_array = list_arr.value(index);
ScalarValue::convert_list_array_to_scalar_vec(&nested_array)?
.into_iter()
.flatten()
.collect()
}
};
scalars_vec.push(scalars);
}
} else {
let scalars = ScalarValue::convert_non_list_array_to_scalars(array)?;
scalars_vec.push(scalars);
}
Ok(scalars_vec)
}

/// Retrieve ScalarValue for each row in `array`
///
/// Example
Expand Down Expand Up @@ -2190,37 +2136,6 @@ impl ScalarValue {
Ok(scalars)
}

/// Convert non-ListArray to `Vec<ScalarValue>`
///
/// Example
/// ```
/// use datafusion_common::ScalarValue;
/// use arrow::array::Int32Array;
///
/// let list_arr = Int32Array::from(vec![Some(1), Some(2), Some(3), None, Some(4), Some(5)]);
///
/// let scalar_vec = ScalarValue::convert_non_list_array_to_scalars(&list_arr).unwrap();
///
/// let expected = vec![
/// ScalarValue::Int32(Some(1)),
/// ScalarValue::Int32(Some(2)),
/// ScalarValue::Int32(Some(3)),
/// ScalarValue::Int32(None),
/// ScalarValue::Int32(Some(4)),
/// ScalarValue::Int32(Some(5)),
/// ];
///
/// assert_eq!(scalar_vec, expected);
/// ```
pub fn convert_non_list_array_to_scalars(array: &dyn Array) -> Result<Vec<Self>> {
let mut scalars = Vec::with_capacity(array.len());
for index in 0..array.len() {
let scalar = ScalarValue::try_from_array(array, index)?;
scalars.push(scalar);
}
Ok(scalars)
}

// 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

0 comments on commit 1c82d51

Please sign in to comment.