mbutrovich opened a new issue, #27728:
URL: https://github.com/apache/datafusion/issues/27728

   ### Describe the bug
   
   `MaterializingSortMergeJoinStream` calls `.expect("Failed to push output 
batch")` on `BatchCoalescer::push_batch` in 
[`on_children_exhausted`](https://github.com/apache/datafusion/blob/9d894e1ae001391cfde2f6d3078ac1989396ff90/datafusion/physical-plan/src/joins/sort_merge_join/materializing_stream.rs#L985-L988)
 and in 
[`stage_filtered_output`](https://github.com/apache/datafusion/blob/9d894e1ae001391cfde2f6d3078ac1989396ff90/datafusion/physical-plan/src/joins/sort_merge_join/materializing_stream.rs#L1059-L1062).
 `push_batch` returns an error when it cannot concatenate the batches it holds, 
so the join panics where it should return that error. Both functions return 
`Result`, so `?` would propagate it.
   
   ### To Reproduce
   
   A filtered left join whose output coalescer combines two staged batches 
whose `Dictionary(Int8, Utf8)` columns hold 200 values between them. Each build 
batch holds 101 values, and the filter keeps half of each batch's pairs, so 
neither stage fills an output batch by itself. Added to 
`datafusion/physical-plan/src/joins/sort_merge_join/tests.rs`:
   
   ```rust
   #[tokio::test]
   async fn coalescer_error_panics() -> Result<()> {
       use arrow::datatypes::Int8Type;
       let left_schema = Arc::new(Schema::new(vec![
           Field::new("lk", DataType::Int32, false),
           Field::new("lx", DataType::Int32, false),
       ]));
       let right_schema = Arc::new(Schema::new(vec![
           Field::new("rk", DataType::Int32, false),
           Field::new("rx", DataType::Int32, false),
           Field::new(
               "p",
               DataType::Dictionary(Box::new(DataType::Int8), 
Box::new(DataType::Utf8)),
               false,
           ),
       ]));
       let left = RecordBatch::try_new(
           Arc::clone(&left_schema),
           vec![
               Arc::new(Int32Array::from((0..200).collect::<Vec<_>>())),
               Arc::new(Int32Array::from(vec![0; 200])),
           ],
       )?;
       // Each key has one row that fails `lx <= rx` and one that passes
       let right_batch = |base: i32, tag: &str| -> Result<RecordBatch> {
           let (mut k, mut x, mut p) = (vec![], vec![], vec![]);
           for i in 0..100 {
               k.extend([base + i, base + i]);
               x.extend([-1, 0]);
               p.extend([format!("{tag}-fails"), format!("{tag}{i}")]);
           }
           Ok(RecordBatch::try_new(
               Arc::clone(&right_schema),
               vec![
                   Arc::new(Int32Array::from(k)),
                   Arc::new(Int32Array::from(x)),
                   
Arc::new(p.iter().map(String::as_str).collect::<DictionaryArray<Int8Type>>()),
               ],
           )?)
       };
       let right = vec![right_batch(0, "a")?, right_batch(100, "b")?];
       let left_exec = TestMemoryExec::try_new_exec(&[vec![left]], 
Arc::clone(&left_schema), None)?;
       let right_exec = TestMemoryExec::try_new_exec(&[right], 
Arc::clone(&right_schema), None)?;
       let on: JoinOn = vec![(
           Arc::new(Column::new_with_schema("lk", &left_schema)?) as _,
           Arc::new(Column::new_with_schema("rk", &right_schema)?) as _,
       )];
       let filter = JoinFilter::new(
           Arc::new(BinaryExpr::new(
               Arc::new(Column::new("lx", 0)),
               Operator::LtEq,
               Arc::new(Column::new("rx", 1)),
           )),
           vec![
               ColumnIndex { index: 1, side: JoinSide::Left },
               ColumnIndex { index: 1, side: JoinSide::Right },
           ],
           Arc::new(Schema::new(vec![
               Field::new("lx", DataType::Int32, false),
               Field::new("rx", DataType::Int32, false),
           ])),
       );
       let join = SortMergeJoinExec::try_new(
           left_exec,
           right_exec,
           on,
           Some(filter),
           Left,
           vec![SortOptions::default()],
           NullEquality::NullEqualsNothing,
       )?;
       let ctx = Arc::new(
           
TaskContext::default().with_session_config(SessionConfig::new().with_batch_size(200)),
       );
       let _ = common::collect(join.execute(0, ctx)?).await;
       Ok(())
   }
   ```
   
   It panics:
   
   ```
   panicked at 
datafusion/physical-plan/src/joins/sort_merge_join/materializing_stream.rs:988:22:
   Failed to push output batch: ComputeError("Failed to concatenate column 'p': 
Dictionary key bigger than the key type")
   ```
   
   ### Expected behavior
   
   The join returns the error. `HashJoinExec` returns the same overflow as an 
error: the same tables joined with a hash join in `datafusion-cli` fail with 
`Execution error: Dictionary key type Int8 cannot represent 200 distinct 
values`.


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to