Skip to content

Commit 1c591f7

Browse files
committed
Add recursive unnesting test for repeated references preserving order
1 parent 520e3d9 commit 1c591f7

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

datafusion/core/tests/dataframe/unnest_chunks.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,60 @@ async fn unnest_chunks_stacked_unnest_preserves_order() -> Result<()> {
330330

331331
Ok(())
332332
}
333+
334+
#[tokio::test]
335+
async fn unnest_chunks_recursive_repeated_refs_preserve_order() -> Result<()> {
336+
let ctx = batch_slicing_ctx(2);
337+
338+
ctx.sql(
339+
"CREATE TABLE recursive_unnest_table AS VALUES \
340+
(struct([1], 'a'), [[[1],[2]],[[1,1]]], [struct([1],[[1,2]])]), \
341+
(struct([2], 'b'), [[[3,4],[5]],[[null,6],null,[7,8]]], [struct([2],[[3],[4]])])",
342+
)
343+
.await?;
344+
345+
let dataframe = ctx
346+
.sql(
347+
"SELECT \
348+
unnest(column2), \
349+
unnest(unnest(column2)), \
350+
unnest(unnest(unnest(column2))), \
351+
unnest(unnest(unnest(column2))) + 1 \
352+
FROM recursive_unnest_table",
353+
)
354+
.await?;
355+
356+
let results = dataframe.collect().await?;
357+
358+
assert_snapshot!(
359+
batches_to_string(&results),
360+
@r"
361+
+----------------------------------------+------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------+
362+
| UNNEST(recursive_unnest_table.column2) | UNNEST(UNNEST(recursive_unnest_table.column2)) | UNNEST(UNNEST(UNNEST(recursive_unnest_table.column2))) | UNNEST(UNNEST(UNNEST(recursive_unnest_table.column2))) + Int64(1) |
363+
+----------------------------------------+------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------+
364+
| [[1], [2]] | [1] | 1 | 2 |
365+
| [[1, 1]] | [2] | | |
366+
| [[1], [2]] | [1, 1] | 2 | 3 |
367+
| [[1, 1]] | | | |
368+
| [[1], [2]] | [1] | 1 | 2 |
369+
| [[1, 1]] | [2] | 1 | 2 |
370+
| [[1], [2]] | [1, 1] | | |
371+
| [[1, 1]] | | | |
372+
| [[3, 4], [5]] | [3, 4] | 3 | 4 |
373+
| [[, 6], , [7, 8]] | [5] | 4 | 5 |
374+
| [[3, 4], [5]] | [, 6] | 5 | 6 |
375+
| [[, 6], , [7, 8]] | | | |
376+
| | [7, 8] | | |
377+
| [[3, 4], [5]] | [3, 4] | | |
378+
| [[, 6], , [7, 8]] | [5] | 6 | 7 |
379+
| [[3, 4], [5]] | [, 6] | | |
380+
| [[, 6], , [7, 8]] | | | |
381+
| | [7, 8] | | |
382+
| [[3, 4], [5]] | | 7 | 8 |
383+
| [[, 6], , [7, 8]] | | 8 | 9 |
384+
+----------------------------------------+------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------+
385+
"
386+
);
387+
388+
Ok(())
389+
}

0 commit comments

Comments
 (0)