Search in sources :

Example 1 with ReduceService

use of com.linkedin.pinot.common.query.ReduceService in project pinot by linkedin.

the class BrokerRequestHandler method processBrokerRequest.

/**
   * Main method to process the request.
   * <p>Following lifecycle stages:
   * <ul>
   *   <li>1. Find the candidate servers to be queried for each set of segments from the routing table.</li>
   *   <li>2. Select servers for each segment set and scatter request to the servers.</li>
   *   <li>3. Gather responses from the servers.</li>
   *   <li>4. Deserialize the server responses.</li>
   *   <li>5. Reduce (merge) the server responses and create a broker response to be returned.</li>
   * </ul>
   *
   * @param brokerRequest broker request to be processed.
   * @param scatterGatherStats scatter-gather statistics.
   * @param requestId broker request ID.
   * @return broker response.
   * @throws InterruptedException
   */
@Nonnull
public BrokerResponse processBrokerRequest(@Nonnull BrokerRequest brokerRequest, @Nonnull ScatterGatherStats scatterGatherStats, long requestId) throws InterruptedException {
    String tableName = brokerRequest.getQuerySource().getTableName();
    ResponseType responseType = BrokerResponseFactory.getResponseType(brokerRequest.getResponseFormat());
    LOGGER.debug("Broker Response Type: {}", responseType.name());
    String offlineTableName = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(tableName);
    if (!_routingTable.routingTableExists(offlineTableName)) {
        offlineTableName = null;
    }
    String realtimeTableName = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(tableName);
    if (!_routingTable.routingTableExists(realtimeTableName)) {
        realtimeTableName = null;
    }
    if ((offlineTableName == null) && (realtimeTableName == null)) {
        // No table matches the broker request.
        LOGGER.warn("No table matches the name: {}", tableName);
        _brokerMetrics.addMeteredTableValue(tableName, BrokerMeter.RESOURCE_MISSING_EXCEPTIONS, 1);
        return BrokerResponseFactory.getStaticNoTableHitBrokerResponse(responseType);
    } else {
        // At least one table matches the broker request.
        BrokerRequest offlineBrokerRequest = null;
        BrokerRequest realtimeBrokerRequest = null;
        // TODO: get time column name from schema or table config so that we can apply it in realtime only use case.
        // We get timeColumnName from time boundary service currently, which only exists for offline table.
        String timeColumnName = (offlineTableName != null) ? getTimeColumnName(offlineTableName) : null;
        if ((offlineTableName != null) && (realtimeTableName != null)) {
            // Hybrid table.
            offlineBrokerRequest = _optimizer.optimize(getOfflineBrokerRequest(brokerRequest), timeColumnName);
            realtimeBrokerRequest = _optimizer.optimize(getRealtimeBrokerRequest(brokerRequest), timeColumnName);
        } else if (offlineTableName != null) {
            // Offline table only.
            brokerRequest.getQuerySource().setTableName(offlineTableName);
            offlineBrokerRequest = _optimizer.optimize(brokerRequest, timeColumnName);
        } else {
            // Realtime table only.
            brokerRequest.getQuerySource().setTableName(realtimeTableName);
            realtimeBrokerRequest = _optimizer.optimize(brokerRequest, timeColumnName);
        }
        ReduceService reduceService = _reduceServiceRegistry.get(responseType);
        // TODO: wire up the customized BucketingSelection.
        return processOptimizedBrokerRequests(brokerRequest, offlineBrokerRequest, realtimeBrokerRequest, reduceService, scatterGatherStats, null, requestId);
    }
}
Also used : ReduceService(com.linkedin.pinot.common.query.ReduceService) BrokerRequest(com.linkedin.pinot.common.request.BrokerRequest) ResponseType(com.linkedin.pinot.common.response.BrokerResponseFactory.ResponseType) Nonnull(javax.annotation.Nonnull)

Aggregations

ReduceService (com.linkedin.pinot.common.query.ReduceService)1 BrokerRequest (com.linkedin.pinot.common.request.BrokerRequest)1 ResponseType (com.linkedin.pinot.common.response.BrokerResponseFactory.ResponseType)1 Nonnull (javax.annotation.Nonnull)1