-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
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. |
efe52c4
to
e14c2e6
Compare
e14c2e6
to
3821748
Compare
/run-all-tests |
@Kingwl
|
expression/builtin_json.go
Outdated
return res, true, json.ErrInvalidJSONPathWildcard | ||
} | ||
var exists bool | ||
obj, exists = obj.Extract([]json.PathExpression{pathExpr}) |
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.
the type of extracted obj maybe not the type of array or object.
3599f48
to
d5f9755
Compare
expression/builtin_json.go
Outdated
if obj.Type() != "OBJECT" && obj.Type() != "ARRAY" { | ||
return 1, false, nil | ||
} | ||
return int64(obj.GetElemCount()), false, nil |
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.
this line is useless.
expression/integration_test.go
Outdated
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]')`) |
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.
merge testcases to save lines.
return 1, false, nil | ||
} | ||
|
||
if len(b.args) == 2 { |
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.
how about:
if len(b.args) == 1 {
return int64(obj.GetElemCount()), false, nil
}
// handle the case that len(b.args) == 2
...
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.
actually, I'm ready to extract the common path visit but in a other pr(some other pr are conflicted with that)
LGTM |
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. |
@XuHuaiyu PTAL |
expression/builtin_json.go
Outdated
return res, isNull, errors.Trace(err) | ||
} | ||
|
||
if obj.Type() != "OBJECT" && obj.Type() != "ARRAY" { |
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.
Could we use Typecode
here?
14b5b3d
to
d7ad4e8
Compare
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.
LGTM
/run-all-tests |
/run-integration-ddl-test |
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
Code changes
Related changes