Search in sources :

Example 26 with NoSuchObjectException

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

the class TestObjectStore method dropAllStoreObjects.

private static void dropAllStoreObjects(RawStore store) throws MetaException, InvalidObjectException, InvalidInputException {
    try {
        Deadline.registerIfNot(100000);
        List<Function> functions = store.getAllFunctions();
        for (Function func : functions) {
            store.dropFunction(func.getDbName(), func.getFunctionName());
        }
        List<String> dbs = store.getAllDatabases();
        for (String db : dbs) {
            List<String> tbls = store.getAllTables(db);
            for (String tbl : tbls) {
                Deadline.startTimer("getPartition");
                List<Partition> parts = store.getPartitions(db, tbl, 100);
                for (Partition part : parts) {
                    store.dropPartition(db, tbl, part.getValues());
                }
                // Find any constraints and drop them
                Set<String> constraints = new HashSet<>();
                List<SQLPrimaryKey> pk = store.getPrimaryKeys(db, tbl);
                if (pk != null) {
                    for (SQLPrimaryKey pkcol : pk) {
                        constraints.add(pkcol.getPk_name());
                    }
                }
                List<SQLForeignKey> fks = store.getForeignKeys(null, null, db, tbl);
                if (fks != null) {
                    for (SQLForeignKey fkcol : fks) {
                        constraints.add(fkcol.getFk_name());
                    }
                }
                for (String constraint : constraints) {
                    store.dropConstraint(db, tbl, constraint);
                }
                store.dropTable(db, tbl);
            }
            store.dropDatabase(db);
        }
        List<String> roles = store.listRoleNames();
        for (String role : roles) {
            store.removeRole(role);
        }
    } catch (NoSuchObjectException e) {
    }
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) SQLPrimaryKey(org.apache.hadoop.hive.metastore.api.SQLPrimaryKey) SQLForeignKey(org.apache.hadoop.hive.metastore.api.SQLForeignKey) Function(org.apache.hadoop.hive.metastore.api.Function) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) HashSet(java.util.HashSet)

Example 27 with NoSuchObjectException

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

the class TestOldSchema method dropAllStoreObjects.

private static void dropAllStoreObjects(RawStore store) throws MetaException, InvalidObjectException, InvalidInputException {
    try {
        Deadline.registerIfNot(100000);
        Deadline.startTimer("getPartition");
        List<String> dbs = store.getAllDatabases();
        for (int i = 0; i < dbs.size(); i++) {
            String db = dbs.get(i);
            List<String> tbls = store.getAllTables(db);
            for (String tbl : tbls) {
                List<Partition> parts = store.getPartitions(db, tbl, 100);
                for (Partition part : parts) {
                    store.dropPartition(db, tbl, part.getValues());
                }
                store.dropTable(db, tbl);
            }
            store.dropDatabase(db);
        }
    } catch (NoSuchObjectException e) {
    }
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 28 with NoSuchObjectException

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

the class TestTablesCreateDropAlterTruncate method testDropTableCaseInsensitive.

@Test
public void testDropTableCaseInsensitive() throws Exception {
    Table table = testTables[0];
    // Test in upper case
    client.dropTable(table.getDbName().toUpperCase(), table.getTableName().toUpperCase());
    try {
        client.getTable(table.getDbName(), table.getTableName());
        Assert.fail("Expected a NoSuchObjectException to be thrown");
    } catch (NoSuchObjectException exception) {
    // Expected exception
    }
    // Test in mixed case
    client.createTable(table);
    client.dropTable("DeFaUlt", "TeST_tAbLE");
    try {
        client.getTable(table.getDbName(), table.getTableName());
        Assert.fail("Expected a NoSuchObjectException to be thrown");
    } catch (NoSuchObjectException exception) {
    // Expected exception
    }
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 29 with NoSuchObjectException

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

the class TestDatabases method testCreateGetDeleteDatabase.

/**
 * This test creates and queries a database and then drops it. Good for testing the happy path.
 * @throws Exception
 */
@Test
public void testCreateGetDeleteDatabase() throws Exception {
    Database database = getDatabaseWithAllParametersSet();
    client.createDatabase(database);
    Database createdDatabase = client.getDatabase(database.getName());
    // The createTime will be set on the server side, so the comparison should skip it
    Assert.assertEquals("Comparing databases", database, createdDatabase);
    Assert.assertTrue("The directory should be created", metaStore.isPathExists(new Path(database.getLocationUri())));
    client.dropDatabase(database.getName());
    Assert.assertFalse("The directory should be removed", metaStore.isPathExists(new Path(database.getLocationUri())));
    try {
        client.getDatabase(database.getName());
        Assert.fail("Expected a NoSuchObjectException to be thrown");
    } catch (NoSuchObjectException exception) {
    // Expected exception
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Database(org.apache.hadoop.hive.metastore.api.Database) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Example 30 with NoSuchObjectException

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

the class TestExchangePartitions method checkRemainingPartitions.

private void checkRemainingPartitions(Table sourceTable, Table destTable, List<Partition> partitions) throws Exception {
    for (Partition partition : partitions) {
        // Check if the partitions exist in the sourceTable
        Partition resultPart = client.getPartition(sourceTable.getDbName(), sourceTable.getTableName(), partition.getValues());
        Assert.assertNotNull(resultPart);
        Assert.assertEquals(partition, resultPart);
        Assert.assertTrue(metaStore.isPathExists(new Path(partition.getSd().getLocation())));
        // Check if the partitions don't exist in the destTable
        try {
            client.getPartition(destTable.getDbName(), destTable.getTableName(), partition.getValues());
            Assert.fail("The partition '" + partition.getValues().toString() + "'should not exists, therefore NoSuchObjectException should have been thrown.");
        } catch (NoSuchObjectException e) {
        // Expected exception
        }
        String partName = Warehouse.makePartName(sourceTable.getPartitionKeys(), partition.getValues());
        Assert.assertFalse(metaStore.isPathExists(new Path(destTable.getSd().getLocation() + "/" + partName)));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Partition(org.apache.hadoop.hive.metastore.api.Partition) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Aggregations

NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)144 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)74 TException (org.apache.thrift.TException)55 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)47 Table (org.apache.hadoop.hive.metastore.api.Table)45 Partition (org.apache.hadoop.hive.metastore.api.Partition)44 ArrayList (java.util.ArrayList)42 IOException (java.io.IOException)39 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)36 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)30 Test (org.junit.Test)24 Database (org.apache.hadoop.hive.metastore.api.Database)22 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)21 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)20 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)20 Path (org.apache.hadoop.fs.Path)19 Query (javax.jdo.Query)17 SQLException (java.sql.SQLException)16 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)13 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)13