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 19 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
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]>
acarbonetto
acarbonetto previously approved these changes Jan 9, 2025
Signed-off-by: Kenrick Yap <[email protected]>
Signed-off-by: Kenrick Yap <[email protected]>
result =
executeQuery(
String.format(
"source=%s | where json_valid(json_string) | fields test_name",
Copy link
Member

@LantaoJin LantaoJin Jan 13, 2025

Choose a reason for hiding this comment

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

what if the json_string is null? Could you add a test case for null

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
5 participants