{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tikv/pulls/comments/127121386","pull_request_review_id":49671895,"id":127121386,"diff_hunk":"@@ -0,0 +1,73 @@\n+// Copyright 2017 PingCAP, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+// FIXME: remove following later\n+#![allow(dead_code)]\n+\n+use std::collections::BTreeMap;\n+\n+use super::Json;\n+use super::super::super::datum::Datum;\n+use super::super::super::{Result, Error};\n+\n+impl Json {\n+    // https://dev.mysql.com/doc/refman/5.7/en/json-creation-functions.html#function_json-object\n+    pub fn to_object(kvs: &[Datum]) -> Result<Json> {\n+        let len = kvs.len();\n+        if len & 1 == 1 {\n+            return Err(Error::Other(box_err!(\"Incorrect parameter count in the call to native \\\n+                                              function 'JSON_OBJECT'\")));\n+        }\n+        let mut map = BTreeMap::new();\n+        let mut idx = 0;\n+        while idx < len {\n+            let key = match kvs[idx] {\n+                Datum::Null => {\n+                    return Err(invalid_type!(\"JSON documents may not contain NULL member names\"));\n+                }\n+                _ => try!(kvs[idx].to_string()),\n+            };\n+            let val = try!(kvs[idx + 1].clone().into_json());\n+            map.insert(key, val);\n+            idx += 2;\n+        }\n+        Ok(Json::Object(map))\n+    }\n+}\n+\n+#[cfg(test)]\n+mod test {\n+    use super::*;\n+\n+    #[test]\n+    fn test_json_object() {\n+        let d = vec![Datum::I64(1)];\n+        assert!(Json::to_object(&d).is_err());\n+\n+        let d = vec![Datum::I64(1), Datum::Bytes(b\"sdf\".to_vec()), Datum::Null, Datum::U64(2)];\n+        assert!(Json::to_object(&d).is_err());\n+\n+        let d = vec![Datum::I64(1),\n+                     Datum::Bytes(b\"sdf\".to_vec()),\n+                     Datum::Bytes(b\"asd\".to_vec()),\n+                     Datum::Bytes(b\"qwe\".to_vec()),\n+                     Datum::I64(2),\n+                     Datum::Json(r#\"{\"3\":4}\"#.parse().unwrap())];\n+        let ep_json = r#\"{\"1\":\"sdf\",\"2\":{\"3\":4},\"asd\":\"qwe\"}\"#.parse().unwrap();\n+        assert_eq!(Json::to_object(&d).unwrap(), ep_json);","path":"src/util/codec/mysql/json/json_object.rs","position":67,"original_position":67,"commit_id":"584ecfe12f4518b486eb74aefb071d667a0d75a6","original_commit_id":"584ecfe12f4518b486eb74aefb071d667a0d75a6","user":{"login":"hhkbp2","id":1933824,"avatar_url":"https://avatars0.githubusercontent.com/u/1933824?v=3","gravatar_id":"","url":"https://api.github.com/users/hhkbp2","html_url":"https://github.com/hhkbp2","followers_url":"https://api.github.com/users/hhkbp2/followers","following_url":"https://api.github.com/users/hhkbp2/following{/other_user}","gists_url":"https://api.github.com/users/hhkbp2/gists{/gist_id}","starred_url":"https://api.github.com/users/hhkbp2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hhkbp2/subscriptions","organizations_url":"https://api.github.com/users/hhkbp2/orgs","repos_url":"https://api.github.com/users/hhkbp2/repos","events_url":"https://api.github.com/users/hhkbp2/events{/privacy}","received_events_url":"https://api.github.com/users/hhkbp2/received_events","type":"User","site_admin":false},"body":"Dito. List the test cases to avoid duplicate code.","created_at":"2017-07-13T03:34:18Z","updated_at":"2017-07-13T03:34:18Z","html_url":"https://github.com/pingcap/tikv/pull/2025#discussion_r127121386","pull_request_url":"https://api.github.com/repos/pingcap/tikv/pulls/2025","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/comments/127121386"},"html":{"href":"https://github.com/pingcap/tikv/pull/2025#discussion_r127121386"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/2025"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tikv/pulls/2025","id":129890500,"html_url":"https://github.com/pingcap/tikv/pull/2025","diff_url":"https://github.com/pingcap/tikv/pull/2025.diff","patch_url":"https://github.com/pingcap/tikv/pull/2025.patch","issue_url":"https://api.github.com/repos/pingcap/tikv/issues/2025","number":2025,"state":"open","locked":false,"title":"evaluator: impl json_object and json_array","user":{"login":"lishihai9017","id":670947,"avatar_url":"https://avatars3.githubusercontent.com/u/670947?v=3","gravatar_id":"","url":"https://api.github.com/users/lishihai9017","html_url":"https://github.com/lishihai9017","followers_url":"https://api.github.com/users/lishihai9017/followers","following_url":"https://api.github.com/users/lishihai9017/following{/other_user}","gists_url":"https://api.github.com/users/lishihai9017/gists{/gist_id}","starred_url":"https://api.github.com/users/lishihai9017/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lishihai9017/subscriptions","organizations_url":"https://api.github.com/users/lishihai9017/orgs","repos_url":"https://api.github.com/users/lishihai9017/repos","events_url":"https://api.github.com/users/lishihai9017/events{/privacy}","received_events_url":"https://api.github.com/users/lishihai9017/received_events","type":"User","site_admin":false},"body":"Hi\r\nThis PR add JSON_OBECT and JSON_ARRAY function.\r\n\r\nPTAL @AndreMouche @andelf @hhkbp2 ","created_at":"2017-07-11T12:04:03Z","updated_at":"2017-07-13T03:34:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a453d2c434246f909ab681618fd5336bc5f54baf","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tikv/pulls/2025/commits","review_comments_url":"https://api.github.com/repos/pingcap/tikv/pulls/2025/comments","review_comment_url":"https://api.github.com/repos/pingcap/tikv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tikv/issues/2025/comments","statuses_url":"https://api.github.com/repos/pingcap/tikv/statuses/584ecfe12f4518b486eb74aefb071d667a0d75a6","head":{"label":"pingcap:lishihai/add-create-json-functions","ref":"lishihai/add-create-json-functions","sha":"584ecfe12f4518b486eb74aefb071d667a0d75a6","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars0.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":48833910,"name":"tikv","full_name":"pingcap/tikv","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars0.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tikv","description":"Distributed transactional key value database powered by Rust and Raft","fork":false,"url":"https://api.github.com/repos/pingcap/tikv","forks_url":"https://api.github.com/repos/pingcap/tikv/forks","keys_url":"https://api.github.com/repos/pingcap/tikv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tikv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tikv/teams","hooks_url":"https://api.github.com/repos/pingcap/tikv/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tikv/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tikv/events","assignees_url":"https://api.github.com/repos/pingcap/tikv/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tikv/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tikv/tags","blobs_url":"https://api.github.com/repos/pingcap/tikv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tikv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tikv/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tikv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tikv/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tikv/languages","stargazers_url":"https://api.github.com/repos/pingcap/tikv/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tikv/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tikv/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tikv/subscription","commits_url":"https://api.github.com/repos/pingcap/tikv/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tikv/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tikv/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tikv/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tikv/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tikv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tikv/merges","archive_url":"https://api.github.com/repos/pingcap/tikv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tikv/downloads","issues_url":"https://api.github.com/repos/pingcap/tikv/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tikv/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tikv/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tikv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tikv/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tikv/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tikv/deployments","created_at":"2015-12-31T04:51:32Z","updated_at":"2017-07-13T01:04:46Z","pushed_at":"2017-07-13T03:20:30Z","git_url":"git://github.com/pingcap/tikv.git","ssh_url":"git@github.com:pingcap/tikv.git","clone_url":"https://github.com/pingcap/tikv.git","svn_url":"https://github.com/pingcap/tikv","homepage":"https://pingcap.com","size":9287,"stargazers_count":1981,"watchers_count":1981,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":206,"mirror_url":null,"open_issues_count":99,"forks":206,"open_issues":99,"watchers":1981,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"4b19680fcc90fbafcb3c2f7d2eb9e2cc1e5e87a0","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars0.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":48833910,"name":"tikv","full_name":"pingcap/tikv","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars0.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tikv","description":"Distributed transactional key value database powered by Rust and Raft","fork":false,"url":"https://api.github.com/repos/pingcap/tikv","forks_url":"https://api.github.com/repos/pingcap/tikv/forks","keys_url":"https://api.github.com/repos/pingcap/tikv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tikv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tikv/teams","hooks_url":"https://api.github.com/repos/pingcap/tikv/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tikv/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tikv/events","assignees_url":"https://api.github.com/repos/pingcap/tikv/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tikv/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tikv/tags","blobs_url":"https://api.github.com/repos/pingcap/tikv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tikv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tikv/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tikv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tikv/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tikv/languages","stargazers_url":"https://api.github.com/repos/pingcap/tikv/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tikv/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tikv/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tikv/subscription","commits_url":"https://api.github.com/repos/pingcap/tikv/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tikv/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tikv/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tikv/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tikv/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tikv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tikv/merges","archive_url":"https://api.github.com/repos/pingcap/tikv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tikv/downloads","issues_url":"https://api.github.com/repos/pingcap/tikv/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tikv/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tikv/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tikv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tikv/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tikv/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tikv/deployments","created_at":"2015-12-31T04:51:32Z","updated_at":"2017-07-13T01:04:46Z","pushed_at":"2017-07-13T03:20:30Z","git_url":"git://github.com/pingcap/tikv.git","ssh_url":"git@github.com:pingcap/tikv.git","clone_url":"https://github.com/pingcap/tikv.git","svn_url":"https://github.com/pingcap/tikv","homepage":"https://pingcap.com","size":9287,"stargazers_count":1981,"watchers_count":1981,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":206,"mirror_url":null,"open_issues_count":99,"forks":206,"open_issues":99,"watchers":1981,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/2025"},"html":{"href":"https://github.com/pingcap/tikv/pull/2025"},"issue":{"href":"https://api.github.com/repos/pingcap/tikv/issues/2025"},"comments":{"href":"https://api.github.com/repos/pingcap/tikv/issues/2025/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/2025/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/2025/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tikv/statuses/584ecfe12f4518b486eb74aefb071d667a0d75a6"}}}}
{"actor":{"display_login":"hhkbp2"}}