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;
}
Aggregations