Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java client for Apache Druid #14338

Closed
iamtomkeen opened this issue May 24, 2023 · 3 comments
Closed

Java client for Apache Druid #14338

iamtomkeen opened this issue May 24, 2023 · 3 comments
Labels

Comments

@iamtomkeen
Copy link

iamtomkeen commented May 24, 2023

Apparently druidry is not maintained anymore.

Can anyone advise the best common approach to querying Druid from Java application at the moment?

@aleksi75
Copy link
Contributor

aleksi75 commented Sep 13, 2023

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.

Copy link

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.

@github-actions github-actions bot added the stale label Jun 20, 2024
Copy link

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.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants