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

mysql/json: json_merge #1951

Merged
merged 13 commits into from
Jun 23, 2017
Merged

mysql/json: json_merge #1951

merged 13 commits into from
Jun 23, 2017

Conversation

AndreMouche
Copy link
Member

Hi,
This PR implement JSON_MERGE for document, related PR in tidb is pingcap/tidb#3374, and the relate source file in tidb is
https://github.com/pingcap/tidb/blob/master/util/types/json/functions.go#L208

@hhkbp2 @hicqu @andelf @lishihai9017 PTAL

Json::Array(array)
}
};
let mut left_num = suffixes.len();
Copy link
Contributor

Choose a reason for hiding this comment

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

normally lhs & rhs will be a good name.
left_num is ambiguous

let mut left_num = suffixes.len();
for suffix in suffixes {
data = match (data, suffix) {
(Json::Array(mut array), Json::Array(mut sub_array)) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

will ref mut works?

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems not @andelf

}
(obj, suffix) => {
// rule 3, 4
let mut array = Vec::with_capacity(left_num + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

? why left_num +1

}
};
let mut left_num = suffixes.len();
for suffix in suffixes {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a Iterator::fold pattern

#[test]
fn test_merge() {
let test_cases = vec![
(r#"{"a": 1}"#,r#"{"b": 2}"#, r#"{"a": 1, "b": 2}"#),
Copy link
Contributor

Choose a reason for hiding this comment

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

spaces

@AndreMouche
Copy link
Member Author

@lishihai9017 @andelf @hhkbp2 @hicqu PTAL

@hicqu
Copy link
Contributor

hicqu commented Jun 23, 2017

LGTM.

@andelf
Copy link
Contributor

andelf commented Jun 23, 2017

LGTM

@AndreMouche AndreMouche merged commit bd95721 into master Jun 23, 2017
@AndreMouche AndreMouche deleted the shirly/json_merge branch June 23, 2017 07:59
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.

3 participants