trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
9.95k stars 2.87k forks source link

Json path doesn’t support complete array or slice array #6254

Open pPanda-beta opened 3 years ago

pPanda-beta commented 3 years ago

When we execute :

SELECT JSON_EXTRACT(' { "root": [ {"a": 1}, {"a": 2} ] } ', '$.root[::].a')

or

SELECT JSON_EXTRACT(' { "root": [ {"a": 1}, {"a": 2} ] } ', '$.root[*].a')

or

SELECT JSON_EXTRACT(' { "root": [ {"a": 1}, {"a": 2} ] } ', '$.root[:].a')

we expect result : (As per documentation)

[1, 2]

But we get :

io.prestosql.spi.PrestoException: Invalid JSON path: '$.root[::].a'
    at io.prestosql.operator.scalar.JsonPathTokenizer.invalidJsonPath(JsonPathTokenizer.java:196)
    at io.prestosql.operator.scalar.JsonPathTokenizer.matchUnquotedSubscript(JsonPathTokenizer.java:109)
    at io.prestosql.operator.scalar.JsonPathTokenizer.computeNext(JsonPathTokenizer.java:63)
    at io.prestosql.operator.scalar.JsonPathTokenizer.computeNext(JsonPathTokenizer.java:26)
    at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:141)

Possible reason:

https://github.com/prestosql/presto/blob/f92c6c39404e602c38bbd5e88b818fffea77111f/presto-main/src/main/java/io/prestosql/operator/scalar/JsonPathTokenizer.java#L107-L110

Correct Json path specification :

https://goessner.net/articles/JsonPath/ And emulation at https://jsonpath.com/

pPanda-beta commented 3 years ago

/keep_alive

pPanda-beta commented 3 years ago

/keep_fresh

pPanda-beta commented 3 years ago

/keep_fresh