{"action":"created","issue":{"url":"https://api.github.com/repos/OpenRefine/OpenRefine/issues/1480","repository_url":"https://api.github.com/repos/OpenRefine/OpenRefine","labels_url":"https://api.github.com/repos/OpenRefine/OpenRefine/issues/1480/labels{/name}","comments_url":"https://api.github.com/repos/OpenRefine/OpenRefine/issues/1480/comments","events_url":"https://api.github.com/repos/OpenRefine/OpenRefine/issues/1480/events","html_url":"https://github.com/OpenRefine/OpenRefine/pull/1480","id":296461129,"number":1480,"title":"Add a new range() function to GREL","user":{"login":"joanneong","id":24493463,"avatar_url":"https://avatars1.githubusercontent.com/u/24493463?v=4","gravatar_id":"","url":"https://api.github.com/users/joanneong","html_url":"https://github.com/joanneong","followers_url":"https://api.github.com/users/joanneong/followers","following_url":"https://api.github.com/users/joanneong/following{/other_user}","gists_url":"https://api.github.com/users/joanneong/gists{/gist_id}","starred_url":"https://api.github.com/users/joanneong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joanneong/subscriptions","organizations_url":"https://api.github.com/users/joanneong/orgs","repos_url":"https://api.github.com/users/joanneong/repos","events_url":"https://api.github.com/users/joanneong/events{/privacy}","received_events_url":"https://api.github.com/users/joanneong/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2018-02-12T17:30:45Z","updated_at":"2018-02-15T20:37:32Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/OpenRefine/OpenRefine/pulls/1480","html_url":"https://github.com/OpenRefine/OpenRefine/pull/1480","diff_url":"https://github.com/OpenRefine/OpenRefine/pull/1480.diff","patch_url":"https://github.com/OpenRefine/OpenRefine/pull/1480.patch"},"body":"Fixes #1319 \r\n\r\nThe original specification that @thadguidry suggested for the `range` function was:\r\n\r\n> It will work like this...\r\n>\r\n>can take accept a String form:\r\n>range(\"2-4\") --> [2,3,4]\r\n>\r\n>or a String form in a value\r\n>range(value) --> [2,3,4]\r\n>\r\n>or 2 numbers\r\n>range(2, 4) --> [2,3,4]\r\n>\r\n>and doing join(\",\") will convert the Array to a String\r\n>range(2,4).join(\",\"). --> 2,3,4\r\n\r\nHowever, because of issues such as [cells being unable to display arrays](https://github.com/OpenRefine/OpenRefine/issues/1088) and the [potential confusion it can cause](https://github.com/OpenRefine/OpenRefine/issues/1475), I have taken the liberty to display the results of `range` as a string with comma-separated values instead.\r\n\r\nHence, my implementation works like this:\r\n\r\n**(a) String arguments**\r\n1. `range(\"2-4\") --> 2, 3, 4`\r\n2. `range(\"4-2\") --> 4, 3, 2` \r\n3. `range(\"2, 4\") --> 2, 3, 4` \r\n4. `range(\"4, 2\") --> 4, 3, 2`\r\n5. `range(value) --> 2, 3, 4 //given that value is written as 2-4 (text) or 2, 4 (text) in the cell`\r\n\r\n**(b) Integer arguments**\r\n1. `range(2, 4) --> 2, 3, 4`\r\n2. `range(4, 2) --> 4, 3, 2`\r\n\r\n*`range(value)` does not apply to integer arguments since `2, 4` is stored as text in a cell.\r\n\r\n**Additional notes**\r\n1. Given valid arguments, either an increasing sequence or a decreasing sequence is returned depending on whether the `rangeStart` value is larger than the `rangeEnd` value.\r\n2. Integer arguments cannot be negative; otherwise, an `EvalError` is returned.\r\n3. Numeric arguments can only be integers, and decimal values will cause an `EvalError` to be returned.\r\n4. It is okay to have whitespace(s) within the string (e.g. `range(\"2   -   4  \")` will work as well).\r\n \r\n**Questions to discuss**\r\n1. Should the implementation use integers? What about `long` or `BigInteger`? Should we worry about when users try to input very large values (e.g. 2980572305402385707520357208) to the `range` function?\r\n2. Should the result returned be an array as @thadguidry has suggested? In this case, the result will directly be displayed in the cells after the transformation without having to use `join`, but is this consistent with other functions already provided by OpenRefine?\r\n3. Should negative integers, or even decimal numbers be supported by this function?\r\n\r\nLastly, I have also added some basic tests for the new function (although more comprehensive testing can be done with real examples). I am willing to help to update the documentation on GitHub pages for this function after it is approved :)\r\n\r\nThanks for reading this lengthy pull request message, and I look forward to any incoming feedback :)"},"comment":{"url":"https://api.github.com/repos/OpenRefine/OpenRefine/issues/comments/366053963","html_url":"https://github.com/OpenRefine/OpenRefine/pull/1480#issuecomment-366053963","issue_url":"https://api.github.com/repos/OpenRefine/OpenRefine/issues/1480","id":366053963,"user":{"login":"thadguidry","id":986438,"avatar_url":"https://avatars2.githubusercontent.com/u/986438?v=4","gravatar_id":"","url":"https://api.github.com/users/thadguidry","html_url":"https://github.com/thadguidry","followers_url":"https://api.github.com/users/thadguidry/followers","following_url":"https://api.github.com/users/thadguidry/following{/other_user}","gists_url":"https://api.github.com/users/thadguidry/gists{/gist_id}","starred_url":"https://api.github.com/users/thadguidry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thadguidry/subscriptions","organizations_url":"https://api.github.com/users/thadguidry/orgs","repos_url":"https://api.github.com/users/thadguidry/repos","events_url":"https://api.github.com/users/thadguidry/events{/privacy}","received_events_url":"https://api.github.com/users/thadguidry/received_events","type":"User","site_admin":false},"created_at":"2018-02-15T20:37:32Z","updated_at":"2018-02-15T20:37:32Z","author_association":"OWNER","body":"@joanneong @wetneb What if we just added a Range Type as well ?  We could look into using existing libraries to gain benefits for future expansion and also add a Range Type so we can do map-reducing Range overlap/compare/etc once we implement Beam support later this year ?\r\n1. https://github.com/google/guava/wiki/RangesExplained\r\n2. https://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/Range.html\r\n\r\nI think (in a new issue someone can create) we probably want to additionally have users tell us from a new drop-down menu option \r\n\r\nEdit cells -> Common transforms -> To range \r\n\r\nthat a column is full of Range type values.  Because I'm seeing this kind of data about Ranges in the wild in scientific data sets both old and new... So to make @joanneong life even harder on this issue .... :)\r\n\r\n```\r\n\r\n1-9      <-- The OP's original format and why we have this issue \r\n[1-9]\r\n1..9\r\n(1..9)\r\n[1..9]    <-- Not seeing this one in any datasets however\r\n```\r\n\r\n\r\n"}}
{"actor":{"display_login":"thadguidry"}}