{"action":"created","comment":{"url":"https://api.github.com/repos/mldbai/mldb/pulls/comments/63739553","id":63739553,"diff_hunk":"@@ -0,0 +1,72 @@\n+/** builtin_geo_functions.cc\n+    Jeremy Barnes, 14 June 2015\n+    This file is part of MLDB. Copyright 2015 Datacratic. All rights reserved.\n+\n+    Builtin geometric functions for SQL.\n+*/\n+\n+#include \"mldb/sql/builtin_functions.h\"\n+#include \"mldb/ext/s2/s2.h\"\n+#include \"mldb/ext/s2/s2latlng.h\"\n+#include \"mldb/types/basic_value_descriptions.h\"\n+\n+\n+using namespace std;\n+\n+\n+namespace Datacratic {\n+namespace MLDB {\n+namespace Builtins {\n+\n+/*****************************************************************************/\n+/* GEOGRAPHICAL FUNCTIONS                                                    */\n+/*****************************************************************************/\n+\n+static constexpr double EARTH_EQUATORIAL_RADIUS_METERS = 6378137.0;\n+static constexpr double EARTH_POLAR_RADIUS_METERS      = 6356752.3;\n+\n+// https://en.wikipedia.org/w/index.php?title=Earth_radius&action=edit&section=16\n+static constexpr double EARTH_MEAN_RADIUS_METERS       = 6371008.8;\n+\n+BoundFunction geo_distance(const std::vector<BoundSqlExpression> & args)\n+{\n+    checkArgsSize(args.size(), 4);\n+\n+    auto outputInfo\n+        = std::make_shared<Float64ValueInfo>();\n+        \n+    return {[=] (const std::vector<ExpressionValue> & args,\n+                 const SqlRowScope & scope) -> ExpressionValue\n+            {\n+                ExcAssertEqual(args.size(), 4);\n+\n+                Date ts = calcTs(args[0], args[1], args[2], args[3]);\n+                \n+                if (args[0].empty() || args[1].empty()\n+                    || args[2].empty() || args[3].empty())\n+                    return ExpressionValue::null(ts);\n+                \n+                double lat1 = args[0].getAtom().toDouble();\n+                double lon1 = args[1].getAtom().toDouble();\n+                double lat2 = args[2].getAtom().toDouble();\n+                double lon2 = args[3].getAtom().toDouble();\n+\n+                S2LatLng point1 = S2LatLng::FromDegrees(lat1, lon1).Normalized();\n+                S2LatLng point2 = S2LatLng::FromDegrees(lat2, lon2).Normalized();\n+                \n+                double dist = point1.GetDistance(point2).radians()","path":"sql/builtin_geo_functions.cc","position":57,"original_position":57,"commit_id":"5ffcd29985b9d51a583ba5aaf8370f643b317c4a","original_commit_id":"5ffcd29985b9d51a583ba5aaf8370f643b317c4a","user":{"login":"nicolaskruchten","id":203523,"avatar_url":"https://avatars.githubusercontent.com/u/203523?v=3","gravatar_id":"","url":"https://api.github.com/users/nicolaskruchten","html_url":"https://github.com/nicolaskruchten","followers_url":"https://api.github.com/users/nicolaskruchten/followers","following_url":"https://api.github.com/users/nicolaskruchten/following{/other_user}","gists_url":"https://api.github.com/users/nicolaskruchten/gists{/gist_id}","starred_url":"https://api.github.com/users/nicolaskruchten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicolaskruchten/subscriptions","organizations_url":"https://api.github.com/users/nicolaskruchten/orgs","repos_url":"https://api.github.com/users/nicolaskruchten/repos","events_url":"https://api.github.com/users/nicolaskruchten/events{/privacy}","received_events_url":"https://api.github.com/users/nicolaskruchten/received_events","type":"User","site_admin":false},"body":"This provides a partial answer: http://www.movable-type.co.uk/scripts/gis-faq-5.1.html","created_at":"2016-05-18T16:46:11Z","updated_at":"2016-05-18T16:46:11Z","html_url":"https://github.com/mldbai/mldb/pull/379#discussion_r63739553","pull_request_url":"https://api.github.com/repos/mldbai/mldb/pulls/379","_links":{"self":{"href":"https://api.github.com/repos/mldbai/mldb/pulls/comments/63739553"},"html":{"href":"https://github.com/mldbai/mldb/pull/379#discussion_r63739553"},"pull_request":{"href":"https://api.github.com/repos/mldbai/mldb/pulls/379"}}},"pull_request":{"url":"https://api.github.com/repos/mldbai/mldb/pulls/379","id":70538378,"html_url":"https://github.com/mldbai/mldb/pull/379","diff_url":"https://github.com/mldbai/mldb/pull/379.diff","patch_url":"https://github.com/mldbai/mldb/pull/379.patch","issue_url":"https://api.github.com/repos/mldbai/mldb/issues/379","number":379,"state":"open","locked":false,"title":"Added S2 spherical geometry library as a submodule (MLDB-1666)","user":{"login":"jeremybarnes","id":112556,"avatar_url":"https://avatars.githubusercontent.com/u/112556?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremybarnes","html_url":"https://github.com/jeremybarnes","followers_url":"https://api.github.com/users/jeremybarnes/followers","following_url":"https://api.github.com/users/jeremybarnes/following{/other_user}","gists_url":"https://api.github.com/users/jeremybarnes/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremybarnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremybarnes/subscriptions","organizations_url":"https://api.github.com/users/jeremybarnes/orgs","repos_url":"https://api.github.com/users/jeremybarnes/repos","events_url":"https://api.github.com/users/jeremybarnes/events{/privacy}","received_events_url":"https://api.github.com/users/jeremybarnes/received_events","type":"User","site_admin":false},"body":"This PR adds a single geo_distance function to MLDB.  Underneath the hood, it imports the S2 library which allows us to represent and compute various geographical functions within MLDB.\r\n\r\nThe purpose of the PR is for comments and design discussion.\r\n","created_at":"2016-05-18T14:31:10Z","updated_at":"2016-05-18T16:46:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9315e19d884b4f91775d6b57b00ada0714e9189c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mldbai/mldb/pulls/379/commits","review_comments_url":"https://api.github.com/repos/mldbai/mldb/pulls/379/comments","review_comment_url":"https://api.github.com/repos/mldbai/mldb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mldbai/mldb/issues/379/comments","statuses_url":"https://api.github.com/repos/mldbai/mldb/statuses/5ffcd29985b9d51a583ba5aaf8370f643b317c4a","head":{"label":"mldbai:MLDB-1666-spherical-geometry","ref":"MLDB-1666-spherical-geometry","sha":"5ffcd29985b9d51a583ba5aaf8370f643b317c4a","user":{"login":"mldbai","id":11510172,"avatar_url":"https://avatars.githubusercontent.com/u/11510172?v=3","gravatar_id":"","url":"https://api.github.com/users/mldbai","html_url":"https://github.com/mldbai","followers_url":"https://api.github.com/users/mldbai/followers","following_url":"https://api.github.com/users/mldbai/following{/other_user}","gists_url":"https://api.github.com/users/mldbai/gists{/gist_id}","starred_url":"https://api.github.com/users/mldbai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mldbai/subscriptions","organizations_url":"https://api.github.com/users/mldbai/orgs","repos_url":"https://api.github.com/users/mldbai/repos","events_url":"https://api.github.com/users/mldbai/events{/privacy}","received_events_url":"https://api.github.com/users/mldbai/received_events","type":"Organization","site_admin":false},"repo":{"id":47634692,"name":"mldb","full_name":"mldbai/mldb","owner":{"login":"mldbai","id":11510172,"avatar_url":"https://avatars.githubusercontent.com/u/11510172?v=3","gravatar_id":"","url":"https://api.github.com/users/mldbai","html_url":"https://github.com/mldbai","followers_url":"https://api.github.com/users/mldbai/followers","following_url":"https://api.github.com/users/mldbai/following{/other_user}","gists_url":"https://api.github.com/users/mldbai/gists{/gist_id}","starred_url":"https://api.github.com/users/mldbai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mldbai/subscriptions","organizations_url":"https://api.github.com/users/mldbai/orgs","repos_url":"https://api.github.com/users/mldbai/repos","events_url":"https://api.github.com/users/mldbai/events{/privacy}","received_events_url":"https://api.github.com/users/mldbai/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mldbai/mldb","description":"MLDB is the Machine Learning Database","fork":false,"url":"https://api.github.com/repos/mldbai/mldb","forks_url":"https://api.github.com/repos/mldbai/mldb/forks","keys_url":"https://api.github.com/repos/mldbai/mldb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mldbai/mldb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mldbai/mldb/teams","hooks_url":"https://api.github.com/repos/mldbai/mldb/hooks","issue_events_url":"https://api.github.com/repos/mldbai/mldb/issues/events{/number}","events_url":"https://api.github.com/repos/mldbai/mldb/events","assignees_url":"https://api.github.com/repos/mldbai/mldb/assignees{/user}","branches_url":"https://api.github.com/repos/mldbai/mldb/branches{/branch}","tags_url":"https://api.github.com/repos/mldbai/mldb/tags","blobs_url":"https://api.github.com/repos/mldbai/mldb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mldbai/mldb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mldbai/mldb/git/refs{/sha}","trees_url":"https://api.github.com/repos/mldbai/mldb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mldbai/mldb/statuses/{sha}","languages_url":"https://api.github.com/repos/mldbai/mldb/languages","stargazers_url":"https://api.github.com/repos/mldbai/mldb/stargazers","contributors_url":"https://api.github.com/repos/mldbai/mldb/contributors","subscribers_url":"https://api.github.com/repos/mldbai/mldb/subscribers","subscription_url":"https://api.github.com/repos/mldbai/mldb/subscription","commits_url":"https://api.github.com/repos/mldbai/mldb/commits{/sha}","git_commits_url":"https://api.github.com/repos/mldbai/mldb/git/commits{/sha}","comments_url":"https://api.github.com/repos/mldbai/mldb/comments{/number}","issue_comment_url":"https://api.github.com/repos/mldbai/mldb/issues/comments{/number}","contents_url":"https://api.github.com/repos/mldbai/mldb/contents/{+path}","compare_url":"https://api.github.com/repos/mldbai/mldb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mldbai/mldb/merges","archive_url":"https://api.github.com/repos/mldbai/mldb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mldbai/mldb/downloads","issues_url":"https://api.github.com/repos/mldbai/mldb/issues{/number}","pulls_url":"https://api.github.com/repos/mldbai/mldb/pulls{/number}","milestones_url":"https://api.github.com/repos/mldbai/mldb/milestones{/number}","notifications_url":"https://api.github.com/repos/mldbai/mldb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mldbai/mldb/labels{/name}","releases_url":"https://api.github.com/repos/mldbai/mldb/releases{/id}","deployments_url":"https://api.github.com/repos/mldbai/mldb/deployments","created_at":"2015-12-08T16:34:16Z","updated_at":"2016-05-17T16:47:51Z","pushed_at":"2016-05-18T15:26:00Z","git_url":"git://github.com/mldbai/mldb.git","ssh_url":"git@github.com:mldbai/mldb.git","clone_url":"https://github.com/mldbai/mldb.git","svn_url":"https://github.com/mldbai/mldb","homepage":"http://mldb.ai","size":20412,"stargazers_count":65,"watchers_count":65,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":16,"forks":5,"open_issues":16,"watchers":65,"default_branch":"master"}},"base":{"label":"mldbai:master","ref":"master","sha":"5898e9e54da3ebd6fd55298696b7676f28cb027a","user":{"login":"mldbai","id":11510172,"avatar_url":"https://avatars.githubusercontent.com/u/11510172?v=3","gravatar_id":"","url":"https://api.github.com/users/mldbai","html_url":"https://github.com/mldbai","followers_url":"https://api.github.com/users/mldbai/followers","following_url":"https://api.github.com/users/mldbai/following{/other_user}","gists_url":"https://api.github.com/users/mldbai/gists{/gist_id}","starred_url":"https://api.github.com/users/mldbai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mldbai/subscriptions","organizations_url":"https://api.github.com/users/mldbai/orgs","repos_url":"https://api.github.com/users/mldbai/repos","events_url":"https://api.github.com/users/mldbai/events{/privacy}","received_events_url":"https://api.github.com/users/mldbai/received_events","type":"Organization","site_admin":false},"repo":{"id":47634692,"name":"mldb","full_name":"mldbai/mldb","owner":{"login":"mldbai","id":11510172,"avatar_url":"https://avatars.githubusercontent.com/u/11510172?v=3","gravatar_id":"","url":"https://api.github.com/users/mldbai","html_url":"https://github.com/mldbai","followers_url":"https://api.github.com/users/mldbai/followers","following_url":"https://api.github.com/users/mldbai/following{/other_user}","gists_url":"https://api.github.com/users/mldbai/gists{/gist_id}","starred_url":"https://api.github.com/users/mldbai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mldbai/subscriptions","organizations_url":"https://api.github.com/users/mldbai/orgs","repos_url":"https://api.github.com/users/mldbai/repos","events_url":"https://api.github.com/users/mldbai/events{/privacy}","received_events_url":"https://api.github.com/users/mldbai/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mldbai/mldb","description":"MLDB is the Machine Learning Database","fork":false,"url":"https://api.github.com/repos/mldbai/mldb","forks_url":"https://api.github.com/repos/mldbai/mldb/forks","keys_url":"https://api.github.com/repos/mldbai/mldb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mldbai/mldb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mldbai/mldb/teams","hooks_url":"https://api.github.com/repos/mldbai/mldb/hooks","issue_events_url":"https://api.github.com/repos/mldbai/mldb/issues/events{/number}","events_url":"https://api.github.com/repos/mldbai/mldb/events","assignees_url":"https://api.github.com/repos/mldbai/mldb/assignees{/user}","branches_url":"https://api.github.com/repos/mldbai/mldb/branches{/branch}","tags_url":"https://api.github.com/repos/mldbai/mldb/tags","blobs_url":"https://api.github.com/repos/mldbai/mldb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mldbai/mldb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mldbai/mldb/git/refs{/sha}","trees_url":"https://api.github.com/repos/mldbai/mldb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mldbai/mldb/statuses/{sha}","languages_url":"https://api.github.com/repos/mldbai/mldb/languages","stargazers_url":"https://api.github.com/repos/mldbai/mldb/stargazers","contributors_url":"https://api.github.com/repos/mldbai/mldb/contributors","subscribers_url":"https://api.github.com/repos/mldbai/mldb/subscribers","subscription_url":"https://api.github.com/repos/mldbai/mldb/subscription","commits_url":"https://api.github.com/repos/mldbai/mldb/commits{/sha}","git_commits_url":"https://api.github.com/repos/mldbai/mldb/git/commits{/sha}","comments_url":"https://api.github.com/repos/mldbai/mldb/comments{/number}","issue_comment_url":"https://api.github.com/repos/mldbai/mldb/issues/comments{/number}","contents_url":"https://api.github.com/repos/mldbai/mldb/contents/{+path}","compare_url":"https://api.github.com/repos/mldbai/mldb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mldbai/mldb/merges","archive_url":"https://api.github.com/repos/mldbai/mldb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mldbai/mldb/downloads","issues_url":"https://api.github.com/repos/mldbai/mldb/issues{/number}","pulls_url":"https://api.github.com/repos/mldbai/mldb/pulls{/number}","milestones_url":"https://api.github.com/repos/mldbai/mldb/milestones{/number}","notifications_url":"https://api.github.com/repos/mldbai/mldb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mldbai/mldb/labels{/name}","releases_url":"https://api.github.com/repos/mldbai/mldb/releases{/id}","deployments_url":"https://api.github.com/repos/mldbai/mldb/deployments","created_at":"2015-12-08T16:34:16Z","updated_at":"2016-05-17T16:47:51Z","pushed_at":"2016-05-18T15:26:00Z","git_url":"git://github.com/mldbai/mldb.git","ssh_url":"git@github.com:mldbai/mldb.git","clone_url":"https://github.com/mldbai/mldb.git","svn_url":"https://github.com/mldbai/mldb","homepage":"http://mldb.ai","size":20412,"stargazers_count":65,"watchers_count":65,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":16,"forks":5,"open_issues":16,"watchers":65,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mldbai/mldb/pulls/379"},"html":{"href":"https://github.com/mldbai/mldb/pull/379"},"issue":{"href":"https://api.github.com/repos/mldbai/mldb/issues/379"},"comments":{"href":"https://api.github.com/repos/mldbai/mldb/issues/379/comments"},"review_comments":{"href":"https://api.github.com/repos/mldbai/mldb/pulls/379/comments"},"review_comment":{"href":"https://api.github.com/repos/mldbai/mldb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mldbai/mldb/pulls/379/commits"},"statuses":{"href":"https://api.github.com/repos/mldbai/mldb/statuses/5ffcd29985b9d51a583ba5aaf8370f643b317c4a"}}}}