Class QueryLogicCompatToolChest
- java.lang.Object
-
- org.apache.druid.query.QueryToolChest<Object,Query<Object>>
-
- org.apache.druid.query.QueryLogicCompatToolChest
-
public class QueryLogicCompatToolChest extends QueryToolChest<Object,Query<Object>>
-
-
Constructor Summary
Constructors Constructor Description QueryLogicCompatToolChest(RowSignature resultRowSignature)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.fasterxml.jackson.core.type.TypeReference<Object>getResultTypeReference()Returns a TypeReference object that is just passed through to Jackson in order to deserialize the results of this type of query.QueryMetrics<? super Query<Object>>makeMetrics(Query<Object> query)Creates aQueryMetricsobject that is used to generate metrics for this specific query type.com.google.common.base.Function<Object,Object>makePreComputeManipulatorFn(Query<Object> 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.RowSignatureresultArraySignature(Query<Object> query)Returns aRowSignaturefor the arrays returned byQueryToolChest.resultsAsArrays(QueryType, org.apache.druid.java.util.common.guava.Sequence<ResultType>).Sequence<Object[]>resultsAsArrays(Query<Object> query, Sequence<Object> resultSequence)Converts a sequence of this query's ResultType into arrays.Optional<Sequence<FrameSignaturePair>>resultsAsFrames(Query<Object> query, Sequence<Object> resultSequence, MemoryAllocatorFactory memoryAllocatorFactory, boolean useNestedForUnknownTypes)Converts a sequence of this query's ResultType into a sequence ofFrameSignaturePair.-
Methods inherited from class org.apache.druid.query.QueryToolChest
canExecuteFully, canPerformSubquery, createMergeFn, createResultComparator, decorateObjectMapper, filterSegments, getBaseResultType, getBySegmentResultType, getCacheStrategy, getCacheStrategy, makePostComputeManipulatorFn, mergeResults, mergeResults, postMergeQueryDecoration, preMergeQueryDecoration
-
-
-
-
Constructor Detail
-
QueryLogicCompatToolChest
public QueryLogicCompatToolChest(RowSignature resultRowSignature)
-
-
Method Detail
-
resultArraySignature
public RowSignature resultArraySignature(Query<Object> query)
Description copied from class:QueryToolChestReturns aRowSignaturefor the arrays returned byQueryToolChest.resultsAsArrays(QueryType, org.apache.druid.java.util.common.guava.Sequence<ResultType>). The returned signature will be the same length as each array returned byQueryToolChest.resultsAsArrays(QueryType, org.apache.druid.java.util.common.guava.Sequence<ResultType>).- Overrides:
resultArraySignaturein classQueryToolChest<Object,Query<Object>>- Parameters:
query- same query passed toQueryToolChest.resultsAsArrays(QueryType, org.apache.druid.java.util.common.guava.Sequence<ResultType>)- Returns:
- row signature
-
makeMetrics
public QueryMetrics<? super Query<Object>> makeMetrics(Query<Object> 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<Object,Query<Object>>- 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<Object,Object> makePreComputeManipulatorFn(Query<Object> 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<Object,Query<Object>>- 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<Object> 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<Object,Query<Object>>- Returns:
- A TypeReference to indicate to Jackson what type of data will exist for this query
-
resultsAsArrays
public Sequence<Object[]> resultsAsArrays(Query<Object> query, Sequence<Object> resultSequence)
Description copied from class:QueryToolChestConverts a sequence of this query's ResultType into arrays. The array signature is given byQueryToolChest.resultArraySignature(QueryType). This functionality is useful because it allows higher-level processors to operate on the results of any query in a consistent way. This is useful for the SQL layer and for any algorithm that might operate on the results of an inner query.Not all query types support this method. They will throw
UnsupportedOperationException, and they cannot be used by the SQL layer or by generic higher-level algorithms.Some query types return less information after translating their results into arrays, especially in situations where there is no clear way to translate fully rich results into flat arrays. For example, the scan query does not include the segmentId in its array-based results, because it could potentially conflict with a 'segmentId' field in the actual datasource being scanned.
It is possible that there will be multiple arrays returned for a single result object. For example, in the topN query, each
TopNResultValuewill generate a separate array for each of itsvalues.By convention, the array form should include the __time column, if present, as a long (milliseconds since epoch).
- Overrides:
resultsAsArraysin classQueryToolChest<Object,Query<Object>>resultSequence- results of the form returned byQueryToolChest.mergeResults(org.apache.druid.query.QueryRunner<ResultType>)- Returns:
- results in array form
-
resultsAsFrames
public Optional<Sequence<FrameSignaturePair>> resultsAsFrames(Query<Object> query, Sequence<Object> resultSequence, MemoryAllocatorFactory memoryAllocatorFactory, boolean useNestedForUnknownTypes)
Description copied from class:QueryToolChestConverts a sequence of this query's ResultType into a sequence ofFrameSignaturePair. The array signature is the one give byQueryToolChest.resultArraySignature(Query). If the toolchest doesn't support this method, then it can return an empty optional. It is the duty of the callees to throw an appropriate exception in that case or use an alternative fallback approachCheck documentation of
QueryToolChest.resultsAsArrays(Query, Sequence)as the behaviour of the rows represented by the frame sequence is identical.Each Frame has a separate
RowSignaturebecause for some query types like the Scan query, every column in the final result might not be present in the individual ResultType (and subsequently Frame). Therefore, this is done to preserve the space by not populating the column in that particular Frame and omitting it from its signature- Overrides:
resultsAsFramesin classQueryToolChest<Object,Query<Object>>- Parameters:
query- Query being executed by the toolchest. Used to determine the rowSignature of the FramesresultSequence- results of the form returned byQueryToolChest.mergeResults(QueryRunner)useNestedForUnknownTypes- true if the unknown types in the results can be serded using complex types
-
-