{"action":"created","issue":{"url":"https://api.github.com/repos/OpenTSDB/opentsdb/issues/651","labels_url":"https://api.github.com/repos/OpenTSDB/opentsdb/issues/651/labels{/name}","comments_url":"https://api.github.com/repos/OpenTSDB/opentsdb/issues/651/comments","events_url":"https://api.github.com/repos/OpenTSDB/opentsdb/issues/651/events","html_url":"https://github.com/OpenTSDB/opentsdb/issues/651","id":120152404,"number":651,"title":"Get the first and last value timestamp for a given metric","user":{"login":"spicoflorin","id":4939817,"avatar_url":"https://avatars.githubusercontent.com/u/4939817?v=3","gravatar_id":"","url":"https://api.github.com/users/spicoflorin","html_url":"https://github.com/spicoflorin","followers_url":"https://api.github.com/users/spicoflorin/followers","following_url":"https://api.github.com/users/spicoflorin/following{/other_user}","gists_url":"https://api.github.com/users/spicoflorin/gists{/gist_id}","starred_url":"https://api.github.com/users/spicoflorin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spicoflorin/subscriptions","organizations_url":"https://api.github.com/users/spicoflorin/orgs","repos_url":"https://api.github.com/users/spicoflorin/repos","events_url":"https://api.github.com/users/spicoflorin/events{/privacy}","received_events_url":"https://api.github.com/users/spicoflorin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/OpenTSDB/opentsdb/labels/feature%20request","name":"feature request","color":"c1ff8f"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-03T11:45:12Z","updated_at":"2015-12-15T16:37:20Z","closed_at":null,"body":"Hello!\r\nI have a scenario where for a given metric I need to get the first timestamp (oldest registration) and the last timestamp (newes registration) for it ( not the timestamps when the record was written in HBASE).\r\nFor getting the last timestamp (not the one wrriten in HBASE) I found something in the API, class  net.opentsdb.meta.TSUIDQuery, method getLastPoint(final boolean resolve_names, final int back_scan)  that unfortunately is not suitable for my case. \r\nI'm importing historical data only with timestamps from 2007 and I have to use this method with the back_scan enabled (due to the fact I don't want the HBASE timestamp). For this use case, the back_scan should be set up to a great value  24hours*365days*8years that  will take a long, long time to get back the results.\r\nHow can I get these values using Java API?\r\n\r\nI got a comment from Chris Larsen:\r\n\"That would require a new API but wouldn't be too difficult to implement. Right now when you issue a regular query we create an HBase scanner with the \"start\" set to the metric name and the starting timestamp (or a little earlier). In your case you'd just set it to the metric and either zero out the timestamp or leave it out of the start key. Set the scanner filter properly and maybe maxRows to 1 (if you only have one series you need), then scan and it will pick up the first row. Parse the row for the first value and bam, there's your first point.\r\nThe LAST point would be a bit trickier. Ideally we'd use a reverse scan. I think these were introduced in 0.98 and you'd do the same thing, set the start key to \"<metric>999999999\" or something, set max rows to 1 and see what row you get back, that'll have the max value. This would require a little bit of work in AsyncHBase to support the reverse scanner but it wouldn't be too bad.\r\n\"\r\n"},"comment":{"url":"https://api.github.com/repos/OpenTSDB/opentsdb/issues/comments/164820748","html_url":"https://github.com/OpenTSDB/opentsdb/issues/651#issuecomment-164820748","issue_url":"https://api.github.com/repos/OpenTSDB/opentsdb/issues/651","id":164820748,"user":{"login":"tudorcodrea","id":16150005,"avatar_url":"https://avatars.githubusercontent.com/u/16150005?v=3","gravatar_id":"","url":"https://api.github.com/users/tudorcodrea","html_url":"https://github.com/tudorcodrea","followers_url":"https://api.github.com/users/tudorcodrea/followers","following_url":"https://api.github.com/users/tudorcodrea/following{/other_user}","gists_url":"https://api.github.com/users/tudorcodrea/gists{/gist_id}","starred_url":"https://api.github.com/users/tudorcodrea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tudorcodrea/subscriptions","organizations_url":"https://api.github.com/users/tudorcodrea/orgs","repos_url":"https://api.github.com/users/tudorcodrea/repos","events_url":"https://api.github.com/users/tudorcodrea/events{/privacy}","received_events_url":"https://api.github.com/users/tudorcodrea/received_events","type":"User","site_admin":false},"created_at":"2015-12-15T16:37:20Z","updated_at":"2015-12-15T16:37:20Z","body":"Hi,\r\nI am also in the need of a requirement such as this one. I am working on some implementation  following Chris Larsen's  solution. I started with returning the first timeStamp for a metric (oldest value) and I found the place where the configured scanner is sent further, at QueryUtil with method getMetricScanner. In here, I forced the scanner to return only the first row and the first registration using: scanner.setMaxNumRows(1);         scanner.setMaxNumKeyValues(1); scanner.setMaxNumKeyValues(1); \r\nAfter running with these changes the OpenTSDB api still returns the entire table of timeStamps and values for the metric.\r\nWhat I am overlooking, and what other constraints should I apply and where to the Scanner in order to obtain only one result instead of all data for a metric?\r\n"}}