mirror of https://github.com/apache/druid.git
remove isDescending from Query interface, move to TimeseriesQuery (#16917)
* remove isDescending from Query interface, since it is only actually settable and usable by TimeseriesQuery
This commit is contained in:
parent
fb7103ccef
commit
518f642028
|
@ -146,12 +146,6 @@ public class MaterializedViewQuery<T> implements Query<T>
|
||||||
return query.getContext();
|
return query.getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDescending()
|
|
||||||
{
|
|
||||||
return query.isDescending();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Ordering<T> getResultOrdering()
|
public Ordering<T> getResultOrdering()
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,7 +57,6 @@ public abstract class BaseQuery<T> implements Query<T>
|
||||||
public static final String SUB_QUERY_ID = "subQueryId";
|
public static final String SUB_QUERY_ID = "subQueryId";
|
||||||
public static final String SQL_QUERY_ID = "sqlQueryId";
|
public static final String SQL_QUERY_ID = "sqlQueryId";
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
private final boolean descending;
|
|
||||||
private final QueryContext context;
|
private final QueryContext context;
|
||||||
private final QuerySegmentSpec querySegmentSpec;
|
private final QuerySegmentSpec querySegmentSpec;
|
||||||
private volatile Duration duration;
|
private volatile Duration duration;
|
||||||
|
@ -69,13 +68,12 @@ public abstract class BaseQuery<T> implements Query<T>
|
||||||
Map<String, Object> context
|
Map<String, Object> context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this(dataSource, querySegmentSpec, false, context, Granularities.ALL);
|
this(dataSource, querySegmentSpec, context, Granularities.ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseQuery(
|
public BaseQuery(
|
||||||
DataSource dataSource,
|
DataSource dataSource,
|
||||||
QuerySegmentSpec querySegmentSpec,
|
QuerySegmentSpec querySegmentSpec,
|
||||||
boolean descending,
|
|
||||||
Map<String, Object> context,
|
Map<String, Object> context,
|
||||||
Granularity granularity
|
Granularity granularity
|
||||||
)
|
)
|
||||||
|
@ -87,7 +85,6 @@ public abstract class BaseQuery<T> implements Query<T>
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.context = QueryContext.of(context);
|
this.context = QueryContext.of(context);
|
||||||
this.querySegmentSpec = querySegmentSpec;
|
this.querySegmentSpec = querySegmentSpec;
|
||||||
this.descending = descending;
|
|
||||||
this.granularity = granularity;
|
this.granularity = granularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,14 +95,6 @@ public abstract class BaseQuery<T> implements Query<T>
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
@Override
|
|
||||||
@JsonInclude(Include.NON_DEFAULT)
|
|
||||||
public boolean isDescending()
|
|
||||||
{
|
|
||||||
return descending;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonProperty("intervals")
|
@JsonProperty("intervals")
|
||||||
public QuerySegmentSpec getQuerySegmentSpec()
|
public QuerySegmentSpec getQuerySegmentSpec()
|
||||||
{
|
{
|
||||||
|
@ -205,8 +194,7 @@ public abstract class BaseQuery<T> implements Query<T>
|
||||||
@SuppressWarnings("unchecked") // assumes T is Comparable; see method javadoc
|
@SuppressWarnings("unchecked") // assumes T is Comparable; see method javadoc
|
||||||
public Ordering<T> getResultOrdering()
|
public Ordering<T> getResultOrdering()
|
||||||
{
|
{
|
||||||
Ordering retVal = Ordering.natural();
|
return (Ordering<T>) Ordering.natural();
|
||||||
return descending ? retVal.reverse() : retVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -253,8 +241,7 @@ public abstract class BaseQuery<T> implements Query<T>
|
||||||
BaseQuery<?> baseQuery = (BaseQuery<?>) o;
|
BaseQuery<?> baseQuery = (BaseQuery<?>) o;
|
||||||
|
|
||||||
// Must use getDuration() instead of "duration" because duration is lazily computed.
|
// Must use getDuration() instead of "duration" because duration is lazily computed.
|
||||||
return descending == baseQuery.descending &&
|
return Objects.equals(dataSource, baseQuery.dataSource) &&
|
||||||
Objects.equals(dataSource, baseQuery.dataSource) &&
|
|
||||||
Objects.equals(context, baseQuery.context) &&
|
Objects.equals(context, baseQuery.context) &&
|
||||||
Objects.equals(querySegmentSpec, baseQuery.querySegmentSpec) &&
|
Objects.equals(querySegmentSpec, baseQuery.querySegmentSpec) &&
|
||||||
Objects.equals(getDuration(), baseQuery.getDuration()) &&
|
Objects.equals(getDuration(), baseQuery.getDuration()) &&
|
||||||
|
@ -265,6 +252,6 @@ public abstract class BaseQuery<T> implements Query<T>
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
// Must use getDuration() instead of "duration" because duration is lazily computed.
|
// Must use getDuration() instead of "duration" because duration is lazily computed.
|
||||||
return Objects.hash(dataSource, descending, context, querySegmentSpec, getDuration(), granularity);
|
return Objects.hash(dataSource, context, querySegmentSpec, getDuration(), granularity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,8 +166,6 @@ public interface Query<T>
|
||||||
return context().getHumanReadableBytes(key, defaultValue);
|
return context().getHumanReadableBytes(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isDescending();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comparator that represents the order in which results are generated from the
|
* Comparator that represents the order in which results are generated from the
|
||||||
* {@link QueryRunnerFactory#createRunner(Segment)} and
|
* {@link QueryRunnerFactory#createRunner(Segment)} and
|
||||||
|
|
|
@ -202,7 +202,7 @@ public class GroupByQuery extends BaseQuery<ResultRow>
|
||||||
final Map<String, Object> context
|
final Map<String, Object> context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
super(dataSource, querySegmentSpec, false, context, granularity);
|
super(dataSource, querySegmentSpec, context, granularity);
|
||||||
|
|
||||||
this.virtualColumns = VirtualColumns.nullToEmpty(virtualColumns);
|
this.virtualColumns = VirtualColumns.nullToEmpty(virtualColumns);
|
||||||
this.dimFilter = dimFilter;
|
this.dimFilter = dimFilter;
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class SearchQuery extends BaseQuery<Result<SearchResultValue>>
|
||||||
@JsonProperty("context") Map<String, Object> context
|
@JsonProperty("context") Map<String, Object> context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
super(dataSource, querySegmentSpec, false, context, Granularities.nullToAll(granularity));
|
super(dataSource, querySegmentSpec, context, Granularities.nullToAll(granularity));
|
||||||
Preconditions.checkNotNull(querySegmentSpec, "Must specify an interval");
|
Preconditions.checkNotNull(querySegmentSpec, "Must specify an interval");
|
||||||
|
|
||||||
this.dimFilter = dimFilter;
|
this.dimFilter = dimFilter;
|
||||||
|
|
|
@ -110,12 +110,6 @@ public class SelectQuery implements Query<Object>
|
||||||
throw new RuntimeException(REMOVED_ERROR_MESSAGE);
|
throw new RuntimeException(REMOVED_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDescending()
|
|
||||||
{
|
|
||||||
throw new RuntimeException(REMOVED_ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Ordering<Object> getResultOrdering()
|
public Ordering<Object> getResultOrdering()
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,6 +25,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Ordering;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.druid.java.util.common.granularity.Granularity;
|
import org.apache.druid.java.util.common.granularity.Granularity;
|
||||||
import org.apache.druid.query.BaseQuery;
|
import org.apache.druid.query.BaseQuery;
|
||||||
|
@ -68,6 +69,7 @@ public class TimeseriesQuery extends BaseQuery<Result<TimeseriesResultValue>>
|
||||||
private final DimFilter dimFilter;
|
private final DimFilter dimFilter;
|
||||||
private final List<AggregatorFactory> aggregatorSpecs;
|
private final List<AggregatorFactory> aggregatorSpecs;
|
||||||
private final List<PostAggregator> postAggregatorSpecs;
|
private final List<PostAggregator> postAggregatorSpecs;
|
||||||
|
private final boolean descending;
|
||||||
private final int limit;
|
private final int limit;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
|
@ -84,7 +86,7 @@ public class TimeseriesQuery extends BaseQuery<Result<TimeseriesResultValue>>
|
||||||
@JsonProperty("context") Map<String, Object> context
|
@JsonProperty("context") Map<String, Object> context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
super(dataSource, querySegmentSpec, descending, context, granularity);
|
super(dataSource, querySegmentSpec, context, granularity);
|
||||||
|
|
||||||
// The below should be executed after context is initialized.
|
// The below should be executed after context is initialized.
|
||||||
final String timestampField = getTimestampResultField();
|
final String timestampField = getTimestampResultField();
|
||||||
|
@ -97,6 +99,7 @@ public class TimeseriesQuery extends BaseQuery<Result<TimeseriesResultValue>>
|
||||||
this.aggregatorSpecs,
|
this.aggregatorSpecs,
|
||||||
postAggregatorSpecs == null ? ImmutableList.of() : postAggregatorSpecs
|
postAggregatorSpecs == null ? ImmutableList.of() : postAggregatorSpecs
|
||||||
);
|
);
|
||||||
|
this.descending = descending;
|
||||||
this.limit = (limit == 0) ? Integer.MAX_VALUE : limit;
|
this.limit = (limit == 0) ? Integer.MAX_VALUE : limit;
|
||||||
Preconditions.checkArgument(this.limit > 0, "limit must be greater than 0");
|
Preconditions.checkArgument(this.limit > 0, "limit must be greater than 0");
|
||||||
}
|
}
|
||||||
|
@ -148,6 +151,13 @@ public class TimeseriesQuery extends BaseQuery<Result<TimeseriesResultValue>>
|
||||||
return postAggregatorSpecs;
|
return postAggregatorSpecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
||||||
|
public boolean isDescending()
|
||||||
|
{
|
||||||
|
return descending;
|
||||||
|
}
|
||||||
|
|
||||||
@JsonProperty("limit")
|
@JsonProperty("limit")
|
||||||
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = LimitJsonIncludeFilter.class)
|
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = LimitJsonIncludeFilter.class)
|
||||||
public int getLimit()
|
public int getLimit()
|
||||||
|
@ -155,6 +165,7 @@ public class TimeseriesQuery extends BaseQuery<Result<TimeseriesResultValue>>
|
||||||
return limit;
|
return limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isGrandTotal()
|
public boolean isGrandTotal()
|
||||||
{
|
{
|
||||||
return context().getBoolean(CTX_GRAND_TOTAL, false);
|
return context().getBoolean(CTX_GRAND_TOTAL, false);
|
||||||
|
@ -195,6 +206,13 @@ public class TimeseriesQuery extends BaseQuery<Result<TimeseriesResultValue>>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ordering<Result<TimeseriesResultValue>> getResultOrdering()
|
||||||
|
{
|
||||||
|
Ordering<Result<TimeseriesResultValue>> retVal = Ordering.natural();
|
||||||
|
return descending ? retVal.reverse() : retVal;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TimeseriesQuery withQuerySegmentSpec(QuerySegmentSpec querySegmentSpec)
|
public TimeseriesQuery withQuerySegmentSpec(QuerySegmentSpec querySegmentSpec)
|
||||||
{
|
{
|
||||||
|
|
|
@ -228,7 +228,7 @@ public class TimeseriesQueryQueryToolChest extends QueryToolChest<Result<Timeser
|
||||||
@Override
|
@Override
|
||||||
public Comparator<Result<TimeseriesResultValue>> createResultComparator(Query<Result<TimeseriesResultValue>> query)
|
public Comparator<Result<TimeseriesResultValue>> createResultComparator(Query<Result<TimeseriesResultValue>> query)
|
||||||
{
|
{
|
||||||
return ResultGranularTimestampComparator.create(query.getGranularity(), query.isDescending());
|
return ResultGranularTimestampComparator.create(query.getGranularity(), ((TimeseriesQuery) query).isDescending());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result<TimeseriesResultValue> getNullTimeseriesResultValue(TimeseriesQuery query)
|
private Result<TimeseriesResultValue> getNullTimeseriesResultValue(TimeseriesQuery query)
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class TopNQuery extends BaseQuery<Result<TopNResultValue>>
|
||||||
@JsonProperty("context") Map<String, Object> context
|
@JsonProperty("context") Map<String, Object> context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
super(dataSource, querySegmentSpec, false, context, granularity);
|
super(dataSource, querySegmentSpec, context, granularity);
|
||||||
|
|
||||||
Preconditions.checkNotNull(dimensionSpec, "dimensionSpec can't be null");
|
Preconditions.checkNotNull(dimensionSpec, "dimensionSpec can't be null");
|
||||||
Preconditions.checkNotNull(topNMetricSpec, "must specify a metric");
|
Preconditions.checkNotNull(topNMetricSpec, "must specify a metric");
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class TopNQueryQueryToolChest extends QueryToolChest<Result<TopNResultVal
|
||||||
{
|
{
|
||||||
final ResultMergeQueryRunner<Result<TopNResultValue>> delegateRunner = new ResultMergeQueryRunner<>(
|
final ResultMergeQueryRunner<Result<TopNResultValue>> delegateRunner = new ResultMergeQueryRunner<>(
|
||||||
runner,
|
runner,
|
||||||
query -> ResultGranularTimestampComparator.create(query.getGranularity(), query.isDescending()),
|
query -> ResultGranularTimestampComparator.create(query.getGranularity(), false),
|
||||||
query -> {
|
query -> {
|
||||||
TopNQuery topNQuery = (TopNQuery) query;
|
TopNQuery topNQuery = (TopNQuery) query;
|
||||||
return new TopNBinaryFn(
|
return new TopNBinaryFn(
|
||||||
|
|
|
@ -464,12 +464,6 @@ public class QueryContextTest
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDescending()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Ordering<Integer> getResultOrdering()
|
public Ordering<Integer> getResultOrdering()
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,7 +68,6 @@ public class LoggingRequestLogger implements RequestLogger
|
||||||
MDC.put("hasFilters", Boolean.toString(query.hasFilters()));
|
MDC.put("hasFilters", Boolean.toString(query.hasFilters()));
|
||||||
MDC.put("remoteAddr", requestLogLine.getRemoteAddr());
|
MDC.put("remoteAddr", requestLogLine.getRemoteAddr());
|
||||||
MDC.put("duration", query.getDuration().toString());
|
MDC.put("duration", query.getDuration().toString());
|
||||||
MDC.put("descending", Boolean.toString(query.isDescending()));
|
|
||||||
if (setContextMDC) {
|
if (setContextMDC) {
|
||||||
final Iterable<Map.Entry<String, Object>> entries = query.getContext() == null
|
final Iterable<Map.Entry<String, Object>> entries = query.getContext() == null
|
||||||
? ImmutableList.of()
|
? ImmutableList.of()
|
||||||
|
|
|
@ -219,7 +219,6 @@ public class LoggingRequestLoggerTest
|
||||||
Assert.assertEquals("false", map.get("hasFilters"));
|
Assert.assertEquals("false", map.get("hasFilters"));
|
||||||
Assert.assertEquals("fake", map.get("queryType"));
|
Assert.assertEquals("fake", map.get("queryType"));
|
||||||
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
|
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
|
||||||
Assert.assertEquals("false", map.get("descending"));
|
|
||||||
Assert.assertEquals("false", map.get("isNested"));
|
Assert.assertEquals("false", map.get("isNested"));
|
||||||
Assert.assertNull(map.get("foo"));
|
Assert.assertNull(map.get("foo"));
|
||||||
}
|
}
|
||||||
|
@ -235,7 +234,6 @@ public class LoggingRequestLoggerTest
|
||||||
Assert.assertEquals("false", map.get("hasFilters"));
|
Assert.assertEquals("false", map.get("hasFilters"));
|
||||||
Assert.assertEquals("fake", map.get("queryType"));
|
Assert.assertEquals("fake", map.get("queryType"));
|
||||||
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
|
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
|
||||||
Assert.assertEquals("false", map.get("descending"));
|
|
||||||
Assert.assertEquals("false", map.get("isNested"));
|
Assert.assertEquals("false", map.get("isNested"));
|
||||||
Assert.assertEquals("bar", map.get("foo"));
|
Assert.assertEquals("bar", map.get("foo"));
|
||||||
}
|
}
|
||||||
|
@ -256,7 +254,6 @@ public class LoggingRequestLoggerTest
|
||||||
Assert.assertEquals("false", map.get("hasFilters"));
|
Assert.assertEquals("false", map.get("hasFilters"));
|
||||||
Assert.assertEquals("fake", map.get("queryType"));
|
Assert.assertEquals("fake", map.get("queryType"));
|
||||||
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
|
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
|
||||||
Assert.assertEquals("false", map.get("descending"));
|
|
||||||
Assert.assertEquals("true", map.get("isNested"));
|
Assert.assertEquals("true", map.get("isNested"));
|
||||||
Assert.assertNull(map.get("foo"));
|
Assert.assertNull(map.get("foo"));
|
||||||
}
|
}
|
||||||
|
@ -278,7 +275,6 @@ public class LoggingRequestLoggerTest
|
||||||
Assert.assertEquals("fake", map.get("queryType"));
|
Assert.assertEquals("fake", map.get("queryType"));
|
||||||
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
|
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
|
||||||
Assert.assertEquals("true", map.get("isNested"));
|
Assert.assertEquals("true", map.get("isNested"));
|
||||||
Assert.assertEquals("false", map.get("descending"));
|
|
||||||
Assert.assertNull(map.get("foo"));
|
Assert.assertNull(map.get("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +295,6 @@ public class LoggingRequestLoggerTest
|
||||||
Assert.assertEquals("false", map.get("hasFilters"));
|
Assert.assertEquals("false", map.get("hasFilters"));
|
||||||
Assert.assertEquals("fake", map.get("queryType"));
|
Assert.assertEquals("fake", map.get("queryType"));
|
||||||
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
|
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
|
||||||
Assert.assertEquals("false", map.get("descending"));
|
|
||||||
Assert.assertNull(map.get("foo"));
|
Assert.assertNull(map.get("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue