Search in sources :

Example 1 with QueryType

use of org.apache.drill.exec.proto.UserBitShared.QueryType 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;
}
Also used : AwaitableUserResultsListener(org.apache.drill.exec.rpc.user.AwaitableUserResultsListener) Stopwatch(com.google.common.base.Stopwatch) QueryType(org.apache.drill.exec.proto.UserBitShared.QueryType)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 QueryType (org.apache.drill.exec.proto.UserBitShared.QueryType)1 AwaitableUserResultsListener (org.apache.drill.exec.rpc.user.AwaitableUserResultsListener)1