-
Notifications
You must be signed in to change notification settings - Fork 42
/
Query.java
52 lines (42 loc) · 2.1 KB
/
Query.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import com.microsoft.azure.kusto.data.Client;
import com.microsoft.azure.kusto.data.ClientFactory;
import com.microsoft.azure.kusto.data.ClientRequestProperties;
import com.microsoft.azure.kusto.data.HttpClientProperties;
import com.microsoft.azure.kusto.data.KustoOperationResult;
import com.microsoft.azure.kusto.data.KustoResultSetTable;
import com.microsoft.azure.kusto.data.auth.ConnectionStringBuilder;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class Query {
public static void main(String[] args) {
try {
ConnectionStringBuilder csb = ConnectionStringBuilder.createWithAadApplicationCredentials(
System.getProperty("clusterPath"),
System.getProperty("appId"),
System.getProperty("appKey"),
System.getProperty("appTenant"));
HttpClientProperties properties = HttpClientProperties.builder()
.keepAlive(true)
.maxKeepAliveTime(120)
.maxConnectionsPerRoute(40)
.maxConnectionsTotal(40)
.build();
Client client = ClientFactory.createClient(csb, properties);
KustoOperationResult results = client.execute(".show version");
KustoResultSetTable mainTableResult = results.getPrimaryResults();
System.out.printf("Kusto sent back %s rows.%n", mainTableResult.count());
// iterate values
while (mainTableResult.next()) {
List<Object> nextValue = mainTableResult.getCurrentRow();
}
// in case we want to pass client request properties
ClientRequestProperties clientRequestProperties = new ClientRequestProperties();
clientRequestProperties.setTimeoutInMilliSec(TimeUnit.MINUTES.toMillis(1));
results = client.execute(System.getProperty("dbName"), System.getProperty("query"), clientRequestProperties);
} catch (Exception e) {
e.printStackTrace();
}
}
}