Airblader commented on a change in pull request #16776:
URL: https://github.com/apache/flink/pull/16776#discussion_r687674609
##########
File path: docs/data/sql_functions.yml
##########
@@ -596,6 +596,41 @@ json:
'strict $.b' FALSE ON ERROR);
```
+ - sql: JSON_VALUE(jsonValue, path [RETURNING <expr>] [ { NULL | ERROR |
DEFAULT <defaultExpr> } ON EMPTY ] [ { NULL | ERROR | DEFAULT <defaultExpr> }
ON ERROR ])
+ table: STRING.jsonValue(STRING path [, returnType, onEmpty,
defaultOnEmpty, onError, defaultOnError])
+ description: |
+ Extracts a scalar from a JSON string.
+
+ This method searches a JSON string for a given path expression and
returns the value if the
+ value at that path is scalar. Non-scalar values cannot be returned. By
default, the value is
+ returned as `DataTypes#STRING()`. Using `returningType` a different type
can be chosen, with
+ types with the following type roots being supported:
+
+ * `VARCHAR`
+ * `BOOLEAN`
+ * `INTEGER`
+ * `DOUBLE`
+
+ For empty path expressions or errors a behavior can be defined to either
return `null`, raise
+ an error or return a defined default value instead. When omitted, the
default is
+ `NULL ON EMPTY` or `NULL ON ERROR`, respectively.
+
+ ```
+ // STRING: "true"
+ JSON_VALUE('{"a": true}', '$.a')
+
+ // BOOLEAN: true
+ JSON_VALUE('{"a": true}', '$.a' RETURNING BOOLEAN)
+
+ // BOOLEAN: 'false'
Review comment:
> Is this still boolean? Derived from the default value or how does this
work?
Oops, no; it will be a string. The default value is applied before the
conversion to the output type.
> Does the default/error value need to be the same type as return type?
It does not, which was part of the point of this example (and will hopefully
be clear after I fix it)
> Does the default/error value need to be a literal?
It doesn't, and of course that also means the default value can cause an
error as well, which has defined behavior. I'll add a sentence about that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]