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();
}
}
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();
}
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();
}
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);
}
}
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();
}
Aggregations