-
Notifications
You must be signed in to change notification settings - Fork 747
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
support PARSE_JSON / TRY_PARSE_JSON function #4534
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/databend/databend/q6ch5RiXBiEcBb1CusQaDyJMq7Hs |
Thanks for the contribution! Please review the labels and make any necessary changes. |
tests/suites/0_stateless/02_function/02_0048_function_semi_structureds_parse_json.result
Outdated
Show resolved
Hide resolved
return Ok(NullType::arc()); | ||
} | ||
|
||
Ok(Arc::new(NullableType::create(VariantType::arc()))) |
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.
If SUPPRESS_PARSE_ERROR is false, the return type should not be nullable.
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.
parse_json
may also yield null, for example:
mysql> select parse_json('');
+----------------+
| parse_json('') |
+----------------+
| NULL |
+----------------+
1 row in set (0.01 sec)
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.
So what's the difference between JsonValue::Null
and DataValue::Null
?
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.
DataValue::Null
is a SQL null, and JsonValue::Null
is a JSON null. Detailed description can refer to this document:
https://docs.snowflake.com/en/sql-reference/functions/parse_json.html#usage-notes
mysql> select parse_json(null), parse_json(''), parse_json('null');
+------------------+----------------+--------------------+
| parse_json(NULL) | parse_json('') | parse_json('null') |
+------------------+----------------+--------------------+
| NULL | NULL | null |
+------------------+----------------+--------------------+
1 row in set (0.02 sec)
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.
So If SUPPRESS_PARSE_ERROR is false, it's JsonColumn
not Nullable(JsonColumn)
.
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.
if SUPPRESS_PARSE_ERROR is false, it should also return Nullable(JsonColumn). Because if the input value is an empty string, it should return a SQL null.
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.
So the right way is:
- parse_json -> SUPPRESS_PARSE_ERROR true -> JsonColumn
- try_parse_json -> SUPPRESS_PARSE_ERROR false -> Nullable(JsonColumn)
I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/
Summary
Support PARSE_JSON function
Support TRY_PARSE_JSON function
Changelog
Related Issues
Fixes #4476
Test Plan
Unit Tests
Stateless Tests