use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by cdapio.
the class CLITestBase method createHiveDB.
private void createHiveDB(String hiveDb) throws Exception {
QueryClient queryClient = getQueryClient();
ListenableFuture<ExploreExecutionResult> future = queryClient.execute(NamespaceId.DEFAULT, "create database " + hiveDb);
assertExploreQuerySuccess(future);
future = queryClient.execute(NamespaceId.DEFAULT, "describe database " + hiveDb);
assertExploreQuerySuccess(future);
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by cdapio.
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();
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by cdapio.
the class HiveExploreServiceTestRun method testNamespaceCreationDeletion.
@Test
public void testNamespaceCreationDeletion() throws Exception {
NamespaceId testNamespace = new NamespaceId("test");
ListenableFuture<ExploreExecutionResult> future = exploreClient.schemas(null, null);
assertStatementResult(future, true, ImmutableList.of(new ColumnDesc("TABLE_SCHEM", "STRING", 1, "Schema name."), new ColumnDesc("TABLE_CATALOG", "STRING", 2, "Catalog name.")), ImmutableList.of(new QueryResult(Lists.newArrayList(NAMESPACE_DATABASE, "")), new QueryResult(Lists.newArrayList(OTHER_NAMESPACE_DATABASE, "")), new QueryResult(Lists.newArrayList(DEFAULT_DATABASE, ""))));
future = exploreClient.addNamespace(new NamespaceMeta.Builder().setName("test").build());
future.get();
createNamespace(testNamespace);
try {
future = exploreClient.schemas(null, null);
assertStatementResult(future, true, ImmutableList.of(new ColumnDesc("TABLE_SCHEM", "STRING", 1, "Schema name."), new ColumnDesc("TABLE_CATALOG", "STRING", 2, "Catalog name.")), ImmutableList.of(new QueryResult(Lists.newArrayList(NAMESPACE_DATABASE, "")), new QueryResult(Lists.newArrayList(OTHER_NAMESPACE_DATABASE, "")), new QueryResult(Lists.newArrayList("cdap_" + testNamespace.getNamespace(), "")), new QueryResult(Lists.newArrayList(DEFAULT_DATABASE, ""))));
future = exploreClient.removeNamespace(testNamespace);
future.get();
future = exploreClient.schemas(null, null);
assertStatementResult(future, true, ImmutableList.of(new ColumnDesc("TABLE_SCHEM", "STRING", 1, "Schema name."), new ColumnDesc("TABLE_CATALOG", "STRING", 2, "Catalog name.")), ImmutableList.of(new QueryResult(Lists.<Object>newArrayList(NAMESPACE_DATABASE, "")), new QueryResult(Lists.<Object>newArrayList(OTHER_NAMESPACE_DATABASE, "")), new QueryResult(Lists.<Object>newArrayList(DEFAULT_DATABASE, ""))));
} finally {
deleteNamespace(testNamespace);
}
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by cdapio.
the class HiveExploreServiceTestRun method testQueriesCount.
@Test
public void testQueriesCount() throws Exception {
NamespaceId testNamespace1 = new NamespaceId("testQueriesCount");
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(testNamespace1).build();
namespaceAdmin.create(namespaceMeta);
exploreClient.addNamespace(namespaceMeta).get();
try {
Assert.assertEquals(0, exploreService.getActiveQueryCount(testNamespace1));
ListenableFuture<ExploreExecutionResult> future = exploreClient.submit(testNamespace1, "show tables");
ExploreExecutionResult result = null;
try {
result = future.get();
Assert.assertEquals(1, exploreService.getActiveQueryCount(testNamespace1));
} finally {
if (result != null) {
result.close();
}
Assert.assertEquals(0, exploreService.getActiveQueryCount(testNamespace1));
}
} finally {
exploreClient.removeNamespace(testNamespace1).get();
}
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by cdapio.
the class HiveExploreStructuredRecordTestRun method testObjectMappedTable.
@Test
public void testObjectMappedTable() throws Exception {
// Add a ObjectMappedTable instance
final DatasetId datasetId = NAMESPACE_ID.dataset("person");
datasetFramework.addInstance(ObjectMappedTable.class.getName(), datasetId, ObjectMappedTableProperties.builder().setType(Person.class).setRowKeyExploreName("id").setRowKeyExploreType(Schema.Type.STRING).build());
// Insert data using sql
String command = String.format("INSERT into %s (id, firstname, lastname, age) VALUES (\"%s\", \"%s\", \"%s\", %d)", getDatasetHiveName(datasetId), "bobby", "Bobby", "Bob", 15);
ExploreExecutionResult result = exploreClient.submit(NAMESPACE_ID, command).get();
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, result.getStatus().getStatus());
transactional.execute(new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
// Read the data back via dataset directly
ObjectMappedTable<Person> objTable = context.getDataset(datasetId.getDataset());
Person person = objTable.read("bobby");
Assert.assertNotNull(person);
Assert.assertEquals("Bobby", person.getFirstName());
Assert.assertEquals("Bob", person.getLastName());
Assert.assertEquals(15, person.getAge());
}
});
// Delete the dataset, hence also drop the table.
datasetFramework.deleteInstance(datasetId);
}
Aggregations