Search in sources :

Example 41 with ExploreException

use of co.cask.cdap.explore.service.ExploreException in project cdap by caskdata.

the class TestSQLQueryTestRun method testSQLQueryWithCustomMapping.

@Test(timeout = 120000L)
public void testSQLQueryWithCustomMapping() throws Exception {
    // trying to create a cdap namespace with custom hive database when the database does not exists in hive should
    // fail.
    String customHiveDatabase = "custom_db";
    try {
        namespaceAdmin.create(new NamespaceMeta.Builder().setName(testSpace).setHiveDatabase(customHiveDatabase).build());
        Assert.fail();
    } catch (NamespaceCannotBeCreatedException e) {
        // expected exception. Make sure that the namespace creation failed because of explore exception
        Assert.assertTrue(e.getCause() instanceof ExploreException);
    }
    // create the custom database in hive
    try (Connection connection = getQueryClient();
        ResultSet results = connection.prepareStatement(String.format("CREATE DATABASE %s", customHiveDatabase)).executeQuery()) {
        // run a query over the dataset
        Assert.assertNotNull(results);
    }
    // check that the custom hive database got created
    checkDatabaseExists(customHiveDatabase);
    // now the namespace create should work
    namespaceAdmin.create(new NamespaceMeta.Builder().setName(testSpace).setHiveDatabase(customHiveDatabase).build());
    // test some sql query on this custom hive database
    testSQLQuery();
    // delete the cdap namespace
    namespaceAdmin.delete(testSpace);
    // deleting the cdap namespace should not have deleted the custom hive database
    checkDatabaseExists(customHiveDatabase);
}
Also used : NamespaceCannotBeCreatedException(co.cask.cdap.common.NamespaceCannotBeCreatedException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ExploreException(co.cask.cdap.explore.service.ExploreException) Test(org.junit.Test)

Aggregations

ExploreException (co.cask.cdap.explore.service.ExploreException)41 QueryHandle (co.cask.cdap.proto.QueryHandle)16 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)14 HttpResponse (co.cask.common.http.HttpResponse)12 OperationHandle (org.apache.hive.service.cli.OperationHandle)12 SessionHandle (org.apache.hive.service.cli.SessionHandle)12 SQLException (java.sql.SQLException)11 IOException (java.io.IOException)9 HandleNotFoundException (co.cask.cdap.explore.service.HandleNotFoundException)6 TableNotFoundException (co.cask.cdap.explore.service.TableNotFoundException)4 Path (javax.ws.rs.Path)4 QueryStatus (co.cask.cdap.proto.QueryStatus)3 FileNotFoundException (java.io.FileNotFoundException)3 TException (org.apache.thrift.TException)3 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)2 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 HBaseDDLExecutor (co.cask.cdap.spi.hbase.HBaseDDLExecutor)2 ImmutableList (com.google.common.collect.ImmutableList)2 JsonObject (com.google.gson.JsonObject)2 HashMap (java.util.HashMap)2