{"action":"created","comment":{"url":"https://api.github.com/repos/graphprotocol/graph-node/pulls/comments/218540827","pull_request_review_id":156502603,"id":218540827,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxODU0MDgyNw==","diff_hunk":"@@ -290,19 +290,27 @@ impl BasicStore for Store {\n         }\n \n         // Add order by filters to query\n-        if let Some(order_attribute) = query.order_by {\n+        if let Some((order_attribute, value_type)) = query.order_by {\n             let direction = query\n                 .order_direction\n                 .map(|direction| match direction {\n                     StoreOrder::Ascending => String::from(\"ASC\"),\n                     StoreOrder::Descending => String::from(\"DESC\"),\n                 }).unwrap_or(String::from(\"ASC\"));\n-\n+            let cast_type = match value_type {\n+                ValueType::BigInt => \"::numeric\".to_string(),\n+                ValueType::Boolean => \"::boolean\".to_string(),\n+                ValueType::Bytes => \"\".to_string(),\n+                ValueType::Float => \"::float\".to_string(),\n+                ValueType::ID => \"\".to_string(),\n+                ValueType::Int => \"::bigint\".to_string(),\n+                ValueType::String => \"\".to_string(),\n+            };","path":"store/postgres/src/store.rs","position":21,"original_position":21,"commit_id":"0d9ed62adfab506228716466e0f21e3621bb2ba9","original_commit_id":"0d9ed62adfab506228716466e0f21e3621bb2ba9","user":{"login":"leodasvacas","id":9885558,"node_id":"MDQ6VXNlcjk4ODU1NTg=","avatar_url":"https://avatars3.githubusercontent.com/u/9885558?v=4","gravatar_id":"","url":"https://api.github.com/users/leodasvacas","html_url":"https://github.com/leodasvacas","followers_url":"https://api.github.com/users/leodasvacas/followers","following_url":"https://api.github.com/users/leodasvacas/following{/other_user}","gists_url":"https://api.github.com/users/leodasvacas/gists{/gist_id}","starred_url":"https://api.github.com/users/leodasvacas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leodasvacas/subscriptions","organizations_url":"https://api.github.com/users/leodasvacas/orgs","repos_url":"https://api.github.com/users/leodasvacas/repos","events_url":"https://api.github.com/users/leodasvacas/events{/privacy}","received_events_url":"https://api.github.com/users/leodasvacas/received_events","type":"User","site_admin":false},"body":"Here you can move the `to_string()` to after the match, so this line will be `}.to_string();`","created_at":"2018-09-18T18:16:31Z","updated_at":"2018-09-18T18:16:31Z","html_url":"https://github.com/graphprotocol/graph-node/pull/376#discussion_r218540827","pull_request_url":"https://api.github.com/repos/graphprotocol/graph-node/pulls/376","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/graphprotocol/graph-node/pulls/comments/218540827"},"html":{"href":"https://github.com/graphprotocol/graph-node/pull/376#discussion_r218540827"},"pull_request":{"href":"https://api.github.com/repos/graphprotocol/graph-node/pulls/376"}}},"pull_request":{"url":"https://api.github.com/repos/graphprotocol/graph-node/pulls/376","id":216071012,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE2MDcxMDEy","html_url":"https://github.com/graphprotocol/graph-node/pull/376","diff_url":"https://github.com/graphprotocol/graph-node/pull/376.diff","patch_url":"https://github.com/graphprotocol/graph-node/pull/376.patch","issue_url":"https://api.github.com/repos/graphprotocol/graph-node/issues/376","number":376,"state":"open","locked":false,"title":"Postgres order_by attribute cast to correct data type before performing comparisons","user":{"login":"fordN","id":1591297,"node_id":"MDQ6VXNlcjE1OTEyOTc=","avatar_url":"https://avatars3.githubusercontent.com/u/1591297?v=4","gravatar_id":"","url":"https://api.github.com/users/fordN","html_url":"https://github.com/fordN","followers_url":"https://api.github.com/users/fordN/followers","following_url":"https://api.github.com/users/fordN/following{/other_user}","gists_url":"https://api.github.com/users/fordN/gists{/gist_id}","starred_url":"https://api.github.com/users/fordN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fordN/subscriptions","organizations_url":"https://api.github.com/users/fordN/orgs","repos_url":"https://api.github.com/users/fordN/repos","events_url":"https://api.github.com/users/fordN/events{/privacy}","received_events_url":"https://api.github.com/users/fordN/received_events","type":"User","site_admin":false},"body":"Resolves #331 \r\n\r\nThis PR fixes the filter query bug where all `order_by` comparisons were done in alphabetical order because the `jsonb` objects are returned as `text`; when adding an `order_by` filter the `jsonb` attribute must be cast from text to the correct data type before performing comparisons \r\n\r\nA new enum was created, `ValueType`, with a variant for each supported data type.  `ValueType` is now passed into the `order_by` query fragment builder and used to decide which data cast to perform before ordering.  The `order_by` queries have all been updated to now include `NULLS LAST`, so null values will not appear in the beginning of the filtered set.\r\n\r\nData casting from `jsonb::text` before comparing:\r\n  - BigInt -> cast to `numeric`\r\n  - Int -> cast to `bigint`\r\n  - String -> leave as `text`\r\n  - Float -> cast to `double precision`\r\n  - Id -> leave as `text`\r\n  - Bytes -> leave as `text`\r\n  - Boolean -> cast to `boolean`\r\n\r\n\r\n\r\n","created_at":"2018-09-17T18:20:47Z","updated_at":"2018-09-18T18:16:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c72eaeac83945c67368011063859ff1a3de0d951","assignee":{"login":"fordN","id":1591297,"node_id":"MDQ6VXNlcjE1OTEyOTc=","avatar_url":"https://avatars3.githubusercontent.com/u/1591297?v=4","gravatar_id":"","url":"https://api.github.com/users/fordN","html_url":"https://github.com/fordN","followers_url":"https://api.github.com/users/fordN/followers","following_url":"https://api.github.com/users/fordN/following{/other_user}","gists_url":"https://api.github.com/users/fordN/gists{/gist_id}","starred_url":"https://api.github.com/users/fordN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fordN/subscriptions","organizations_url":"https://api.github.com/users/fordN/orgs","repos_url":"https://api.github.com/users/fordN/repos","events_url":"https://api.github.com/users/fordN/events{/privacy}","received_events_url":"https://api.github.com/users/fordN/received_events","type":"User","site_admin":false},"assignees":[{"login":"fordN","id":1591297,"node_id":"MDQ6VXNlcjE1OTEyOTc=","avatar_url":"https://avatars3.githubusercontent.com/u/1591297?v=4","gravatar_id":"","url":"https://api.github.com/users/fordN","html_url":"https://github.com/fordN","followers_url":"https://api.github.com/users/fordN/followers","following_url":"https://api.github.com/users/fordN/following{/other_user}","gists_url":"https://api.github.com/users/fordN/gists{/gist_id}","starred_url":"https://api.github.com/users/fordN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fordN/subscriptions","organizations_url":"https://api.github.com/users/fordN/orgs","repos_url":"https://api.github.com/users/fordN/repos","events_url":"https://api.github.com/users/fordN/events{/privacy}","received_events_url":"https://api.github.com/users/fordN/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":915843397,"node_id":"MDU6TGFiZWw5MTU4NDMzOTc=","url":"https://api.github.com/repos/graphprotocol/graph-node/labels/pending%20review","name":"pending review","color":"ededed","default":false},{"id":933836988,"node_id":"MDU6TGFiZWw5MzM4MzY5ODg=","url":"https://api.github.com/repos/graphprotocol/graph-node/labels/review","name":"review","color":"ededed","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/graphprotocol/graph-node/pulls/376/commits","review_comments_url":"https://api.github.com/repos/graphprotocol/graph-node/pulls/376/comments","review_comment_url":"https://api.github.com/repos/graphprotocol/graph-node/pulls/comments{/number}","comments_url":"https://api.github.com/repos/graphprotocol/graph-node/issues/376/comments","statuses_url":"https://api.github.com/repos/graphprotocol/graph-node/statuses/0d9ed62adfab506228716466e0f21e3621bb2ba9","head":{"label":"graphprotocol:ford/orderby-query-data-cast","ref":"ford/orderby-query-data-cast","sha":"0d9ed62adfab506228716466e0f21e3621bb2ba9","user":{"login":"graphprotocol","id":38020273,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM4MDIwMjcz","avatar_url":"https://avatars2.githubusercontent.com/u/38020273?v=4","gravatar_id":"","url":"https://api.github.com/users/graphprotocol","html_url":"https://github.com/graphprotocol","followers_url":"https://api.github.com/users/graphprotocol/followers","following_url":"https://api.github.com/users/graphprotocol/following{/other_user}","gists_url":"https://api.github.com/users/graphprotocol/gists{/gist_id}","starred_url":"https://api.github.com/users/graphprotocol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graphprotocol/subscriptions","organizations_url":"https://api.github.com/users/graphprotocol/orgs","repos_url":"https://api.github.com/users/graphprotocol/repos","events_url":"https://api.github.com/users/graphprotocol/events{/privacy}","received_events_url":"https://api.github.com/users/graphprotocol/received_events","type":"Organization","site_admin":false},"repo":{"id":130174051,"node_id":"MDEwOlJlcG9zaXRvcnkxMzAxNzQwNTE=","name":"graph-node","full_name":"graphprotocol/graph-node","private":false,"owner":{"login":"graphprotocol","id":38020273,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM4MDIwMjcz","avatar_url":"https://avatars2.githubusercontent.com/u/38020273?v=4","gravatar_id":"","url":"https://api.github.com/users/graphprotocol","html_url":"https://github.com/graphprotocol","followers_url":"https://api.github.com/users/graphprotocol/followers","following_url":"https://api.github.com/users/graphprotocol/following{/other_user}","gists_url":"https://api.github.com/users/graphprotocol/gists{/gist_id}","starred_url":"https://api.github.com/users/graphprotocol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graphprotocol/subscriptions","organizations_url":"https://api.github.com/users/graphprotocol/orgs","repos_url":"https://api.github.com/users/graphprotocol/repos","events_url":"https://api.github.com/users/graphprotocol/events{/privacy}","received_events_url":"https://api.github.com/users/graphprotocol/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/graphprotocol/graph-node","description":"Graph Node indexes data from immutable datasources and serves it over GraphQL","fork":false,"url":"https://api.github.com/repos/graphprotocol/graph-node","forks_url":"https://api.github.com/repos/graphprotocol/graph-node/forks","keys_url":"https://api.github.com/repos/graphprotocol/graph-node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/graphprotocol/graph-node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/graphprotocol/graph-node/teams","hooks_url":"https://api.github.com/repos/graphprotocol/graph-node/hooks","issue_events_url":"https://api.github.com/repos/graphprotocol/graph-node/issues/events{/number}","events_url":"https://api.github.com/repos/graphprotocol/graph-node/events","assignees_url":"https://api.github.com/repos/graphprotocol/graph-node/assignees{/user}","branches_url":"https://api.github.com/repos/graphprotocol/graph-node/branches{/branch}","tags_url":"https://api.github.com/repos/graphprotocol/graph-node/tags","blobs_url":"https://api.github.com/repos/graphprotocol/graph-node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/graphprotocol/graph-node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/graphprotocol/graph-node/git/refs{/sha}","trees_url":"https://api.github.com/repos/graphprotocol/graph-node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/graphprotocol/graph-node/statuses/{sha}","languages_url":"https://api.github.com/repos/graphprotocol/graph-node/languages","stargazers_url":"https://api.github.com/repos/graphprotocol/graph-node/stargazers","contributors_url":"https://api.github.com/repos/graphprotocol/graph-node/contributors","subscribers_url":"https://api.github.com/repos/graphprotocol/graph-node/subscribers","subscription_url":"https://api.github.com/repos/graphprotocol/graph-node/subscription","commits_url":"https://api.github.com/repos/graphprotocol/graph-node/commits{/sha}","git_commits_url":"https://api.github.com/repos/graphprotocol/graph-node/git/commits{/sha}","comments_url":"https://api.github.com/repos/graphprotocol/graph-node/comments{/number}","issue_comment_url":"https://api.github.com/repos/graphprotocol/graph-node/issues/comments{/number}","contents_url":"https://api.github.com/repos/graphprotocol/graph-node/contents/{+path}","compare_url":"https://api.github.com/repos/graphprotocol/graph-node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/graphprotocol/graph-node/merges","archive_url":"https://api.github.com/repos/graphprotocol/graph-node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/graphprotocol/graph-node/downloads","issues_url":"https://api.github.com/repos/graphprotocol/graph-node/issues{/number}","pulls_url":"https://api.github.com/repos/graphprotocol/graph-node/pulls{/number}","milestones_url":"https://api.github.com/repos/graphprotocol/graph-node/milestones{/number}","notifications_url":"https://api.github.com/repos/graphprotocol/graph-node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/graphprotocol/graph-node/labels{/name}","releases_url":"https://api.github.com/repos/graphprotocol/graph-node/releases{/id}","deployments_url":"https://api.github.com/repos/graphprotocol/graph-node/deployments","created_at":"2018-04-19T07:13:50Z","updated_at":"2018-09-18T16:02:06Z","pushed_at":"2018-09-18T18:07:29Z","git_url":"git://github.com/graphprotocol/graph-node.git","ssh_url":"git@github.com:graphprotocol/graph-node.git","clone_url":"https://github.com/graphprotocol/graph-node.git","svn_url":"https://github.com/graphprotocol/graph-node","homepage":"https://thegraph.com","size":1893,"stargazers_count":125,"watchers_count":125,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"archived":false,"open_issues_count":82,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":11,"open_issues":82,"watchers":125,"default_branch":"master"}},"base":{"label":"graphprotocol:master","ref":"master","sha":"091cad4dc0b13f71c7d1968ef04b65c3970a355e","user":{"login":"graphprotocol","id":38020273,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM4MDIwMjcz","avatar_url":"https://avatars2.githubusercontent.com/u/38020273?v=4","gravatar_id":"","url":"https://api.github.com/users/graphprotocol","html_url":"https://github.com/graphprotocol","followers_url":"https://api.github.com/users/graphprotocol/followers","following_url":"https://api.github.com/users/graphprotocol/following{/other_user}","gists_url":"https://api.github.com/users/graphprotocol/gists{/gist_id}","starred_url":"https://api.github.com/users/graphprotocol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graphprotocol/subscriptions","organizations_url":"https://api.github.com/users/graphprotocol/orgs","repos_url":"https://api.github.com/users/graphprotocol/repos","events_url":"https://api.github.com/users/graphprotocol/events{/privacy}","received_events_url":"https://api.github.com/users/graphprotocol/received_events","type":"Organization","site_admin":false},"repo":{"id":130174051,"node_id":"MDEwOlJlcG9zaXRvcnkxMzAxNzQwNTE=","name":"graph-node","full_name":"graphprotocol/graph-node","private":false,"owner":{"login":"graphprotocol","id":38020273,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM4MDIwMjcz","avatar_url":"https://avatars2.githubusercontent.com/u/38020273?v=4","gravatar_id":"","url":"https://api.github.com/users/graphprotocol","html_url":"https://github.com/graphprotocol","followers_url":"https://api.github.com/users/graphprotocol/followers","following_url":"https://api.github.com/users/graphprotocol/following{/other_user}","gists_url":"https://api.github.com/users/graphprotocol/gists{/gist_id}","starred_url":"https://api.github.com/users/graphprotocol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graphprotocol/subscriptions","organizations_url":"https://api.github.com/users/graphprotocol/orgs","repos_url":"https://api.github.com/users/graphprotocol/repos","events_url":"https://api.github.com/users/graphprotocol/events{/privacy}","received_events_url":"https://api.github.com/users/graphprotocol/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/graphprotocol/graph-node","description":"Graph Node indexes data from immutable datasources and serves it over GraphQL","fork":false,"url":"https://api.github.com/repos/graphprotocol/graph-node","forks_url":"https://api.github.com/repos/graphprotocol/graph-node/forks","keys_url":"https://api.github.com/repos/graphprotocol/graph-node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/graphprotocol/graph-node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/graphprotocol/graph-node/teams","hooks_url":"https://api.github.com/repos/graphprotocol/graph-node/hooks","issue_events_url":"https://api.github.com/repos/graphprotocol/graph-node/issues/events{/number}","events_url":"https://api.github.com/repos/graphprotocol/graph-node/events","assignees_url":"https://api.github.com/repos/graphprotocol/graph-node/assignees{/user}","branches_url":"https://api.github.com/repos/graphprotocol/graph-node/branches{/branch}","tags_url":"https://api.github.com/repos/graphprotocol/graph-node/tags","blobs_url":"https://api.github.com/repos/graphprotocol/graph-node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/graphprotocol/graph-node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/graphprotocol/graph-node/git/refs{/sha}","trees_url":"https://api.github.com/repos/graphprotocol/graph-node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/graphprotocol/graph-node/statuses/{sha}","languages_url":"https://api.github.com/repos/graphprotocol/graph-node/languages","stargazers_url":"https://api.github.com/repos/graphprotocol/graph-node/stargazers","contributors_url":"https://api.github.com/repos/graphprotocol/graph-node/contributors","subscribers_url":"https://api.github.com/repos/graphprotocol/graph-node/subscribers","subscription_url":"https://api.github.com/repos/graphprotocol/graph-node/subscription","commits_url":"https://api.github.com/repos/graphprotocol/graph-node/commits{/sha}","git_commits_url":"https://api.github.com/repos/graphprotocol/graph-node/git/commits{/sha}","comments_url":"https://api.github.com/repos/graphprotocol/graph-node/comments{/number}","issue_comment_url":"https://api.github.com/repos/graphprotocol/graph-node/issues/comments{/number}","contents_url":"https://api.github.com/repos/graphprotocol/graph-node/contents/{+path}","compare_url":"https://api.github.com/repos/graphprotocol/graph-node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/graphprotocol/graph-node/merges","archive_url":"https://api.github.com/repos/graphprotocol/graph-node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/graphprotocol/graph-node/downloads","issues_url":"https://api.github.com/repos/graphprotocol/graph-node/issues{/number}","pulls_url":"https://api.github.com/repos/graphprotocol/graph-node/pulls{/number}","milestones_url":"https://api.github.com/repos/graphprotocol/graph-node/milestones{/number}","notifications_url":"https://api.github.com/repos/graphprotocol/graph-node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/graphprotocol/graph-node/labels{/name}","releases_url":"https://api.github.com/repos/graphprotocol/graph-node/releases{/id}","deployments_url":"https://api.github.com/repos/graphprotocol/graph-node/deployments","created_at":"2018-04-19T07:13:50Z","updated_at":"2018-09-18T16:02:06Z","pushed_at":"2018-09-18T18:07:29Z","git_url":"git://github.com/graphprotocol/graph-node.git","ssh_url":"git@github.com:graphprotocol/graph-node.git","clone_url":"https://github.com/graphprotocol/graph-node.git","svn_url":"https://github.com/graphprotocol/graph-node","homepage":"https://thegraph.com","size":1893,"stargazers_count":125,"watchers_count":125,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"archived":false,"open_issues_count":82,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":11,"open_issues":82,"watchers":125,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/graphprotocol/graph-node/pulls/376"},"html":{"href":"https://github.com/graphprotocol/graph-node/pull/376"},"issue":{"href":"https://api.github.com/repos/graphprotocol/graph-node/issues/376"},"comments":{"href":"https://api.github.com/repos/graphprotocol/graph-node/issues/376/comments"},"review_comments":{"href":"https://api.github.com/repos/graphprotocol/graph-node/pulls/376/comments"},"review_comment":{"href":"https://api.github.com/repos/graphprotocol/graph-node/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/graphprotocol/graph-node/pulls/376/commits"},"statuses":{"href":"https://api.github.com/repos/graphprotocol/graph-node/statuses/0d9ed62adfab506228716466e0f21e3621bb2ba9"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"leodasvacas"}}