Observe Performance Cookbook: Flatten Less First

Problem

A JSON flattening operation is taking a long time or using a lot of query credits.

Solution

Try flatten_single or flatten_leaves instead of flatten_all or flatten. If flatten_single or flatten_leaves gets the correct data, that will help performance.

Explanation

The flatten and flatten_all OPAL verbs perform more work to extract more data. They recurse the JSON object’s structure to create key-value pairs. If the needed elements are at the top of the structure, flatten_single may be all that is necessary to extract. If the needed elements are at the bottom of the structure, flatten_leaves may be useful for extracting those elements and discarding the intermediates.