-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support PPL JSON
functions: construction and extraction
#780
Conversation
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
87ab7d1
to
f88a820
Compare
JSON
functionsJSON
functions (part1)
JSON
functions (part1)JSON
functions: construction and extraction
@YANG-DB @penghuo , I'd like to separate this requirement to multiple PRs due to the different complexity of difference functions. Updated Oct 21: To align with the requirement, the construction |
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Hello @YANG-DB @LantaoJin Thanks or adding this feature quickly. One QQ, what's the syntax to access values within an array? |
…-project#780) * first commit Signed-off-by: Lantao Jin <ltjin@amazon.com> * add docs and fix IT Signed-off-by: Lantao Jin <ltjin@amazon.com> * add examples for json_extract() Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix missing import and doc link Signed-off-by: Lantao Jin <ltjin@amazon.com> * minor Signed-off-by: Lantao Jin <ltjin@amazon.com> * add UT and optimize the doc Signed-off-by: Lantao Jin <ltjin@amazon.com> * typo Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix the issue when merge conflicts Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com>
Description
This PR is the 1st part of addressing JSON functions requirement. It includes JSON construction and extraction related functions:
The 2nd part (not this PR) of JSON functions are conversion and truncation functions:
PPL JSON Functions
JSON
Description
json(value)
Evaluates whether a value can be parsed as JSON. Returns the json string if valid, null otherwise.Argument type: STRING/JSON_ARRAY/JSON_OBJECT
Return type: STRING
A STRING expression of a valid JSON object format.
Example:
JSON_OBJECT
Description
json_object(<key>, <value>[, <key>, <value>]...)
returns a JSON object from members of key-value pairs.Argument type:
Return type: JSON_OBJECT (Spark StructType)
A StructType expression of a valid JSON object.
Example:
JSON_ARRAY
Description
json_array(<value>...)
Creates a JSON ARRAY using a list of values.Argument type:
Return type: ARRAY (Spark ArrayType)
An array of any supported data type for a valid JSON array.
Example:
JSON_ARRAY_LENGTH
Description
json_array_length(jsonArray)
Returns the number of elements in the outermost JSON array.Argument type: STRING/JSON_ARRAY
A STRING expression of a valid JSON array format, or JSON_ARRAY object.
Return type: INTEGER
NULL
is returned in case of any other valid JSON string,NULL
or an invalid JSON.Example:
JSON_EXTRACT
Description
json_extract(jsonStr, path)
Extracts json object from a json string based on json path specified. Return null if the input json string is invalid.Argument type: STRING, STRING
Return type: STRING
A STRING expression of a valid JSON object format.
NULL
is returned in case of an invalid JSON.Example:
JSON_KEYS
Description
json_keys(jsonStr)
Returns all the keys of the outermost JSON object as an array.Argument type: STRING
A STRING expression of a valid JSON object format.
Return type: ARRAY[STRING]
NULL
is returned in case of any other valid JSON string, or an empty string, or an invalid JSON.Example:
JSON_VALID
Description
json_valid(jsonStr)
Evaluates whether a JSON string uses valid JSON syntax and returns TRUE or FALSE.Argument type: STRING
Return type: BOOLEAN
Example:
Issues Resolved
Partial resolve #667
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.