datafusion_expr::logical_plan::builder

Function unnest_with_options

Source
pub fn unnest_with_options(
    input: LogicalPlan,
    columns_to_unnest: Vec<Column>,
    options: UnnestOptions,
) -> Result<LogicalPlan>
Expand description

Create a LogicalPlan::Unnest plan with options This function receive a list of columns to be unnested because multiple unnest can be performed on the same column (e.g unnest with different depth) The new schema will contains post-unnest fields replacing the original field

For example: Input schema as

+---------------------+-------------------+
| col1                | col2              |
+---------------------+-------------------+
| Struct(INT64,INT32) | List(List(Int64)) |
+---------------------+-------------------+

Then unnesting columns with:

  • (col1,Struct)
  • (col2,List([depth=1,depth=2]))

will generate a new schema as

+---------+---------+---------------------+---------------------+
| col1.c0 | col1.c1 | unnest_col2_depth_1 | unnest_col2_depth_2 |
+---------+---------+---------------------+---------------------+
| Int64   | Int32   | List(Int64)         |  Int64              |
+---------+---------+---------------------+---------------------+