From 708bc674fa8ca67dc4c9e714649ba34acb1b39a8 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Tue, 8 Mar 2016 19:37:12 -0800 Subject: [PATCH] Make specifying query context booleans more consistent. Before, some needed to be strings and some needed to be real booleans. Now they can all be either one. --- processing/src/main/java/io/druid/query/BaseQuery.java | 6 ++++++ processing/src/main/java/io/druid/query/Query.java | 2 ++ .../java/io/druid/query/groupby/GroupByQueryHelper.java | 2 +- .../io/druid/query/groupby/GroupByQueryQueryToolChest.java | 2 +- .../java/io/druid/query/timeseries/TimeseriesQuery.java | 2 +- .../src/main/java/io/druid/query/topn/TopNQueryEngine.java | 2 +- .../datasourcemetadata/DataSourceMetadataQueryTest.java | 7 +++++-- .../io/druid/segment/realtime/plumber/RealtimePlumber.java | 2 +- 8 files changed, 18 insertions(+), 7 deletions(-) diff --git a/processing/src/main/java/io/druid/query/BaseQuery.java b/processing/src/main/java/io/druid/query/BaseQuery.java index 9a8629b50ad..69f297a4861 100644 --- a/processing/src/main/java/io/druid/query/BaseQuery.java +++ b/processing/src/main/java/io/druid/query/BaseQuery.java @@ -193,6 +193,12 @@ public abstract class BaseQuery> implements Query return retVal == null ? defaultValue : retVal; } + @Override + public boolean getContextBoolean(String key, boolean defaultValue) + { + return parseBoolean(this, key, defaultValue); + } + protected Map computeOverridenContext(Map overrides) { Map overridden = Maps.newTreeMap(); diff --git a/processing/src/main/java/io/druid/query/Query.java b/processing/src/main/java/io/druid/query/Query.java index 3cfbfcd4479..e22a3e3ebd9 100644 --- a/processing/src/main/java/io/druid/query/Query.java +++ b/processing/src/main/java/io/druid/query/Query.java @@ -81,6 +81,8 @@ public interface Query ContextType getContextValue(String key, ContextType defaultValue); + boolean getContextBoolean(String key, boolean defaultValue); + boolean isDescending(); Ordering getResultOrdering(); diff --git a/processing/src/main/java/io/druid/query/groupby/GroupByQueryHelper.java b/processing/src/main/java/io/druid/query/groupby/GroupByQueryHelper.java index 2ebd302442d..18dd0274931 100644 --- a/processing/src/main/java/io/druid/query/groupby/GroupByQueryHelper.java +++ b/processing/src/main/java/io/druid/query/groupby/GroupByQueryHelper.java @@ -81,7 +81,7 @@ public class GroupByQueryHelper ); final IncrementalIndex index; - if (query.getContextValue("useOffheap", false)) { + if (query.getContextBoolean("useOffheap", false)) { index = new OffheapIncrementalIndex( // use granularity truncated min timestamp // since incoming truncated timestamps may precede timeStart 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 2a379886518..2b8824ec225 100644 --- a/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java +++ b/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java @@ -130,7 +130,7 @@ public class GroupByQueryQueryToolChest extends QueryToolChest> public boolean isSkipEmptyBuckets() { - return Boolean.parseBoolean(getContextValue("skipEmptyBuckets", "false")); + return getContextBoolean("skipEmptyBuckets", false); } public TimeseriesQuery withQuerySegmentSpec(QuerySegmentSpec querySegmentSpec) diff --git a/processing/src/main/java/io/druid/query/topn/TopNQueryEngine.java b/processing/src/main/java/io/druid/query/topn/TopNQueryEngine.java index 0d5a7c6fe1d..0fd9715dc3b 100644 --- a/processing/src/main/java/io/druid/query/topn/TopNQueryEngine.java +++ b/processing/src/main/java/io/druid/query/topn/TopNQueryEngine.java @@ -119,7 +119,7 @@ public class TopNQueryEngine topNAlgorithm = new DimExtractionTopNAlgorithm(capabilities, query); } else if (selector.isAggregateAllMetrics()) { topNAlgorithm = new PooledTopNAlgorithm(capabilities, query, bufferPool); - } else if (selector.isAggregateTopNMetricFirst() || query.getContextValue("doAggregateTopNMetricFirst", false)) { + } else if (selector.isAggregateTopNMetricFirst() || query.getContextBoolean("doAggregateTopNMetricFirst", false)) { topNAlgorithm = new AggregateTopNMetricFirstAlgorithm(capabilities, query, bufferPool); } else { topNAlgorithm = new PooledTopNAlgorithm(capabilities, query, bufferPool); diff --git a/processing/src/test/java/io/druid/query/datasourcemetadata/DataSourceMetadataQueryTest.java b/processing/src/test/java/io/druid/query/datasourcemetadata/DataSourceMetadataQueryTest.java index 7dbcd81bd5b..bb012e6afb1 100644 --- a/processing/src/test/java/io/druid/query/datasourcemetadata/DataSourceMetadataQueryTest.java +++ b/processing/src/test/java/io/druid/query/datasourcemetadata/DataSourceMetadataQueryTest.java @@ -81,7 +81,7 @@ public class DataSourceMetadataQueryTest "useCache", true, "populateCache", - true, + "true", "finalize", true ) @@ -101,8 +101,11 @@ public class DataSourceMetadataQueryTest Assert.assertEquals(1, serdeQuery.getContextValue("priority")); Assert.assertEquals(true, serdeQuery.getContextValue("useCache")); - Assert.assertEquals(true, serdeQuery.getContextValue("populateCache")); + Assert.assertEquals("true", serdeQuery.getContextValue("populateCache")); Assert.assertEquals(true, serdeQuery.getContextValue("finalize")); + Assert.assertEquals(true, serdeQuery.getContextBoolean("useCache", false)); + Assert.assertEquals(true, serdeQuery.getContextBoolean("populateCache", false)); + Assert.assertEquals(true, serdeQuery.getContextBoolean("finalize", false)); } @Test diff --git a/server/src/main/java/io/druid/segment/realtime/plumber/RealtimePlumber.java b/server/src/main/java/io/druid/segment/realtime/plumber/RealtimePlumber.java index 035fee63aed..9bc9d4ab14e 100644 --- a/server/src/main/java/io/druid/segment/realtime/plumber/RealtimePlumber.java +++ b/server/src/main/java/io/druid/segment/realtime/plumber/RealtimePlumber.java @@ -266,7 +266,7 @@ public class RealtimePlumber implements Plumber @Override public QueryRunner getQueryRunner(final Query query) { - final boolean skipIncrementalSegment = query.getContextValue(SKIP_INCREMENTAL_SEGMENT, false); + final boolean skipIncrementalSegment = query.getContextBoolean(SKIP_INCREMENTAL_SEGMENT, false); final QueryRunnerFactory> factory = conglomerate.findFactory(query); final QueryToolChest> toolchest = factory.getToolchest();