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

feat: Add is_json_string UDF #8600

Merged
merged 1 commit into from
Jan 21, 2022
Merged

feat: Add is_json_string UDF #8600

merged 1 commit into from
Jan 21, 2022

Conversation

Gerrrr
Copy link
Contributor

@Gerrrr Gerrrr commented Jan 17, 2022

Description

This PR introduces a new UDF - is_json_string that returns true if the argument string can be parsed as a valid JSON value, false otherwise. See the corresponding section in KIP-59 for more details.

Testing done

Added unit and functional tests.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

Copy link

@jaceklaskowski jaceklaskowski left a comment

Choose a reason for hiding this comment

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

LGTM

@Gerrrr Gerrrr marked this pull request as ready for review January 18, 2022 09:58
@Gerrrr Gerrrr requested review from JimGalasyn and a team as code owners January 18, 2022 09:58
Copy link
Member

@JimGalasyn JimGalasyn left a comment

Choose a reason for hiding this comment

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

LGTM!

@Gerrrr
Copy link
Contributor Author

Gerrrr commented Jan 19, 2022

@jnh5y I extracted JSON parsing in e3e5bf8; will rebase others PRs on top of this one to reuse the new method.

@Gerrrr Gerrrr mentioned this pull request Jan 19, 2022
2 tasks
@Gerrrr Gerrrr mentioned this pull request Jan 19, 2022
2 tasks
@Gerrrr Gerrrr force-pushed the feat-add-is_json_string branch 2 times, most recently from 038574d to dfd1c82 Compare January 20, 2022 17:45
Copy link
Contributor

@guozhangwang guozhangwang left a comment

Choose a reason for hiding this comment

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

Just one question in the check function, otherwise LGTM!

} catch (KsqlFunctionException e) {
return false;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we return true at the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please elaborate the reasoning behind your suggestion? As I see it, this function return true only if the string was parsed as JSON without exception and the underlying node is not MissingNode that represents broken JSON.

In any case, I think it is worth switching to a primitive type to signal that the return value is never null - 2f556c9#diff-48af5e77f4b3c1e1ee5cb1d402f247c3e70b4649c1de07e5171f8526dd0d908aR34.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am going to merge this PR as a bunch of other patches are blocked on it. We can continue the discussion here; I'll do a follow-up patch if necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry my bad, miss-read the line of .parseJson(input).isMissingNode(); please ignore :P

"CREATE STREAM test (K STRING KEY, maybeJSON STRING) WITH (kafka_topic='test_topic', VALUE_FORMAT='JSON');",
"CREATE STREAM OUTPUT AS SELECT K, maybeJSON as JSON FROM test WHERE IS_JSON_STRING(maybeJSON);"
],
"inputs": [
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we test for "" as well, as the docs indicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

5 participants