/** * Constructor. * * @param queryType The type of this query * @param dataSource The datasource * @param context The context * @param incrementQueryId true to fork a new context and bump up the query id, or false to create an exact copy * of the context. */ protected AbstractDruidQuery( QueryType queryType, DataSource dataSource, QueryContext context, boolean incrementQueryId ) { this.queryType = queryType; this.dataSource = dataSource; this.context = context == null ? new QueryContext(Collections.<QueryContext.Param, Object>emptyMap(), null) .withQueryId(RequestLog.getId()) : incrementQueryId ? context.fork() : context; }
/** * Copy-mutate the context on the given field with the given value. * * @param param Field to set in the clone * @param value Value to set in the clone * * @return a clone of this context with the new value set */ protected QueryContext withValue(Param param, Object value) { validateField(param, value); Map<Param, Object> values = new HashMap<>(contextMap); if (value == null) { values.remove(param); } else { values.put(param, value); } return new QueryContext(this, values); }
@Override public boolean handleRequest( RequestContext context, DataApiRequest request, DruidAggregationQuery<?> druidQuery, ResponseProcessor response ) { WebServiceHandler handler = handlerSelector.select(druidQuery, request, context); // Add a timeout to the query if the selected webService is configured with one Integer timeout = handler.getWebService().getTimeout(); // Add a priority to the query if there is one configured Integer priority = handler.getWebService().getServiceConfig().getPriority(); QueryContext qc = druidQuery.getContext().withTimeout(timeout).withPriority(priority); if (!qc.isEmpty()) { druidQuery = druidQuery.withContext(qc); } return handler.handleRequest(context, request, druidQuery, response); } }
DruidQuery<?> druidQuery ) { long seqNum = druidQuery.getContext().getSequenceNumber(); String entityBody; RequestLog.startTiming("DruidQuerySerializationSeq" + seqNum); long totalQueries = druidQuery.getContext().getNumberOfQueries(); String format = String.format("%%0%dd", String.valueOf(totalQueries).length()); String timerName;
/** * Constructor. * * @param copy QueryContext to gather sequence number and total queries from * @param contextMap Map of context values to override with */ protected QueryContext(QueryContext copy, Map<Param, Object> contextMap) { // Ensure that all contained context fields are of the correct type for (Map.Entry<Param, Object> entry: contextMap.entrySet()) { validateField(entry.getKey(), entry.getValue()); } // Store an immutable copy this.contextMap = ImmutableMap.copyOf(contextMap); this.totalQueries = copy.totalQueries; this.sequenceNumber = copy.sequenceNumber; }
/** * Fork the QueryContext, cloning the values and continuing the number fo queries. * * @return the forked context */ @JsonIgnore public QueryContext fork() { return new QueryContext(new HashMap<>(contextMap), this.totalQueries); }
/** * Checks and invokes error if the number of missing intervals are overflowed, i.e. more than the configured limit. * * @param json The json object containing the overflow flag * @param query The query with the schema for processing this response */ private void checkOverflow(JsonNode json, DruidAggregationQuery<?> query) { if (json.get(DruidJsonResponseContentKeys.DRUID_RESPONSE_CONTEXT.getName()) .get(DruidJsonResponseContentKeys.UNCOVERED_INTERVALS_OVERFLOWED.getName()) .asBoolean() ) { logAndGetErrorCallback( ErrorMessageFormat.TOO_MANY_INTERVALS_MISSING.format( query.getContext().getUncoveredIntervalsLimit() ), query ); } }
/** * Constructor. * * @param contextMap Map of context values * @param totalQueries Number of queries that this context is attached to */ public QueryContext(Map<Param, Object> contextMap, AtomicLong totalQueries) { // Ensure that all contained context fields are of the correct type for (Map.Entry<Param, Object> entry: contextMap.entrySet()) { validateField(entry.getKey(), entry.getValue()); } // Store an immutable copy this.contextMap = ImmutableMap.copyOf(contextMap); this.totalQueries = totalQueries == null ? new AtomicLong(0) : totalQueries; this.sequenceNumber = this.totalQueries.incrementAndGet(); }