alamb commented on code in PR #8562:
URL: https://github.com/apache/arrow-datafusion/pull/8562#discussion_r1443407346
##########
datafusion/proto/src/logical_plan/to_proto.rs:
##########
@@ -1189,24 +1188,79 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue {
schema: Some(schema),
};
- match val {
- ScalarValue::List(_) => Ok(protobuf::ScalarValue {
- value: Some(protobuf::scalar_value::Value::ListValue(
- scalar_list_value,
- )),
- }),
- ScalarValue::LargeList(_) => Ok(protobuf::ScalarValue {
- value:
Some(protobuf::scalar_value::Value::LargeListValue(
- scalar_list_value,
- )),
- }),
- ScalarValue::FixedSizeList(_) => Ok(protobuf::ScalarValue {
- value:
Some(protobuf::scalar_value::Value::FixedSizeListValue(
- scalar_list_value,
- )),
- }),
- _ => unreachable!(),
- }
+ Ok(protobuf::ScalarValue {
+ value: Some(protobuf::scalar_value::Value::ListValue(
+ scalar_list_value,
+ )),
+ })
+ }
+ ScalarValue::LargeList(arr) => {
Review Comment:
Would it be possible to avoid the copy/paste in this method by making a
function? Something like the following?
```rust
fn encode_scalar_list_value(array: &Array) ->
Result<protobuf::ScalarListValue> {
...
}
```
##########
datafusion/common/src/scalar.rs:
##########
@@ -359,29 +359,77 @@ impl PartialOrd for ScalarValue {
(FixedSizeBinary(_, _), _) => None,
(LargeBinary(v1), LargeBinary(v2)) => v1.partial_cmp(v2),
(LargeBinary(_), _) => None,
- (List(arr1), List(arr2))
- | (FixedSizeList(arr1), FixedSizeList(arr2))
- | (LargeList(arr1), LargeList(arr2)) => {
- // ScalarValue::List / ScalarValue::FixedSizeList /
ScalarValue::LargeList are ensure to have length 1
+ // ScalarValue::List / ScalarValue::FixedSizeList /
ScalarValue::LargeList are ensure to have length 1
+ (List(arr1), List(arr2)) => {
assert_eq!(arr1.len(), 1);
assert_eq!(arr2.len(), 1);
if arr1.data_type() != arr2.data_type() {
return None;
}
- fn first_array_for_list(arr: &ArrayRef) -> ArrayRef {
- if let Some(arr) = arr.as_list_opt::<i32>() {
- arr.value(0)
- } else if let Some(arr) = arr.as_list_opt::<i64>() {
- arr.value(0)
- } else if let Some(arr) = arr.as_fixed_size_list_opt() {
- arr.value(0)
- } else {
- unreachable!("Since only List / LargeList /
FixedSizeList are supported, this should never happen")
+ fn first_array_for_list(arr: &Arc<ListArray>) -> ArrayRef {
Review Comment:
It would be really nice here to avoid the redundant copy/paste code, perhaps
by making a function with signature like this
```
fn cmp_list_array(arr1: &dyn Array, arr2: &dyn Array) -> Option<Ordering> {
..
}
```
Which then you can call with `Arc<ListArray>` and `Arc<LargeListArray>`
types
--
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]