Closed iamtomkeen closed 2 months ago
At first I would recommend to use 'Druid SQL' and not 'Native queries', but in both cases you just send JSON to a REST endpoint (Broker).
Following a simple example with an 'org.eclipse.jetty.client.HttpClient'
public String callDruid() throws Exception {
HttpClient httpClient = new HttpClient();
httpClient.start();
String result = "{}"; // emtpy JSON as default
try {
final String body = "{ \"query\" : \"SELECT * from your_datasource\ LIMIT 10" }"; // SQL Query as JSON
final String url = DRUID_BROKER_URL_INCL_PORT + "/druid/v2/sql";
final Request request = httpClient.newRequest(url);
request.timeout(60000, TimeUnit.MILLISECONDS);
request.method(HttpMethod.POST);
request.content(new BytesContentProvider(body.getBytes()), MediaType.APPLICATION_JSON_VALUE);
request.header(HttpHeader.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
final ContentResponse response = request.send();
if (HttpStatus.OK_200 == response.getStatus()) {
result = response.getContentAsString();
} else {
LOGGER.warn("callDruid - query received unexpected response status " + response.getStatus() + " and content " + response.getContentAsString());
}
} catch (final InterruptedException | TimeoutException | ExecutionException e) {
LOGGER.error("callDruid - query got exception processing call: " + e.getMessage(), e);
}
httpClient.stop();
return result;
}
Note: This is not an issue, for questions like this better use Google Druid User Group.
This issue has been marked as stale due to 280 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the dev@druid.apache.org list. Thank you for your contributions.
This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.
Apparently druidry is not maintained anymore.
Can anyone advise the best common approach to querying Druid from Java application at the moment?