{"action":"created","comment":{"url":"https://api.github.com/repos/druid-io/druid/pulls/comments/183492522","pull_request_review_id":114501293,"id":183492522,"diff_hunk":"@@ -131,72 +136,96 @@ public TimeseriesQueryQueryToolChest(\n       }\n     };\n \n-    return new QueryRunner<Result<TimeseriesResultValue>>()\n-    {\n-      @Override\n-      public Sequence<Result<TimeseriesResultValue>> run(\n-          final QueryPlus<Result<TimeseriesResultValue>> queryPlus,\n-          final Map<String, Object> responseContext\n-      )\n-      {\n-        final TimeseriesQuery query = (TimeseriesQuery) queryPlus.getQuery();\n-        final Sequence<Result<TimeseriesResultValue>> baseResults = resultMergeQueryRunner.run(\n-            queryPlus.withQuery(\n-                queryPlus.getQuery()\n-                         .withOverriddenContext(\n-                             ImmutableMap.of(TimeseriesQuery.CTX_GRAND_TOTAL, false)\n-                         )\n-            ),\n-            responseContext\n-        );\n+    return (queryPlus, responseContext) -> {\n+      final TimeseriesQuery query = (TimeseriesQuery) queryPlus.getQuery();\n+      final Sequence<Result<TimeseriesResultValue>> baseResults = resultMergeQueryRunner.run(\n+          queryPlus.withQuery(\n+              queryPlus.getQuery()\n+                       .withOverriddenContext(\n+                           ImmutableMap.of(TimeseriesQuery.CTX_GRAND_TOTAL, false)\n+                       )\n+          ),\n+          responseContext\n+      );\n+\n+      final Sequence<Result<TimeseriesResultValue>> finalSequence;\n+\n+      if (query.getGranularity().equals(Granularities.ALL) && !query.isSkipEmptyBuckets()) {\n+        //Usally it is NOT Okay to materialize results via toList(), but Granularity is ALL thus we have only one record\n+        finalSequence = baseResults.toList().isEmpty() ? Sequences.simple(Collections.singletonList(","path":"processing/src/main/java/io/druid/query/timeseries/TimeseriesQueryQueryToolChest.java","position":61,"original_position":61,"commit_id":"69aea177c721b8dbf05b4fbb5e7cc6399b2fd847","original_commit_id":"69aea177c721b8dbf05b4fbb5e7cc6399b2fd847","user":{"login":"gianm","id":1214075,"avatar_url":"https://avatars3.githubusercontent.com/u/1214075?v=4","gravatar_id":"","url":"https://api.github.com/users/gianm","html_url":"https://github.com/gianm","followers_url":"https://api.github.com/users/gianm/followers","following_url":"https://api.github.com/users/gianm/following{/other_user}","gists_url":"https://api.github.com/users/gianm/gists{/gist_id}","starred_url":"https://api.github.com/users/gianm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gianm/subscriptions","organizations_url":"https://api.github.com/users/gianm/orgs","repos_url":"https://api.github.com/users/gianm/repos","events_url":"https://api.github.com/users/gianm/events{/privacy}","received_events_url":"https://api.github.com/users/gianm/received_events","type":"User","site_admin":false},"body":"I believe this will end up running the query on the cluster twice (once for the `toList` and then another time, later, when the `finalSequence` is accumulated). We should avoid this by caching `baseResults.toList()` and doing a `Sequences.simple` out of it once it's computed.","created_at":"2018-04-23T18:23:24Z","updated_at":"2018-04-23T18:27:16Z","html_url":"https://github.com/druid-io/druid/pull/5649#discussion_r183492522","pull_request_url":"https://api.github.com/repos/druid-io/druid/pulls/5649","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/druid-io/druid/pulls/comments/183492522"},"html":{"href":"https://github.com/druid-io/druid/pull/5649#discussion_r183492522"},"pull_request":{"href":"https://api.github.com/repos/druid-io/druid/pulls/5649"}}},"pull_request":{"url":"https://api.github.com/repos/druid-io/druid/pulls/5649","id":181902186,"html_url":"https://github.com/druid-io/druid/pull/5649","diff_url":"https://github.com/druid-io/druid/pull/5649.diff","patch_url":"https://github.com/druid-io/druid/pull/5649.patch","issue_url":"https://api.github.com/repos/druid-io/druid/issues/5649","number":5649,"state":"open","locked":false,"title":"Timeseries results are incoherent for case interval is out of range and case false filter.","user":{"login":"b-slim","id":7376396,"avatar_url":"https://avatars0.githubusercontent.com/u/7376396?v=4","gravatar_id":"","url":"https://api.github.com/users/b-slim","html_url":"https://github.com/b-slim","followers_url":"https://api.github.com/users/b-slim/followers","following_url":"https://api.github.com/users/b-slim/following{/other_user}","gists_url":"https://api.github.com/users/b-slim/gists{/gist_id}","starred_url":"https://api.github.com/users/b-slim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b-slim/subscriptions","organizations_url":"https://api.github.com/users/b-slim/orgs","repos_url":"https://api.github.com/users/b-slim/repos","events_url":"https://api.github.com/users/b-slim/events{/privacy}","received_events_url":"https://api.github.com/users/b-slim/received_events","type":"User","site_admin":false},"body":"**Issue**\r\nTimeseries results are incoherent for case interval is out of range and case  filter  matching zero rows.\r\nIMO intervals and filters need to behave the same thus if user  issue a query with `SkipEmptyBuckets=false` with count aggregator result must be the similar.\r\nPlease look at the unit test to understand the issue (FYI it is not a SQL issue but SQL is a good way to express the issue).\r\n~~**Fix**~~\r\n~~TBH Am no sure what is the best way to fix this. I have added some add some nasty checks for the broker side that returns an empty query runner that does the trick but it make the code looks odd.\r\nFor the Histroical side i was able to added as part of the Timeseries Internal Query processing logic.\r\n_Am still thinking about a better way to fix this_, the reason i am submitting this PR is to collect feedback/suggestions  please let me know if you see a better way to fix this.~~\r\n**Fix V2** I have taken the route suggested by @gianm  and add the the check to mergeResutls.\r\nThe new patch checks for empty results for case Granularity ALL and NoSkipping of empty buckets. \r\n<!-- Reviewable:start -->\r\n---\r\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/druid-io/druid/5649)\r\n<!-- Reviewable:end -->\r\n\r\n","created_at":"2018-04-16T15:21:59Z","updated_at":"2018-04-23T18:27:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a9e16fa87ec18f100ce722ca583de9b05d40667","assignee":{"login":"gianm","id":1214075,"avatar_url":"https://avatars3.githubusercontent.com/u/1214075?v=4","gravatar_id":"","url":"https://api.github.com/users/gianm","html_url":"https://github.com/gianm","followers_url":"https://api.github.com/users/gianm/followers","following_url":"https://api.github.com/users/gianm/following{/other_user}","gists_url":"https://api.github.com/users/gianm/gists{/gist_id}","starred_url":"https://api.github.com/users/gianm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gianm/subscriptions","organizations_url":"https://api.github.com/users/gianm/orgs","repos_url":"https://api.github.com/users/gianm/repos","events_url":"https://api.github.com/users/gianm/events{/privacy}","received_events_url":"https://api.github.com/users/gianm/received_events","type":"User","site_admin":false},"assignees":[{"login":"gianm","id":1214075,"avatar_url":"https://avatars3.githubusercontent.com/u/1214075?v=4","gravatar_id":"","url":"https://api.github.com/users/gianm","html_url":"https://github.com/gianm","followers_url":"https://api.github.com/users/gianm/followers","following_url":"https://api.github.com/users/gianm/following{/other_user}","gists_url":"https://api.github.com/users/gianm/gists{/gist_id}","starred_url":"https://api.github.com/users/gianm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gianm/subscriptions","organizations_url":"https://api.github.com/users/gianm/orgs","repos_url":"https://api.github.com/users/gianm/repos","events_url":"https://api.github.com/users/gianm/events{/privacy}","received_events_url":"https://api.github.com/users/gianm/received_events","type":"User","site_admin":false},{"login":"nishantmonu51","id":5023786,"avatar_url":"https://avatars3.githubusercontent.com/u/5023786?v=4","gravatar_id":"","url":"https://api.github.com/users/nishantmonu51","html_url":"https://github.com/nishantmonu51","followers_url":"https://api.github.com/users/nishantmonu51/followers","following_url":"https://api.github.com/users/nishantmonu51/following{/other_user}","gists_url":"https://api.github.com/users/nishantmonu51/gists{/gist_id}","starred_url":"https://api.github.com/users/nishantmonu51/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishantmonu51/subscriptions","organizations_url":"https://api.github.com/users/nishantmonu51/orgs","repos_url":"https://api.github.com/users/nishantmonu51/repos","events_url":"https://api.github.com/users/nishantmonu51/events{/privacy}","received_events_url":"https://api.github.com/users/nishantmonu51/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":219585748,"url":"https://api.github.com/repos/druid-io/druid/labels/Area%20-%20Querying","name":"Area - Querying","color":"fef2c0","default":false}],"milestone":{"url":"https://api.github.com/repos/druid-io/druid/milestones/25","html_url":"https://github.com/druid-io/druid/milestone/25","labels_url":"https://api.github.com/repos/druid-io/druid/milestones/25/labels","id":3023864,"number":25,"title":"0.13.0","description":"","creator":{"login":"leventov","id":609240,"avatar_url":"https://avatars0.githubusercontent.com/u/609240?v=4","gravatar_id":"","url":"https://api.github.com/users/leventov","html_url":"https://github.com/leventov","followers_url":"https://api.github.com/users/leventov/followers","following_url":"https://api.github.com/users/leventov/following{/other_user}","gists_url":"https://api.github.com/users/leventov/gists{/gist_id}","starred_url":"https://api.github.com/users/leventov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leventov/subscriptions","organizations_url":"https://api.github.com/users/leventov/orgs","repos_url":"https://api.github.com/users/leventov/repos","events_url":"https://api.github.com/users/leventov/events{/privacy}","received_events_url":"https://api.github.com/users/leventov/received_events","type":"User","site_admin":false},"open_issues":17,"closed_issues":41,"state":"open","created_at":"2018-01-09T18:30:01Z","updated_at":"2018-04-20T15:40:18Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/druid-io/druid/pulls/5649/commits","review_comments_url":"https://api.github.com/repos/druid-io/druid/pulls/5649/comments","review_comment_url":"https://api.github.com/repos/druid-io/druid/pulls/comments{/number}","comments_url":"https://api.github.com/repos/druid-io/druid/issues/5649/comments","statuses_url":"https://api.github.com/repos/druid-io/druid/statuses/69aea177c721b8dbf05b4fbb5e7cc6399b2fd847","head":{"label":"b-slim:fix_timeseries","ref":"fix_timeseries","sha":"69aea177c721b8dbf05b4fbb5e7cc6399b2fd847","user":{"login":"b-slim","id":7376396,"avatar_url":"https://avatars0.githubusercontent.com/u/7376396?v=4","gravatar_id":"","url":"https://api.github.com/users/b-slim","html_url":"https://github.com/b-slim","followers_url":"https://api.github.com/users/b-slim/followers","following_url":"https://api.github.com/users/b-slim/following{/other_user}","gists_url":"https://api.github.com/users/b-slim/gists{/gist_id}","starred_url":"https://api.github.com/users/b-slim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b-slim/subscriptions","organizations_url":"https://api.github.com/users/b-slim/orgs","repos_url":"https://api.github.com/users/b-slim/repos","events_url":"https://api.github.com/users/b-slim/events{/privacy}","received_events_url":"https://api.github.com/users/b-slim/received_events","type":"User","site_admin":false},"repo":{"id":26687338,"name":"druid","full_name":"b-slim/druid","owner":{"login":"b-slim","id":7376396,"avatar_url":"https://avatars0.githubusercontent.com/u/7376396?v=4","gravatar_id":"","url":"https://api.github.com/users/b-slim","html_url":"https://github.com/b-slim","followers_url":"https://api.github.com/users/b-slim/followers","following_url":"https://api.github.com/users/b-slim/following{/other_user}","gists_url":"https://api.github.com/users/b-slim/gists{/gist_id}","starred_url":"https://api.github.com/users/b-slim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b-slim/subscriptions","organizations_url":"https://api.github.com/users/b-slim/orgs","repos_url":"https://api.github.com/users/b-slim/repos","events_url":"https://api.github.com/users/b-slim/events{/privacy}","received_events_url":"https://api.github.com/users/b-slim/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/b-slim/druid","description":"Real²time Exploratory Analytics on Large Datasets","fork":true,"url":"https://api.github.com/repos/b-slim/druid","forks_url":"https://api.github.com/repos/b-slim/druid/forks","keys_url":"https://api.github.com/repos/b-slim/druid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/b-slim/druid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/b-slim/druid/teams","hooks_url":"https://api.github.com/repos/b-slim/druid/hooks","issue_events_url":"https://api.github.com/repos/b-slim/druid/issues/events{/number}","events_url":"https://api.github.com/repos/b-slim/druid/events","assignees_url":"https://api.github.com/repos/b-slim/druid/assignees{/user}","branches_url":"https://api.github.com/repos/b-slim/druid/branches{/branch}","tags_url":"https://api.github.com/repos/b-slim/druid/tags","blobs_url":"https://api.github.com/repos/b-slim/druid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/b-slim/druid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/b-slim/druid/git/refs{/sha}","trees_url":"https://api.github.com/repos/b-slim/druid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/b-slim/druid/statuses/{sha}","languages_url":"https://api.github.com/repos/b-slim/druid/languages","stargazers_url":"https://api.github.com/repos/b-slim/druid/stargazers","contributors_url":"https://api.github.com/repos/b-slim/druid/contributors","subscribers_url":"https://api.github.com/repos/b-slim/druid/subscribers","subscription_url":"https://api.github.com/repos/b-slim/druid/subscription","commits_url":"https://api.github.com/repos/b-slim/druid/commits{/sha}","git_commits_url":"https://api.github.com/repos/b-slim/druid/git/commits{/sha}","comments_url":"https://api.github.com/repos/b-slim/druid/comments{/number}","issue_comment_url":"https://api.github.com/repos/b-slim/druid/issues/comments{/number}","contents_url":"https://api.github.com/repos/b-slim/druid/contents/{+path}","compare_url":"https://api.github.com/repos/b-slim/druid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/b-slim/druid/merges","archive_url":"https://api.github.com/repos/b-slim/druid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/b-slim/druid/downloads","issues_url":"https://api.github.com/repos/b-slim/druid/issues{/number}","pulls_url":"https://api.github.com/repos/b-slim/druid/pulls{/number}","milestones_url":"https://api.github.com/repos/b-slim/druid/milestones{/number}","notifications_url":"https://api.github.com/repos/b-slim/druid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/b-slim/druid/labels{/name}","releases_url":"https://api.github.com/repos/b-slim/druid/releases{/id}","deployments_url":"https://api.github.com/repos/b-slim/druid/deployments","created_at":"2014-11-15T17:20:52Z","updated_at":"2018-04-17T21:58:21Z","pushed_at":"2018-04-23T17:09:22Z","git_url":"git://github.com/b-slim/druid.git","ssh_url":"git@github.com:b-slim/druid.git","clone_url":"https://github.com/b-slim/druid.git","svn_url":"https://github.com/b-slim/druid","homepage":"http://druid.io","size":133616,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"druid-io:master","ref":"master","sha":"fbf3fc178e5b19328a0ee42b6d7e226d34e77332","user":{"login":"druid-io","id":4203474,"avatar_url":"https://avatars0.githubusercontent.com/u/4203474?v=4","gravatar_id":"","url":"https://api.github.com/users/druid-io","html_url":"https://github.com/druid-io","followers_url":"https://api.github.com/users/druid-io/followers","following_url":"https://api.github.com/users/druid-io/following{/other_user}","gists_url":"https://api.github.com/users/druid-io/gists{/gist_id}","starred_url":"https://api.github.com/users/druid-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/druid-io/subscriptions","organizations_url":"https://api.github.com/users/druid-io/orgs","repos_url":"https://api.github.com/users/druid-io/repos","events_url":"https://api.github.com/users/druid-io/events{/privacy}","received_events_url":"https://api.github.com/users/druid-io/received_events","type":"Organization","site_admin":false},"repo":{"id":6358188,"name":"druid","full_name":"druid-io/druid","owner":{"login":"druid-io","id":4203474,"avatar_url":"https://avatars0.githubusercontent.com/u/4203474?v=4","gravatar_id":"","url":"https://api.github.com/users/druid-io","html_url":"https://github.com/druid-io","followers_url":"https://api.github.com/users/druid-io/followers","following_url":"https://api.github.com/users/druid-io/following{/other_user}","gists_url":"https://api.github.com/users/druid-io/gists{/gist_id}","starred_url":"https://api.github.com/users/druid-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/druid-io/subscriptions","organizations_url":"https://api.github.com/users/druid-io/orgs","repos_url":"https://api.github.com/users/druid-io/repos","events_url":"https://api.github.com/users/druid-io/events{/privacy}","received_events_url":"https://api.github.com/users/druid-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/druid-io/druid","description":"Column oriented distributed data store ideal for powering interactive applications","fork":false,"url":"https://api.github.com/repos/druid-io/druid","forks_url":"https://api.github.com/repos/druid-io/druid/forks","keys_url":"https://api.github.com/repos/druid-io/druid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/druid-io/druid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/druid-io/druid/teams","hooks_url":"https://api.github.com/repos/druid-io/druid/hooks","issue_events_url":"https://api.github.com/repos/druid-io/druid/issues/events{/number}","events_url":"https://api.github.com/repos/druid-io/druid/events","assignees_url":"https://api.github.com/repos/druid-io/druid/assignees{/user}","branches_url":"https://api.github.com/repos/druid-io/druid/branches{/branch}","tags_url":"https://api.github.com/repos/druid-io/druid/tags","blobs_url":"https://api.github.com/repos/druid-io/druid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/druid-io/druid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/druid-io/druid/git/refs{/sha}","trees_url":"https://api.github.com/repos/druid-io/druid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/druid-io/druid/statuses/{sha}","languages_url":"https://api.github.com/repos/druid-io/druid/languages","stargazers_url":"https://api.github.com/repos/druid-io/druid/stargazers","contributors_url":"https://api.github.com/repos/druid-io/druid/contributors","subscribers_url":"https://api.github.com/repos/druid-io/druid/subscribers","subscription_url":"https://api.github.com/repos/druid-io/druid/subscription","commits_url":"https://api.github.com/repos/druid-io/druid/commits{/sha}","git_commits_url":"https://api.github.com/repos/druid-io/druid/git/commits{/sha}","comments_url":"https://api.github.com/repos/druid-io/druid/comments{/number}","issue_comment_url":"https://api.github.com/repos/druid-io/druid/issues/comments{/number}","contents_url":"https://api.github.com/repos/druid-io/druid/contents/{+path}","compare_url":"https://api.github.com/repos/druid-io/druid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/druid-io/druid/merges","archive_url":"https://api.github.com/repos/druid-io/druid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/druid-io/druid/downloads","issues_url":"https://api.github.com/repos/druid-io/druid/issues{/number}","pulls_url":"https://api.github.com/repos/druid-io/druid/pulls{/number}","milestones_url":"https://api.github.com/repos/druid-io/druid/milestones{/number}","notifications_url":"https://api.github.com/repos/druid-io/druid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/druid-io/druid/labels{/name}","releases_url":"https://api.github.com/repos/druid-io/druid/releases{/id}","deployments_url":"https://api.github.com/repos/druid-io/druid/deployments","created_at":"2012-10-23T19:08:07Z","updated_at":"2018-04-23T16:20:16Z","pushed_at":"2018-04-23T17:59:05Z","git_url":"git://github.com/druid-io/druid.git","ssh_url":"git@github.com:druid-io/druid.git","clone_url":"https://github.com/druid-io/druid.git","svn_url":"https://github.com/druid-io/druid","homepage":"http://druid.io","size":136853,"stargazers_count":6386,"watchers_count":6386,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1574,"mirror_url":null,"archived":false,"open_issues_count":985,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":1574,"open_issues":985,"watchers":6386,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/druid-io/druid/pulls/5649"},"html":{"href":"https://github.com/druid-io/druid/pull/5649"},"issue":{"href":"https://api.github.com/repos/druid-io/druid/issues/5649"},"comments":{"href":"https://api.github.com/repos/druid-io/druid/issues/5649/comments"},"review_comments":{"href":"https://api.github.com/repos/druid-io/druid/pulls/5649/comments"},"review_comment":{"href":"https://api.github.com/repos/druid-io/druid/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/druid-io/druid/pulls/5649/commits"},"statuses":{"href":"https://api.github.com/repos/druid-io/druid/statuses/69aea177c721b8dbf05b4fbb5e7cc6399b2fd847"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"gianm"}}