You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "iamtomkeen (via GitHub)" <gi...@apache.org> on 2023/05/24 08:48:04 UTC
[GitHub] [druid] iamtomkeen opened a new issue, #14338: Java client for Apache Druid
iamtomkeen opened a new issue, #14338:
URL: https://github.com/apache/druid/issues/14338
Apparently [druidry](https://github.com/zapr-oss/druidry) is not supported anymore.
Can anyone advise the best common approach to querying Druid from Java application at the moment?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [I] Java client for Apache Druid (druid)
Posted by "aleksi75 (via GitHub)" <gi...@apache.org>.
aleksi75 commented on issue #14338:
URL: https://github.com/apache/druid/issues/14338#issuecomment-1717797195
At first I would recommend to use '[Druid SQL](https://druid.apache.org/docs/latest/querying/sql/)' and not '[Native queries](https://druid.apache.org/docs/latest/querying/)', but in both cases you just send JSON to an 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](https://groups.google.com/g/druid-user).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org