{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/42713265","id":42713265,"diff_hunk":"@@ -217,75 +253,22 @@ func typeError(v interface{}, target *FieldType) error {\n \t\tv, v, target.String())\n }\n \n-// Cast casts val to certain types and does not return error.\n-func Cast(val interface{}, target *FieldType) (v interface{}) {\n-\ttp := target.Tp\n+func isCastType(tp byte) bool {\n \tswitch tp {\n-\tcase mysql.TypeString:\n-\t\tx, _ := ToString(val)\n-\t\t// TODO: consider target.Charset/Collate\n-\t\tx = truncateStr(x, target.Flen)\n-\t\tif target.Charset == charset.CharsetBin {\n-\t\t\treturn []byte(x)\n-\t\t}\n-\t\treturn x\n-\tcase mysql.TypeDuration:\n-\t\tvar dur mysql.Duration\n-\t\tfsp := mysql.DefaultFsp\n-\t\tif target.Decimal != UnspecifiedLength {\n-\t\t\tfsp = target.Decimal\n-\t\t}\n-\t\tswitch x := val.(type) {\n-\t\tcase mysql.Duration:\n-\t\t\tdur, _ = x.RoundFrac(fsp)\n-\t\tcase mysql.Time:\n-\t\t\tdur, _ = x.ConvertToDuration()\n-\t\t\tdur, _ = dur.RoundFrac(fsp)\n-\t\tcase string:\n-\t\t\tdur, _ = mysql.ParseDuration(x, fsp)\n-\t\tcase *DataItem:\n-\t\t\treturn Cast(x.Data, target)\n-\t\t}\n-\t\treturn dur\n-\tcase mysql.TypeDatetime, mysql.TypeDate:\n-\t\tfsp := mysql.DefaultFsp\n-\t\tif target.Decimal != UnspecifiedLength {\n-\t\t\tfsp = target.Decimal\n-\t\t}\n-\t\tvar t mysql.Time\n-\t\tt.Type = tp\n-\t\tswitch x := val.(type) {\n-\t\tcase mysql.Time:\n-\t\t\tt, _ = x.Convert(tp)\n-\t\t\tt, _ = t.RoundFrac(fsp)\n-\t\tcase mysql.Duration:\n-\t\t\tt, _ = x.ConvertToTime(tp)\n-\t\t\tt, _ = t.RoundFrac(fsp)\n-\t\tcase string:\n-\t\t\tt, _ = mysql.ParseTime(x, tp, fsp)\n-\t\tcase int64:\n-\t\t\tt, _ = mysql.ParseTimeFromNum(x, tp, fsp)\n-\t\tcase *DataItem:\n-\t\t\treturn Cast(x.Data, target)\n-\t\t}\n-\t\treturn t\n-\tcase mysql.TypeLonglong:\n-\t\tif mysql.HasUnsignedFlag(target.Flag) {\n-\t\t\tv, _ = ToUint64(val)\n-\t\t} else {\n-\t\t\tv, _ = ToInt64(val)\n-\t\t}\n-\t\treturn\n-\tcase mysql.TypeNewDecimal:\n-\t\tx, _ := ToDecimal(val)\n-\t\tif target.Decimal != UnspecifiedLength {\n-\t\t\tx = x.Round(int32(target.Decimal))\n-\t\t}\n-\t\t// TODO: check Flen\n-\t\treturn x\n-\tdefault:\n-\t\tpanic(\"should never happen\")\n+\tcase mysql.TypeString, mysql.TypeDuration, mysql.TypeDatetime,\n+\t\tmysql.TypeDate, mysql.TypeLonglong, mysql.TypeNewDecimal:\n+\t\treturn true\n \t}\n+\treturn false\n+}\n+\n+// Cast casts val to certain types and does not return error.\n+func Cast(val interface{}, target *FieldType) (interface{}, error) {\n+\tif !isCastType(target.Tp) {\n+\t\tpanic(\"unknown cast type, should never happen\")","path":"util/types/convert.go","position":188,"original_position":188,"commit_id":"989ae7cc7945dbc0f810d724579704dd87909c0a","original_commit_id":"989ae7cc7945dbc0f810d724579704dd87909c0a","user":{"login":"siddontang","id":1080370,"avatar_url":"https://avatars.githubusercontent.com/u/1080370?v=3","gravatar_id":"","url":"https://api.github.com/users/siddontang","html_url":"https://github.com/siddontang","followers_url":"https://api.github.com/users/siddontang/followers","following_url":"https://api.github.com/users/siddontang/following{/other_user}","gists_url":"https://api.github.com/users/siddontang/gists{/gist_id}","starred_url":"https://api.github.com/users/siddontang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siddontang/subscriptions","organizations_url":"https://api.github.com/users/siddontang/orgs","repos_url":"https://api.github.com/users/siddontang/repos","events_url":"https://api.github.com/users/siddontang/events{/privacy}","received_events_url":"https://api.github.com/users/siddontang/received_events","type":"User","site_admin":false},"body":"return error may be better. ","created_at":"2015-10-22T05:47:42Z","updated_at":"2015-10-22T05:47:42Z","html_url":"https://github.com/pingcap/tidb/pull/434#discussion_r42713265","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/434","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/42713265"},"html":{"href":"https://github.com/pingcap/tidb/pull/434#discussion_r42713265"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/434"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/434","id":48419307,"html_url":"https://github.com/pingcap/tidb/pull/434","diff_url":"https://github.com/pingcap/tidb/pull/434.diff","patch_url":"https://github.com/pingcap/tidb/pull/434.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/434","number":434,"state":"open","locked":false,"title":"[DNM]Fix #382.","user":{"login":"qiuyesuifeng","id":1953644,"avatar_url":"https://avatars.githubusercontent.com/u/1953644?v=3","gravatar_id":"","url":"https://api.github.com/users/qiuyesuifeng","html_url":"https://github.com/qiuyesuifeng","followers_url":"https://api.github.com/users/qiuyesuifeng/followers","following_url":"https://api.github.com/users/qiuyesuifeng/following{/other_user}","gists_url":"https://api.github.com/users/qiuyesuifeng/gists{/gist_id}","starred_url":"https://api.github.com/users/qiuyesuifeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiuyesuifeng/subscriptions","organizations_url":"https://api.github.com/users/qiuyesuifeng/orgs","repos_url":"https://api.github.com/users/qiuyesuifeng/repos","events_url":"https://api.github.com/users/qiuyesuifeng/events{/privacy}","received_events_url":"https://api.github.com/users/qiuyesuifeng/received_events","type":"User","site_admin":false},"body":"issue is:\r\n```\r\ntidb> select cast(\"xxx 10:10:10\" as datetime);\r\n+----------------------------------+\r\n| CAST(\"xxx 10:10:10\" AS datetime) |\r\n+----------------------------------+\r\n| 2010-10-10 00:00:00              |\r\n+----------------------------------+\r\n```","created_at":"2015-10-22T05:35:15Z","updated_at":"2015-10-22T05:47:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ddf7f38976dc771025d872e3b858f98764c8048d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/434/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/434/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/434/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/989ae7cc7945dbc0f810d724579704dd87909c0a","head":{"label":"pingcap:qiuyesuifeng/fix-382","ref":"qiuyesuifeng/fix-382","sha":"989ae7cc7945dbc0f810d724579704dd87909c0a","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.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":41986369,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.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/tidb","description":"TiDB is a distributed SQL database compatible with MySQL protocol.","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","created_at":"2015-09-06T04:01:52Z","updated_at":"2015-10-22T01:26:00Z","pushed_at":"2015-10-22T05:35:17Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":11741,"stargazers_count":2673,"watchers_count":2673,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":259,"mirror_url":null,"open_issues_count":54,"forks":259,"open_issues":54,"watchers":2673,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"7329f8a6a8f6b4f35f0af3c20a577e1c8ab45abd","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.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":41986369,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.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/tidb","description":"TiDB is a distributed SQL database compatible with MySQL protocol.","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","created_at":"2015-09-06T04:01:52Z","updated_at":"2015-10-22T01:26:00Z","pushed_at":"2015-10-22T05:35:17Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":11741,"stargazers_count":2673,"watchers_count":2673,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":259,"mirror_url":null,"open_issues_count":54,"forks":259,"open_issues":54,"watchers":2673,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/434"},"html":{"href":"https://github.com/pingcap/tidb/pull/434"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/434"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/434/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/434/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/434/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/989ae7cc7945dbc0f810d724579704dd87909c0a"}}}}