[ https://issues.apache.org/jira/browse/CALCITE-2864?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16779941#comment-16779941 ]
Hongze Zhang edited comment on CALCITE-2864 at 2/28/19 12:27 AM: ----------------------------------------------------------------- It seems that for now the {{JSON_DEPTH}} (also {{JSON_TYPE}}) expects a {{JsonValueExpression}}[1] as input. It's a common pattern to construct a JSON value. E.g. using {{JSON_DEPTH(col FORMAT AVRO)}} to handle avro JSON data (but we now don't support avro format). I think we can integrate {{JsonValueExpression}} into {{Expression}}[2] in future(maybe in the fix of CALCITE-2869[3], although we did't start to discuss that issue), then remove the parser changes of {{JSON_DEPTH}} and {{JSON_TYPE}} and so on. [1] [https://github.com/apache/calcite/blob/5101703c3bb7e051766f9dc932534a0a7acba0c5/core/src/main/codegen/templates/Parser.jj#L4892] [2] [https://github.com/apache/calcite/blob/e3a319e1f79bc807327bd443433c50c4bbf20866/core/src/main/codegen/templates/Parser.jj#L2991] [3] https://issues.apache.org/jira/browse/CALCITE-2869 was (Author: zhztheplayer): It seems that for now the {{JSON_DEPTH}} (also {{JSON_TYPE}}) expects a {{JsonValueExpression}}[1] as input. It's a common pattern to construct a JSON value. E.g. using {{JSON_DEPTH(col FORMAT AVRO)}} to handle avro JSON data (but we now don't support avro format). I think we can integrate {{JsonValueExpression}} into {{Expression}}[2] in future(maybe in the fix of 2869, although we did't start to discuss that issue), then remove the parser changes of {{JSON_DEPTH}} and {{JSON_TYPE}} and so on. [1] [https://github.com/apache/calcite/blob/5101703c3bb7e051766f9dc932534a0a7acba0c5/core/src/main/codegen/templates/Parser.jj#L4892] [2] [https://github.com/apache/calcite/blob/e3a319e1f79bc807327bd443433c50c4bbf20866/core/src/main/codegen/templates/Parser.jj#L2991] > Add the JSON_DEPTH function > --------------------------- > > Key: CALCITE-2864 > URL: https://issues.apache.org/jira/browse/CALCITE-2864 > Project: Calcite > Issue Type: Sub-task > Reporter: Forward Xu > Assignee: Forward Xu > Priority: Major > Labels: pull-request-available > Fix For: 1.19.0 > > Time Spent: 50m > Remaining Estimate: 0h > > Returns the maximum depth of a JSON document. Returns {{NULL}} if the > argument is {{NULL}}. An error occurs if the argument is not a valid JSON > document. > An empty array, empty object, or scalar value has depth 1. A nonempty array > containing only elements of depth 1 or nonempty object containing only member > values of depth 1 has depth 2. Otherwise, a JSON document has depth greater > than 2. > > Example Sql: > SELECT JSON_DEPTH(v) AS c1 > ,JSON_DEPTH(JSON_VALUE(v, 'lax $.b' ERROR ON ERROR)) AS c2 > ,JSON_DEPTH(JSON_VALUE(v, 'strict $.a[0]' ERROR ON ERROR)) AS c3 > ,JSON_DEPTH(JSON_VALUE(v, 'strict $.a[1]' ERROR ON ERROR)) AS c4 > FROM (VALUES (' > {"a": [10, true],"b": "[10, true]"} > ')) AS t(v) > limit 10; > Result: > c1 c2 c3 c4 > == == == == > 3 2 1 1 -- This message was sent by Atlassian JIRA (v7.6.3#76005)