{"action":"created","issue":{"url":"https://api.github.com/repos/influxdata/influxdb/issues/7415","repository_url":"https://api.github.com/repos/influxdata/influxdb","labels_url":"https://api.github.com/repos/influxdata/influxdb/issues/7415/labels{/name}","comments_url":"https://api.github.com/repos/influxdata/influxdb/issues/7415/comments","events_url":"https://api.github.com/repos/influxdata/influxdb/issues/7415/events","html_url":"https://github.com/influxdata/influxdb/pull/7415","id":181277974,"number":7415,"title":"Add sample function to query language","user":{"login":"desa","id":1477539,"avatar_url":"https://avatars.githubusercontent.com/u/1477539?v=3","gravatar_id":"","url":"https://api.github.com/users/desa","html_url":"https://github.com/desa","followers_url":"https://api.github.com/users/desa/followers","following_url":"https://api.github.com/users/desa/following{/other_user}","gists_url":"https://api.github.com/users/desa/gists{/gist_id}","starred_url":"https://api.github.com/users/desa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/desa/subscriptions","organizations_url":"https://api.github.com/users/desa/orgs","repos_url":"https://api.github.com/users/desa/repos","events_url":"https://api.github.com/users/desa/events{/privacy}","received_events_url":"https://api.github.com/users/desa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-10-05T22:05:15Z","updated_at":"2016-10-06T15:37:09Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/influxdata/influxdb/pulls/7415","html_url":"https://github.com/influxdata/influxdb/pull/7415","diff_url":"https://github.com/influxdata/influxdb/pull/7415.diff","patch_url":"https://github.com/influxdata/influxdb/pull/7415.patch"},"body":"###### Required for all non-trivial PRs\r\n- [ ] Rebased/mergable\r\n- [ ] Tests pass\r\n- [ ] CHANGELOG.md updated\r\n- [x] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed)\r\n\r\n###### Required only if applicable\r\n_You can erase any checkboxes below this note if they are not applicable to your Pull Request._\r\n- [ ] [InfluxQL Spec](https://github.com/influxdata/influxdb/blob/master/influxql/README.md) updated\r\n- [x] Provide example syntax\r\n\r\nThis PR introduces a new function `sample` to InfluxQL that will return a random sample of data. The random points are generated via [reservoir sampling](https://en.wikipedia.org/wiki/Reservoir_sampling). The function works for all field types.\r\n\r\n## Example Usage\r\n\r\nSuppose I insert the following data\r\n\r\n```\r\ncpu,host=A value=1\r\ncpu,host=A value=2\r\ncpu,host=A value=3\r\n```\r\nThen the query can out put any of the following\r\n```\r\nSELECT sample(n, 2) FROM cpu\r\n```\r\n\r\n```\r\nname: cpu\r\ntime\t\t\t\tsample\r\n----\t\t\t\t------\r\n2016-10-05T22:00:58.69326808Z\t1\r\n2016-10-05T22:01:01.819955056Z\t2\r\n```\r\n```\r\nname: cpu\r\ntime\t\t\t\tsample\r\n----\t\t\t\t------\r\n2016-10-05T22:00:58.69326808Z\t1\r\n2016-10-05T22:01:05.420453399Z\t3\r\n```\r\n```\r\nname: cpu\r\ntime\t\t\t\tsample\r\n----\t\t\t\t------\r\n2016-10-05T22:01:01.819955056Z\t2\r\n2016-10-05T22:01:05.420453399Z\t3\r\n```\r\n\r\nIf the querier asks for a sample larger than the number of point it is querying, all points are returned.\r\n\r\n```\r\nSELECT sample(n, 4) FROM cpu\r\n```\r\n```\r\nname: cpu\r\ntime\t\t\t\tsample\r\n----\t\t\t\t------\r\n2016-10-05T22:00:58.69326808Z\t1\r\n2016-10-05T22:01:01.819955056Z\t2\r\n2016-10-05T22:01:05.420453399Z\t3\r\n```"},"comment":{"url":"https://api.github.com/repos/influxdata/influxdb/issues/comments/252000726","html_url":"https://github.com/influxdata/influxdb/pull/7415#issuecomment-252000726","issue_url":"https://api.github.com/repos/influxdata/influxdb/issues/7415","id":252000726,"user":{"login":"desa","id":1477539,"avatar_url":"https://avatars.githubusercontent.com/u/1477539?v=3","gravatar_id":"","url":"https://api.github.com/users/desa","html_url":"https://github.com/desa","followers_url":"https://api.github.com/users/desa/followers","following_url":"https://api.github.com/users/desa/following{/other_user}","gists_url":"https://api.github.com/users/desa/gists{/gist_id}","starred_url":"https://api.github.com/users/desa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/desa/subscriptions","organizations_url":"https://api.github.com/users/desa/orgs","repos_url":"https://api.github.com/users/desa/repos","events_url":"https://api.github.com/users/desa/events{/privacy}","received_events_url":"https://api.github.com/users/desa/received_events","type":"User","site_admin":false},"created_at":"2016-10-06T15:37:08Z","updated_at":"2016-10-06T15:37:08Z","body":"@jsternberg @nathanielc fixed everything you brought up. Let me know if there's anything I missed."}}
{"actor":{"display_login":"desa"}}