{"action":"opened","issue":{"url":"https://api.github.com/repos/druid-io/druid/issues/2973","repository_url":"https://api.github.com/repos/druid-io/druid","labels_url":"https://api.github.com/repos/druid-io/druid/issues/2973/labels{/name}","comments_url":"https://api.github.com/repos/druid-io/druid/issues/2973/comments","events_url":"https://api.github.com/repos/druid-io/druid/issues/2973/events","html_url":"https://github.com/druid-io/druid/issues/2973","id":155293406,"number":2973,"title":"Make a 'trunc' extraction function for numeric dimensions","user":{"login":"vogievetsky","id":177816,"avatar_url":"https://avatars.githubusercontent.com/u/177816?v=3","gravatar_id":"","url":"https://api.github.com/users/vogievetsky","html_url":"https://github.com/vogievetsky","followers_url":"https://api.github.com/users/vogievetsky/followers","following_url":"https://api.github.com/users/vogievetsky/following{/other_user}","gists_url":"https://api.github.com/users/vogievetsky/gists{/gist_id}","starred_url":"https://api.github.com/users/vogievetsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vogievetsky/subscriptions","organizations_url":"https://api.github.com/users/vogievetsky/orgs","repos_url":"https://api.github.com/users/vogievetsky/repos","events_url":"https://api.github.com/users/vogievetsky/events{/privacy}","received_events_url":"https://api.github.com/users/vogievetsky/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-17T15:44:14Z","updated_at":"2016-05-17T15:44:14Z","closed_at":null,"body":"I would like to be able to express the following extraction function:\r\n\r\n```javascript\r\n{\r\n  \"extractionFn\": {\r\n    \"function\": \"function(d){d=Number(d); if(isNaN(d)) return 'null'; return Math.floor((d - 0.5) / 2) * 2 + 0.5;}\",\r\n    \"type\": \"javascript\"\r\n  },\r\n  \"dimension\": \"height_bucket\",\r\n  \"outputName\": \"HeightBucket\",\r\n  \"type\": \"extraction\"\r\n}\r\n```\r\n\r\nWithout using JavaScript (make it native)\r\n\r\nI suggest an extraction function that look like this: \r\n\r\n```javascript\r\n{\r\n  \"extractionFn\": {    \r\n    \"type\": \"trunc\", // or \"floor\"\r\n    \"size\": 2, // optional, defaults to 1\r\n    \"offset\": 0.5 // optional defaults to 0\r\n  },\r\n  \"dimension\": \"height_bucket\",\r\n  \"outputName\": \"HeightBucket\",\r\n  \"type\": \"extraction\"\r\n}\r\n```\r\n\r\nWhich would translate to: `function(d){d=Number(d); if(isNaN(d)) return 'null'; return Math.floor((d - offset) / size) * size + offset;}`\r\n\r\nThis is needed to implement queries like:\r\n\r\n```sql\r\nSELECT TRUNC(commentLength, 10) AS \"commentLengthBucketsOf10\"\r\nFROM \"wikipedia\"\r\nGROUP BY TRUNC(commentLength, 10)\r\n```\r\n"}}