{"action":"created","comment":{"url":"https://api.github.com/repos/quasar-analytics/quasar/pulls/comments/77224235","id":77224235,"diff_hunk":"@@ -0,0 +1,118 @@\n+/*\n+ * Copyright 2014–2016 SlamData 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+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package quasar.physical.marklogic.qscript\n+\n+import quasar.Predef._\n+import quasar.NameGenerator\n+import quasar.ejson.EJson\n+import quasar.fp._\n+import quasar.physical.marklogic.ejson.AsXQuery\n+import quasar.physical.marklogic.xquery._\n+import quasar.physical.marklogic.xquery.syntax._\n+import quasar.qscript.{MapFunc, MapFuncs}, MapFuncs._\n+\n+import matryoshka._, Recursive.ops._\n+import scalaz.Monad\n+import scalaz.std.option._\n+import scalaz.syntax.monad._\n+import scalaz.syntax.show._\n+\n+object MapFuncPlanner {\n+  import expr.{if_, let_}\n+\n+  def apply[T[_[_]]: Recursive: ShowT, F[_]: NameGenerator: Monad]: AlgebraM[F, MapFunc[T, ?], XQuery] = {\n+    case Constant(ejson) => ejson.cata(AsXQuery[EJson].asXQuery).point[F]\n+\n+    // math\n+    case Negate(x) => (-x).point[F]\n+    case Add(x, y) => (x + y).point[F]\n+    case Multiply(x, y) => (x * y).point[F]\n+    case Subtract(x, y) => (x - y).point[F]\n+    case Divide(x, y) => (x div y).point[F]\n+    case Modulo(x, y) => (x mod y).point[F]\n+    case Power(b, e) => math.pow(b, e).point[F]\n+\n+    // relations\n+    // TODO: When to use value vs. general comparisons?\n+    case Not(x) => fn.not(x).point[F]\n+    case Eq(x, y) => (x eq y).point[F]\n+    case Neq(x, y) => (x ne y).point[F]\n+    case Lt(x, y) => (x lt y).point[F]\n+    case Lte(x, y) => (x le y).point[F]\n+    case Gt(x, y) => (x gt y).point[F]\n+    case Gte(x, y) => (x ge y).point[F]\n+    case And(x, y) => (x and y).point[F]\n+    case Or(x, y) => (x or y).point[F]\n+\n+    case Cond(p, t, f) => if_(p).then_(t).else_(f).point[F]\n+\n+    // string\n+    case Lower(s) => fn.lowerCase(s).point[F]\n+    case Upper(s) => fn.upperCase(s).point[F]\n+    case ToString(x) => fn.string(x).point[F]\n+    case Substring(s, loc, len) => fn.substring(s, loc + 1.xqy, some(len)).point[F]\n+\n+    // structural\n+    case MakeArray(x) =>\n+      ejson.singletonArray(x).point[F]\n+\n+    // TODO: Could also just support string keys for now so we can stick with JSON? Or XML?\n+    case MakeMap(k, v) =>\n+      ejson.singletonMap(k, v).point[F]\n+\n+    case ConcatArrays(x, y) =>\n+      ejson.arrayConcat(x, y)\n+\n+    case ProjectField(src, field) =>\n+      for {\n+        m <- freshVar[F]\n+        k <- freshVar[F]\n+        v <- ejson.mapLookup(m.xqy, k.xqy)\n+      } yield {\n+        let_(m -> src, k -> field) return_ {","path":"marklogic/src/main/scala/quasar/physical/marklogic/qscript/MapFuncPlanner.scala","position":86,"original_position":86,"commit_id":"837612bd12d3850718e489f9fb761279abe227f2","original_commit_id":"837612bd12d3850718e489f9fb761279abe227f2","user":{"login":"jedesah","id":1780116,"avatar_url":"https://avatars.githubusercontent.com/u/1780116?v=3","gravatar_id":"","url":"https://api.github.com/users/jedesah","html_url":"https://github.com/jedesah","followers_url":"https://api.github.com/users/jedesah/followers","following_url":"https://api.github.com/users/jedesah/following{/other_user}","gists_url":"https://api.github.com/users/jedesah/gists{/gist_id}","starred_url":"https://api.github.com/users/jedesah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jedesah/subscriptions","organizations_url":"https://api.github.com/users/jedesah/orgs","repos_url":"https://api.github.com/users/jedesah/repos","events_url":"https://api.github.com/users/jedesah/events{/privacy}","received_events_url":"https://api.github.com/users/jedesah/received_events","type":"User","site_admin":false},"body":"After discussing with @sellout, I don't understand why we are using `let_` here. And granted, I am fairly confused, but currently my understand leads me to believe we should only have the `if_` expression here.","created_at":"2016-09-01T18:07:01Z","updated_at":"2016-09-01T18:07:01Z","html_url":"https://github.com/quasar-analytics/quasar/pull/1398#discussion_r77224235","pull_request_url":"https://api.github.com/repos/quasar-analytics/quasar/pulls/1398","_links":{"self":{"href":"https://api.github.com/repos/quasar-analytics/quasar/pulls/comments/77224235"},"html":{"href":"https://github.com/quasar-analytics/quasar/pull/1398#discussion_r77224235"},"pull_request":{"href":"https://api.github.com/repos/quasar-analytics/quasar/pulls/1398"}}},"pull_request":{"url":"https://api.github.com/repos/quasar-analytics/quasar/pulls/1398","id":83565985,"html_url":"https://github.com/quasar-analytics/quasar/pull/1398","diff_url":"https://github.com/quasar-analytics/quasar/pull/1398.diff","patch_url":"https://github.com/quasar-analytics/quasar/pull/1398.patch","issue_url":"https://api.github.com/repos/quasar-analytics/quasar/issues/1398","number":1398,"state":"open","locked":false,"title":"Initial MarkLogic MapFuncs and handful of other QScript ops","user":{"login":"wemrysi","id":32185,"avatar_url":"https://avatars.githubusercontent.com/u/32185?v=3","gravatar_id":"","url":"https://api.github.com/users/wemrysi","html_url":"https://github.com/wemrysi","followers_url":"https://api.github.com/users/wemrysi/followers","following_url":"https://api.github.com/users/wemrysi/following{/other_user}","gists_url":"https://api.github.com/users/wemrysi/gists{/gist_id}","starred_url":"https://api.github.com/users/wemrysi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wemrysi/subscriptions","organizations_url":"https://api.github.com/users/wemrysi/orgs","repos_url":"https://api.github.com/users/wemrysi/repos","events_url":"https://api.github.com/users/wemrysi/events{/privacy}","received_events_url":"https://api.github.com/users/wemrysi/received_events","type":"User","site_admin":false},"body":"Adds a lot of infrastructure for the MarkLogic planner, including variable name generation. Aside from some issues with `Take` (and probably `Drop` as well), generates valid xquery, though still isn't quite correct due to XML <-> JSON conversion issues which I hope to address shortly.","created_at":"2016-09-01T03:43:02Z","updated_at":"2016-09-01T18:07:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"93bad72ce9c5e589d46de31a38181fe8b3636586","assignee":{"login":"jedesah","id":1780116,"avatar_url":"https://avatars.githubusercontent.com/u/1780116?v=3","gravatar_id":"","url":"https://api.github.com/users/jedesah","html_url":"https://github.com/jedesah","followers_url":"https://api.github.com/users/jedesah/followers","following_url":"https://api.github.com/users/jedesah/following{/other_user}","gists_url":"https://api.github.com/users/jedesah/gists{/gist_id}","starred_url":"https://api.github.com/users/jedesah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jedesah/subscriptions","organizations_url":"https://api.github.com/users/jedesah/orgs","repos_url":"https://api.github.com/users/jedesah/repos","events_url":"https://api.github.com/users/jedesah/events{/privacy}","received_events_url":"https://api.github.com/users/jedesah/received_events","type":"User","site_admin":false},"assignees":[{"login":"jedesah","id":1780116,"avatar_url":"https://avatars.githubusercontent.com/u/1780116?v=3","gravatar_id":"","url":"https://api.github.com/users/jedesah","html_url":"https://github.com/jedesah","followers_url":"https://api.github.com/users/jedesah/followers","following_url":"https://api.github.com/users/jedesah/following{/other_user}","gists_url":"https://api.github.com/users/jedesah/gists{/gist_id}","starred_url":"https://api.github.com/users/jedesah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jedesah/subscriptions","organizations_url":"https://api.github.com/users/jedesah/orgs","repos_url":"https://api.github.com/users/jedesah/repos","events_url":"https://api.github.com/users/jedesah/events{/privacy}","received_events_url":"https://api.github.com/users/jedesah/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/quasar-analytics/quasar/pulls/1398/commits","review_comments_url":"https://api.github.com/repos/quasar-analytics/quasar/pulls/1398/comments","review_comment_url":"https://api.github.com/repos/quasar-analytics/quasar/pulls/comments{/number}","comments_url":"https://api.github.com/repos/quasar-analytics/quasar/issues/1398/comments","statuses_url":"https://api.github.com/repos/quasar-analytics/quasar/statuses/837612bd12d3850718e489f9fb761279abe227f2","head":{"label":"wemrysi:feature/ml-mapfunc-structural","ref":"feature/ml-mapfunc-structural","sha":"837612bd12d3850718e489f9fb761279abe227f2","user":{"login":"wemrysi","id":32185,"avatar_url":"https://avatars.githubusercontent.com/u/32185?v=3","gravatar_id":"","url":"https://api.github.com/users/wemrysi","html_url":"https://github.com/wemrysi","followers_url":"https://api.github.com/users/wemrysi/followers","following_url":"https://api.github.com/users/wemrysi/following{/other_user}","gists_url":"https://api.github.com/users/wemrysi/gists{/gist_id}","starred_url":"https://api.github.com/users/wemrysi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wemrysi/subscriptions","organizations_url":"https://api.github.com/users/wemrysi/orgs","repos_url":"https://api.github.com/users/wemrysi/repos","events_url":"https://api.github.com/users/wemrysi/events{/privacy}","received_events_url":"https://api.github.com/users/wemrysi/received_events","type":"User","site_admin":false},"repo":{"id":40374964,"name":"quasar","full_name":"wemrysi/quasar","owner":{"login":"wemrysi","id":32185,"avatar_url":"https://avatars.githubusercontent.com/u/32185?v=3","gravatar_id":"","url":"https://api.github.com/users/wemrysi","html_url":"https://github.com/wemrysi","followers_url":"https://api.github.com/users/wemrysi/followers","following_url":"https://api.github.com/users/wemrysi/following{/other_user}","gists_url":"https://api.github.com/users/wemrysi/gists{/gist_id}","starred_url":"https://api.github.com/users/wemrysi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wemrysi/subscriptions","organizations_url":"https://api.github.com/users/wemrysi/orgs","repos_url":"https://api.github.com/users/wemrysi/repos","events_url":"https://api.github.com/users/wemrysi/events{/privacy}","received_events_url":"https://api.github.com/users/wemrysi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wemrysi/quasar","description":"The engine for SlamData","fork":true,"url":"https://api.github.com/repos/wemrysi/quasar","forks_url":"https://api.github.com/repos/wemrysi/quasar/forks","keys_url":"https://api.github.com/repos/wemrysi/quasar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wemrysi/quasar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wemrysi/quasar/teams","hooks_url":"https://api.github.com/repos/wemrysi/quasar/hooks","issue_events_url":"https://api.github.com/repos/wemrysi/quasar/issues/events{/number}","events_url":"https://api.github.com/repos/wemrysi/quasar/events","assignees_url":"https://api.github.com/repos/wemrysi/quasar/assignees{/user}","branches_url":"https://api.github.com/repos/wemrysi/quasar/branches{/branch}","tags_url":"https://api.github.com/repos/wemrysi/quasar/tags","blobs_url":"https://api.github.com/repos/wemrysi/quasar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wemrysi/quasar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wemrysi/quasar/git/refs{/sha}","trees_url":"https://api.github.com/repos/wemrysi/quasar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wemrysi/quasar/statuses/{sha}","languages_url":"https://api.github.com/repos/wemrysi/quasar/languages","stargazers_url":"https://api.github.com/repos/wemrysi/quasar/stargazers","contributors_url":"https://api.github.com/repos/wemrysi/quasar/contributors","subscribers_url":"https://api.github.com/repos/wemrysi/quasar/subscribers","subscription_url":"https://api.github.com/repos/wemrysi/quasar/subscription","commits_url":"https://api.github.com/repos/wemrysi/quasar/commits{/sha}","git_commits_url":"https://api.github.com/repos/wemrysi/quasar/git/commits{/sha}","comments_url":"https://api.github.com/repos/wemrysi/quasar/comments{/number}","issue_comment_url":"https://api.github.com/repos/wemrysi/quasar/issues/comments{/number}","contents_url":"https://api.github.com/repos/wemrysi/quasar/contents/{+path}","compare_url":"https://api.github.com/repos/wemrysi/quasar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wemrysi/quasar/merges","archive_url":"https://api.github.com/repos/wemrysi/quasar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wemrysi/quasar/downloads","issues_url":"https://api.github.com/repos/wemrysi/quasar/issues{/number}","pulls_url":"https://api.github.com/repos/wemrysi/quasar/pulls{/number}","milestones_url":"https://api.github.com/repos/wemrysi/quasar/milestones{/number}","notifications_url":"https://api.github.com/repos/wemrysi/quasar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wemrysi/quasar/labels{/name}","releases_url":"https://api.github.com/repos/wemrysi/quasar/releases{/id}","deployments_url":"https://api.github.com/repos/wemrysi/quasar/deployments","created_at":"2015-08-07T18:29:08Z","updated_at":"2015-09-14T20:43:00Z","pushed_at":"2016-09-01T04:29:22Z","git_url":"git://github.com/wemrysi/quasar.git","ssh_url":"git@github.com:wemrysi/quasar.git","clone_url":"https://github.com/wemrysi/quasar.git","svn_url":"https://github.com/wemrysi/quasar","homepage":null,"size":13451,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"quasar-analytics:master","ref":"master","sha":"8f9fd2923a08503dd3687fcc9992451fc47ab28a","user":{"login":"quasar-analytics","id":15095906,"avatar_url":"https://avatars.githubusercontent.com/u/15095906?v=3","gravatar_id":"","url":"https://api.github.com/users/quasar-analytics","html_url":"https://github.com/quasar-analytics","followers_url":"https://api.github.com/users/quasar-analytics/followers","following_url":"https://api.github.com/users/quasar-analytics/following{/other_user}","gists_url":"https://api.github.com/users/quasar-analytics/gists{/gist_id}","starred_url":"https://api.github.com/users/quasar-analytics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quasar-analytics/subscriptions","organizations_url":"https://api.github.com/users/quasar-analytics/orgs","repos_url":"https://api.github.com/users/quasar-analytics/repos","events_url":"https://api.github.com/users/quasar-analytics/events{/privacy}","received_events_url":"https://api.github.com/users/quasar-analytics/received_events","type":"Organization","site_admin":false},"repo":{"id":16515058,"name":"quasar","full_name":"quasar-analytics/quasar","owner":{"login":"quasar-analytics","id":15095906,"avatar_url":"https://avatars.githubusercontent.com/u/15095906?v=3","gravatar_id":"","url":"https://api.github.com/users/quasar-analytics","html_url":"https://github.com/quasar-analytics","followers_url":"https://api.github.com/users/quasar-analytics/followers","following_url":"https://api.github.com/users/quasar-analytics/following{/other_user}","gists_url":"https://api.github.com/users/quasar-analytics/gists{/gist_id}","starred_url":"https://api.github.com/users/quasar-analytics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quasar-analytics/subscriptions","organizations_url":"https://api.github.com/users/quasar-analytics/orgs","repos_url":"https://api.github.com/users/quasar-analytics/repos","events_url":"https://api.github.com/users/quasar-analytics/events{/privacy}","received_events_url":"https://api.github.com/users/quasar-analytics/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/quasar-analytics/quasar","description":"A NoSQL analytics engine that embraces post-relational analytics and pushes computation to the data.","fork":false,"url":"https://api.github.com/repos/quasar-analytics/quasar","forks_url":"https://api.github.com/repos/quasar-analytics/quasar/forks","keys_url":"https://api.github.com/repos/quasar-analytics/quasar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/quasar-analytics/quasar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/quasar-analytics/quasar/teams","hooks_url":"https://api.github.com/repos/quasar-analytics/quasar/hooks","issue_events_url":"https://api.github.com/repos/quasar-analytics/quasar/issues/events{/number}","events_url":"https://api.github.com/repos/quasar-analytics/quasar/events","assignees_url":"https://api.github.com/repos/quasar-analytics/quasar/assignees{/user}","branches_url":"https://api.github.com/repos/quasar-analytics/quasar/branches{/branch}","tags_url":"https://api.github.com/repos/quasar-analytics/quasar/tags","blobs_url":"https://api.github.com/repos/quasar-analytics/quasar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/quasar-analytics/quasar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/quasar-analytics/quasar/git/refs{/sha}","trees_url":"https://api.github.com/repos/quasar-analytics/quasar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/quasar-analytics/quasar/statuses/{sha}","languages_url":"https://api.github.com/repos/quasar-analytics/quasar/languages","stargazers_url":"https://api.github.com/repos/quasar-analytics/quasar/stargazers","contributors_url":"https://api.github.com/repos/quasar-analytics/quasar/contributors","subscribers_url":"https://api.github.com/repos/quasar-analytics/quasar/subscribers","subscription_url":"https://api.github.com/repos/quasar-analytics/quasar/subscription","commits_url":"https://api.github.com/repos/quasar-analytics/quasar/commits{/sha}","git_commits_url":"https://api.github.com/repos/quasar-analytics/quasar/git/commits{/sha}","comments_url":"https://api.github.com/repos/quasar-analytics/quasar/comments{/number}","issue_comment_url":"https://api.github.com/repos/quasar-analytics/quasar/issues/comments{/number}","contents_url":"https://api.github.com/repos/quasar-analytics/quasar/contents/{+path}","compare_url":"https://api.github.com/repos/quasar-analytics/quasar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/quasar-analytics/quasar/merges","archive_url":"https://api.github.com/repos/quasar-analytics/quasar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/quasar-analytics/quasar/downloads","issues_url":"https://api.github.com/repos/quasar-analytics/quasar/issues{/number}","pulls_url":"https://api.github.com/repos/quasar-analytics/quasar/pulls{/number}","milestones_url":"https://api.github.com/repos/quasar-analytics/quasar/milestones{/number}","notifications_url":"https://api.github.com/repos/quasar-analytics/quasar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/quasar-analytics/quasar/labels{/name}","releases_url":"https://api.github.com/repos/quasar-analytics/quasar/releases{/id}","deployments_url":"https://api.github.com/repos/quasar-analytics/quasar/deployments","created_at":"2014-02-04T15:01:27Z","updated_at":"2016-08-30T16:30:39Z","pushed_at":"2016-09-01T17:53:19Z","git_url":"git://github.com/quasar-analytics/quasar.git","ssh_url":"git@github.com:quasar-analytics/quasar.git","clone_url":"https://github.com/quasar-analytics/quasar.git","svn_url":"https://github.com/quasar-analytics/quasar","homepage":"http://quasar-analytics.org","size":16360,"stargazers_count":292,"watchers_count":292,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":49,"mirror_url":null,"open_issues_count":62,"forks":49,"open_issues":62,"watchers":292,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/quasar-analytics/quasar/pulls/1398"},"html":{"href":"https://github.com/quasar-analytics/quasar/pull/1398"},"issue":{"href":"https://api.github.com/repos/quasar-analytics/quasar/issues/1398"},"comments":{"href":"https://api.github.com/repos/quasar-analytics/quasar/issues/1398/comments"},"review_comments":{"href":"https://api.github.com/repos/quasar-analytics/quasar/pulls/1398/comments"},"review_comment":{"href":"https://api.github.com/repos/quasar-analytics/quasar/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/quasar-analytics/quasar/pulls/1398/commits"},"statuses":{"href":"https://api.github.com/repos/quasar-analytics/quasar/statuses/837612bd12d3850718e489f9fb761279abe227f2"}}}}
{"actor":{"display_login":"jedesah"}}