diff --git a/processing/src/main/java/io/druid/query/BaseQuery.java b/processing/src/main/java/io/druid/query/BaseQuery.java index ed13f9ddf39..71beaa26652 100644 --- a/processing/src/main/java/io/druid/query/BaseQuery.java +++ b/processing/src/main/java/io/druid/query/BaseQuery.java @@ -37,14 +37,14 @@ public abstract class BaseQuery implements Query { public static String QUERYID = "queryId"; private final DataSource dataSource; - private final Map context; + private final Map context; private final QuerySegmentSpec querySegmentSpec; private volatile Duration duration; public BaseQuery( DataSource dataSource, QuerySegmentSpec querySegmentSpec, - Map context + Map context ) { Preconditions.checkNotNull(dataSource, "dataSource can't be null"); @@ -102,28 +102,28 @@ public abstract class BaseQuery implements Query } @JsonProperty - public Map getContext() + public Map getContext() { return context; } @Override - public String getContextValue(String key) + public ContextType getContextValue(String key) { - return context == null ? null : context.get(key); + return context == null ? null : (ContextType) context.get(key); } @Override - public String getContextValue(String key, String defaultValue) + public ContextType getContextValue(String key, ContextType defaultValue) { - String retVal = getContextValue(key); + ContextType retVal = getContextValue(key); return retVal == null ? defaultValue : retVal; } - protected Map computeOverridenContext(Map overrides) + protected Map computeOverridenContext(Map overrides) { - Map overridden = Maps.newTreeMap(); - final Map context = getContext(); + Map overridden = Maps.newTreeMap(); + final Map context = getContext(); if (context != null) { overridden.putAll(context); } @@ -135,28 +135,41 @@ public abstract class BaseQuery implements Query @Override public String getId() { - return getContextValue(QUERYID); + return (String) getContextValue(QUERYID); } @Override public Query withId(String id) { - return withOverriddenContext(ImmutableMap.of(QUERYID, id)); + return withOverriddenContext(ImmutableMap.of(QUERYID, id)); } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } BaseQuery baseQuery = (BaseQuery) o; - if (context != null ? !context.equals(baseQuery.context) : baseQuery.context != null) return false; - if (dataSource != null ? !dataSource.equals(baseQuery.dataSource) : baseQuery.dataSource != null) return false; - if (duration != null ? !duration.equals(baseQuery.duration) : baseQuery.duration != null) return false; - if (querySegmentSpec != null ? !querySegmentSpec.equals(baseQuery.querySegmentSpec) : baseQuery.querySegmentSpec != null) + if (context != null ? !context.equals(baseQuery.context) : baseQuery.context != null) { return false; + } + if (dataSource != null ? !dataSource.equals(baseQuery.dataSource) : baseQuery.dataSource != null) { + return false; + } + if (duration != null ? !duration.equals(baseQuery.duration) : baseQuery.duration != null) { + return false; + } + if (querySegmentSpec != null + ? !querySegmentSpec.equals(baseQuery.querySegmentSpec) + : baseQuery.querySegmentSpec != null) { + return false; + } return true; } diff --git a/processing/src/main/java/io/druid/query/BySegmentQueryRunner.java b/processing/src/main/java/io/druid/query/BySegmentQueryRunner.java index 79c6a4e03a9..d6150f63456 100644 --- a/processing/src/main/java/io/druid/query/BySegmentQueryRunner.java +++ b/processing/src/main/java/io/druid/query/BySegmentQueryRunner.java @@ -53,7 +53,7 @@ public class BySegmentQueryRunner implements QueryRunner @SuppressWarnings("unchecked") public Sequence run(final Query query) { - if (Boolean.parseBoolean(query.getContextValue("bySegment"))) { + if (Boolean.parseBoolean(query.getContextValue("bySegment"))) { final Sequence baseSequence = base.run(query); return new Sequence() { diff --git a/processing/src/main/java/io/druid/query/BySegmentSkippingQueryRunner.java b/processing/src/main/java/io/druid/query/BySegmentSkippingQueryRunner.java index 1711fb316f9..8e666c30b16 100644 --- a/processing/src/main/java/io/druid/query/BySegmentSkippingQueryRunner.java +++ b/processing/src/main/java/io/druid/query/BySegmentSkippingQueryRunner.java @@ -37,7 +37,7 @@ public abstract class BySegmentSkippingQueryRunner implements QueryRunner @Override public Sequence run(Query query) { - if (Boolean.parseBoolean(query.getContextValue("bySegment"))) { + if (Boolean.parseBoolean(query.getContextValue("bySegment"))) { return baseRunner.run(query); } diff --git a/processing/src/main/java/io/druid/query/ChainedExecutionQueryRunner.java b/processing/src/main/java/io/druid/query/ChainedExecutionQueryRunner.java index 83d2ff48f98..d3600068a23 100644 --- a/processing/src/main/java/io/druid/query/ChainedExecutionQueryRunner.java +++ b/processing/src/main/java/io/druid/query/ChainedExecutionQueryRunner.java @@ -83,7 +83,7 @@ public class ChainedExecutionQueryRunner implements QueryRunner @Override public Sequence run(final Query query) { - final int priority = Integer.parseInt(query.getContextValue("priority", "0")); + final int priority = Integer.parseInt((String) query.getContextValue("priority", "0")); return new BaseSequence>( new BaseSequence.IteratorMaker>() diff --git a/processing/src/main/java/io/druid/query/Druids.java b/processing/src/main/java/io/druid/query/Druids.java index fd2abd13ab8..3ab6b0a8ff7 100644 --- a/processing/src/main/java/io/druid/query/Druids.java +++ b/processing/src/main/java/io/druid/query/Druids.java @@ -304,7 +304,7 @@ public class Druids private QueryGranularity granularity; private List aggregatorSpecs; private List postAggregatorSpecs; - private Map context; + private Map context; private TimeseriesQueryBuilder() { @@ -384,7 +384,7 @@ public class Druids return postAggregatorSpecs; } - public Map getContext() + public Map getContext() { return context; } @@ -465,7 +465,7 @@ public class Druids return this; } - public TimeseriesQueryBuilder context(Map c) + public TimeseriesQueryBuilder context(Map c) { context = c; return this; @@ -505,7 +505,7 @@ public class Druids private QuerySegmentSpec querySegmentSpec; private List dimensions; private SearchQuerySpec querySpec; - private Map context; + private Map context; public SearchQueryBuilder() { @@ -660,7 +660,7 @@ public class Druids return this; } - public SearchQueryBuilder context(Map c) + public SearchQueryBuilder context(Map c) { context = c; return this; @@ -690,7 +690,7 @@ public class Druids { private DataSource dataSource; private QuerySegmentSpec querySegmentSpec; - private Map context; + private Map context; public TimeBoundaryQueryBuilder() { @@ -746,7 +746,7 @@ public class Druids return this; } - public TimeBoundaryQueryBuilder context(Map c) + public TimeBoundaryQueryBuilder context(Map c) { context = c; return this; diff --git a/processing/src/main/java/io/druid/query/FinalizeResultsQueryRunner.java b/processing/src/main/java/io/druid/query/FinalizeResultsQueryRunner.java index 77823a60730..2880332e184 100644 --- a/processing/src/main/java/io/druid/query/FinalizeResultsQueryRunner.java +++ b/processing/src/main/java/io/druid/query/FinalizeResultsQueryRunner.java @@ -48,7 +48,7 @@ public class FinalizeResultsQueryRunner implements QueryRunner @Override public Sequence run(final Query query) { - final boolean isBySegment = Boolean.parseBoolean(query.getContextValue("bySegment")); + final boolean isBySegment = Boolean.parseBoolean(query.getContextValue("bySegment")); final boolean shouldFinalize = Boolean.parseBoolean(query.getContextValue("finalize", "true")); if (shouldFinalize) { Function finalizerFn; @@ -100,7 +100,7 @@ public class FinalizeResultsQueryRunner implements QueryRunner } return Sequences.map( - baseRunner.run(query.withOverriddenContext(ImmutableMap.of("finalize", "false"))), + baseRunner.run(query.withOverriddenContext(ImmutableMap.of("finalize", "false"))), finalizerFn ); } diff --git a/processing/src/main/java/io/druid/query/GroupByParallelQueryRunner.java b/processing/src/main/java/io/druid/query/GroupByParallelQueryRunner.java index fb98968fb43..10dde9b26ea 100644 --- a/processing/src/main/java/io/druid/query/GroupByParallelQueryRunner.java +++ b/processing/src/main/java/io/druid/query/GroupByParallelQueryRunner.java @@ -83,7 +83,7 @@ public class GroupByParallelQueryRunner implements QueryRunner query, configSupplier.get() ); - final int priority = Integer.parseInt(query.getContextValue("priority", "0")); + final int priority = Integer.parseInt((String) query.getContextValue("priority", "0")); if (Iterables.isEmpty(queryables)) { log.warn("No queryables found."); diff --git a/processing/src/main/java/io/druid/query/Query.java b/processing/src/main/java/io/druid/query/Query.java index d58798539ba..10a84328584 100644 --- a/processing/src/main/java/io/druid/query/Query.java +++ b/processing/src/main/java/io/druid/query/Query.java @@ -70,11 +70,11 @@ public interface Query public Duration getDuration(); - public String getContextValue(String key); + public ContextType getContextValue(String key); - public String getContextValue(String key, String defaultValue); + public ContextType getContextValue(String key, ContextType defaultValue); - public Query withOverriddenContext(Map contextOverride); + public Query withOverriddenContext(Map contextOverride); public Query withQuerySegmentSpec(QuerySegmentSpec spec); diff --git a/processing/src/main/java/io/druid/query/groupby/GroupByQuery.java b/processing/src/main/java/io/druid/query/groupby/GroupByQuery.java index 80322a29531..3f04f30b8aa 100644 --- a/processing/src/main/java/io/druid/query/groupby/GroupByQuery.java +++ b/processing/src/main/java/io/druid/query/groupby/GroupByQuery.java @@ -86,7 +86,7 @@ public class GroupByQuery extends BaseQuery @JsonProperty("having") HavingSpec havingSpec, @JsonProperty("limitSpec") LimitSpec limitSpec, @JsonProperty("orderBy") LimitSpec orderBySpec, - @JsonProperty("context") Map context + @JsonProperty("context") Map context ) { super(dataSource, querySegmentSpec, context); @@ -147,7 +147,7 @@ public class GroupByQuery extends BaseQuery HavingSpec havingSpec, LimitSpec orderBySpec, Function, Sequence> orderByLimitFn, - Map context + Map context ) { super(dataSource, querySegmentSpec, context); @@ -222,7 +222,7 @@ public class GroupByQuery extends BaseQuery } @Override - public GroupByQuery withOverriddenContext(Map contextOverride) + public GroupByQuery withOverriddenContext(Map contextOverride) { return new GroupByQuery( getDataSource(), @@ -268,7 +268,7 @@ public class GroupByQuery extends BaseQuery private List postAggregatorSpecs; private HavingSpec havingSpec; - private Map context; + private Map context; private LimitSpec limitSpec = null; private List orderByColumnSpecs = Lists.newArrayList(); @@ -443,7 +443,7 @@ public class GroupByQuery extends BaseQuery return this; } - public Builder setContext(Map context) + public Builder setContext(Map context) { this.context = context; return this; diff --git a/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java b/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java index 0f032f50121..1b77f2299ba 100644 --- a/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java +++ b/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java @@ -58,7 +58,7 @@ public class GroupByQueryQueryToolChest extends QueryToolChest NO_MERGE_CONTEXT = ImmutableMap.of(GROUP_BY_MERGE_KEY, "false"); + private static final Map NO_MERGE_CONTEXT = ImmutableMap.of(GROUP_BY_MERGE_KEY, "false"); private final Supplier configSupplier; private GroupByQueryEngine engine; // For running the outer query around a subquery @@ -80,7 +80,7 @@ public class GroupByQueryQueryToolChest extends QueryToolChest run(Query input) { - if (Boolean.valueOf(input.getContextValue(GROUP_BY_MERGE_KEY, "true"))) { + if (Boolean.valueOf((String) input.getContextValue(GROUP_BY_MERGE_KEY, "true"))) { return mergeGroupByResults(((GroupByQuery) input).withOverriddenContext(NO_MERGE_CONTEXT), runner); } else { return runner.run(input); diff --git a/processing/src/main/java/io/druid/query/metadata/metadata/SegmentMetadataQuery.java b/processing/src/main/java/io/druid/query/metadata/metadata/SegmentMetadataQuery.java index 4f7d27d2d73..d01a4f4c6a4 100644 --- a/processing/src/main/java/io/druid/query/metadata/metadata/SegmentMetadataQuery.java +++ b/processing/src/main/java/io/druid/query/metadata/metadata/SegmentMetadataQuery.java @@ -40,7 +40,7 @@ public class SegmentMetadataQuery extends BaseQuery @JsonProperty("intervals") QuerySegmentSpec querySegmentSpec, @JsonProperty("toInclude") ColumnIncluderator toInclude, @JsonProperty("merge") Boolean merge, - @JsonProperty("context") Map context + @JsonProperty("context") Map context ) { super(new TableDataSource(dataSource), querySegmentSpec, context); @@ -74,7 +74,7 @@ public class SegmentMetadataQuery extends BaseQuery } @Override - public Query withOverriddenContext(Map contextOverride) + public Query withOverriddenContext(Map contextOverride) { return new SegmentMetadataQuery( ((TableDataSource)getDataSource()).getName(), diff --git a/processing/src/main/java/io/druid/query/search/SearchQueryQueryToolChest.java b/processing/src/main/java/io/druid/query/search/SearchQueryQueryToolChest.java index 59fe269de51..6e14ef1c1f3 100644 --- a/processing/src/main/java/io/druid/query/search/SearchQueryQueryToolChest.java +++ b/processing/src/main/java/io/druid/query/search/SearchQueryQueryToolChest.java @@ -294,7 +294,7 @@ public class SearchQueryQueryToolChest extends QueryToolChest> @JsonProperty("searchDimensions") List dimensions, @JsonProperty("query") SearchQuerySpec querySpec, @JsonProperty("sort") SearchSortSpec sortSpec, - @JsonProperty("context") Map context + @JsonProperty("context") Map context ) { super(dataSource, querySegmentSpec, context); @@ -112,7 +112,7 @@ public class SearchQuery extends BaseQuery> } @Override - public SearchQuery withOverriddenContext(Map contextOverrides) + public SearchQuery withOverriddenContext(Map contextOverrides) { return new SearchQuery( getDataSource(), diff --git a/processing/src/main/java/io/druid/query/select/SelectQuery.java b/processing/src/main/java/io/druid/query/select/SelectQuery.java index bcd29cb7f96..7556006734f 100644 --- a/processing/src/main/java/io/druid/query/select/SelectQuery.java +++ b/processing/src/main/java/io/druid/query/select/SelectQuery.java @@ -53,7 +53,7 @@ public class SelectQuery extends BaseQuery> @JsonProperty("dimensions") List dimensions, @JsonProperty("metrics") List metrics, @JsonProperty("pagingSpec") PagingSpec pagingSpec, - @JsonProperty("context") Map context + @JsonProperty("context") Map context ) { super(dataSource, querySegmentSpec, context); @@ -120,7 +120,7 @@ public class SelectQuery extends BaseQuery> ); } - public SelectQuery withOverriddenContext(Map contextOverrides) + public SelectQuery withOverriddenContext(Map contextOverrides) { return new SelectQuery( getDataSource(), diff --git a/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java b/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java index bad00f2bb87..357854f1958 100644 --- a/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java +++ b/processing/src/main/java/io/druid/query/timeboundary/TimeBoundaryQuery.java @@ -54,7 +54,7 @@ public class TimeBoundaryQuery extends BaseQuery public TimeBoundaryQuery( @JsonProperty("dataSource") DataSource dataSource, @JsonProperty("intervals") QuerySegmentSpec querySegmentSpec, - @JsonProperty("context") Map context + @JsonProperty("context") Map context ) { super( @@ -78,7 +78,7 @@ public class TimeBoundaryQuery extends BaseQuery } @Override - public TimeBoundaryQuery withOverriddenContext(Map contextOverrides) + public TimeBoundaryQuery withOverriddenContext(Map contextOverrides) { return new TimeBoundaryQuery( getDataSource(), diff --git a/processing/src/main/java/io/druid/query/timeseries/TimeseriesQuery.java b/processing/src/main/java/io/druid/query/timeseries/TimeseriesQuery.java index a1de320f5ec..3a03018a63e 100644 --- a/processing/src/main/java/io/druid/query/timeseries/TimeseriesQuery.java +++ b/processing/src/main/java/io/druid/query/timeseries/TimeseriesQuery.java @@ -55,7 +55,7 @@ public class TimeseriesQuery extends BaseQuery> @JsonProperty("granularity") QueryGranularity granularity, @JsonProperty("aggregations") List aggregatorSpecs, @JsonProperty("postAggregations") List postAggregatorSpecs, - @JsonProperty("context") Map context + @JsonProperty("context") Map context ) { super(dataSource, querySegmentSpec, context); @@ -116,7 +116,7 @@ public class TimeseriesQuery extends BaseQuery> ); } - public TimeseriesQuery withOverriddenContext(Map contextOverrides) + public TimeseriesQuery withOverriddenContext(Map contextOverrides) { return new TimeseriesQuery( getDataSource(), diff --git a/processing/src/main/java/io/druid/query/topn/TopNQuery.java b/processing/src/main/java/io/druid/query/topn/TopNQuery.java index dc59a663b2c..0e7a796d045 100644 --- a/processing/src/main/java/io/druid/query/topn/TopNQuery.java +++ b/processing/src/main/java/io/druid/query/topn/TopNQuery.java @@ -62,7 +62,7 @@ public class TopNQuery extends BaseQuery> @JsonProperty("granularity") QueryGranularity granularity, @JsonProperty("aggregations") List aggregatorSpecs, @JsonProperty("postAggregations") List postAggregatorSpecs, - @JsonProperty("context") Map context + @JsonProperty("context") Map context ) { super(dataSource, querySegmentSpec, context); @@ -178,7 +178,7 @@ public class TopNQuery extends BaseQuery> ); } - public TopNQuery withOverriddenContext(Map contextOverrides) + public TopNQuery withOverriddenContext(Map contextOverrides) { return new TopNQuery( getDataSource(), diff --git a/processing/src/main/java/io/druid/query/topn/TopNQueryBuilder.java b/processing/src/main/java/io/druid/query/topn/TopNQueryBuilder.java index 21efd3b8351..8f78ffe6191 100644 --- a/processing/src/main/java/io/druid/query/topn/TopNQueryBuilder.java +++ b/processing/src/main/java/io/druid/query/topn/TopNQueryBuilder.java @@ -69,7 +69,7 @@ public class TopNQueryBuilder private QueryGranularity granularity; private List aggregatorSpecs; private List postAggregatorSpecs; - private Map context; + private Map context; public TopNQueryBuilder() { @@ -130,7 +130,7 @@ public class TopNQueryBuilder return postAggregatorSpecs; } - public Map getContext() + public Map getContext() { return context; } @@ -290,7 +290,7 @@ public class TopNQueryBuilder return this; } - public TopNQueryBuilder context(Map c) + public TopNQueryBuilder context(Map c) { context = c; return this; diff --git a/processing/src/main/java/io/druid/query/topn/TopNQueryQueryToolChest.java b/processing/src/main/java/io/druid/query/topn/TopNQueryQueryToolChest.java index 6f0400a1f1b..a7d77fde396 100644 --- a/processing/src/main/java/io/druid/query/topn/TopNQueryQueryToolChest.java +++ b/processing/src/main/java/io/druid/query/topn/TopNQueryQueryToolChest.java @@ -339,7 +339,7 @@ public class TopNQueryQueryToolChest extends QueryToolChest implements QueryRunner final List> cachedResults = Lists.newArrayList(); final Map cachePopulatorMap = Maps.newHashMap(); - final boolean useCache = Boolean.parseBoolean(query.getContextValue("useCache", "true")) && strategy != null; - final boolean populateCache = Boolean.parseBoolean(query.getContextValue("populateCache", "true")) + final boolean useCache = Boolean.parseBoolean((String) query.getContextValue("useCache", "true")) && strategy != null; + final boolean populateCache = Boolean.parseBoolean((String) query.getContextValue("populateCache", "true")) && strategy != null; - final boolean isBySegment = Boolean.parseBoolean(query.getContextValue("bySegment", "false")); + final boolean isBySegment = Boolean.parseBoolean((String) query.getContextValue("bySegment", "false")); - ImmutableMap.Builder contextBuilder = new ImmutableMap.Builder<>(); + ImmutableMap.Builder contextBuilder = new ImmutableMap.Builder<>(); - final String priority = query.getContextValue("priority", "0"); + final String priority = (String) query.getContextValue("priority", "0"); contextBuilder.put("priority", priority); if (populateCache) { diff --git a/server/src/test/java/io/druid/client/CachingClusteredClientTest.java b/server/src/test/java/io/druid/client/CachingClusteredClientTest.java index 40045ec8fa7..f1cd1451a78 100644 --- a/server/src/test/java/io/druid/client/CachingClusteredClientTest.java +++ b/server/src/test/java/io/druid/client/CachingClusteredClientTest.java @@ -121,7 +121,7 @@ public class CachingClusteredClientTest */ private static final int RANDOMNESS = 10; - public static final ImmutableMap CONTEXT = ImmutableMap.of(); + public static final ImmutableMap CONTEXT = ImmutableMap.of(); public static final MultipleIntervalSegmentSpec SEG_SPEC = new MultipleIntervalSegmentSpec(ImmutableList.of()); public static final String DATA_SOURCE = "test"; @@ -325,7 +325,7 @@ public class CachingClusteredClientTest testQueryCaching( 1, true, - builder.context(ImmutableMap.of("useCache", "false", + builder.context(ImmutableMap.of("useCache", "false", "populateCache", "true")).build(), new Interval("2011-01-01/2011-01-02"), makeTimeResults(new DateTime("2011-01-01"), 50, 5000) ); @@ -339,7 +339,7 @@ public class CachingClusteredClientTest testQueryCaching( 1, false, - builder.context(ImmutableMap.of("useCache", "false", + builder.context(ImmutableMap.of("useCache", "false", "populateCache", "false")).build(), new Interval("2011-01-01/2011-01-02"), makeTimeResults(new DateTime("2011-01-01"), 50, 5000) ); @@ -351,7 +351,7 @@ public class CachingClusteredClientTest testQueryCaching( 1, false, - builder.context(ImmutableMap.of("useCache", "true", + builder.context(ImmutableMap.of("useCache", "true", "populateCache", "false")).build(), new Interval("2011-01-01/2011-01-02"), makeTimeResults(new DateTime("2011-01-01"), 50, 5000) );