Restore backwards compatibility of Query. (#4185)

This commit is contained in:
Gian Merlino 2017-04-20 01:47:50 +09:00 committed by Roman Leventov
parent 5b69f2eff2
commit 60caa641f3
5 changed files with 10 additions and 11 deletions

View File

@ -176,12 +176,6 @@ public abstract class BaseQuery<T extends Comparable<T>> implements Query<T>
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)
{

View File

@ -99,6 +99,4 @@ public interface Query<T>
String getId();
Query<T> withDataSource(DataSource dataSource);
Query<T> withDefaultTimeout(long defaultTimeout);
}

View File

@ -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
@ -114,6 +115,11 @@ public class QueryContexts
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);

View File

@ -106,7 +106,7 @@ public class QueryContextsTest
);
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));
}
@ -121,7 +121,7 @@ public class QueryContextsTest
);
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));
}
}

View File

@ -40,6 +40,7 @@ import io.druid.java.util.common.guava.Yielders;
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;
@ -190,7 +191,7 @@ public class QueryResource implements QueryCountStatsProvider
queryId = UUID.randomUUID().toString();
query = query.withId(queryId);
}
query = query.withDefaultTimeout(config.getDefaultQueryTimeout());
query = QueryContexts.withDefaultTimeout(query, config.getDefaultQueryTimeout());
toolChest = warehouse.getToolChest(query);