use of org.apache.drill.exec.store.druid.druid.DruidScanResponse in project drill by apache.
the class DruidRecordReader method next.
@Override
public int next() {
writer.allocate();
writer.reset();
Stopwatch watch = Stopwatch.createStarted();
try {
String query = getQuery();
DruidScanResponse druidScanResponse = druidQueryClient.executeQuery(query);
setNextOffset(druidScanResponse);
int docCount = 0;
for (ObjectNode eventNode : druidScanResponse.getEvents()) {
writer.setPosition(docCount);
jsonReader.setSource(eventNode);
try {
jsonReader.write(writer);
} catch (IOException e) {
throw UserException.dataReadError(e).message("Failure while reading document").addContext("Failed Query", query).addContext("Parser was at record", eventNode.toString()).addContext(e.getMessage()).build(logger);
}
docCount++;
}
writer.setValueCount(docCount);
logger.debug("Took {} ms to get {} records", watch.elapsed(TimeUnit.MILLISECONDS), docCount);
return docCount;
} catch (Exception e) {
throw UserException.dataReadError(e).message("Failure while executing druid query").addContext(e.getMessage()).build(logger);
}
}
use of org.apache.drill.exec.store.druid.druid.DruidScanResponse in project drill by apache.
the class DruidQueryClient method parseResponse.
private DruidScanResponse parseResponse(ArrayNode responses) {
String segmentId = "empty";
ArrayList<ObjectNode> events = new ArrayList<>();
ArrayList<String> columns = new ArrayList<>();
if (responses.size() > 0) {
ObjectNode firstNode = (ObjectNode) responses.get(0);
segmentId = firstNode.get("segmentId").textValue();
ArrayNode columnsNode = (ArrayNode) firstNode.get("columns");
ArrayNode eventsNode = (ArrayNode) firstNode.get("events");
for (int i = 0; i < columnsNode.size(); i++) {
String column = columnsNode.get(i).textValue();
columns.add(column);
}
for (int i = 0; i < eventsNode.size(); i++) {
ObjectNode eventNode = (ObjectNode) eventsNode.get(i);
events.add(eventNode);
}
}
return new DruidScanResponse(segmentId, columns, events);
}
use of org.apache.drill.exec.store.druid.druid.DruidScanResponse in project drill by apache.
the class DruidQueryClientTest method executeQueryCalledSuccessfullyParseQueryResults.
@Test
public void executeQueryCalledSuccessfullyParseQueryResults() throws Exception {
String result = "[{\"segmentId\":\"wikipedia_2016-06-27T14:00:00.000Z_2016-06-27T15:00:00.000Z_2021-12-11T11:12:16.106Z\",\"columns\":[\"__time\",\"channel\",\"cityName\",\"comment\",\"countryIsoCode\",\"countryName\",\"diffUrl\",\"flags\",\"isAnonymous\",\"isMinor\",\"isNew\",\"isRobot\",\"isUnpatrolled\",\"metroCode\",\"namespace\",\"page\",\"regionIsoCode\",\"regionName\",\"user\",\"sum_deleted\",\"sum_deltaBucket\",\"sum_added\",\"sum_commentLength\",\"count\",\"sum_delta\"],\"events\":[{\"__time\":1467036000000,\"channel\":\"#de.wikipedia\",\"cityName\":null,\"comment\":\"Bitte [[WP:Literatur]] beachten.\",\"countryIsoCode\":null,\"countryName\":null,\"diffUrl\":\"https://de.wikipedia.org/w/index.php?diff=155672392&oldid=155667393\",\"flags\":null,\"isAnonymous\":\"false\",\"isMinor\":\"false\",\"isNew\":\"false\",\"isRobot\":\"false\",\"isUnpatrolled\":\"false\",\"metroCode\":null,\"namespace\":\"Main\",\"page\":\"Walfang\",\"regionIsoCode\":null,\"regionName\":null,\"user\":\"Dansker\",\"sum_deleted\":133,\"sum_deltaBucket\":-200,\"sum_added\":0,\"sum_commentLength\":32,\"count\":1,\"sum_delta\":-133}]}]";
InputStream inputStream = new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8.name()));
when(httpEntity.getContent()).thenReturn(inputStream);
DruidScanResponse response = druidQueryClient.executeQuery(QUERY);
assertThat(response.getEvents()).isNotEmpty();
assertThat(response.getEvents().size()).isEqualTo(1);
assertThat(response.getEvents().get(0).get("user").textValue()).isEqualTo("Dansker");
assertThat(response.getEvents().get(0).get("sum_deleted").intValue()).isEqualTo(133);
}
use of org.apache.drill.exec.store.druid.druid.DruidScanResponse in project drill by apache.
the class DruidQueryClientTest method executeQueryCalledNoResponsesFoundReturnsEmptyEventList.
@Test
public void executeQueryCalledNoResponsesFoundReturnsEmptyEventList() throws Exception {
InputStream inputStream = new ByteArrayInputStream("[]".getBytes(StandardCharsets.UTF_8.name()));
when(httpEntity.getContent()).thenReturn(inputStream);
DruidScanResponse response = druidQueryClient.executeQuery(QUERY);
assertThat(response.getEvents()).isEmpty();
}
Aggregations