Search in sources :

Example 46 with RE

use of org.apache.druid.java.util.common.RE in project hive by apache.

the class DruidQueryRecordReader method createQueryResultsIterator.

public JsonParserIterator<R> createQueryResultsIterator() {
    JsonParserIterator<R> iterator = null;
    String filterExprSerialized = conf.get(TableScanDesc.FILTER_EXPR_CONF_STR);
    if (filterExprSerialized != null) {
        ExprNodeGenericFuncDesc filterExpr = SerializationUtilities.deserializeExpression(filterExprSerialized);
        query = DruidStorageHandlerUtils.addDynamicFilters(query, filterExpr, conf, true);
    }
    // Result type definition used to read the rows, this is query dependent.
    JavaType resultsType = getResultTypeDef();
    boolean initialized = false;
    int currentLocationIndex = 0;
    Exception ex = null;
    while (!initialized && currentLocationIndex < locations.length) {
        String address = locations[currentLocationIndex++];
        if (Strings.isNullOrEmpty(address)) {
            throw new RE("can not fetch results from empty or null host value");
        }
        // Execute query
        LOG.debug("Retrieving data from druid location[{}] using query:[{}] ", address, query);
        try {
            Request request = DruidStorageHandlerUtils.createSmileRequest(address, query);
            Future<InputStream> inputStreamFuture = httpClient.go(request, new InputStreamResponseHandler());
            // noinspection unchecked
            iterator = new JsonParserIterator(smileMapper, resultsType, inputStreamFuture, request.getUrl().toString(), query);
            iterator.init();
            initialized = true;
        } catch (Exception e) {
            if (iterator != null) {
                // We got exception while querying results from this host.
                CloseQuietly.close(iterator);
            }
            LOG.error("Failure getting results for query[{}] from host[{}] because of [{}]", query, address, e.getMessage());
            if (ex == null) {
                ex = e;
            } else {
                ex.addSuppressed(e);
            }
        }
    }
    if (!initialized) {
        throw new RE(ex, "Failure getting results for query[%s] from locations[%s] because of [%s]", query, locations, Objects.requireNonNull(ex).getMessage());
    }
    return iterator;
}
Also used : InputStream(java.io.InputStream) Request(org.apache.druid.java.util.http.client.Request) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JavaType(com.fasterxml.jackson.databind.JavaType) RE(org.apache.druid.java.util.common.RE) InputStreamResponseHandler(org.apache.druid.java.util.http.client.response.InputStreamResponseHandler)

Aggregations

RE (org.apache.druid.java.util.common.RE)46 IOException (java.io.IOException)11 Request (org.apache.druid.java.util.http.client.Request)10 URL (java.net.URL)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 ExecutionException (java.util.concurrent.ExecutionException)5 ISE (org.apache.druid.java.util.common.ISE)5 Map (java.util.Map)4 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)4 JavaType (com.fasterxml.jackson.databind.JavaType)3 HashMap (java.util.HashMap)3 DataSegment (org.apache.druid.timeline.DataSegment)3 OSSException (com.aliyun.oss.OSSException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ApiException (io.kubernetes.client.openapi.ApiException)2 File (java.io.File)2