STRUCT data type
A STRUCT is a complex data type with a fixed set of named fields. Its fields can have different data types, including primitive types and other complex types. In Cloudera Data Visualization, you can expand a STRUCT to find its component fields and use primitive fields in visuals.
STRUCT syntax
column_name STRUCT < name : type [COMMENT 'comment_string'], ... >
type ::= primitive_type | complex_type
A STRUCT has a fixed number of named fields, and each field can be a
different type. A field within a STRUCT can also be another
STRUCT, an ARRAY, or a
MAP
STRUCTs in dataset fields
On the dataset’s Fields page, a basic STRUCT
data type may look something like the following example. You can expand a field to
see its components, and continue expanding any nested complex fields, or collapse
everything for a simple view.
In the customers dataset shown, email_preferences is a STRUCT. The orders array also contains nested STRUCT fields, including orders.item.
When you click Edit, you can change the data type of a primitive field, such as orders.pos. You cannot change the type of a STRUCT, ARRAY, or MAP field itself. Primitive fields within a complex field can have their own field settings.
Using STRUCT fields in visuals
You cannot add a STRUCT field 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, the table visual shown uses email_preferences.email_format to
display each customer’s email format. It also uses addresses.value.city to
display the city from a nested STRUCT within the addresses map.
Both fields are placed on the Dimensions shelf.
Changing field properties
You can change the properties of a primitive field after adding it to a visual. To change the displayed name of address.value.city, open the field’s FIELD PROPERTIES menu, expand Alias, and enter City. The shelf then shows City for that field.
Using STRUCT fields in expressions
The expression editor supports references to fields within STRUCTs in both datasets and visuals. Use the field path to identify the component you want to include in an expression..
