DrillClient client = null;
Preconditions.checkArgument(!(planLocation == null && queryString == null), "Must provide either query file or query string");
Preconditions.checkArgument(!(planLocation != null && queryString != null), "Must provide either query file or query string, not both");
RemoteServiceSet serviceSet = null;
Drillbit[] drillbits = null;
try{
if (local) {
serviceSet = RemoteServiceSet.getLocalServiceSet();
drillbits = new Drillbit[bits];
for (int i = 0; i < bits; i++) {
drillbits[i] = new Drillbit(config, serviceSet);
drillbits[i].run();
}
client = new DrillClient(config, serviceSet.getCoordinator());
} else {
ZKClusterCoordinator clusterCoordinator = new ZKClusterCoordinator(config, zkQuorum);
clusterCoordinator.start(10000);
client = new DrillClient(config, clusterCoordinator);
}
client.connect();
String plan;
if (queryString == null) {
plan = Charsets.UTF_8.decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get(planLocation)))).toString();
} else {
plan = queryString;
}
return submitQuery(client, plan, type, format, width);
} catch(Throwable th) {
System.err.println("Query Failed due to : " + th.getMessage());
return -1;
}finally{
if(client != null) client.close();
if(local){
for(Drillbit b : drillbits){
b.close();
}
serviceSet.close();
}
}
}