Flatten struct

Supported in: Batch, Streaming

Take all fields in a struct and turn them into columns in the output dataset.

Transform categories: Struct

Declared arguments

  • Dataset - Dataset containing struct column.
    Table
  • Expression - Expression evaluating to a struct column that will be flattened.
    Expression<Struct>
  • Max depth - The depth level specifying how deep a nested struct will be flattened.
    Literal<Integer>
  • optional Column prefix - Add a prefix to all columns created during the flatten.
    Literal<String>
  • optional Separator - Separate field names coming from nested structs.
    Literal<String>

Examples

Example 1: Base case

Argument values:

  • Dataset: ri.foundry.main.dataset.a
  • Expression: raw
  • Max depth: 2
  • Column prefix: new_
  • Separator: null

Input:

raw
{
airline: {
id: NA,
name: new air,
},
tail_no: NA-123,
}
{
airline: {
id: FA,
name: foundry airways,
},
tail_no: FA-123,
}

Output:

new_airline_namenew_airline_idnew_tail_noraw
new airNANA-123{
airline: {
id: NA,
name: new air,
},
tail_no: NA-123,
}
foundry airwaysFAFA-123{
airline: {
id: FA,
name: foundry airways,
},
tail_no: FA-123,
}

Example 2: Base case

Argument values:

  • Dataset: ri.foundry.main.dataset.a
  • Expression: raw
  • Max depth: 2
  • Column prefix: new_
  • Separator: #SEPARATOR#

Input:

raw
{
airline: {
id: NA,
name: new air,
},
tail_no: NA-123,
}
{
airline: {
id: FA,
name: foundry airways,
},
tail_no: FA-123,
}

Output:

new_airline#SEPARATOR#namenew_airline#SEPARATOR#idnew_tail_noraw
new airNANA-123{
airline: {
id: NA,
name: new air,
},
tail_no: NA-123,
}
foundry airwaysFAFA-123{
airline: {
id: FA,
name: foundry airways,
},
tail_no: FA-123,
}

Example 3: Null case

Argument values:

  • Dataset: ri.foundry.main.dataset.a
  • Expression: raw
  • Max depth: 2
  • Column prefix: new_
  • Separator: null

Input:

raw
null
{
airline: null,
tail_no: NA-123,
}
{
airline: {
id: FA,
name: null,
},
tail_no: FA-123,
}

Output:

new_airline_namenew_airline_idnew_tail_noraw
nullnullnullnull
nullnullNA-123{
airline: null,
tail_no: NA-123,
}
nullFAFA-123{
airline: {
id: FA,
name: null,
},
tail_no: FA-123,
}