Search in sources :

Example 1 with AwaitableUserResultsListener

use of org.apache.drill.exec.rpc.user.AwaitableUserResultsListener in project drill by apache.

the class DrillSeparatePlanningTest method getResultsHelper.

private void getResultsHelper(final QueryPlanFragments planFragments) throws Exception {
    for (PlanFragment fragment : planFragments.getFragmentsList()) {
        DrillbitEndpoint assignedNode = fragment.getAssignment();
        @SuppressWarnings("resource") DrillClient fragmentClient = new DrillClient(true);
        Properties props = new Properties();
        props.setProperty("drillbit", assignedNode.getAddress() + ":" + assignedNode.getUserPort());
        fragmentClient.connect(props);
        ShowResultsUserResultsListener myListener = new ShowResultsUserResultsListener(getAllocator());
        AwaitableUserResultsListener listenerBits = new AwaitableUserResultsListener(myListener);
        fragmentClient.runQuery(QueryType.SQL, "select hostname, user_port from sys.drillbits where `current`=true", listenerBits);
        int row = listenerBits.await();
        assertEquals(1, row);
        List<Map<String, String>> records = myListener.getRecords();
        assertEquals(1, records.size());
        Map<String, String> record = records.get(0);
        assertEquals(2, record.size());
        Iterator<Entry<String, String>> iter = record.entrySet().iterator();
        Entry<String, String> entry;
        String host = null;
        String port = null;
        for (int i = 0; i < 2; i++) {
            entry = iter.next();
            if (entry.getKey().equalsIgnoreCase("hostname")) {
                host = entry.getValue();
            } else if (entry.getKey().equalsIgnoreCase("user_port")) {
                port = entry.getValue();
            } else {
                fail("Unknown field: " + entry.getKey());
            }
        }
        assertTrue(props.getProperty("drillbit").equalsIgnoreCase(host + ":" + port));
        List<PlanFragment> fragmentList = Lists.newArrayList();
        fragmentList.add(fragment);
        //AwaitableUserResultsListener listener =
        //     new AwaitableUserResultsListener(new PrintingResultsListener(client.getConfig(), Format.TSV, VectorUtil.DEFAULT_COLUMN_WIDTH));
        AwaitableUserResultsListener listener = new AwaitableUserResultsListener(new SilentListener());
        fragmentClient.runQuery(QueryType.EXECUTION, fragmentList, listener);
        @SuppressWarnings("unused") int rows = listener.await();
        fragmentClient.close();
    }
}
Also used : Properties(java.util.Properties) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) AwaitableUserResultsListener(org.apache.drill.exec.rpc.user.AwaitableUserResultsListener) Entry(java.util.Map.Entry) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) DrillClient(org.apache.drill.exec.client.DrillClient) Map(java.util.Map)

Example 2 with AwaitableUserResultsListener

use of org.apache.drill.exec.rpc.user.AwaitableUserResultsListener in project drill by apache.

the class DrillSeparatePlanningTest method getCombinedResultsHelper.

private void getCombinedResultsHelper(final QueryPlanFragments planFragments) throws Exception {
    ShowResultsUserResultsListener myListener = new ShowResultsUserResultsListener(getAllocator());
    @SuppressWarnings("unused") AwaitableUserResultsListener listenerBits = new AwaitableUserResultsListener(myListener);
    //AwaitableUserResultsListener listener =
    //     new AwaitableUserResultsListener(new PrintingResultsListener(client.getConfig(), Format.TSV, VectorUtil.DEFAULT_COLUMN_WIDTH));
    AwaitableUserResultsListener listener = new AwaitableUserResultsListener(new SilentListener());
    client.runQuery(QueryType.EXECUTION, planFragments.getFragmentsList(), listener);
    @SuppressWarnings("unused") int rows = listener.await();
}
Also used : AwaitableUserResultsListener(org.apache.drill.exec.rpc.user.AwaitableUserResultsListener) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)

Example 3 with AwaitableUserResultsListener

use of org.apache.drill.exec.rpc.user.AwaitableUserResultsListener in project drill by apache.

the class QueryTestUtil method testRunAndPrint.

/**
   * Execute a SQL query, and print the results.
   *
   * @param drillClient drill client to use
   * @param type type of the query
   * @param queryString query string
   * @return number of rows returned
   * @throws Exception
   */
public static int testRunAndPrint(final DrillClient drillClient, final QueryType type, final String queryString) throws Exception {
    final String query = normalizeQuery(queryString);
    DrillConfig config = drillClient.getConfig();
    AwaitableUserResultsListener resultListener = new AwaitableUserResultsListener(config.getBoolean(TEST_QUERY_PRINTING_SILENT) ? new SilentListener() : new PrintingResultsListener(config, Format.TSV, VectorUtil.DEFAULT_COLUMN_WIDTH));
    drillClient.runQuery(type, query, resultListener);
    return resultListener.await();
}
Also used : AwaitableUserResultsListener(org.apache.drill.exec.rpc.user.AwaitableUserResultsListener) SilentListener(org.apache.drill.BaseTestQuery.SilentListener) DrillConfig(org.apache.drill.common.config.DrillConfig) PrintingResultsListener(org.apache.drill.exec.client.PrintingResultsListener)

Example 4 with AwaitableUserResultsListener

use of org.apache.drill.exec.rpc.user.AwaitableUserResultsListener in project drill by apache.

the class QueryBuilder method runAndWait.

public long runAndWait(UserResultsListener listener) {
    AwaitableUserResultsListener resultListener = new AwaitableUserResultsListener(listener);
    withListener(resultListener);
    try {
        return resultListener.await();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : AwaitableUserResultsListener(org.apache.drill.exec.rpc.user.AwaitableUserResultsListener) UserException(org.apache.drill.common.exceptions.UserException) RpcException(org.apache.drill.exec.rpc.RpcException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException)

Example 5 with AwaitableUserResultsListener

use of org.apache.drill.exec.rpc.user.AwaitableUserResultsListener in project drill by apache.

the class BaseTestQuery method runSQL.

protected static void runSQL(String sql) throws Exception {
    final AwaitableUserResultsListener listener = new AwaitableUserResultsListener(new SilentListener());
    testWithListener(QueryType.SQL, sql, listener);
    listener.await();
}
Also used : AwaitableUserResultsListener(org.apache.drill.exec.rpc.user.AwaitableUserResultsListener)

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