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

Fix handling null string in json_extract() #6439

Closed

Conversation

xiaodouchen
Copy link
Contributor

SIMDJsonExtractFunction returned null directly when there was only one value mapped to the json path and it was null. However, in Presto, the function returns null string instead of null value for this case.

Fixes #6437

`SIMDJsonExtractFunction` returned null directly when there was only one
value mapped to the json path and it was null. However, in Presto, the
function returns null string instead of null value for this case.

Fixes facebookincubator#6437
@netlify
Copy link

netlify bot commented Sep 6, 2023

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit b97a15a
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/64f85d1d533cf60008ccd13d

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 6, 2023
@@ -549,7 +549,7 @@ TEST_F(JsonFunctionsTest, jsonExtract) {
EXPECT_EQ(
"3", jsonExtract("{\"x\": {\"a\" : 1, \"b\" : [2, 3]} }", "$.x.b[1]"));
EXPECT_EQ("2", jsonExtract("[1,2,3]", "$[1]"));
EXPECT_EQ(std::nullopt, jsonExtract("[1,null,3]", "$[1]"));
EXPECT_EQ("null", jsonExtract("[1,null,3]", "$[1]"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is what I see in Presto,

presto:di> select json_extract('[1,null,3]', '#[1]');
 _col0
-------
 NULL
(1 row)

Do you see something different?

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 run test case of testJsonExtract() in TestJsonExtractFunctions.java of Presto.

// pass
assertFunction(format("JSON_EXTRACT('%s', '%s')", "[1,null,3]", "$[1]"), JSON, "null");

// fail
assertFunction(format("JSON_EXTRACT('%s', '%s')", "[1,null,3]", "$[1]"), JSON, null);

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Looks like I had a typo above:

presto:di> select json_extract('[1,null,3]', '$[1]');
 _col0
-------
 null
(1 row)

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

Thank you for the fix.

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mbasmanova merged this pull request in 524591e.

@conbench-facebook
Copy link

Conbench analyzed the 1 benchmark run on commit 524591e0.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

codyschierbeck pushed a commit to codyschierbeck/velox that referenced this pull request Sep 27, 2023
Summary:
`SIMDJsonExtractFunction` returned null directly when there was only one value mapped to the json path and it was null. However, in Presto, the function returns null string instead of null value for this case.

Fixes facebookincubator#6437

Pull Request resolved: facebookincubator#6439

Reviewed By: Yuhta

Differential Revision: D49009808

Pulled By: mbasmanova

fbshipit-source-id: c98e8fbce8d420ebed06403a4b9d3beb5ab8ee47
codyschierbeck pushed a commit to codyschierbeck/velox that referenced this pull request Sep 27, 2023
Summary:
`SIMDJsonExtractFunction` returned null directly when there was only one value mapped to the json path and it was null. However, in Presto, the function returns null string instead of null value for this case.

Fixes facebookincubator#6437

Pull Request resolved: facebookincubator#6439

Reviewed By: Yuhta

Differential Revision: D49009808

Pulled By: mbasmanova

fbshipit-source-id: c98e8fbce8d420ebed06403a4b9d3beb5ab8ee47
codyschierbeck pushed a commit to codyschierbeck/velox that referenced this pull request Sep 27, 2023
Summary:
`SIMDJsonExtractFunction` returned null directly when there was only one value mapped to the json path and it was null. However, in Presto, the function returns null string instead of null value for this case.

Fixes facebookincubator#6437

Pull Request resolved: facebookincubator#6439

Reviewed By: Yuhta

Differential Revision: D49009808

Pulled By: mbasmanova

fbshipit-source-id: c98e8fbce8d420ebed06403a4b9d3beb5ab8ee47
ericyuliu pushed a commit to ericyuliu/velox that referenced this pull request Oct 12, 2023
Summary:
`SIMDJsonExtractFunction` returned null directly when there was only one value mapped to the json path and it was null. However, in Presto, the function returns null string instead of null value for this case.

Fixes facebookincubator#6437

Pull Request resolved: facebookincubator#6439

Reviewed By: Yuhta

Differential Revision: D49009808

Pulled By: mbasmanova

fbshipit-source-id: c98e8fbce8d420ebed06403a4b9d3beb5ab8ee47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

json_extract() get wrong result when the input contains "null"
3 participants