{"action":"created","comment":{"url":"https://api.github.com/repos/m3db/m3/pulls/comments/214457306","pull_request_review_id":151527215,"id":214457306,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNDQ1NzMwNg==","diff_hunk":"@@ -0,0 +1,229 @@\n+// Copyright (c) 2018 Uber Technologies, Inc.\n+//\n+// Permission is hereby granted, free of charge, to any person obtaining a copy\n+// of this software and associated documentation files (the \"Software\"), to deal\n+// in the Software without restriction, including without limitation the rights\n+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+// copies of the Software, and to permit persons to whom the Software is\n+// furnished to do so, subject to the following conditions:\n+//\n+// The above copyright notice and this permission notice shall be included in\n+// all copies or substantial portions of the Software.\n+//\n+// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+// THE SOFTWARE.\n+\n+package aggregation\n+\n+import (\n+\t\"fmt\"\n+\t\"math\"\n+\t\"strconv\"\n+\n+\t\"github.com/m3db/m3/src/query/block\"\n+\t\"github.com/m3db/m3/src/query/executor/transform\"\n+\t\"github.com/m3db/m3/src/query/functions/utils\"\n+\t\"github.com/m3db/m3/src/query/models\"\n+\t\"github.com/m3db/m3/src/query/parser\"\n+)\n+\n+const (\n+\t// CountValuesType counts the number of non nan elements with the same value\n+\tCountValuesType = \"count_values\"\n+)\n+\n+// NewCountValuesOp creates a new take operation\n+func NewCountValuesOp(\n+\topType string,\n+\tparams NodeParams,\n+) (parser.Params, error) {\n+\tif opType != CountValuesType {\n+\t\treturn baseOp{}, fmt.Errorf(\"operator not supported: %s\", opType)\n+\t}\n+\n+\treturn newCountValuesOp(params, opType), nil\n+}\n+\n+// countValuesOp stores required properties for take ops\n+type countValuesOp struct {\n+\tparams NodeParams\n+\topType string\n+}\n+\n+// OpType for the operator\n+func (o countValuesOp) OpType() string {\n+\treturn o.opType\n+}\n+\n+// String representation\n+func (o countValuesOp) String() string {\n+\treturn fmt.Sprintf(\"type: %s\", o.OpType())\n+}\n+\n+// Node creates an execution node\n+func (o countValuesOp) Node(\n+\tcontroller *transform.Controller,\n+\t_ transform.Options,\n+) transform.OpNode {\n+\treturn &countValuesNode{\n+\t\top:         o,\n+\t\tcontroller: controller,\n+\t}\n+}\n+\n+func newCountValuesOp(params NodeParams, opType string) countValuesOp {\n+\treturn countValuesOp{\n+\t\tparams: params,\n+\t\topType: opType,\n+\t}\n+}\n+\n+type countValuesNode struct {\n+\top         countValuesOp\n+\tcontroller *transform.Controller\n+}\n+\n+type bucketColumn []float64\n+\n+type bucketBlock struct {\n+\tcolumns      []bucketColumn\n+\tindexMapping map[float64]int\n+}\n+\n+// Process the block\n+func (n *countValuesNode) Process(ID parser.NodeID, b block.Block) error {\n+\tstepIter, err := b.StepIter()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tparams := n.op.params\n+\tmeta := stepIter.Meta()\n+\tseriesMetas := utils.FlattenMetadata(meta, stepIter.SeriesMeta())\n+\tbuckets, metas := utils.GroupSeries(\n+\t\tparams.MatchingTags,\n+\t\tparams.Without,\n+\t\tn.op.opType,\n+\t\tseriesMetas,\n+\t)\n+\n+\tstepCount := stepIter.StepCount()\n+\ttempBlock := make([]bucketBlock, len(buckets))\n+\tfor i := range tempBlock {\n+\t\ttempBlock[i].columns = make([]bucketColumn, stepCount)\n+\t\ttempBlock[i].indexMapping = make(map[float64]int, 10)\n+\t}\n+\n+\tfor columnIndex := 0; stepIter.Next(); columnIndex++ {\n+\t\tstep, err := stepIter.Current()\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\tvalues := step.Values()\n+\t\tfor bucketIndex, bucket := range buckets {\n+\t\t\tcurrentBucketBlock := tempBlock[bucketIndex]\n+\t\t\t// If not on the first column, generate appropriate number of rows full of NaNs\n+\t\t\tif columnIndex > 0 {\n+\t\t\t\tpreviousLen := len(currentBucketBlock.columns[columnIndex-1])","path":"src/query/functions/aggregation/count_values.go","position":133,"original_position":133,"commit_id":"29f4aca7ff1ab36bc026475944368ec2ba6e2ca7","original_commit_id":"29f4aca7ff1ab36bc026475944368ec2ba6e2ca7","user":{"login":"arnikola","id":14959893,"node_id":"MDQ6VXNlcjE0OTU5ODkz","avatar_url":"https://avatars0.githubusercontent.com/u/14959893?v=4","gravatar_id":"","url":"https://api.github.com/users/arnikola","html_url":"https://github.com/arnikola","followers_url":"https://api.github.com/users/arnikola/followers","following_url":"https://api.github.com/users/arnikola/following{/other_user}","gists_url":"https://api.github.com/users/arnikola/gists{/gist_id}","starred_url":"https://api.github.com/users/arnikola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arnikola/subscriptions","organizations_url":"https://api.github.com/users/arnikola/orgs","repos_url":"https://api.github.com/users/arnikola/repos","events_url":"https://api.github.com/users/arnikola/events{/privacy}","received_events_url":"https://api.github.com/users/arnikola/received_events","type":"User","site_admin":false},"body":"Good call, makes this and a few other length calculations a fair bit nicer","created_at":"2018-08-31T19:42:01Z","updated_at":"2018-08-31T19:42:01Z","html_url":"https://github.com/m3db/m3/pull/874#discussion_r214457306","pull_request_url":"https://api.github.com/repos/m3db/m3/pulls/874","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/m3db/m3/pulls/comments/214457306"},"html":{"href":"https://github.com/m3db/m3/pull/874#discussion_r214457306"},"pull_request":{"href":"https://api.github.com/repos/m3db/m3/pulls/874"}},"in_reply_to_id":214414376},"pull_request":{"url":"https://api.github.com/repos/m3db/m3/pulls/874","id":212227901,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEyMjI3OTAx","html_url":"https://github.com/m3db/m3/pull/874","diff_url":"https://github.com/m3db/m3/pull/874.diff","patch_url":"https://github.com/m3db/m3/pull/874.patch","issue_url":"https://api.github.com/repos/m3db/m3/issues/874","number":874,"state":"open","locked":false,"title":"Arnikola/count values","user":{"login":"arnikola","id":14959893,"node_id":"MDQ6VXNlcjE0OTU5ODkz","avatar_url":"https://avatars0.githubusercontent.com/u/14959893?v=4","gravatar_id":"","url":"https://api.github.com/users/arnikola","html_url":"https://github.com/arnikola","followers_url":"https://api.github.com/users/arnikola/followers","following_url":"https://api.github.com/users/arnikola/following{/other_user}","gists_url":"https://api.github.com/users/arnikola/gists{/gist_id}","starred_url":"https://api.github.com/users/arnikola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arnikola/subscriptions","organizations_url":"https://api.github.com/users/arnikola/orgs","repos_url":"https://api.github.com/users/arnikola/repos","events_url":"https://api.github.com/users/arnikola/events{/privacy}","received_events_url":"https://api.github.com/users/arnikola/received_events","type":"User","site_admin":false},"body":"Adds the count_value function. This function is a bit peculiar in that it's the only one that I'm aware of that can actually *increase* the number of series in a block.\r\n\r\nUnfortunately this translates rather poorly to the current model for building blocks, as series can be added at a later step while iterating over the block.","created_at":"2018-08-30T22:25:22Z","updated_at":"2018-08-31T19:42:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3eaaae23513b5a82ea0993acd5b6c61e052ae935","assignee":null,"assignees":[],"requested_reviewers":[{"login":"benraskin92","id":4688976,"node_id":"MDQ6VXNlcjQ2ODg5NzY=","avatar_url":"https://avatars0.githubusercontent.com/u/4688976?v=4","gravatar_id":"","url":"https://api.github.com/users/benraskin92","html_url":"https://github.com/benraskin92","followers_url":"https://api.github.com/users/benraskin92/followers","following_url":"https://api.github.com/users/benraskin92/following{/other_user}","gists_url":"https://api.github.com/users/benraskin92/gists{/gist_id}","starred_url":"https://api.github.com/users/benraskin92/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benraskin92/subscriptions","organizations_url":"https://api.github.com/users/benraskin92/orgs","repos_url":"https://api.github.com/users/benraskin92/repos","events_url":"https://api.github.com/users/benraskin92/events{/privacy}","received_events_url":"https://api.github.com/users/benraskin92/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/m3db/m3/pulls/874/commits","review_comments_url":"https://api.github.com/repos/m3db/m3/pulls/874/comments","review_comment_url":"https://api.github.com/repos/m3db/m3/pulls/comments{/number}","comments_url":"https://api.github.com/repos/m3db/m3/issues/874/comments","statuses_url":"https://api.github.com/repos/m3db/m3/statuses/29f4aca7ff1ab36bc026475944368ec2ba6e2ca7","head":{"label":"m3db:arnikola/count_values","ref":"arnikola/count_values","sha":"29f4aca7ff1ab36bc026475944368ec2ba6e2ca7","user":{"login":"m3db","id":19937171,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5OTM3MTcx","avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"repo":{"id":61153677,"node_id":"MDEwOlJlcG9zaXRvcnk2MTE1MzY3Nw==","name":"m3","full_name":"m3db/m3","owner":{"login":"m3db","id":19937171,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5OTM3MTcx","avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/m3db/m3","description":"M3 monorepo - Distributed TSDB and Query Engine, Prometheus Sidecar, Metrics Platform","fork":false,"url":"https://api.github.com/repos/m3db/m3","forks_url":"https://api.github.com/repos/m3db/m3/forks","keys_url":"https://api.github.com/repos/m3db/m3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m3db/m3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m3db/m3/teams","hooks_url":"https://api.github.com/repos/m3db/m3/hooks","issue_events_url":"https://api.github.com/repos/m3db/m3/issues/events{/number}","events_url":"https://api.github.com/repos/m3db/m3/events","assignees_url":"https://api.github.com/repos/m3db/m3/assignees{/user}","branches_url":"https://api.github.com/repos/m3db/m3/branches{/branch}","tags_url":"https://api.github.com/repos/m3db/m3/tags","blobs_url":"https://api.github.com/repos/m3db/m3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m3db/m3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m3db/m3/git/refs{/sha}","trees_url":"https://api.github.com/repos/m3db/m3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m3db/m3/statuses/{sha}","languages_url":"https://api.github.com/repos/m3db/m3/languages","stargazers_url":"https://api.github.com/repos/m3db/m3/stargazers","contributors_url":"https://api.github.com/repos/m3db/m3/contributors","subscribers_url":"https://api.github.com/repos/m3db/m3/subscribers","subscription_url":"https://api.github.com/repos/m3db/m3/subscription","commits_url":"https://api.github.com/repos/m3db/m3/commits{/sha}","git_commits_url":"https://api.github.com/repos/m3db/m3/git/commits{/sha}","comments_url":"https://api.github.com/repos/m3db/m3/comments{/number}","issue_comment_url":"https://api.github.com/repos/m3db/m3/issues/comments{/number}","contents_url":"https://api.github.com/repos/m3db/m3/contents/{+path}","compare_url":"https://api.github.com/repos/m3db/m3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m3db/m3/merges","archive_url":"https://api.github.com/repos/m3db/m3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m3db/m3/downloads","issues_url":"https://api.github.com/repos/m3db/m3/issues{/number}","pulls_url":"https://api.github.com/repos/m3db/m3/pulls{/number}","milestones_url":"https://api.github.com/repos/m3db/m3/milestones{/number}","notifications_url":"https://api.github.com/repos/m3db/m3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m3db/m3/labels{/name}","releases_url":"https://api.github.com/repos/m3db/m3/releases{/id}","deployments_url":"https://api.github.com/repos/m3db/m3/deployments","created_at":"2016-06-14T20:29:45Z","updated_at":"2018-08-31T18:56:40Z","pushed_at":"2018-08-31T19:27:14Z","git_url":"git://github.com/m3db/m3.git","ssh_url":"git@github.com:m3db/m3.git","clone_url":"https://github.com/m3db/m3.git","svn_url":"https://github.com/m3db/m3","homepage":"https://m3db.io/","size":13451,"stargazers_count":1040,"watchers_count":1040,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":71,"mirror_url":null,"archived":false,"open_issues_count":127,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":71,"open_issues":127,"watchers":1040,"default_branch":"master"}},"base":{"label":"m3db:master","ref":"master","sha":"50bf1108d5548ebd128f8d28cfaabad68bd8e34b","user":{"login":"m3db","id":19937171,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5OTM3MTcx","avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"repo":{"id":61153677,"node_id":"MDEwOlJlcG9zaXRvcnk2MTE1MzY3Nw==","name":"m3","full_name":"m3db/m3","owner":{"login":"m3db","id":19937171,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5OTM3MTcx","avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/m3db/m3","description":"M3 monorepo - Distributed TSDB and Query Engine, Prometheus Sidecar, Metrics Platform","fork":false,"url":"https://api.github.com/repos/m3db/m3","forks_url":"https://api.github.com/repos/m3db/m3/forks","keys_url":"https://api.github.com/repos/m3db/m3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m3db/m3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m3db/m3/teams","hooks_url":"https://api.github.com/repos/m3db/m3/hooks","issue_events_url":"https://api.github.com/repos/m3db/m3/issues/events{/number}","events_url":"https://api.github.com/repos/m3db/m3/events","assignees_url":"https://api.github.com/repos/m3db/m3/assignees{/user}","branches_url":"https://api.github.com/repos/m3db/m3/branches{/branch}","tags_url":"https://api.github.com/repos/m3db/m3/tags","blobs_url":"https://api.github.com/repos/m3db/m3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m3db/m3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m3db/m3/git/refs{/sha}","trees_url":"https://api.github.com/repos/m3db/m3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m3db/m3/statuses/{sha}","languages_url":"https://api.github.com/repos/m3db/m3/languages","stargazers_url":"https://api.github.com/repos/m3db/m3/stargazers","contributors_url":"https://api.github.com/repos/m3db/m3/contributors","subscribers_url":"https://api.github.com/repos/m3db/m3/subscribers","subscription_url":"https://api.github.com/repos/m3db/m3/subscription","commits_url":"https://api.github.com/repos/m3db/m3/commits{/sha}","git_commits_url":"https://api.github.com/repos/m3db/m3/git/commits{/sha}","comments_url":"https://api.github.com/repos/m3db/m3/comments{/number}","issue_comment_url":"https://api.github.com/repos/m3db/m3/issues/comments{/number}","contents_url":"https://api.github.com/repos/m3db/m3/contents/{+path}","compare_url":"https://api.github.com/repos/m3db/m3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m3db/m3/merges","archive_url":"https://api.github.com/repos/m3db/m3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m3db/m3/downloads","issues_url":"https://api.github.com/repos/m3db/m3/issues{/number}","pulls_url":"https://api.github.com/repos/m3db/m3/pulls{/number}","milestones_url":"https://api.github.com/repos/m3db/m3/milestones{/number}","notifications_url":"https://api.github.com/repos/m3db/m3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m3db/m3/labels{/name}","releases_url":"https://api.github.com/repos/m3db/m3/releases{/id}","deployments_url":"https://api.github.com/repos/m3db/m3/deployments","created_at":"2016-06-14T20:29:45Z","updated_at":"2018-08-31T18:56:40Z","pushed_at":"2018-08-31T19:27:14Z","git_url":"git://github.com/m3db/m3.git","ssh_url":"git@github.com:m3db/m3.git","clone_url":"https://github.com/m3db/m3.git","svn_url":"https://github.com/m3db/m3","homepage":"https://m3db.io/","size":13451,"stargazers_count":1040,"watchers_count":1040,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":71,"mirror_url":null,"archived":false,"open_issues_count":127,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":71,"open_issues":127,"watchers":1040,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/m3db/m3/pulls/874"},"html":{"href":"https://github.com/m3db/m3/pull/874"},"issue":{"href":"https://api.github.com/repos/m3db/m3/issues/874"},"comments":{"href":"https://api.github.com/repos/m3db/m3/issues/874/comments"},"review_comments":{"href":"https://api.github.com/repos/m3db/m3/pulls/874/comments"},"review_comment":{"href":"https://api.github.com/repos/m3db/m3/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/m3db/m3/pulls/874/commits"},"statuses":{"href":"https://api.github.com/repos/m3db/m3/statuses/29f4aca7ff1ab36bc026475944368ec2ba6e2ca7"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"arnikola"}}