ARRAY data type
An ARRAY is a complex data type that contains any number of elements of the same type. Its elements can be primitive values or complex values, such as STRUCTs, MAPs, or other ARRAYs. In Cloudera Data Visualization, expand an ARRAY to find the individual fields you can use in visuals.
ARRAY syntax
column_name ARRAY < type >
type ::= primitive_type | complex_type
ARRAY data types represent collections with arbitrary numbers of
elements, where each element is the same type. The element type can
be a primitive or complex data type. Cloudera Data Visualization exposes
these components of an ARRAY. An ARRAY type is like a miniature
table, with two columns:
- POS
-
The position of an element in the array, accessed as
array_name.pos. - ITEM
-
The value of an array element, accessed as
array_name.item. If the value is complex, expanditemto access its fields.Access as
array_name.item
For example, the orders array in the screenshots contains
orders.pos and orders.item. The
orders.item STRUCT contains another array,
orders.item.items.
ARRAYs in dataset fields
On the dataset's Fields page, an example of a basic
ARRAY data type may look like the following example. You can
expand an ARRAY to see its pos and item
components, and continue expanding any nested complex fields.
In the customers dataset shown, orders is an ARRAY.
Its orders.item component is a STRUCT that contains the
orders.item.items ARRAY. You can expand each level to reach
primitive fields such as orders.pos and the quantity field within
orders.item.items.item.
When you click Edit, you can change the data type of a
primitive component, such as orders.pos. You cannot change the data
type of an ARRAY field itself.
Using ARRAY fields in visuals
You cannot add an ARRAY as a whole to a visual shelf. Expand it in the visual builder and add the primitive field that contains the data you need.
For example, in a Bars visual you might place name on the X
Axis shelf. The quantity field within
orders.item.items.item.qty is aggregated with sum on the
X Axis shelf, and orders.pos is on the
Colors shelf.
Changing field properties
You can change the properties of a primitive field after adding it to a visual. For example, open the quantity field’s menu on the X Axis shelf and select to change its aggregation from Sum to avg.
Using ARRAY fields in expressions
The expression editor supports the use of ARRAY fields, in both
datasets and visuals. Use the component’s field path to identify the data you want
to include in an expression.
