Search in sources :

Example 6 with AwaitableUserResultsListener

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

Example 7 with AwaitableUserResultsListener

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();
}
Also used : AwaitableUserResultsListener(org.apache.drill.exec.rpc.user.AwaitableUserResultsListener) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) PrintingResultsListener(org.apache.drill.exec.client.PrintingResultsListener) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) Test(org.junit.Test)

Aggregations

AwaitableUserResultsListener (org.apache.drill.exec.rpc.user.AwaitableUserResultsListener)7 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)3 PrintingResultsListener (org.apache.drill.exec.client.PrintingResultsListener)2 Stopwatch (com.google.common.base.Stopwatch)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 SilentListener (org.apache.drill.BaseTestQuery.SilentListener)1 DrillConfig (org.apache.drill.common.config.DrillConfig)1 UserException (org.apache.drill.common.exceptions.UserException)1 DrillClient (org.apache.drill.exec.client.DrillClient)1 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)1 PlanFragment (org.apache.drill.exec.proto.BitControl.PlanFragment)1 QueryType (org.apache.drill.exec.proto.UserBitShared.QueryType)1 RpcException (org.apache.drill.exec.rpc.RpcException)1 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)1 Test (org.junit.Test)1