flatten_single

Type of operation: Semistructured

Description

Given an object or array input, flatten the first level of child elements into key-value columns.

The key and value child element columns are named ‘_c_NAME_path’ and ‘_c_NAME_value’. NAME is replaced with the original column name.

Flatten_single is a less expensive operation than flatten or flatten_all. The default is to not suggest column types (‘suggesttypes’ = ‘false’.) See also flatten, flatten_leaves, and flatten_all.

Usage

flatten_single pathexpression, [ suggesttypes ]

Argument

Type

Optional

Repeatable

Restrictions

pathexpression

array or object

no

no

column

suggesttypes

bool

yes

no

none

Accelerable

flatten_single is always accelerable if the input is accelerable. A dataset that only uses accelerable verbs can be accelerated, making queries on the dataset respond faster.

Examples

flatten_single foo

Given this JSON in column foo:

foo

{"a":{"aa":1},"b":{"bb":[{"bb1":2},{"bb2":3}]}}

flatten_single produces:

_c_foo_path

_c_foo_value

a

{"aa":1}

b

{"bb":[{"bb1":2},{"bb2":3}]}

It recurses the JSON object and produces new columns that contain the path and values of the top level of keys in foo. Column ‘foo’ will be removed.

flatten_single foo, true

Given this JSON in column foo:

foo

{"a":{"aa":1},"b":{"bb":[{"bb1":2},{"bb2":3}]}}

flatten_single produces:

_c_foo_path

_c_foo_value

_c_foo_type

a

{"aa":1}

object

b

{"bb":[{"bb1":2},{"bb2":3}]}

object

It recurses the JSON object and produces new columns that contain the path and values of the top level of keys in foo. It will also attempt to determine the value’s type, creating a third (hidden) column named ‘_c_foo_type’. Column ‘foo’ will be removed.

Aliases

  • flattensingle (deprecated)