-
Notifications
You must be signed in to change notification settings - Fork 158
PPL: Add json
function and cast(x as json)
function
#3243
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
PPL: Add json
function and cast(x as json)
function
#3243
Conversation
2ccf4ab
to
3ec16e0
Compare
core/src/main/java/org/opensearch/sql/expression/json/JsonFunctions.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperators.java
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/json/JsonFunctionsTest.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/json/JsonFunctionsTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Kenrick Yap <[email protected]>
Signed-off-by: Kenrick Yap <[email protected]>
Signed-off-by: Kenrick Yap <[email protected]>
Signed-off-by: Kenrick Yap <[email protected]>
Signed-off-by: Kenrick Yap <[email protected]>
core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/datetime/YearweekTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM minor nits
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
core/src/test/java/org/opensearch/sql/expression/json/JsonFunctionsTest.java
Show resolved
Hide resolved
@@ -1,14 +1,24 @@ | |||
{"index":{"_id":"0"}} | |||
{"test_name":"json nested object", "json_string":"{\"a\":\"1\",\"b\":{\"c\":\"2\",\"d\":\"3\"}}"} | |||
{"test_name":"json nested object", "json_string":"{\"a\":\"1\", \"b\": {\"c\": \"3\"}, \"d\": [1, 2, 3]}"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u also add a use case for inner json obj that has an array ?
{"a":{"b":{"c":[....]}}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"d" is mapped to an array. Do you want an object within in an array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO looking good - added some minor comments...
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Tests added. Thank you for looking. |
@acarbonetto can u plz resolve the conflicts ? |
Signed-off-by: Andrew Carbonetto <[email protected]>
jsonNode = objectMapper.readTree(json.stringValue()); | ||
} catch (JsonProcessingException e) { | ||
final String errorFormat = "JSON string '%s' is not valid. Error details: %s"; | ||
throw new SemanticCheckException(String.format(errorFormat, json, e.getMessage()), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: SemanticCheckExcpetion
is not a proper exception to throw here. Maybe change it to ExpressionEvaluationException
(add a two-parameters construction)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Lantao. I will address shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except a minor comment
Merging to main. Thanks for contribution. @acarbonetto please address this minor comment #3243 (comment) in your followup PR. |
Description
For OpenSearch-PPL, adds the
json()
andcast(expression as json)
functions. Both of these functions can be used to convert a json-encoded string into an expression object. These functions return any expression type that is valid json (object, array, or scalar). Unfortunately, because the return type is unknown, the expression's return type isUNDEFINED
.The user can use
cast
to convert the types where necessary for scalar types. For example:The following casts are available to convert json-encoded scalars:
int
,long
,double
,float
,boolean
.Related Issues
Resolves #3209
Check List
--signoff
.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.