{"action":"created","comment":{"url":"https://api.github.com/repos/druid-io/druid/pulls/comments/23083842","id":23083842,"diff_hunk":"@@ -0,0 +1,154 @@\n+/*\n+ * Druid - a distributed column store.\n+ * Copyright (C) 2012, 2013  Metamarkets Group Inc.\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2\n+ * of the License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n+ */\n+\n+package io.druid.query.datasourcemetadata;\n+\n+import com.fasterxml.jackson.core.type.TypeReference;\n+import com.google.common.base.Function;\n+import com.google.common.base.Functions;\n+import com.google.common.base.Predicate;\n+import com.google.common.collect.Iterables;\n+import com.google.common.collect.Lists;\n+import com.google.common.collect.Ordering;\n+import com.metamx.common.guava.MergeSequence;\n+import com.metamx.common.guava.Sequence;\n+import com.metamx.common.guava.Sequences;\n+import com.metamx.emitter.service.ServiceMetricEvent;\n+import io.druid.collections.OrderedMergeSequence;\n+import io.druid.query.BySegmentSkippingQueryRunner;\n+import io.druid.query.CacheStrategy;\n+import io.druid.query.DataSourceUtil;\n+import io.druid.query.Query;\n+import io.druid.query.QueryRunner;\n+import io.druid.query.QueryToolChest;\n+import io.druid.query.Result;\n+import io.druid.query.aggregation.MetricManipulationFn;\n+import io.druid.timeline.LogicalSegment;\n+\n+import java.util.List;\n+import java.util.Map;\n+\n+/**\n+ */\n+public class DataSourceQueryQueryToolChest\n+    extends QueryToolChest<Result<DataSourceMetadataResultValue>, DataSourceMetadataQuery>\n+{\n+  private static final TypeReference<Result<DataSourceMetadataResultValue>> TYPE_REFERENCE = new TypeReference<Result<DataSourceMetadataResultValue>>()\n+  {\n+  };\n+\n+  @Override\n+  public <T extends LogicalSegment> List<T> filterSegments(DataSourceMetadataQuery query, List<T> segments)\n+  {\n+    if (segments.size() <= 1) {\n+      return segments;\n+    }\n+\n+    final T min = segments.get(0);\n+    final T max = segments.get(segments.size() - 1);\n+\n+    return Lists.newArrayList(\n+        Iterables.filter(\n+            segments,\n+            new Predicate<T>()\n+            {\n+              @Override\n+              public boolean apply(T input)\n+              {\n+                return (min != null && input.getInterval().overlaps(min.getInterval())) ||\n+                       (max != null && input.getInterval().overlaps(max.getInterval()));\n+              }\n+            }\n+        )\n+    );\n+  }\n+\n+  @Override\n+  public QueryRunner<Result<DataSourceMetadataResultValue>> mergeResults(\n+      final QueryRunner<Result<DataSourceMetadataResultValue>> runner\n+  )\n+  {\n+    return new BySegmentSkippingQueryRunner<Result<DataSourceMetadataResultValue>>(runner)\n+    {\n+      @Override\n+      protected Sequence<Result<DataSourceMetadataResultValue>> doRun(\n+          QueryRunner<Result<DataSourceMetadataResultValue>> baseRunner,\n+          Query<Result<DataSourceMetadataResultValue>> input,\n+          Map<String, Object> context\n+      )\n+      {\n+        DataSourceMetadataQuery query = (DataSourceMetadataQuery) input;\n+        return Sequences.simple(\n+            query.mergeResults(\n+                Sequences.toList(\n+                    baseRunner.run(query, context),\n+                    Lists.<Result<DataSourceMetadataResultValue>>newArrayList()\n+                )\n+            )\n+        );\n+      }\n+    };\n+  }\n+\n+  @Override\n+  public Sequence<Result<DataSourceMetadataResultValue>> mergeSequences(Sequence<Sequence<Result<DataSourceMetadataResultValue>>> seqOfSequences)\n+  {\n+    return new OrderedMergeSequence<>(getOrdering(), seqOfSequences);\n+  }\n+\n+  @Override\n+  public Sequence<Result<DataSourceMetadataResultValue>> mergeSequencesUnordered(Sequence<Sequence<Result<DataSourceMetadataResultValue>>> seqOfSequences)\n+  {\n+    return new MergeSequence<>(getOrdering(), seqOfSequences);\n+  }\n+\n+  @Override\n+  public ServiceMetricEvent.Builder makeMetricBuilder(DataSourceMetadataQuery query)\n+  {\n+    return new ServiceMetricEvent.Builder()\n+        .setUser2(DataSourceUtil.getMetricName(query.getDataSource()))\n+        .setUser4(query.getType())\n+        .setUser6(\"false\");\n+  }\n+\n+  @Override\n+  public Function<Result<DataSourceMetadataResultValue>, Result<DataSourceMetadataResultValue>> makePreComputeManipulatorFn(\n+      DataSourceMetadataQuery query, MetricManipulationFn fn\n+  )\n+  {\n+    return Functions.identity();\n+  }\n+\n+  @Override\n+  public TypeReference<Result<DataSourceMetadataResultValue>> getResultTypeReference()\n+  {\n+    return TYPE_REFERENCE;\n+  }\n+\n+  @Override\n+  public CacheStrategy getCacheStrategy(DataSourceMetadataQuery query)\n+  {\n+    return null;","path":"processing/src/main/java/io/druid/query/datasourcemetadata/DataSourceQueryQueryToolChest.java","position":147,"original_position":147,"commit_id":"c7452b75f6150d1fe9e81aea1c1b567f51df279f","original_commit_id":"c7452b75f6150d1fe9e81aea1c1b567f51df279f","user":{"login":"nishantmonu51","id":5023786,"avatar_url":"https://avatars.githubusercontent.com/u/5023786?v=3","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},"body":"the maxIngestedEventTime changes with every new event ingested, probably it would make sense to make it cacheable when we start exposing more info from this query, ","created_at":"2015-01-16T14:49:52Z","updated_at":"2015-01-16T14:49:52Z","html_url":"https://github.com/druid-io/druid/pull/1031#discussion_r23083842","pull_request_url":"https://api.github.com/repos/druid-io/druid/pulls/1031","_links":{"self":{"href":"https://api.github.com/repos/druid-io/druid/pulls/comments/23083842"},"html":{"href":"https://github.com/druid-io/druid/pull/1031#discussion_r23083842"},"pull_request":{"href":"https://api.github.com/repos/druid-io/druid/pulls/1031"}}},"pull_request":{"url":"https://api.github.com/repos/druid-io/druid/pulls/1031","id":27424851,"html_url":"https://github.com/druid-io/druid/pull/1031","diff_url":"https://github.com/druid-io/druid/pull/1031.diff","patch_url":"https://github.com/druid-io/druid/pull/1031.patch","issue_url":"https://api.github.com/repos/druid-io/druid/issues/1031","number":1031,"state":"open","locked":false,"title":"DataSourceMetadata query","user":{"login":"nishantmonu51","id":5023786,"avatar_url":"https://avatars.githubusercontent.com/u/5023786?v=3","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},"body":"DataSourceMetadata query - \r\nexpose maxIngestedEventTime for dataSource","created_at":"2015-01-15T12:28:37Z","updated_at":"2015-01-16T14:49:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cd60c7eed28175e6693ea8f014adb04b2f194499","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/druid-io/druid/pulls/1031/commits","review_comments_url":"https://api.github.com/repos/druid-io/druid/pulls/1031/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/1031/comments","statuses_url":"https://api.github.com/repos/druid-io/druid/statuses/c7452b75f6150d1fe9e81aea1c1b567f51df279f","head":{"label":"metamx:ingestmetadata-query","ref":"ingestmetadata-query","sha":"c7452b75f6150d1fe9e81aea1c1b567f51df279f","user":{"login":"metamx","id":299329,"avatar_url":"https://avatars.githubusercontent.com/u/299329?v=3","gravatar_id":"","url":"https://api.github.com/users/metamx","html_url":"https://github.com/metamx","followers_url":"https://api.github.com/users/metamx/followers","following_url":"https://api.github.com/users/metamx/following{/other_user}","gists_url":"https://api.github.com/users/metamx/gists{/gist_id}","starred_url":"https://api.github.com/users/metamx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metamx/subscriptions","organizations_url":"https://api.github.com/users/metamx/orgs","repos_url":"https://api.github.com/users/metamx/repos","events_url":"https://api.github.com/users/metamx/events{/privacy}","received_events_url":"https://api.github.com/users/metamx/received_events","type":"Organization","site_admin":false},"repo":{"id":28248872,"name":"druid","full_name":"metamx/druid","owner":{"login":"metamx","id":299329,"avatar_url":"https://avatars.githubusercontent.com/u/299329?v=3","gravatar_id":"","url":"https://api.github.com/users/metamx","html_url":"https://github.com/metamx","followers_url":"https://api.github.com/users/metamx/followers","following_url":"https://api.github.com/users/metamx/following{/other_user}","gists_url":"https://api.github.com/users/metamx/gists{/gist_id}","starred_url":"https://api.github.com/users/metamx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metamx/subscriptions","organizations_url":"https://api.github.com/users/metamx/orgs","repos_url":"https://api.github.com/users/metamx/repos","events_url":"https://api.github.com/users/metamx/events{/privacy}","received_events_url":"https://api.github.com/users/metamx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/metamx/druid","description":"Real²time Exploratory Analytics on Large Datasets","fork":true,"url":"https://api.github.com/repos/metamx/druid","forks_url":"https://api.github.com/repos/metamx/druid/forks","keys_url":"https://api.github.com/repos/metamx/druid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/metamx/druid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/metamx/druid/teams","hooks_url":"https://api.github.com/repos/metamx/druid/hooks","issue_events_url":"https://api.github.com/repos/metamx/druid/issues/events{/number}","events_url":"https://api.github.com/repos/metamx/druid/events","assignees_url":"https://api.github.com/repos/metamx/druid/assignees{/user}","branches_url":"https://api.github.com/repos/metamx/druid/branches{/branch}","tags_url":"https://api.github.com/repos/metamx/druid/tags","blobs_url":"https://api.github.com/repos/metamx/druid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/metamx/druid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/metamx/druid/git/refs{/sha}","trees_url":"https://api.github.com/repos/metamx/druid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/metamx/druid/statuses/{sha}","languages_url":"https://api.github.com/repos/metamx/druid/languages","stargazers_url":"https://api.github.com/repos/metamx/druid/stargazers","contributors_url":"https://api.github.com/repos/metamx/druid/contributors","subscribers_url":"https://api.github.com/repos/metamx/druid/subscribers","subscription_url":"https://api.github.com/repos/metamx/druid/subscription","commits_url":"https://api.github.com/repos/metamx/druid/commits{/sha}","git_commits_url":"https://api.github.com/repos/metamx/druid/git/commits{/sha}","comments_url":"https://api.github.com/repos/metamx/druid/comments{/number}","issue_comment_url":"https://api.github.com/repos/metamx/druid/issues/comments/{number}","contents_url":"https://api.github.com/repos/metamx/druid/contents/{+path}","compare_url":"https://api.github.com/repos/metamx/druid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/metamx/druid/merges","archive_url":"https://api.github.com/repos/metamx/druid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/metamx/druid/downloads","issues_url":"https://api.github.com/repos/metamx/druid/issues{/number}","pulls_url":"https://api.github.com/repos/metamx/druid/pulls{/number}","milestones_url":"https://api.github.com/repos/metamx/druid/milestones{/number}","notifications_url":"https://api.github.com/repos/metamx/druid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/metamx/druid/labels{/name}","releases_url":"https://api.github.com/repos/metamx/druid/releases{/id}","created_at":"2014-12-19T22:30:25Z","updated_at":"2015-01-14T01:52:44Z","pushed_at":"2015-01-16T05:25:41Z","git_url":"git://github.com/metamx/druid.git","ssh_url":"git@github.com:metamx/druid.git","clone_url":"https://github.com/metamx/druid.git","svn_url":"https://github.com/metamx/druid","homepage":"http://druid.io","size":88362,"stargazers_count":7,"watchers_count":7,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":0,"forks":7,"open_issues":0,"watchers":7,"default_branch":"master"}},"base":{"label":"druid-io:master","ref":"master","sha":"6f1537d1534739ffda1d86aea531327c342e418e","user":{"login":"druid-io","id":4203474,"avatar_url":"https://avatars.githubusercontent.com/u/4203474?v=3","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://avatars.githubusercontent.com/u/4203474?v=3","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":"Real²time Exploratory Analytics on Large Datasets","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}","created_at":"2012-10-23T19:08:07Z","updated_at":"2015-01-16T01:54:11Z","pushed_at":"2015-01-16T01:58:41Z","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":152685,"stargazers_count":1319,"watchers_count":1319,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":283,"mirror_url":null,"open_issues_count":142,"forks":283,"open_issues":142,"watchers":1319,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/druid-io/druid/pulls/1031"},"html":{"href":"https://github.com/druid-io/druid/pull/1031"},"issue":{"href":"https://api.github.com/repos/druid-io/druid/issues/1031"},"comments":{"href":"https://api.github.com/repos/druid-io/druid/issues/1031/comments"},"review_comments":{"href":"https://api.github.com/repos/druid-io/druid/pulls/1031/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/1031/commits"},"statuses":{"href":"https://api.github.com/repos/druid-io/druid/statuses/c7452b75f6150d1fe9e81aea1c1b567f51df279f"}}}}