Package org.apache.druid.query.context
Class ResponseContext
java.lang.Object
org.apache.druid.query.context.ResponseContext
- Direct Known Subclasses:
ConcurrentResponseContext,DefaultResponseContext
The context for storing and passing data between chains of
QueryRunners.
The context is also transferred between Druid nodes with all the data it contains.
The response context consists of a set of key/value pairs. Keys are those defined in
the Keys registry. Keys are indexed by key instance, not by name. The
key defines the type of the associated value, including logic to merge values and
to deserialize JSON values for that key.
Structure
The context has evolved to perform multiple tasks. First, it holds two kinds of information:- Information to be returned in the query response header. These are values tagged as being in the header.
- Values passed within a single server. These are tagged with not being in the header.
- Registers the keys to be used in the header. But, since it also holds internal information, the internal information also needs keys, though the corresponding values are never serialized.
- Gathers information for the query as a whole.
- Merges information back up the query tree: from multiple segments, from multiple servers, etc.
- Manages headers size by dropping fields when the header would get too large.
A result is that the information the context, when inspected by a calling query, may be incomplete if some of it was previously dropped by the called query.
API
The query profile needs to obtain the full, untruncated information. To do this it piggy-backs on the set operations to obtain the full value. To ensure this is possible, code that works with standard values should call the set (or add) functions provided which will do the needed map update.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstract key class which provides most functionality except the type-specific merge logic.static classBoolean valued attribute with the semantics that once the flag is set true, it stays true.static classLong valued attribute that holds the accumulation of values assigned.static interfaceThe base interface of a response context key.static classGlobal registry of response context keys.static classLong valued attribute that holds the latest value assigned.static classSerialization result ofResponseContext.static classString valued attribute that holds the latest value assigned. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(ResponseContext.Key key, Object value) Adds (merges) a new value associated with a key to an old value.voidaddCpuNanos(long ns) voidaddMissingSegments(List<SegmentDescriptor> descriptors) voidaddRemainingResponse(String id, int count) voidaddRowScanCount(long count) static ResponseContextCreate an empty DefaultResponseContext instancestatic ResponseContextdeserialize(String responseContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Deserializes a string intoResponseContextusing givenObjectMapper.get(ResponseContext.Key key) protected abstract Map<ResponseContext.Key, Object> List<org.joda.time.Interval> voidInitialize fields for a query context.voidvoidvoidvoidmerge(ResponseContext responseContext) Merges a response context into the current.put(ResponseContext.Key key, Object value) Associates the specified object with the specified extension key.voidputEntityTag(String eTag) voidputQueryFailDeadlineMs(long deadlineMs) voidputTimeoutTime(long time) voidputUncoveredIntervals(List<org.joda.time.Interval> intervals, boolean overflowed) serializeWith(com.fasterxml.jackson.databind.ObjectMapper objectMapper, int maxCharsNumber) Serializes the context given that the resulting string length is less than the provided limit.toMap()
-
Constructor Details
-
ResponseContext
public ResponseContext()
-
-
Method Details
-
getDelegate
-
toMap
-
createEmpty
Create an empty DefaultResponseContext instance- Returns:
- empty DefaultResponseContext instance
-
initialize
public void initialize()Initialize fields for a query context. Not needed when merging. -
initializeRemainingResponses
public void initializeRemainingResponses() -
initializeMissingSegments
public void initializeMissingSegments() -
initializeRowScanCount
public void initializeRowScanCount() -
deserialize
public static ResponseContext deserialize(String responseContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper) throws IOException Deserializes a string intoResponseContextusing givenObjectMapper.- Throws:
IllegalStateException- if one of the deserialized map keys has not been registered.IOException
-
put
Associates the specified object with the specified extension key.- Throws:
IllegalStateException- if the key has not been registered.
-
putUncoveredIntervals
-
putEntityTag
-
putTimeoutTime
public void putTimeoutTime(long time) -
putQueryFailDeadlineMs
public void putQueryFailDeadlineMs(long deadlineMs) -
get
-
getRemainingResponses
-
getUncoveredIntervals
-
getMissingSegments
-
getEntityTag
-
getTotalBytes
-
getTimeoutTime
-
getRowScanCount
-
getCpuNanos
-
remove
-
add
Adds (merges) a new value associated with a key to an old value. See merge function of a context key for a specific implementation.- Throws:
IllegalStateException- if the key has not been registered.
-
addRemainingResponse
-
addMissingSegments
-
addRowScanCount
public void addRowScanCount(long count) -
addCpuNanos
public void addCpuNanos(long ns) -
merge
Merges a response context into the current.- Throws:
IllegalStateException- If a key of theresponseContexthas not been registered.
-
serializeWith
public ResponseContext.SerializationResult serializeWith(com.fasterxml.jackson.databind.ObjectMapper objectMapper, int maxCharsNumber) throws com.fasterxml.jackson.core.JsonProcessingException Serializes the context given that the resulting string length is less than the provided limit. This method removes some elements from context collections if it's needed to satisfy the limit. There is no explicit priorities of keys which values are being truncated. Any kind of key can be removed, the key's @{code canDrop()} attribute indicates which can be dropped. (The unit tests use a string key.) Thus keys as equally prioritized and starts removing elements from the array which serialized value length is the biggest. The resulting string will be correctly deserialized toResponseContext.- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-