Search in sources :

Example 76 with NoSuchObjectException

use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.

the class TestHiveMetaStore method testSimpleTypeApi.

public void testSimpleTypeApi() throws Exception {
    try {
        client.dropType(serdeConstants.INT_TYPE_NAME);
        Type typ1 = new Type();
        typ1.setName(serdeConstants.INT_TYPE_NAME);
        boolean ret = client.createType(typ1);
        assertTrue("Unable to create type", ret);
        Type typ1_2 = client.getType(serdeConstants.INT_TYPE_NAME);
        assertNotNull(typ1_2);
        assertEquals(typ1.getName(), typ1_2.getName());
        ret = client.dropType(serdeConstants.INT_TYPE_NAME);
        assertTrue("unable to drop type integer", ret);
        boolean exceptionThrown = false;
        try {
            client.getType(serdeConstants.INT_TYPE_NAME);
        } catch (NoSuchObjectException e) {
            exceptionThrown = true;
        }
        assertTrue("Expected NoSuchObjectException", exceptionThrown);
    } catch (Exception e) {
        System.err.println(StringUtils.stringifyException(e));
        System.err.println("testSimpleTypeApi() failed.");
        throw e;
    }
}
Also used : Type(org.apache.hadoop.hive.metastore.api.Type) ResourceType(org.apache.hadoop.hive.metastore.api.ResourceType) FunctionType(org.apache.hadoop.hive.metastore.api.FunctionType) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) ConfigValSecurityException(org.apache.hadoop.hive.metastore.api.ConfigValSecurityException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 77 with NoSuchObjectException

use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.

the class TestMarkPartition method testMarkingPartitionSet.

public void testMarkingPartitionSet() throws CommandNeedRetryException, MetaException, TException, NoSuchObjectException, UnknownDBException, UnknownTableException, InvalidPartitionException, UnknownPartitionException, InterruptedException {
    HiveMetaStoreClient msc = new HiveMetaStoreClient(hiveConf);
    driver = new Driver(hiveConf);
    driver.run("drop database if exists hive2215 cascade");
    driver.run("create database hive2215");
    driver.run("use hive2215");
    driver.run("drop table if exists tmptbl");
    driver.run("create table tmptbl (a string) partitioned by (b string)");
    driver.run("alter table tmptbl add partition (b='2011')");
    Map<String, String> kvs = new HashMap<String, String>();
    kvs.put("b", "'2011'");
    msc.markPartitionForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
    assert msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
    Thread.sleep(10000);
    assert !msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
    kvs.put("b", "'2012'");
    assert !msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
    try {
        msc.markPartitionForEvent("hive2215", "tmptbl2", kvs, PartitionEventType.LOAD_DONE);
        assert false;
    } catch (Exception e) {
        assert e instanceof UnknownTableException;
    }
    try {
        msc.isPartitionMarkedForEvent("hive2215", "tmptbl2", kvs, PartitionEventType.LOAD_DONE);
        assert false;
    } catch (Exception e) {
        assert e instanceof UnknownTableException;
    }
    kvs.put("a", "'2012'");
    try {
        msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
        assert false;
    } catch (Exception e) {
        assert e instanceof InvalidPartitionException;
    }
}
Also used : UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) HashMap(java.util.HashMap) Driver(org.apache.hadoop.hive.ql.Driver) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) TException(org.apache.thrift.TException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) CommandNeedRetryException(org.apache.hadoop.hive.ql.CommandNeedRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException)

Example 78 with NoSuchObjectException

use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.

the class TestMetaStoreEndFunctionListener method testEndFunctionListener.

public void testEndFunctionListener() throws Exception {
    /* Objective here is to ensure that when exceptions are thrown in HiveMetaStore in API methods
     * they bubble up and are stored in the MetaStoreEndFunctionContext objects
     */
    String dbName = "hive3524";
    String tblName = "tmptbl";
    int listSize = 0;
    driver.run("create database " + dbName);
    try {
        msc.getDatabase("UnknownDB");
    } catch (Exception e) {
    }
    listSize = DummyEndFunctionListener.funcNameList.size();
    String func_name = DummyEndFunctionListener.funcNameList.get(listSize - 1);
    MetaStoreEndFunctionContext context = DummyEndFunctionListener.contextList.get(listSize - 1);
    assertEquals(func_name, "get_database");
    assertFalse(context.isSuccess());
    Exception e = context.getException();
    assertTrue((e != null));
    assertTrue((e instanceof NoSuchObjectException));
    assertEquals(context.getInputTableName(), null);
    driver.run("use " + dbName);
    driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName));
    String tableName = "Unknown";
    try {
        msc.getTable(dbName, tableName);
    } catch (Exception e1) {
    }
    listSize = DummyEndFunctionListener.funcNameList.size();
    func_name = DummyEndFunctionListener.funcNameList.get(listSize - 1);
    context = DummyEndFunctionListener.contextList.get(listSize - 1);
    assertEquals(func_name, "get_table");
    assertFalse(context.isSuccess());
    e = context.getException();
    assertTrue((e != null));
    assertTrue((e instanceof NoSuchObjectException));
    assertEquals(context.getInputTableName(), tableName);
    try {
        msc.getPartition("hive3524", tblName, "b=2012");
    } catch (Exception e2) {
    }
    listSize = DummyEndFunctionListener.funcNameList.size();
    func_name = DummyEndFunctionListener.funcNameList.get(listSize - 1);
    context = DummyEndFunctionListener.contextList.get(listSize - 1);
    assertEquals(func_name, "get_partition_by_name");
    assertFalse(context.isSuccess());
    e = context.getException();
    assertTrue((e != null));
    assertTrue((e instanceof NoSuchObjectException));
    assertEquals(context.getInputTableName(), tblName);
    try {
        driver.run("drop table Unknown");
    } catch (Exception e4) {
    }
    listSize = DummyEndFunctionListener.funcNameList.size();
    func_name = DummyEndFunctionListener.funcNameList.get(listSize - 1);
    context = DummyEndFunctionListener.contextList.get(listSize - 1);
    assertEquals(func_name, "get_table");
    assertFalse(context.isSuccess());
    e = context.getException();
    assertTrue((e != null));
    assertTrue((e instanceof NoSuchObjectException));
    assertEquals(context.getInputTableName(), "Unknown");
}
Also used : NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 79 with NoSuchObjectException

use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.

the class TestHiveMetaStore method testDatabaseLocation.

public void testDatabaseLocation() throws Throwable {
    try {
        // clear up any existing databases
        silentDropDatabase(TEST_DB1_NAME);
        Database db = new Database();
        db.setName(TEST_DB1_NAME);
        String dbLocation = HiveConf.getVar(hiveConf, HiveConf.ConfVars.METASTOREWAREHOUSE) + "/_testDB_create_";
        db.setLocationUri(dbLocation);
        client.createDatabase(db);
        db = client.getDatabase(TEST_DB1_NAME);
        assertEquals("name of returned db is different from that of inserted db", TEST_DB1_NAME, db.getName());
        assertEquals("location of the returned db is different from that of inserted db", warehouse.getDnsPath(new Path(dbLocation)).toString(), db.getLocationUri());
        client.dropDatabase(TEST_DB1_NAME);
        silentDropDatabase(TEST_DB1_NAME);
        boolean objectNotExist = false;
        try {
            client.getDatabase(TEST_DB1_NAME);
        } catch (NoSuchObjectException e) {
            objectNotExist = true;
        }
        assertTrue("Database " + TEST_DB1_NAME + " exists ", objectNotExist);
        db = new Database();
        db.setName(TEST_DB1_NAME);
        dbLocation = HiveConf.getVar(hiveConf, HiveConf.ConfVars.METASTOREWAREHOUSE) + "/_testDB_file_";
        FileSystem fs = FileSystem.get(new Path(dbLocation).toUri(), hiveConf);
        fs.createNewFile(new Path(dbLocation));
        fs.deleteOnExit(new Path(dbLocation));
        db.setLocationUri(dbLocation);
        boolean createFailed = false;
        try {
            client.createDatabase(db);
        } catch (MetaException cantCreateDB) {
            System.err.println(cantCreateDB.getMessage());
            createFailed = true;
        }
        assertTrue("Database creation succeeded even location exists and is a file", createFailed);
        objectNotExist = false;
        try {
            client.getDatabase(TEST_DB1_NAME);
        } catch (NoSuchObjectException e) {
            objectNotExist = true;
        }
        assertTrue("Database " + TEST_DB1_NAME + " exists when location is specified and is a file", objectNotExist);
    } catch (Throwable e) {
        System.err.println(StringUtils.stringifyException(e));
        System.err.println("testDatabaseLocation() failed.");
        throw e;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) Database(org.apache.hadoop.hive.metastore.api.Database) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 80 with NoSuchObjectException

use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project presto by prestodb.

the class ThriftHiveMetastore method getAllTables.

@Override
public Optional<List<String>> getAllTables(String databaseName) {
    Callable<List<String>> getAllTables = stats.getGetAllTables().wrap(() -> {
        try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) {
            return client.getAllTables(databaseName);
        }
    });
    Callable<Void> getDatabase = stats.getGetDatabase().wrap(() -> {
        try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) {
            client.getDatabase(databaseName);
            return null;
        }
    });
    try {
        return retry().stopOn(NoSuchObjectException.class).stopOnIllegalExceptions().run("getAllTables", () -> {
            List<String> tables = getAllTables.call();
            if (tables.isEmpty()) {
                // Check to see if the database exists
                getDatabase.call();
            }
            return Optional.of(tables);
        });
    } catch (NoSuchObjectException e) {
        return Optional.empty();
    } catch (TException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : TException(org.apache.thrift.TException) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) PrestoException(com.facebook.presto.spi.PrestoException) SchemaAlreadyExistsException(com.facebook.presto.hive.SchemaAlreadyExistsException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) PartitionNotFoundException(com.facebook.presto.hive.PartitionNotFoundException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) HiveViewNotSupportedException(com.facebook.presto.hive.HiveViewNotSupportedException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) PrestoException(com.facebook.presto.spi.PrestoException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Aggregations

NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)93 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)56 TException (org.apache.thrift.TException)42 Table (org.apache.hadoop.hive.metastore.api.Table)33 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)31 Partition (org.apache.hadoop.hive.metastore.api.Partition)31 ArrayList (java.util.ArrayList)29 IOException (java.io.IOException)23 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)23 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)22 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)15 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)13 Database (org.apache.hadoop.hive.metastore.api.Database)11 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)11 HCatException (org.apache.hive.hcatalog.common.HCatException)11 Path (org.apache.hadoop.fs.Path)10 SQLException (java.sql.SQLException)8 List (java.util.List)7 Query (javax.jdo.Query)7 ConfigValSecurityException (org.apache.hadoop.hive.metastore.api.ConfigValSecurityException)7