The FLATTEN directive separates the elements in a repeated field into individual records. Use the FLATTEN directive for arrays. To flatten a record column with nested value, use the FLATTEN-RECORD directive.
Note: In releases before CDAP 6.7.0, due to a bug, the FLATTEN directive worked with both an array and a record column with nested values. Starting in CDAP 6.7.0, the FLATTEN directive only works with arrays.
Syntax
Code Block |
---|
flatten :column [,:column]* |
...
The directive would result in these three distinct records:
x | y | z |
---|---|---|
5 | "a string" | 1 |
5 | "a string" | 2 |
5 | "a string" | 3 |
The directive takes a single argument, which must be an array (the z
column in this example). In this case, using the "all" (*
) wildcard as the argument to flatten is not supported and would return an error.