jonahgao commented on code in PR #9592:
URL: https://github.com/apache/arrow-datafusion/pull/9592#discussion_r1522777692
##########
datafusion/sqllogictest/test_files/unnest.slt:
##########
@@ -254,5 +249,89 @@ select * from unnest([1,2,(select sum(column3) from
unnest_table)]);
2
10
+## Unnest is the sub-expression of other expression
+query II
+select unnest(column1) as a, column3 from unnest_table;
+----
+1 1
+2 1
+3 1
+4 2
+5 2
+6 3
+12 NULL
+
+query BI
+select unnest(column1) is not null, column3 from unnest_table;
+----
+true 1
+true 1
+true 1
+true 2
+true 2
+true 3
+true NULL
+
+query II
+select -unnest(column1) as a, column3 from unnest_table;
+----
+-1 1
+-2 1
+-3 1
+-4 2
+-5 2
+-6 3
+-12 NULL
+
+query II
+select unnest(array_remove(column1, 3)) as a, column3 from unnest_table;
+----
+1 1
+2 1
+4 2
+5 2
+6 3
+12 NULL
+
+query II
+select unnest(array_remove(column1, 3)) as c1, column3 from unnest_table order
by c1 desc, column3;
+----
+12 NULL
+6 3
+5 2
+4 2
+2 1
+1 1
+
+query II
+select unnest(array_remove(column1, 3)) - 1 as c1, column3 from unnest_table;
+----
+0 1
+1 1
+3 2
+4 2
+5 3
+11 NULL
+
+
+## Unnest multiple columns
+query II
+select unnest(column1), unnest(column2) from unnest_table;
Review Comment:
The result of this query should be incorrect. In DuckDB:
```sh
D CREATE TABLE unnest_table
AS VALUES
([1,2,3], [7], 1),
([4,5], [8,9,10], 2),
([6], [11,12], 3),
([12], [null, 42, null], null),
-- null array to verify the `preserve_nulls` option
(null, null, 4)
;
D select unnest(col0), unnest(col1) from unnest_table;
┌──────────────┬──────────────┐
│ unnest(col0) │ unnest(col1) │
│ int32 │ int32 │
├──────────────┼──────────────┤
│ 1 │ 7 │
│ 2 │ │
│ 3 │ │
│ 4 │ 8 │
│ 5 │ 9 │
│ │ 10 │
│ 6 │ 11 │
│ │ 12 │
│ 12 │ │
│ │ 42 │
│ │ │
├──────────────┴──────────────┤
│ 11 rows 2 columns │
└─────────────────────────────┘
```
For multiple unnest expressions, we might need to extend the functionality
of `UnnestExec` to support it. I think we could implement it later, maybe in
another PR.
--
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]