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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
