alamb commented on code in PR #2332:
URL: https://github.com/apache/arrow-datafusion/pull/2332#discussion_r857517340
##########
datafusion/common/src/scalar.rs:
##########
@@ -1391,6 +1391,29 @@ impl ScalarValue {
}
Self::Struct(Some(Box::new(field_values)),
Box::new(fields.clone()))
}
+ DataType::FixedSizeList(nested_type, _len) => {
+ let list_array = array
+ .as_any()
+ .downcast_ref::<FixedSizeListArray>()
+ .ok_or_else(|| {
+ DataFusionError::Internal(
+ "Failed to downcast
FixedSizeListArray".to_string(),
+ )
+ })?;
Review Comment:
This is fine -- I also think it is fine to panic in this case where the data
type didn't match the array type as this is not an error condition DataFusion
is expected to handle in the normal case:
```suggestion
.unwrap();
```
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -90,18 +90,12 @@ fn array_array(args: &[&dyn Array]) -> Result<ArrayRef> {
/// put values in an array.
pub fn array(values: &[ColumnarValue]) -> Result<ColumnarValue> {
- let arrays: Vec<&dyn Array> = values
- .iter()
- .map(|value| {
- if let ColumnarValue::Array(value) = value {
- Ok(value.as_ref())
- } else {
- Err(DataFusionError::NotImplemented(
- "Array is not implemented for scalar values.".to_string(),
- ))
- }
- })
- .collect::<Result<_>>()?;
-
- Ok(ColumnarValue::Array(array_array(&arrays)?))
+ let mut arrays: Vec<ArrayRef> = vec![];
+ for x in values {
+ match x {
+ ColumnarValue::Array(array) => arrays.push(array.clone()),
+ ColumnarValue::Scalar(scalar) =>
arrays.push(scalar.to_array().clone()),
+ }
+ }
Review Comment:
If you wanted to write this slightly more idomatically it could be
```suggestion
let arrays: Vec<ArrayRef> = values.iter().map(|x| {
match x {
ColumnarValue::Array(array) => array.clone(),
ColumnarValue::Scalar(scalar) => scalar.to_array().clone(),
})
.collect()
}
```
However, I don't think it makes any practical difference
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]