githubEdit

jsonExtractIndex

This section contains reference documentation for the JSONEXTRACTINDEX function.

Evaluates the 'jsonPath' on jsonField, returns the result as the type 'resultsType', use optional defaultValuefor null or parsing error.

The function closely mirrors JSONEXTRACTSCALAR, however, since it extracts values from a JSON Index, it allows for additional filtering to be pushed down.

Compared to JSONEXTRACTSCALAR, this is most useful when extraction is required on a large number of docs, or on large docs. When filtering is highly specific, the original JSONEXTRACTSCALAR implementation is usually faster. For a simple comparsion, see the initial PR #11739arrow-up-right

Signature

JSONEXTRACTINDEX(jsonField, 'jsonPath', 'resultsType', [defaultValue], [filter])

Arguments
Description

jsonField

An Identifier/Expression contains JSON documents.

'jsonPath'

Follows JsonPath Syntaxarrow-up-right to read values from JSON documents.

'resultsType'

One of the Pinot supported data types:INT, LONG, FLOAT, DOUBLE, BOOLEAN, TIMESTAMP, STRING,

INT_ARRAY, LONG_ARRAY, FLOAT_ARRAY, DOUBLE_ARRAY, STRING_ARRAY.

'filter'

Pushes down a filter to avoid extracting values that do not match, e.g. "$.arrField[*].f2" > 2.

circle-exclamation

Usage Examples

The examples in this section are based on the Batch JSON Quick Start. In particular we'll be querying the row WHERE id = 7044874109:

SELECT repo
from githubEvents 
WHERE id = 7044874109
repo

{"id":115911530,"name":"LimeVista/Tapes","url":"https://api.github.com/repos/LimeVista/Tapes"}

The following examples show how to use the JSONEXTRACTINDEX function:

id
name

7044874109

LimeVista/Tapes

id
name

7044874109

dummyValue

id
name

7044874109

LimeVista/Tapes

Array Extraction

The below examples will use the shown arrayField

repo

{"id":"xyz"","arrayField": [{"f1": 1, "f2": 2}, {"f1": 3, "f2": 4}, {"f2": 6}, {"f1": 0, "f2": 5}]}

Extract array values as MV

id
arrayValues

123

[1, 3, 0]

Filtering is also allowed on array values:

id
arrayValues

123

[3, 0]

id
arrayValues

123

[]

Last updated

Was this helpful?