Skip to content
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

json-valid PPL function #3230

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

kenrickyap
Copy link

Description

Based on this feature request: #3207

Added json_valid request.

### `JSON_VALID`

**Description**

`json_valid(jsonStr)` Evaluates whether a json-encoded string contains valid JSON syntax and returns TRUE or FALSE.

**Argument type:** STRING

**Return type:** BOOLEAN

Example:

    os> source=people | eval `valid_json` = json_valid('[1,2,3,4]'), `invalid_json` = json_valid('{"invalid": "json"') | fields `valid_json`, `invalid_json`
    fetched rows / total rows = 1/1
    +--------------+----------------+
    | valid_json   | invalid_json   |
    +--------------+----------------+
    | True         | False          |
    +--------------+----------------+

    os> source=accounts | where json_valid('[1,2,3,4]') and isnull(email) | fields account_number, email
    fetched rows / total rows = 1/1
    +------------------+---------+
    | account_number   | email   |
    |------------------+---------|
    | 13               | null    |
    +------------------+---------+

Related Issues

Resolves #3207

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

Signed-off-by: Kenrick Yap <[email protected]>
@YANG-DB
Copy link
Member

YANG-DB commented Jan 6, 2025

@kenrickyap can you please add the relevant documentation for this new function?

Signed-off-by: Kenrick Yap <[email protected]>
@kenrickyap
Copy link
Author

@kenrickyap can you please add the relevant documentation for this new function?

Added doctest, integ-test, and unit tests

@kenrickyap kenrickyap marked this pull request as ready for review January 6, 2025 23:28
@kenrickyap kenrickyap marked this pull request as draft January 7, 2025 00:26
Signed-off-by: Kenrick Yap <[email protected]>
Signed-off-by: Kenrick Yap <[email protected]>
@kenrickyap
Copy link
Author

3 unit test are failing due to 2024 -> 2025 year change

DateTimeFunctionTest > testWeekOfYearWithTimeType()
ExtractTest > testExtractDatePartWithTimeType()
YearweekTest > testYearweekWithTimeType()

There is existing issues for said failed test cases: #2477

I have disabled test until above issue is addressed

Signed-off-by: Kenrick Yap <[email protected]>
Signed-off-by: Kenrick Yap <[email protected]>
@kenrickyap kenrickyap marked this pull request as ready for review January 7, 2025 21:45
Signed-off-by: Kenrick Yap <[email protected]>
@kenrickyap
Copy link
Author

pipeline is failing as disabled test are affecting code coverage. will first resolve #2477, then merge this ticket

kenrickyap and others added 4 commits January 9, 2025 13:01
Co-authored-by: Andrew Carbonetto <[email protected]>
Signed-off-by: kenrickyap <[email protected]>
….java

Co-authored-by: Andrew Carbonetto <[email protected]>
Signed-off-by: kenrickyap <[email protected]>
Signed-off-by: Kenrick Yap <[email protected]>
Signed-off-by: Kenrick Yap <[email protected]>
Signed-off-by: Kenrick Yap <[email protected]>
@@ -0,0 +1,35 @@
====================
IP Address Functions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the title IP Address Functions ?

{"test_name":"json array", "json_string":"[1, 2, 3, 4]"}
{"test_name":"json scalar string", "json_string":"\"abc\""}
{"test_name":"json empty string","json_string":""}
{"test_name":"json invalid object", "json_string":"{\"invalid\":\"json\", \"string\"}"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add complex nested json object sample ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add json_valid as a PPL function
4 participants