Search in sources :

Example 66 with QueryHandle

use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.

the class BaseHiveExploreServiceTest method createNamespace.

/**
 * Create a namespace because app fabric is not started in explore tests.
 */
protected static void createNamespace(NamespaceId namespaceId) throws Exception {
    namespacePathLocator.get(namespaceId).mkdirs();
    NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(namespaceId).build();
    namespaceAdmin.create(namespaceMeta);
    if (!NamespaceId.DEFAULT.equals(namespaceId)) {
        QueryHandle handle = exploreService.createNamespace(namespaceMeta);
        waitForCompletionStatus(handle, 50, TimeUnit.MILLISECONDS, 40);
    }
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) QueryHandle(io.cdap.cdap.proto.QueryHandle)

Example 67 with QueryHandle

use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.

the class HiveExploreServiceTestRun method previewResultsTest.

@Test
public void previewResultsTest() throws Exception {
    DatasetId myTable2 = NAMESPACE_ID.dataset("my_table_2");
    DatasetId myTable3 = NAMESPACE_ID.dataset("my_table_3");
    DatasetId myTable4 = NAMESPACE_ID.dataset("my_table_4");
    DatasetId myTable5 = NAMESPACE_ID.dataset("my_table_5");
    DatasetId myTable6 = NAMESPACE_ID.dataset("my_table_6");
    datasetFramework.addInstance("keyStructValueTable", myTable2, DatasetProperties.EMPTY);
    datasetFramework.addInstance("keyStructValueTable", myTable3, DatasetProperties.EMPTY);
    datasetFramework.addInstance("keyStructValueTable", myTable4, DatasetProperties.EMPTY);
    datasetFramework.addInstance("keyStructValueTable", myTable5, DatasetProperties.EMPTY);
    datasetFramework.addInstance("keyStructValueTable", myTable6, DatasetProperties.EMPTY);
    try {
        QueryHandle handle = exploreService.execute(NAMESPACE_ID, "show tables");
        QueryStatus status = waitForCompletionStatus(handle, 200, TimeUnit.MILLISECONDS, 50);
        Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
        List<QueryResult> firstPreview = exploreService.previewResults(handle);
        Assert.assertEquals(ImmutableList.of(new QueryResult(ImmutableList.<Object>of(MY_TABLE_NAME)), new QueryResult(ImmutableList.<Object>of(getDatasetHiveName(myTable2))), new QueryResult(ImmutableList.<Object>of(getDatasetHiveName(myTable3))), new QueryResult(ImmutableList.<Object>of(getDatasetHiveName(myTable4))), new QueryResult(ImmutableList.<Object>of(getDatasetHiveName(myTable5)))), firstPreview);
        // test that preview results do not change even when the query cursor is updated by nextResults
        List<QueryResult> endResults = exploreService.nextResults(handle, 100);
        Assert.assertEquals(ImmutableList.of(new QueryResult(ImmutableList.<Object>of(getDatasetHiveName(myTable6)))), endResults);
        List<QueryResult> secondPreview = exploreService.previewResults(handle);
        Assert.assertEquals(firstPreview, secondPreview);
        Assert.assertEquals(ImmutableList.<QueryResult>of(), exploreService.nextResults(handle, 100));
        try {
            // All results are fetched, query should be inactive now
            exploreService.previewResults(handle);
            Assert.fail("HandleNotFoundException expected - query should be inactive.");
        } catch (HandleNotFoundException e) {
            Assert.assertTrue(e.isInactive());
        // Expected exception
        }
        // now test preview on a query that doesn't return any results
        handle = exploreService.execute(NAMESPACE_ID, "select * from " + getDatasetHiveName(myTable2));
        status = waitForCompletionStatus(handle, 200, TimeUnit.MILLISECONDS, 50);
        Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
        Assert.assertTrue(exploreService.previewResults(handle).isEmpty());
        // calling preview again should return the same thing. it should not throw an exception
        Assert.assertTrue(exploreService.previewResults(handle).isEmpty());
    } finally {
        datasetFramework.deleteInstance(myTable2);
        datasetFramework.deleteInstance(myTable3);
        datasetFramework.deleteInstance(myTable4);
        datasetFramework.deleteInstance(myTable5);
        datasetFramework.deleteInstance(myTable6);
    }
}
Also used : QueryResult(io.cdap.cdap.proto.QueryResult) QueryHandle(io.cdap.cdap.proto.QueryHandle) QueryStatus(io.cdap.cdap.proto.QueryStatus) DatasetId(io.cdap.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 68 with QueryHandle

use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.

the class HiveExploreServiceTimeoutTest method testCloseQuery.

@Test
public void testCloseQuery() throws Exception {
    QueryHandle handle = exploreService.execute(NAMESPACE_ID, "drop table if exists not_existing_table_name");
    exploreService.close(handle);
    try {
        exploreService.getStatus(handle);
        Assert.fail("Should throw HandleNotFoundException due to operation cleanup");
    } catch (HandleNotFoundException e) {
    // Expected exception due to timeout
    }
}
Also used : QueryHandle(io.cdap.cdap.proto.QueryHandle) Test(org.junit.Test)

Example 69 with QueryHandle

use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.

the class HiveExploreServiceTimeoutTest method testTimeoutNoResults.

@Test
public void testTimeoutNoResults() throws Exception {
    Set<Long> beforeTxns = transactionManager.getCurrentState().getInProgress().keySet();
    QueryHandle handle = exploreService.execute(NAMESPACE_ID, "drop table if exists not_existing_table_name");
    Set<Long> queryTxns = Sets.difference(transactionManager.getCurrentState().getInProgress().keySet(), beforeTxns);
    Assert.assertFalse(queryTxns.isEmpty());
    QueryStatus status = waitForCompletionStatus(handle, 200, TimeUnit.MILLISECONDS, 20);
    Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
    Assert.assertFalse(status.hasResults());
    List<ColumnDesc> schema = exploreService.getResultSchema(handle);
    // Sleep for some time for txn to get closed
    TimeUnit.SECONDS.sleep(1);
    // Make sure that the transaction got closed
    Assert.assertEquals(ImmutableSet.<Long>of(), Sets.intersection(queryTxns, transactionManager.getCurrentState().getInProgress().keySet()).immutableCopy());
    // Check if calls using inactive handle still work
    Assert.assertEquals(status, exploreService.getStatus(handle));
    Assert.assertEquals(schema, exploreService.getResultSchema(handle));
    exploreService.close(handle);
    // Sleep for timeout to happen
    TimeUnit.SECONDS.sleep(INACTIVE_OPERATION_TIMEOUT_SECS + 3);
    try {
        exploreService.getStatus(handle);
        Assert.fail("Should throw HandleNotFoundException due to operation cleanup");
    } catch (HandleNotFoundException e) {
    // Expected exception due to timeout
    }
}
Also used : QueryHandle(io.cdap.cdap.proto.QueryHandle) ColumnDesc(io.cdap.cdap.proto.ColumnDesc) QueryStatus(io.cdap.cdap.proto.QueryStatus) Test(org.junit.Test)

Example 70 with QueryHandle

use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.

the class HiveExploreServiceTimeoutTest method testTimeoutRunning.

@Test
public void testTimeoutRunning() throws Exception {
    Set<Long> beforeTxns = transactionManager.getCurrentState().getInProgress().keySet();
    QueryHandle handle = exploreService.execute(NAMESPACE_ID, "select key, value from " + MY_TABLE_NAME);
    Set<Long> queryTxns = Sets.difference(transactionManager.getCurrentState().getInProgress().keySet(), beforeTxns);
    Assert.assertFalse(queryTxns.isEmpty());
    // Sleep for timeout to happen
    TimeUnit.SECONDS.sleep(ACTIVE_OPERATION_TIMEOUT_SECS + 3);
    try {
        exploreService.getStatus(handle);
        Assert.fail("Should throw HandleNotFoundException due to operation timeout");
    } catch (HandleNotFoundException e) {
    // Expected exception due to timeout
    }
    // Make sure that the transaction got closed
    Assert.assertEquals(ImmutableSet.<Long>of(), Sets.intersection(queryTxns, transactionManager.getCurrentState().getInProgress().keySet()).immutableCopy());
}
Also used : QueryHandle(io.cdap.cdap.proto.QueryHandle) Test(org.junit.Test)

Aggregations

QueryHandle (io.cdap.cdap.proto.QueryHandle)70 ExploreException (io.cdap.cdap.explore.service.ExploreException)40 SQLException (java.sql.SQLException)26 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)22 OperationHandle (org.apache.hive.service.cli.OperationHandle)22 SessionHandle (org.apache.hive.service.cli.SessionHandle)22 HandleNotFoundException (io.cdap.cdap.explore.service.HandleNotFoundException)18 QueryStatus (io.cdap.cdap.proto.QueryStatus)16 Path (javax.ws.rs.Path)16 IOException (java.io.IOException)14 Callable (java.util.concurrent.Callable)10 POST (javax.ws.rs.POST)10 Test (org.junit.Test)10 JsonObject (com.google.gson.JsonObject)8 UnsupportedTypeException (io.cdap.cdap.api.data.schema.UnsupportedTypeException)8 JsonSyntaxException (com.google.gson.JsonSyntaxException)6 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)6 BadRequestException (io.cdap.cdap.common.BadRequestException)6 ColumnDesc (io.cdap.cdap.proto.ColumnDesc)6 QueryResult (io.cdap.cdap.proto.QueryResult)6