Skip to content

Commit 57aeeb1

Browse files
committed
impl
1 parent 33f18b5 commit 57aeeb1

File tree

1 file changed

+50
-22
lines changed

1 file changed

+50
-22
lines changed

native/core/src/execution/planner.rs

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use arrow::array::{
8989
Float64Array, Int16Array, Int32Array, Int64Array, Int8Array, ListArray, NullArray,
9090
StringBuilder, TimestampMicrosecondArray,
9191
};
92-
use arrow::buffer::{BooleanBuffer, OffsetBuffer};
92+
use arrow::buffer::{BooleanBuffer, NullBuffer, OffsetBuffer};
9393
use datafusion::common::utils::SingleRowListArrayBuilder;
9494
use datafusion::physical_plan::coalesce_batches::CoalesceBatchesExec;
9595
use datafusion::physical_plan::filter::FilterExec;
@@ -484,10 +484,8 @@ impl PhysicalPlanner {
484484
}
485485
},
486486
Value::ListVal(values) => {
487-
dbg!(&values);
488-
489-
if let DataType::List(f) = data_type {
490-
SingleRowListArrayBuilder::new(literal_to_array_ref(f.data_type().clone(), values.clone())?).build_list_scalar()
487+
if let DataType::List(ref f) = data_type {
488+
SingleRowListArrayBuilder::new(literal_to_array_ref(data_type, values.clone())?).build_list_scalar()
491489
} else {
492490
return Err(GeneralError(format!(
493491
"Expected DataType::List but got {data_type:?}"
@@ -2826,29 +2824,29 @@ fn literal_to_array_ref(
28262824
.collect();
28272825

28282826
// Convert Vec<ArrayRef> into Vec<&dyn Array> for concat()
2829-
let child_refs: Vec<&dyn arrow::array::Array> =
2827+
let child_refs: Vec<&dyn Array> =
28302828
child_arrays.iter().map(|a| a.as_ref()).collect();
28312829

2832-
// Concatenate all child arrays' *values* into one array
2833-
// Example: [[1,2,3], [4,5,6]] → values = [1,2,3,4,5,6]
2834-
let concat = arrow::compute::concat(&child_refs).unwrap();
2835-
28362830
// --- Build offsets for the parent list ---
28372831
let mut offsets = Vec::with_capacity(child_arrays.len() + 1);
2838-
offsets.push(0); // first list always starts at 0
2832+
offsets.push(0); // the first list always starts at 0
28392833
let mut sum = 0;
28402834
for arr in &child_arrays {
2841-
sum += arr.len() as i32; // each child's length adds to total
2842-
offsets.push(sum); // store cumulative sum as next offset
2835+
sum += arr.len() as i32; // each child's length adds to the total
2836+
offsets.push(sum); // store cumulative sum as the next offset
28432837
}
28442838

2839+
// Concatenate all child arrays' *values* into one array
2840+
// Example: [[1,2,3], [4,5,6]] → values = [1,2,3,4,5,6]
2841+
let concat = arrow::compute::concat(&child_refs)?;
2842+
28452843
// Create and return the parent ListArray
28462844
Ok(Arc::new(ListArray::new(
28472845
// Field: item type matches the concatenated child's type
28482846
FieldRef::from(Field::new("item", concat.data_type().clone(), true)),
2849-
OffsetBuffer::new(offsets.into()), // where each sublist starts/ends
2850-
concat, // the flattened values array
2851-
None, // no null bitmap at this level
2847+
OffsetBuffer::new(offsets.into()),
2848+
concat,
2849+
Some(NullBuffer::from(list_literal.null_mask)),
28522850
)))
28532851
}
28542852
dt => Err(GeneralError(format!(
@@ -3701,8 +3699,11 @@ mod tests {
37013699
ListLiteral {
37023700
..Default::default()
37033701
},
3702+
ListLiteral {
3703+
..Default::default()
3704+
},
37043705
],
3705-
null_mask: vec![true, true, true, false],
3706+
null_mask: vec![true, true, true, false, true],
37063707
..Default::default()
37073708
},
37083709
ListLiteral {
@@ -3714,11 +3715,11 @@ mod tests {
37143715
null_mask: vec![true],
37153716
..Default::default()
37163717
},
3717-
ListLiteral {
3718-
..Default::default()
3719-
},
3718+
// ListLiteral {
3719+
// ..Default::default()
3720+
// },
37203721
],
3721-
null_mask: vec![true, true, false],
3722+
null_mask: vec![true, true],
37223723
..Default::default()
37233724
};
37243725

@@ -3742,8 +3743,35 @@ mod tests {
37423743
true, // outer list nullable
37433744
)));
37443745

3746+
let data = ListLiteral {
3747+
list_values: vec![
3748+
ListLiteral {
3749+
int_values: vec![1, 2],
3750+
null_mask: vec![true, true],
3751+
..Default::default()
3752+
},
3753+
ListLiteral {
3754+
..Default::default()
3755+
}
3756+
],
3757+
null_mask: vec![true, false],
3758+
..Default::default()
3759+
};
3760+
3761+
let nested_type = DataType::List(FieldRef::from(Field::new(
3762+
"item",
3763+
DataType::List(
3764+
Field::new("item", DataType::Int32, true).into(),
3765+
), true)));
3766+
37453767
let array = literal_to_array_ref(nested_type, data)?;
37463768

3769+
dbg!(&array);
3770+
dbg!(&array.nulls());
3771+
3772+
3773+
3774+
37473775
// Top-level should be ListArray<ListArray<Int32>>
37483776
let list_outer = array.as_any().downcast_ref::<ListArray>().unwrap();
37493777
assert_eq!(list_outer.len(), 2);
@@ -3752,7 +3780,7 @@ mod tests {
37523780
let first_elem = list_outer.value(0);
37533781
dbg!(&first_elem);
37543782
let list_inner = first_elem.as_any().downcast_ref::<ListArray>().unwrap();
3755-
assert_eq!(list_inner.len(), 4);
3783+
assert_eq!(list_inner.len(), 5);
37563784

37573785
// Inner values
37583786
let v0 = list_inner.value(0);

0 commit comments

Comments
 (0)