{"action":"opened","number":38,"pull_request":{"url":"https://api.github.com/repos/github/github-ds/pulls/38","id":187512051,"html_url":"https://github.com/github/github-ds/pull/38","diff_url":"https://github.com/github/github-ds/pull/38.diff","patch_url":"https://github.com/github/github-ds/pull/38.patch","issue_url":"https://api.github.com/repos/github/github-ds/issues/38","number":38,"state":"open","locked":false,"title":"Don't de-dup values in results array","user":{"login":"eileencodes","id":1080678,"avatar_url":"https://avatars0.githubusercontent.com/u/1080678?v=4","gravatar_id":"","url":"https://api.github.com/users/eileencodes","html_url":"https://github.com/eileencodes","followers_url":"https://api.github.com/users/eileencodes/followers","following_url":"https://api.github.com/users/eileencodes/following{/other_user}","gists_url":"https://api.github.com/users/eileencodes/gists{/gist_id}","starred_url":"https://api.github.com/users/eileencodes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eileencodes/subscriptions","organizations_url":"https://api.github.com/users/eileencodes/orgs","repos_url":"https://api.github.com/users/eileencodes/repos","events_url":"https://api.github.com/users/eileencodes/events{/privacy}","received_events_url":"https://api.github.com/users/eileencodes/received_events","type":"User","site_admin":true},"body":"Problem:\r\n\r\nIf a user passed duplicate column names to GitHub::DS, for example\r\n`sql.add(SELECT id, NULL, NULL, name from repositories)` the valued\r\nreturned by `result` wouldn't line up with the column names. Instead\r\nwhat would be returned is:\r\n\r\n```\r\nsql.results\r\n[[1, nil, \"repo name\"], [2, nil, \"repo name 2\"]]\r\n```\r\n\r\ninstead of the correct value set:\r\n\r\n```\r\nsql.results\r\n[[1, nil, nil, \"repo name\"], [2, nil, nil, \"repo name 2\"]]\r\n```\r\n\r\nThis is because we were calling `to_ary` on the\r\n`ActiveRecord::Base#result`. This would loop through the columns and\r\nrows and pair them up into a hash. The underlying problem is hashes\r\ncannot contain keys with the same value, and Ruby will de-dup the keys\r\nbefore retunring the result.\r\n\r\nSolution: \r\nTo fix this problem we can instead call `rows` on the returned results\r\nwhich will give us all the rows. If we want `hash_results` instead we\r\ncan accept that a hash de-dups the values since we likely will never\r\nturn a hash back into a SQL statement.\r\n\r\nOriginally I considered raising if there were duplicate columns passed\r\nin but after some investigation into Rails I found that Rails is able to\r\ntake `[\"title\", \"title\"]` as the columns and then apply those columns\r\nproperly to the joined tables, so that wasn't a viable solution.\r\n\r\nAfter considering the options it makes sense for results to return ALL\r\nthe results and for the hash to return just the de-duplicated keys. This\r\nis the behavior in Rails for many years so this behavior seems correct.\r\n\r\ncc/ @rhettg @spraints @jdennes ","created_at":"2018-05-11T16:31:32Z","updated_at":"2018-05-11T16:31:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/github/github-ds/pulls/38/commits","review_comments_url":"https://api.github.com/repos/github/github-ds/pulls/38/comments","review_comment_url":"https://api.github.com/repos/github/github-ds/pulls/comments{/number}","comments_url":"https://api.github.com/repos/github/github-ds/issues/38/comments","statuses_url":"https://api.github.com/repos/github/github-ds/statuses/44b8c2d388dc1a0d74e878715b124789a1bd8b7d","head":{"label":"github:fix-results-when-duplicate-column-name-is-passed","ref":"fix-results-when-duplicate-column-name-is-passed","sha":"44b8c2d388dc1a0d74e878715b124789a1bd8b7d","user":{"login":"github","id":9919,"avatar_url":"https://avatars1.githubusercontent.com/u/9919?v=4","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"repo":{"id":75887039,"name":"github-ds","full_name":"github/github-ds","owner":{"login":"github","id":9919,"avatar_url":"https://avatars1.githubusercontent.com/u/9919?v=4","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/github/github-ds","description":"A collection of Ruby libraries for working with SQL on top of ActiveRecord's connection","fork":false,"url":"https://api.github.com/repos/github/github-ds","forks_url":"https://api.github.com/repos/github/github-ds/forks","keys_url":"https://api.github.com/repos/github/github-ds/keys{/key_id}","collaborators_url":"https://api.github.com/repos/github/github-ds/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/github/github-ds/teams","hooks_url":"https://api.github.com/repos/github/github-ds/hooks","issue_events_url":"https://api.github.com/repos/github/github-ds/issues/events{/number}","events_url":"https://api.github.com/repos/github/github-ds/events","assignees_url":"https://api.github.com/repos/github/github-ds/assignees{/user}","branches_url":"https://api.github.com/repos/github/github-ds/branches{/branch}","tags_url":"https://api.github.com/repos/github/github-ds/tags","blobs_url":"https://api.github.com/repos/github/github-ds/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/github/github-ds/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/github/github-ds/git/refs{/sha}","trees_url":"https://api.github.com/repos/github/github-ds/git/trees{/sha}","statuses_url":"https://api.github.com/repos/github/github-ds/statuses/{sha}","languages_url":"https://api.github.com/repos/github/github-ds/languages","stargazers_url":"https://api.github.com/repos/github/github-ds/stargazers","contributors_url":"https://api.github.com/repos/github/github-ds/contributors","subscribers_url":"https://api.github.com/repos/github/github-ds/subscribers","subscription_url":"https://api.github.com/repos/github/github-ds/subscription","commits_url":"https://api.github.com/repos/github/github-ds/commits{/sha}","git_commits_url":"https://api.github.com/repos/github/github-ds/git/commits{/sha}","comments_url":"https://api.github.com/repos/github/github-ds/comments{/number}","issue_comment_url":"https://api.github.com/repos/github/github-ds/issues/comments{/number}","contents_url":"https://api.github.com/repos/github/github-ds/contents/{+path}","compare_url":"https://api.github.com/repos/github/github-ds/compare/{base}...{head}","merges_url":"https://api.github.com/repos/github/github-ds/merges","archive_url":"https://api.github.com/repos/github/github-ds/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/github/github-ds/downloads","issues_url":"https://api.github.com/repos/github/github-ds/issues{/number}","pulls_url":"https://api.github.com/repos/github/github-ds/pulls{/number}","milestones_url":"https://api.github.com/repos/github/github-ds/milestones{/number}","notifications_url":"https://api.github.com/repos/github/github-ds/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/github/github-ds/labels{/name}","releases_url":"https://api.github.com/repos/github/github-ds/releases{/id}","deployments_url":"https://api.github.com/repos/github/github-ds/deployments","created_at":"2016-12-08T00:19:19Z","updated_at":"2018-04-23T19:25:51Z","pushed_at":"2018-05-11T16:31:07Z","git_url":"git://github.com/github/github-ds.git","ssh_url":"git@github.com:github/github-ds.git","clone_url":"https://github.com/github/github-ds.git","svn_url":"https://github.com/github/github-ds","homepage":"","size":168,"stargazers_count":429,"watchers_count":429,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":17,"open_issues":2,"watchers":429,"default_branch":"master"}},"base":{"label":"github:master","ref":"master","sha":"ecbe03755b4223e1d8a5f7272ca6cd2e87147a8e","user":{"login":"github","id":9919,"avatar_url":"https://avatars1.githubusercontent.com/u/9919?v=4","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"repo":{"id":75887039,"name":"github-ds","full_name":"github/github-ds","owner":{"login":"github","id":9919,"avatar_url":"https://avatars1.githubusercontent.com/u/9919?v=4","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/github/github-ds","description":"A collection of Ruby libraries for working with SQL on top of ActiveRecord's connection","fork":false,"url":"https://api.github.com/repos/github/github-ds","forks_url":"https://api.github.com/repos/github/github-ds/forks","keys_url":"https://api.github.com/repos/github/github-ds/keys{/key_id}","collaborators_url":"https://api.github.com/repos/github/github-ds/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/github/github-ds/teams","hooks_url":"https://api.github.com/repos/github/github-ds/hooks","issue_events_url":"https://api.github.com/repos/github/github-ds/issues/events{/number}","events_url":"https://api.github.com/repos/github/github-ds/events","assignees_url":"https://api.github.com/repos/github/github-ds/assignees{/user}","branches_url":"https://api.github.com/repos/github/github-ds/branches{/branch}","tags_url":"https://api.github.com/repos/github/github-ds/tags","blobs_url":"https://api.github.com/repos/github/github-ds/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/github/github-ds/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/github/github-ds/git/refs{/sha}","trees_url":"https://api.github.com/repos/github/github-ds/git/trees{/sha}","statuses_url":"https://api.github.com/repos/github/github-ds/statuses/{sha}","languages_url":"https://api.github.com/repos/github/github-ds/languages","stargazers_url":"https://api.github.com/repos/github/github-ds/stargazers","contributors_url":"https://api.github.com/repos/github/github-ds/contributors","subscribers_url":"https://api.github.com/repos/github/github-ds/subscribers","subscription_url":"https://api.github.com/repos/github/github-ds/subscription","commits_url":"https://api.github.com/repos/github/github-ds/commits{/sha}","git_commits_url":"https://api.github.com/repos/github/github-ds/git/commits{/sha}","comments_url":"https://api.github.com/repos/github/github-ds/comments{/number}","issue_comment_url":"https://api.github.com/repos/github/github-ds/issues/comments{/number}","contents_url":"https://api.github.com/repos/github/github-ds/contents/{+path}","compare_url":"https://api.github.com/repos/github/github-ds/compare/{base}...{head}","merges_url":"https://api.github.com/repos/github/github-ds/merges","archive_url":"https://api.github.com/repos/github/github-ds/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/github/github-ds/downloads","issues_url":"https://api.github.com/repos/github/github-ds/issues{/number}","pulls_url":"https://api.github.com/repos/github/github-ds/pulls{/number}","milestones_url":"https://api.github.com/repos/github/github-ds/milestones{/number}","notifications_url":"https://api.github.com/repos/github/github-ds/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/github/github-ds/labels{/name}","releases_url":"https://api.github.com/repos/github/github-ds/releases{/id}","deployments_url":"https://api.github.com/repos/github/github-ds/deployments","created_at":"2016-12-08T00:19:19Z","updated_at":"2018-04-23T19:25:51Z","pushed_at":"2018-05-11T16:31:07Z","git_url":"git://github.com/github/github-ds.git","ssh_url":"git@github.com:github/github-ds.git","clone_url":"https://github.com/github/github-ds.git","svn_url":"https://github.com/github/github-ds","homepage":"","size":168,"stargazers_count":429,"watchers_count":429,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":17,"open_issues":2,"watchers":429,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/github/github-ds/pulls/38"},"html":{"href":"https://github.com/github/github-ds/pull/38"},"issue":{"href":"https://api.github.com/repos/github/github-ds/issues/38"},"comments":{"href":"https://api.github.com/repos/github/github-ds/issues/38/comments"},"review_comments":{"href":"https://api.github.com/repos/github/github-ds/pulls/38/comments"},"review_comment":{"href":"https://api.github.com/repos/github/github-ds/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/github/github-ds/pulls/38/commits"},"statuses":{"href":"https://api.github.com/repos/github/github-ds/statuses/44b8c2d388dc1a0d74e878715b124789a1bd8b7d"}},"author_association":"MEMBER","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":false,"commits":1,"additions":30,"deletions":3,"changed_files":2}}
{"actor":{"display_login":"eileencodes"}}