Class DataSourceQueryQueryToolChest
- java.lang.Object
-
- org.apache.druid.query.QueryToolChest<Result<DataSourceMetadataResultValue>,DataSourceMetadataQuery>
-
- org.apache.druid.query.datasourcemetadata.DataSourceQueryQueryToolChest
-
public class DataSourceQueryQueryToolChest extends QueryToolChest<Result<DataSourceMetadataResultValue>,DataSourceMetadataQuery>
-
-
Constructor Summary
Constructors Constructor Description DataSourceQueryQueryToolChest(GenericQueryMetricsFactory queryMetricsFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends LogicalSegment>
List<T>filterSegments(DataSourceMetadataQuery query, List<T> segments)This method is called to allow the query to prune segments that it does not believe need to actually be queried.CacheStrategygetCacheStrategy(DataSourceMetadataQuery query)LikeQueryToolChest.getCacheStrategy(Query, ObjectMapper)but the caller doesn't supply the object mapper for deserializing and converting the cached data to desired type.CacheStrategygetCacheStrategy(DataSourceMetadataQuery query, com.fasterxml.jackson.databind.ObjectMapper mapper)Returns a CacheStrategy to be used to load data into the cache and remove it from the cache.com.fasterxml.jackson.core.type.TypeReference<Result<DataSourceMetadataResultValue>>getResultTypeReference()Returns a TypeReference object that is just passed through to Jackson in order to deserialize the results of this type of query.QueryMetrics<Query<?>>makeMetrics(DataSourceMetadataQuery query)Creates aQueryMetricsobject that is used to generate metrics for this specific query type.com.google.common.base.Function<Result<DataSourceMetadataResultValue>,Result<DataSourceMetadataResultValue>>makePreComputeManipulatorFn(DataSourceMetadataQuery query, MetricManipulationFn fn)Creates a Function that can take in a ResultType and return a new ResultType having applied the MetricManipulatorFn to each of the metrics.QueryRunner<Result<DataSourceMetadataResultValue>>mergeResults(QueryRunner<Result<DataSourceMetadataResultValue>> runner)This method wraps a QueryRunner.-
Methods inherited from class org.apache.druid.query.QueryToolChest
canExecuteFully, canPerformSubquery, createMergeFn, createResultComparator, decorateObjectMapper, getBaseResultType, getBySegmentResultType, makePostComputeManipulatorFn, mergeResults, postMergeQueryDecoration, preMergeQueryDecoration, resultArraySignature, resultsAsArrays, resultsAsFrames
-
-
-
-
Constructor Detail
-
DataSourceQueryQueryToolChest
@Inject public DataSourceQueryQueryToolChest(GenericQueryMetricsFactory queryMetricsFactory)
-
-
Method Detail
-
filterSegments
public <T extends LogicalSegment> List<T> filterSegments(DataSourceMetadataQuery query, List<T> segments)
Description copied from class:QueryToolChestThis method is called to allow the query to prune segments that it does not believe need to actually be queried. It can use whatever criteria it wants in order to do the pruning, it just needs to return the list of Segments it actually wants to see queried.- Overrides:
filterSegmentsin classQueryToolChest<Result<DataSourceMetadataResultValue>,DataSourceMetadataQuery>- Type Parameters:
T- A Generic parameter because Java is cool- Parameters:
query- The query being processedsegments- The list of candidate segments to be queried- Returns:
- The list of segments to actually query
-
mergeResults
public QueryRunner<Result<DataSourceMetadataResultValue>> mergeResults(QueryRunner<Result<DataSourceMetadataResultValue>> runner)
Description copied from class:QueryToolChestThis method wraps a QueryRunner. The input QueryRunner, by contract, will provide a series of ResultType objects in time order (ascending or descending). This method should return a new QueryRunner that merges the stream of ordered ResultType objects.A default implementation constructs a
ResultMergeQueryRunnerwhich creates aCombiningSequenceusing the suppliedQueryRunnerwithQueryToolChest.createResultComparator(Query)andQueryToolChest.createMergeFn(Query)} supplied by this toolchest.Generally speaking, the logic that exists in makePostComputeManipulatorFn should actually exist in this method. Additionally, if a query supports PostAggregations, this method should take steps to ensure that it computes PostAggregations a minimum number of times. This is most commonly achieved by computing the PostAgg results during merge and also rewriting the query such that it has the minimum number of PostAggs (most often zero).
- Overrides:
mergeResultsin classQueryToolChest<Result<DataSourceMetadataResultValue>,DataSourceMetadataQuery>- Parameters:
runner- A QueryRunner that provides a series of ResultType objects in time order (ascending or descending)- Returns:
- a QueryRunner that merges the stream of ordered ResultType objects
-
makeMetrics
public QueryMetrics<Query<?>> makeMetrics(DataSourceMetadataQuery query)
Description copied from class:QueryToolChestCreates aQueryMetricsobject that is used to generate metrics for this specific query type. This exists to allow for query-specific dimensions and metrics. That is, the ToolChest is expected to set some meaningful dimensions for metrics given this query type. Examples might be the topN threshold for a TopN query or the number of dimensions included for a groupBy query.QueryToolChests for query types in core (druid-processing) and public extensions (belonging to the Druid source tree) should use delegate this method to
GenericQueryMetricsFactory.makeMetrics(Query)on an injected instance ofGenericQueryMetricsFactory, as long as they don't need to emit custom dimensions and/or metrics.If some custom dimensions and/or metrics should be emitted for a query type, a plan described in "Making subinterfaces of QueryMetrics" section in
QueryMetrics's class-level Javadocs should be followed.One way or another, this method should ensure that
QueryMetrics.query(Query)is called with the given query passed on the created QueryMetrics object before returning.- Specified by:
makeMetricsin classQueryToolChest<Result<DataSourceMetadataResultValue>,DataSourceMetadataQuery>- Parameters:
query- The query that is being processed- Returns:
- A QueryMetrics that can be used to make metrics for the provided query
-
makePreComputeManipulatorFn
public com.google.common.base.Function<Result<DataSourceMetadataResultValue>,Result<DataSourceMetadataResultValue>> makePreComputeManipulatorFn(DataSourceMetadataQuery query, MetricManipulationFn fn)
Description copied from class:QueryToolChestCreates a Function that can take in a ResultType and return a new ResultType having applied the MetricManipulatorFn to each of the metrics.This function's primary purpose is to help work around some challenges that exist around deserializing results across the wire. Specifically, different aggregators will generate different object types in a result set, if we wanted jackson to be able to deserialize these directly, we'd need to generate a response class for each query that jackson could use to deserialize things. That is not what we do. Instead, we have jackson deserialize Object instances and then use a MetricManipulatorFn to convert from those object instances to the actual object that the aggregator expects. As such, this would be more effectively named "makeObjectDeserializingFn".
It is safe and acceptable for implementations of this method to first validate that the MetricManipulationFn is
MetricManipulatorFns.DESERIALIZING_INSTANCEand throw an exception if it is not. If such an exception is ever thrown, it is indicative of a bug in the caller which should be fixed by not calling this method with anything other than the deserializing manipulator function.There are some implementations where this was also tasked with computing PostAggregators, but this is actually not a good place to compute those as this function can be called in a number of cases when PostAggs are not really meaningful to compute. Instead, PostAggs should be computed in the mergeResults call and the mergeResults implementation should take care to ensure that PostAggs are only computed the minimum number of times necessary.
This function is called very early in the processing pipeline on the Broker.
- Specified by:
makePreComputeManipulatorFnin classQueryToolChest<Result<DataSourceMetadataResultValue>,DataSourceMetadataQuery>- Parameters:
query- The Query that is currently being processedfn- The function that should be applied to all metrics in the results- Returns:
- A function that will apply the provided fn to all metrics in the input ResultType object
-
getResultTypeReference
public com.fasterxml.jackson.core.type.TypeReference<Result<DataSourceMetadataResultValue>> getResultTypeReference()
Description copied from class:QueryToolChestReturns a TypeReference object that is just passed through to Jackson in order to deserialize the results of this type of query.- Specified by:
getResultTypeReferencein classQueryToolChest<Result<DataSourceMetadataResultValue>,DataSourceMetadataQuery>- Returns:
- A TypeReference to indicate to Jackson what type of data will exist for this query
-
getCacheStrategy
public CacheStrategy getCacheStrategy(DataSourceMetadataQuery query)
Description copied from class:QueryToolChestLikeQueryToolChest.getCacheStrategy(Query, ObjectMapper)but the caller doesn't supply the object mapper for deserializing and converting the cached data to desired type. It's upto the individual implementations to decide the appropriate action in that case. It can either throw an exception outright or decide if the query requires the object mapper for proper downstream processing and work with the generic java types if not.- Overrides:
getCacheStrategyin classQueryToolChest<Result<DataSourceMetadataResultValue>,DataSourceMetadataQuery>
-
getCacheStrategy
public CacheStrategy getCacheStrategy(DataSourceMetadataQuery query, @Nullable com.fasterxml.jackson.databind.ObjectMapper mapper)
Description copied from class:QueryToolChestReturns a CacheStrategy to be used to load data into the cache and remove it from the cache.This is optional. If it returns null, caching is effectively disabled for the query.
- Overrides:
getCacheStrategyin classQueryToolChest<Result<DataSourceMetadataResultValue>,DataSourceMetadataQuery>- Parameters:
query- The query whose results might be cachedmapper- Object mapper to convert the deserialized generic java objects to desired types. It can be nullable to preserve backward compatibility.- Returns:
- A CacheStrategy that can be used to populate and read from the Cache
-
-