Struct Functions¶
This page lists all struct functions available in Spark SQL.
named_struct¶
named_struct(name1, val1, name2, val2, ...) - Creates a struct with the given field names and values.
Arguments:
- nameN - A STRING literal giving the name of the N-th struct field. It must not be NULL.
- valN - An expression of any type providing the value for the field named nameN. Names and values are supplied as alternating arguments, so the total number of arguments must be even.
Examples:
> SELECT named_struct("a", 1, "b", 2, "c", 3);
{"a":1,"b":2,"c":3}
Since: 1.5.0
struct¶
struct(col1, col2, col3, ...) - Creates a struct with the given field values.
Arguments:
- colN - The field values of the struct. There can be zero or more of them,
each an expression of any type. Field names are assigned as
colNby default unless the value is a named expression.
Examples:
> SELECT struct(1, 2, 3);
{"col1":1,"col2":2,"col3":3}
Since: 1.4.0