|
18 | 18 | //! Expression simplification API |
19 | 19 |
|
20 | 20 | use arrow::{ |
21 | | - array::{AsArray, new_null_array}, |
| 21 | + array::{Array, AsArray, new_null_array}, |
22 | 22 | datatypes::{DataType, Field, Schema}, |
23 | 23 | record_batch::RecordBatch, |
24 | 24 | }; |
@@ -652,6 +652,17 @@ impl ConstEvaluator { |
652 | 652 | if source_fields.len() != target_fields.len() { |
653 | 653 | return false; |
654 | 654 | } |
| 655 | + |
| 656 | + // Don't const-fold struct casts with empty (0-row) literals |
| 657 | + // The simplifier uses a 1-row input batch, which causes dimension mismatches |
| 658 | + // when evaluating 0-row struct literals |
| 659 | + if let Expr::Literal(ScalarValue::Struct(struct_array), _) = |
| 660 | + expr.as_ref() |
| 661 | + { |
| 662 | + if struct_array.len() == 0 { |
| 663 | + return false; |
| 664 | + } |
| 665 | + } |
655 | 666 | } |
656 | 667 | true |
657 | 668 | } |
@@ -5069,7 +5080,7 @@ mod tests { |
5069 | 5080 | ]); |
5070 | 5081 |
|
5071 | 5082 | // Create an empty struct with the source fields |
5072 | | - let arrays: Vec<Arc<dyn arrow::array::Array>> = vec![ |
| 5083 | + let arrays: Vec<Arc<dyn Array>> = vec![ |
5073 | 5084 | Arc::new(arrow::array::Int32Array::new(vec![].into(), None)), |
5074 | 5085 | Arc::new(arrow::array::Int32Array::new(vec![].into(), None)), |
5075 | 5086 | ]; |
@@ -5109,7 +5120,7 @@ mod tests { |
5109 | 5120 | ]); |
5110 | 5121 |
|
5111 | 5122 | // Create an empty struct with the source fields |
5112 | | - let arrays: Vec<Arc<dyn arrow::array::Array>> = vec![ |
| 5123 | + let arrays: Vec<Arc<dyn Array>> = vec![ |
5113 | 5124 | Arc::new(arrow::array::Int32Array::new(vec![].into(), None)), |
5114 | 5125 | Arc::new(arrow::array::Int32Array::new(vec![].into(), None)), |
5115 | 5126 | ]; |
@@ -5148,7 +5159,7 @@ mod tests { |
5148 | 5159 | ]); |
5149 | 5160 |
|
5150 | 5161 | // Create an empty struct with the source fields |
5151 | | - let arrays: Vec<Arc<dyn arrow::array::Array>> = vec![ |
| 5162 | + let arrays: Vec<Arc<dyn Array>> = vec![ |
5152 | 5163 | Arc::new(arrow::array::Int32Array::new(vec![].into(), None)), |
5153 | 5164 | Arc::new(arrow::array::Int32Array::new(vec![].into(), None)), |
5154 | 5165 | ]; |
|
0 commit comments