{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/11578","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/11578/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/11578/comments","events_url":"https://api.github.com/repos/apache/spark/issues/11578/events","html_url":"https://github.com/apache/spark/pull/11578","id":139286771,"number":11578,"title":"[SPARK-13742][Core] Add non-iterator interface to RandomSampler","user":{"login":"viirya","id":68855,"avatar_url":"https://avatars.githubusercontent.com/u/68855?v=3","gravatar_id":"","url":"https://api.github.com/users/viirya","html_url":"https://github.com/viirya","followers_url":"https://api.github.com/users/viirya/followers","following_url":"https://api.github.com/users/viirya/following{/other_user}","gists_url":"https://api.github.com/users/viirya/gists{/gist_id}","starred_url":"https://api.github.com/users/viirya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viirya/subscriptions","organizations_url":"https://api.github.com/users/viirya/orgs","repos_url":"https://api.github.com/users/viirya/repos","events_url":"https://api.github.com/users/viirya/events{/privacy}","received_events_url":"https://api.github.com/users/viirya/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-08T14:08:41Z","updated_at":"2016-03-08T14:09:30Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/11578","html_url":"https://github.com/apache/spark/pull/11578","diff_url":"https://github.com/apache/spark/pull/11578.diff","patch_url":"https://github.com/apache/spark/pull/11578.patch"},"body":"JIRA: https://issues.apache.org/jira/browse/SPARK-13742\r\n\r\n## What changes were proposed in this pull request?\r\n\r\n`RandomSampler.sample` currently accepts iterator as input and output another iterator. This makes it inappropriate to use in wholestage codegen of `Sampler` operator #11517. This change is to add non-iterator interface to `RandomSampler`.\r\n\r\nThis change adds a new method `def sample(): Int` to the trait `RandomSampler`. As we don't need to know the actual values of the sampling items, so this new method takes no arguments.\r\n\r\nThis method will decide whether to sample the next item or not. It returns how many times the next item will be sampled.\r\n\r\nFor `BernoulliSampler` and `BernoulliCellSampler`, the returned sampling times can only be 0 or 1. It simply means whether to sample the next item or not.\r\n\r\nFor `PoissonSampler`, the returned value can be more than 1, meaning the next item will be sampled multiple times.\r\n\r\n## How was this patch tested?\r\n\r\nTests are added into `RandomSamplerSuite`."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/193797633","html_url":"https://github.com/apache/spark/pull/11578#issuecomment-193797633","issue_url":"https://api.github.com/repos/apache/spark/issues/11578","id":193797633,"user":{"login":"viirya","id":68855,"avatar_url":"https://avatars.githubusercontent.com/u/68855?v=3","gravatar_id":"","url":"https://api.github.com/users/viirya","html_url":"https://github.com/viirya","followers_url":"https://api.github.com/users/viirya/followers","following_url":"https://api.github.com/users/viirya/following{/other_user}","gists_url":"https://api.github.com/users/viirya/gists{/gist_id}","starred_url":"https://api.github.com/users/viirya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viirya/subscriptions","organizations_url":"https://api.github.com/users/viirya/orgs","repos_url":"https://api.github.com/users/viirya/repos","events_url":"https://api.github.com/users/viirya/events{/privacy}","received_events_url":"https://api.github.com/users/viirya/received_events","type":"User","site_admin":false},"created_at":"2016-03-08T14:09:30Z","updated_at":"2016-03-08T14:09:30Z","body":"cc @mengxr @rxin @holdenk "}}