use of co.cask.cdap.proto.QueryInfo in project cdap by caskdata.
the class BaseHiveExploreService method getQueries.
@Override
public List<QueryInfo> getQueries(NamespaceId namespace) throws ExploreException, SQLException {
startAndWait();
List<QueryInfo> result = new ArrayList<>();
String namespaceHiveDb = getHiveDatabase(namespace.getNamespace());
for (Map.Entry<QueryHandle, OperationInfo> entry : activeHandleCache.asMap().entrySet()) {
try {
if (namespaceHiveDb.equals(entry.getValue().getHiveDatabase())) {
// we use empty query statement for get tables, get schemas, we don't need to return it this method call.
if (!entry.getValue().getStatement().isEmpty()) {
QueryStatus status = getStatus(entry.getKey());
result.add(new QueryInfo(entry.getValue().getTimestamp(), entry.getValue().getStatement(), entry.getKey(), status, true));
}
}
} catch (HandleNotFoundException e) {
// ignore the handle not found exception. this method returns all queries and handle, if the
// handle is removed from the internal cache, then there is no point returning them from here.
}
}
for (Map.Entry<QueryHandle, InactiveOperationInfo> entry : inactiveHandleCache.asMap().entrySet()) {
InactiveOperationInfo inactiveOperationInfo = entry.getValue();
if (namespaceHiveDb.equals(inactiveOperationInfo.getHiveDatabase())) {
// we use empty query statement for get tables, get schemas, we don't need to return it this method call.
if (!inactiveOperationInfo.getStatement().isEmpty()) {
if (inactiveOperationInfo.getStatus() == null) {
LOG.error("Null status for query {}, handle {}", inactiveOperationInfo.getStatement(), entry.getKey());
}
result.add(new QueryInfo(inactiveOperationInfo.getTimestamp(), inactiveOperationInfo.getStatement(), entry.getKey(), inactiveOperationInfo.getStatus(), false));
}
}
}
Collections.sort(result);
return result;
}
use of co.cask.cdap.proto.QueryInfo in project cdap by caskdata.
the class NamespacedExploreQueryExecutorHttpHandler method getQueryLiveHandles.
@GET
@Path("data/explore/queries")
public void getQueryLiveHandles(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @QueryParam("offset") @DefaultValue("9223372036854775807") long offset, @QueryParam("cursor") @DefaultValue("next") String cursor, @QueryParam("limit") @DefaultValue("50") int limit) throws ExploreException, SQLException {
boolean isForward = "next".equals(cursor);
// this operation doesn't interact with hive, so doesn't require impersonation
List<QueryInfo> queries = exploreService.getQueries(new NamespaceId(namespaceId));
// return the queries by after filtering (> offset) and limiting number of queries
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(filterQueries(queries, offset, isForward, limit)));
}
use of co.cask.cdap.proto.QueryInfo in project cdap by caskdata.
the class HiveExploreServiceTestRun method testQueriesList.
@Test
public void testQueriesList() throws Exception {
ListenableFuture<ExploreExecutionResult> future;
ExploreExecutionResult results;
List<QueryInfo> queries;
// Use different namespaces than the other tests so that when its run in a suite there isn't a chance of
// stray queries polluting this test
NamespaceId testNamespace1 = new NamespaceId("test1");
NamespaceId testNamespace2 = new NamespaceId("test2");
NamespaceMeta testNamespace1Meta = new NamespaceMeta.Builder().setName(testNamespace1).build();
namespaceAdmin.create(testNamespace1Meta);
NamespaceMeta testNamespace2Meta = new NamespaceMeta.Builder().setName(testNamespace2).build();
namespaceAdmin.create(testNamespace2Meta);
exploreClient.addNamespace(testNamespace1Meta).get();
exploreClient.addNamespace(testNamespace2Meta).get();
exploreClient.submit(testNamespace1, "create table my_table (first INT, second STRING)").get();
future = exploreClient.submit(testNamespace1, "show tables");
future.get();
future = exploreClient.submit(testNamespace2, "show tables");
future.get();
future = exploreClient.submit(testNamespace1, "select * from my_table");
results = future.get();
queries = exploreService.getQueries(testNamespace1);
Assert.assertEquals(2, queries.size());
Assert.assertEquals("select * from my_table", queries.get(0).getStatement());
Assert.assertEquals("FINISHED", queries.get(0).getStatus().toString());
Assert.assertTrue(queries.get(0).isHasResults());
Assert.assertTrue(queries.get(0).isActive());
Assert.assertEquals("show tables", queries.get(1).getStatement());
Assert.assertEquals("FINISHED", queries.get(1).getStatus().toString());
Assert.assertTrue(queries.get(1).isHasResults());
Assert.assertTrue(queries.get(1).isActive());
// Make the last query inactive
while (results.hasNext()) {
results.next();
}
queries = exploreService.getQueries(testNamespace1);
Assert.assertEquals(2, queries.size());
Assert.assertEquals("select * from my_table", queries.get(0).getStatement());
Assert.assertEquals("FINISHED", queries.get(0).getStatus().toString());
Assert.assertTrue(queries.get(0).isHasResults());
Assert.assertFalse(queries.get(0).isActive());
Assert.assertEquals("show tables", queries.get(1).getStatement());
Assert.assertEquals("FINISHED", queries.get(1).getStatus().toString());
Assert.assertTrue(queries.get(1).isHasResults());
Assert.assertTrue(queries.get(1).isActive());
// Close last query
results.close();
queries = exploreService.getQueries(testNamespace1);
Assert.assertEquals(1, queries.size());
Assert.assertEquals("show tables", queries.get(0).getStatement());
queries = exploreService.getQueries(testNamespace2);
Assert.assertEquals(1, queries.size());
Assert.assertEquals("show tables", queries.get(0).getStatement());
Assert.assertEquals("FINISHED", queries.get(0).getStatus().toString());
Assert.assertTrue(queries.get(0).isHasResults());
Assert.assertTrue(queries.get(0).isActive());
// Make sure queries are reverse ordered by timestamp
exploreClient.submit(testNamespace1, "show tables").get();
exploreClient.submit(testNamespace1, "show tables").get();
exploreClient.submit(testNamespace1, "show tables").get();
exploreClient.submit(testNamespace1, "show tables").get();
queries = exploreService.getQueries(testNamespace1);
List<Long> timestamps = Lists.newArrayList();
Assert.assertEquals(5, queries.size());
for (QueryInfo queryInfo : queries) {
Assert.assertNotNull(queryInfo.getStatement());
Assert.assertNotNull(queryInfo.getQueryHandle());
Assert.assertTrue(queryInfo.isActive());
Assert.assertEquals("FINISHED", queryInfo.getStatus().toString());
Assert.assertEquals("show tables", queryInfo.getStatement());
timestamps.add(queryInfo.getTimestamp());
}
// verify the ordering
Assert.assertTrue(Ordering.natural().reverse().isOrdered(timestamps));
exploreClient.submit(testNamespace1, "drop table if exists my_table").get();
exploreClient.removeNamespace(testNamespace1).get();
exploreClient.removeNamespace(testNamespace2).get();
}
Aggregations