use of org.apache.drill.exec.rpc.user.AwaitableUserResultsListener in project drill by apache.
the class QuerySubmitter method submitQuery.
public int submitQuery(DrillClient client, String plan, String type, String format, int width) throws Exception {
String[] queries;
QueryType queryType;
type = type.toLowerCase();
switch(type) {
case "sql":
queryType = QueryType.SQL;
queries = plan.trim().split(";");
break;
case "logical":
queryType = QueryType.LOGICAL;
queries = new String[] { plan };
break;
case "physical":
queryType = QueryType.PHYSICAL;
queries = new String[] { plan };
break;
default:
System.out.println("Invalid query type: " + type);
return -1;
}
Format outputFormat;
format = format.toLowerCase();
switch(format) {
case "csv":
outputFormat = Format.CSV;
break;
case "tsv":
outputFormat = Format.TSV;
break;
case "table":
outputFormat = Format.TABLE;
break;
default:
System.out.println("Invalid format type: " + format);
return -1;
}
Stopwatch watch = Stopwatch.createUnstarted();
for (String query : queries) {
AwaitableUserResultsListener listener = new AwaitableUserResultsListener(new PrintingResultsListener(client.getConfig(), outputFormat, width));
watch.start();
client.runQuery(queryType, query, listener);
int rows = listener.await();
System.out.println(String.format("%d record%s selected (%f seconds)", rows, rows > 1 ? "s" : "", (float) watch.elapsed(TimeUnit.MILLISECONDS) / (float) 1000));
if (query != queries[queries.length - 1]) {
System.out.println();
}
watch.stop();
watch.reset();
}
return 0;
}
use of org.apache.drill.exec.rpc.user.AwaitableUserResultsListener in project drill by apache.
the class DrillSeparatePlanningTest method testPlanning.
@Test(timeout = 30000)
public void testPlanning() throws Exception {
final String query = String.format("SELECT dir0, columns[3] FROM dfs_test.`%s/multilevel/csv` order by dir0", TEST_RES_PATH);
updateTestCluster(2, config);
List<QueryDataBatch> results = client.runQuery(QueryType.SQL, "alter session set `planner.slice_target`=1");
for (QueryDataBatch batch : results) {
batch.release();
}
AwaitableUserResultsListener listener = new AwaitableUserResultsListener(new PrintingResultsListener(client.getConfig(), Format.TSV, VectorUtil.DEFAULT_COLUMN_WIDTH));
//AwaitableUserResultsListener listener =
// new AwaitableUserResultsListener(new SilentListener());
client.runQuery(QueryType.SQL, query, listener);
@SuppressWarnings("unused") int rows = listener.await();
}
Aggregations