-
Notifications
You must be signed in to change notification settings - Fork 142
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
base: main
Are you sure you want to change the base?
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]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
9347cad
to
ab9be75
Compare
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[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]>
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.
I think a license header is missing...
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.
Will add.
I'm surprised that it isn't added automagically by spotless.
FunctionExpression exp = DSL.jsonValid(DSL.literal(jsonString)); | ||
return exp.valueOf(); | ||
@Test | ||
void json_returnsSemanticCheckException() { |
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 you add a few more failed tests use cases here ?
@@ -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 ? |
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.