Skip to content

Commit

Permalink
Restore backwards compatibility of Query. (apache#4185)
Browse files Browse the repository at this point in the history
  • Loading branch information
gianm authored and leventov committed Apr 19, 2017
1 parent 5b69f2e commit 60caa64
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
6 changes: 0 additions & 6 deletions processing/src/main/java/io/druid/query/BaseQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,6 @@ public Query withId(String id)
return withOverriddenContext(ImmutableMap.<String, Object>of(QUERYID, id));
}

@Override
public Query<T> withDefaultTimeout(long defaultTimeout)
{
return withOverriddenContext(ImmutableMap.of(QueryContexts.DEFAULT_TIMEOUT_KEY, defaultTimeout));
}

@Override
public boolean equals(Object o)
{
Expand Down
2 changes: 0 additions & 2 deletions processing/src/main/java/io/druid/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,4 @@ public interface Query<T>
String getId();

Query<T> withDataSource(DataSource dataSource);

Query<T> withDefaultTimeout(long defaultTimeout);
}
6 changes: 6 additions & 0 deletions processing/src/main/java/io/druid/query/QueryContexts.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.druid.query;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import io.druid.java.util.common.ISE;

public class QueryContexts
Expand Down Expand Up @@ -114,6 +115,11 @@ public static <T> long getTimeout(Query<T> query, long defaultTimeout)
return timeout;
}

public static <T> Query<T> withDefaultTimeout(Query<T> query, long defaultTimeout)
{
return query.withOverriddenContext(ImmutableMap.of(QueryContexts.DEFAULT_TIMEOUT_KEY, defaultTimeout));
}

static <T> long getDefaultTimeout(Query<T> query)
{
final long defaultTimeout = parseLong(query, DEFAULT_TIMEOUT_KEY, DEFAULT_TIMEOUT_MILLIS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void testEmptyQueryTimeout()
);
Assert.assertEquals(300_000, QueryContexts.getTimeout(query));

query = query.withDefaultTimeout(60_000);
query = QueryContexts.withDefaultTimeout(query, 60_000);
Assert.assertEquals(60_000, QueryContexts.getTimeout(query));
}

Expand All @@ -121,7 +121,7 @@ public void testQueryTimeout()
);
Assert.assertEquals(1000, QueryContexts.getTimeout(query));

query = query.withDefaultTimeout(1_000_000);
query = QueryContexts.withDefaultTimeout(query, 1_000_000);
Assert.assertEquals(1000, QueryContexts.getTimeout(query));
}
}
3 changes: 2 additions & 1 deletion server/src/main/java/io/druid/server/QueryResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import io.druid.query.DruidMetrics;
import io.druid.query.GenericQueryMetricsFactory;
import io.druid.query.Query;
import io.druid.query.QueryContexts;
import io.druid.query.QueryInterruptedException;
import io.druid.query.QueryMetrics;
import io.druid.query.QuerySegmentWalker;
Expand Down Expand Up @@ -190,7 +191,7 @@ public Response doPost(
queryId = UUID.randomUUID().toString();
query = query.withId(queryId);
}
query = query.withDefaultTimeout(config.getDefaultQueryTimeout());
query = QueryContexts.withDefaultTimeout(query, config.getDefaultQueryTimeout());

toolChest = warehouse.getToolChest(query);

Expand Down

0 comments on commit 60caa64

Please sign in to comment.