Search in sources :

Example 16 with ExploreExecutionResult

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);
}
Also used : ExploreExecutionResult(io.cdap.cdap.explore.client.ExploreExecutionResult) QueryClient(io.cdap.cdap.client.QueryClient)

Example 17 with ExploreExecutionResult

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();
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) QueryInfo(io.cdap.cdap.proto.QueryInfo) ExploreExecutionResult(io.cdap.cdap.explore.client.ExploreExecutionResult) Test(org.junit.Test)

Example 18 with ExploreExecutionResult

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);
    }
}
Also used : QueryResult(io.cdap.cdap.proto.QueryResult) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ColumnDesc(io.cdap.cdap.proto.ColumnDesc) ExploreExecutionResult(io.cdap.cdap.explore.client.ExploreExecutionResult) Test(org.junit.Test)

Example 19 with ExploreExecutionResult

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();
    }
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ExploreExecutionResult(io.cdap.cdap.explore.client.ExploreExecutionResult) Test(org.junit.Test)

Example 20 with ExploreExecutionResult

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);
}
Also used : TxRunnable(io.cdap.cdap.api.TxRunnable) ObjectMappedTable(io.cdap.cdap.api.dataset.lib.ObjectMappedTable) DatasetContext(io.cdap.cdap.api.data.DatasetContext) ExploreExecutionResult(io.cdap.cdap.explore.client.ExploreExecutionResult) DatasetId(io.cdap.cdap.proto.id.DatasetId) Test(org.junit.Test)

Aggregations

ExploreExecutionResult (io.cdap.cdap.explore.client.ExploreExecutionResult)52 Test (org.junit.Test)36 ColumnDesc (io.cdap.cdap.proto.ColumnDesc)24 DatasetId (io.cdap.cdap.proto.id.DatasetId)20 QueryResult (io.cdap.cdap.proto.QueryResult)18 Transaction (org.apache.tephra.Transaction)14 Table (io.cdap.cdap.api.dataset.table.Table)10 Schema (io.cdap.cdap.api.data.schema.Schema)6 Put (io.cdap.cdap.api.dataset.table.Put)6 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)6 TransactionAware (org.apache.tephra.TransactionAware)6 ObjectMappedTable (io.cdap.cdap.api.dataset.lib.ObjectMappedTable)4 QueryClient (io.cdap.cdap.client.QueryClient)4 KeyExtendedStructValueTableDefinition (io.cdap.cdap.explore.service.datasets.KeyExtendedStructValueTableDefinition)4 KeyStructValueTableDefinition (io.cdap.cdap.explore.service.datasets.KeyStructValueTableDefinition)4 WritableKeyStructValueTableDefinition (io.cdap.cdap.explore.service.datasets.WritableKeyStructValueTableDefinition)4 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)4 QueryStatus (io.cdap.cdap.proto.QueryStatus)4 TxRunnable (io.cdap.cdap.api.TxRunnable)2 DatasetContext (io.cdap.cdap.api.data.DatasetContext)2