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

expression: add builtin function json_length #7739

Merged
merged 6 commits into from
Sep 27, 2018

Conversation

Kingwl
Copy link
Contributor

@Kingwl Kingwl commented Sep 18, 2018

What problem does this PR solve?

a part of #7546

What is changed and how it works?

add a built in function json_length

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • Has interface methods change

Related changes

  • Need to be included in the release note

@sre-bot
Copy link
Contributor

sre-bot commented Sep 18, 2018

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@CLAassistant
Copy link

CLAassistant commented Sep 18, 2018

CLA assistant check
All committers have signed the CLA.

@Kingwl Kingwl force-pushed the add_json_length branch 3 times, most recently from efe52c4 to e14c2e6 Compare September 18, 2018 09:50
@jackysp
Copy link
Member

jackysp commented Sep 20, 2018

/run-all-tests

@coocood
Copy link
Member

coocood commented Sep 20, 2018

@Kingwl
Tried to run with your branch.
It panics when I execute:

select json_length('{"a": [1, 2, {"aa": "xx"}]}', '$.a[2].aa');

return res, true, json.ErrInvalidJSONPathWildcard
}
var exists bool
obj, exists = obj.Extract([]json.PathExpression{pathExpr})
Copy link
Contributor

Choose a reason for hiding this comment

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

the type of extracted obj maybe not the type of array or object.

if obj.Type() != "OBJECT" && obj.Type() != "ARRAY" {
return 1, false, nil
}
return int64(obj.GetElemCount()), false, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

this line is useless.

r.Check(testkit.Rows("1"))
r = tk.MustQuery(`select json_length('{"a": 1, "b": 2}')`)
r.Check(testkit.Rows("2"))
r = tk.MustQuery(`select json_length('[1, 2, 3]')`)
Copy link
Contributor

Choose a reason for hiding this comment

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

merge testcases to save lines.

return 1, false, nil
}

if len(b.args) == 2 {
Copy link
Member

Choose a reason for hiding this comment

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

how about:

if len(b.args) == 1 {
	return int64(obj.GetElemCount()), false, nil
}
// handle the case that len(b.args) == 2
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, I'm ready to extract the common path visit but in a other pr(some other pr are conflicted with that)

@zz-jason zz-jason added the contribution This PR is from a community contributor. label Sep 25, 2018
@zz-jason
Copy link
Member

LGTM

@zz-jason zz-jason closed this Sep 25, 2018
@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 25, 2018
@zz-jason zz-jason reopened this Sep 25, 2018
@sre-bot
Copy link
Contributor

sre-bot commented Sep 25, 2018

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@zz-jason
Copy link
Member

@XuHuaiyu PTAL

return res, isNull, errors.Trace(err)
}

if obj.Type() != "OBJECT" && obj.Type() != "ARRAY" {
Copy link
Member

@winoros winoros Sep 26, 2018

Choose a reason for hiding this comment

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

Could we use Typecode here?

Copy link
Member

@coocood coocood left a comment

Choose a reason for hiding this comment

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

LGTM

@coocood
Copy link
Member

coocood commented Sep 26, 2018

/run-all-tests

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 27, 2018
@zz-jason zz-jason merged commit 9fd4072 into pingcap:master Sep 27, 2018
@XuHuaiyu XuHuaiyu self-assigned this Sep 27, 2018
@XuHuaiyu
Copy link
Contributor

/run-integration-ddl-test

@Kingwl Kingwl deleted the add_json_length branch September 27, 2018 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression contribution This PR is from a community contributor. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants