Search in sources :

Example 21 with AlreadyExistsException

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

the class TestHiveMetaStoreChecker method testErrorForMissingPartitionsSingleThreaded.

/*
   * Test if single-threaded implementation checker throws HiveException when the there is a dummy
   * directory present in the nested level
   */
@Test
public void testErrorForMissingPartitionsSingleThreaded() throws AlreadyExistsException, HiveException, IOException {
    // set num of threads to 0 so that single-threaded checkMetastore is called
    hive.getConf().setIntVar(HiveConf.ConfVars.METASTORE_FS_HANDLER_THREADS_COUNT, 0);
    Table testTable = createPartitionedTestTable(dbName, tableName, 2, 0);
    // add 10 partitions on the filesystem
    createPartitionsDirectoriesOnFS(testTable, 10);
    // create a fake directory to throw exception
    StringBuilder sb = new StringBuilder(testTable.getDataLocation().toString());
    sb.append(Path.SEPARATOR);
    sb.append("dummyPart=error");
    createDirectory(sb.toString());
    // check result now
    CheckResult result = new CheckResult();
    Exception exception = null;
    try {
        checker.checkMetastore(dbName, tableName, null, result);
    } catch (Exception e) {
        exception = e;
    }
    assertTrue("Expected HiveException", exception != null && exception instanceof HiveException);
    createFile(sb.toString(), "dummyFile");
    result = new CheckResult();
    exception = null;
    try {
        checker.checkMetastore(dbName, tableName, null, result);
    } catch (Exception e) {
        exception = e;
    }
    assertTrue("Expected HiveException", exception != null && exception instanceof HiveException);
}
Also used : MetaException(org.apache.hadoop.hive.metastore.api.MetaException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test)

Example 22 with AlreadyExistsException

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

the class ObjectStore method createISchema.

@Override
public void createISchema(ISchema schema) throws AlreadyExistsException, MetaException, NoSuchObjectException {
    boolean committed = false;
    MISchema mSchema = convertToMISchema(schema);
    try {
        openTransaction();
        if (getMISchema(schema.getDbName(), schema.getName()) != null) {
            throw new AlreadyExistsException("Schema with name " + schema.getDbName() + "." + schema.getName() + " already exists");
        }
        pm.makePersistent(mSchema);
        committed = commitTransaction();
    } finally {
        if (!committed)
            rollbackTransaction();
    }
}
Also used : AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) MISchema(org.apache.hadoop.hive.metastore.model.MISchema)

Example 23 with AlreadyExistsException

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

the class ObjectStore method createWMTrigger.

@Override
public void createWMTrigger(WMTrigger trigger) throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException, MetaException {
    boolean commited = false;
    try {
        openTransaction();
        MWMResourcePlan resourcePlan = getMWMResourcePlan(trigger.getResourcePlanName(), true);
        MWMTrigger mTrigger = new MWMTrigger(resourcePlan, normalizeIdentifier(trigger.getTriggerName()), trigger.getTriggerExpression(), trigger.getActionExpression(), null, trigger.isSetIsInUnmanaged() && trigger.isIsInUnmanaged());
        pm.makePersistent(mTrigger);
        commited = commitTransaction();
    } catch (Exception e) {
        checkForConstraintException(e, "Trigger already exists, use alter: ");
        throw e;
    } finally {
        rollbackAndCleanup(commited, (Query) null);
    }
}
Also used : MWMTrigger(org.apache.hadoop.hive.metastore.model.MWMTrigger) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) JDOCanRetryException(javax.jdo.JDOCanRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) JDOException(javax.jdo.JDOException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException)

Example 24 with AlreadyExistsException

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

the class ObjectStore method alterResourcePlan.

@Override
public WMFullResourcePlan alterResourcePlan(String name, WMNullableResourcePlan changes, boolean canActivateDisabled, boolean canDeactivate, boolean isReplace) throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException, MetaException {
    name = name == null ? null : normalizeIdentifier(name);
    if (isReplace && name == null) {
        throw new InvalidOperationException("Cannot replace without specifying the source plan");
    }
    boolean commited = false;
    Query query = null;
    // This method only returns the result when activating a resource plan.
    // We could also add a boolean flag to be specified by the caller to see
    // when the result might be needed.
    WMFullResourcePlan result = null;
    try {
        openTransaction();
        if (isReplace) {
            result = handleAlterReplace(name, changes);
        } else {
            result = handleSimpleAlter(name, changes, canActivateDisabled, canDeactivate);
        }
        commited = commitTransaction();
        return result;
    } catch (Exception e) {
        checkForConstraintException(e, "Resource plan name should be unique: ");
        throw e;
    } finally {
        rollbackAndCleanup(commited, query);
    }
}
Also used : WMFullResourcePlan(org.apache.hadoop.hive.metastore.api.WMFullResourcePlan) Query(javax.jdo.Query) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) JDOCanRetryException(javax.jdo.JDOCanRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) JDOException(javax.jdo.JDOException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException)

Example 25 with AlreadyExistsException

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

the class ObjectStore method createResourcePlan.

@Override
public void createResourcePlan(WMResourcePlan resourcePlan, String copyFromName, int defaultPoolSize) throws AlreadyExistsException, InvalidObjectException, MetaException, NoSuchObjectException {
    boolean commited = false;
    String rpName = normalizeIdentifier(resourcePlan.getName());
    if (rpName.isEmpty()) {
        throw new InvalidObjectException("Resource name cannot be empty.");
    }
    MWMResourcePlan rp = null;
    if (copyFromName == null) {
        Integer queryParallelism = null;
        if (resourcePlan.isSetQueryParallelism()) {
            queryParallelism = resourcePlan.getQueryParallelism();
            if (queryParallelism <= 0) {
                throw new InvalidObjectException("Query parallelism should be positive.");
            }
        }
        rp = new MWMResourcePlan(rpName, queryParallelism, Status.DISABLED);
    } else {
        rp = new MWMResourcePlan(rpName, null, Status.DISABLED);
    }
    try {
        openTransaction();
        pm.makePersistent(rp);
        if (copyFromName != null) {
            MWMResourcePlan copyFrom = getMWMResourcePlan(copyFromName, false);
            if (copyFrom == null) {
                throw new NoSuchObjectException(copyFromName);
            }
            copyRpContents(rp, copyFrom);
        } else {
            // all the RawStore-s. Right now there's no method to create a pool.
            if (defaultPoolSize > 0) {
                MWMPool defaultPool = new MWMPool(rp, "default", 1.0, defaultPoolSize, null);
                pm.makePersistent(defaultPool);
                rp.setPools(Sets.newHashSet(defaultPool));
                rp.setDefaultPool(defaultPool);
            }
        }
        commited = commitTransaction();
    } catch (InvalidOperationException e) {
        throw new RuntimeException(e);
    } catch (Exception e) {
        checkForConstraintException(e, "Resource plan already exists: ");
        throw e;
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
}
Also used : MWMPool(org.apache.hadoop.hive.metastore.model.MWMPool) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MWMResourcePlan(org.apache.hadoop.hive.metastore.model.MWMResourcePlan) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) JDOCanRetryException(javax.jdo.JDOCanRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) JDOException(javax.jdo.JDOException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException)

Aggregations

AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)30 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)24 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)24 TException (org.apache.thrift.TException)23 IOException (java.io.IOException)16 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)16 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)13 Table (org.apache.hadoop.hive.metastore.api.Table)12 ArrayList (java.util.ArrayList)9 JDODataStoreException (javax.jdo.JDODataStoreException)9 Partition (org.apache.hadoop.hive.metastore.api.Partition)8 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)7 ExecutionException (java.util.concurrent.ExecutionException)6 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)6 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)6 QualifiedName (com.netflix.metacat.common.QualifiedName)5 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)5 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)5 List (java.util.List)5 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)5