Search in sources :

Example 1 with MFunction

use of org.apache.hadoop.hive.metastore.model.MFunction in project hive by apache.

the class ObjectStore method alterFunction.

@Override
public void alterFunction(String dbName, String funcName, Function newFunction) throws InvalidObjectException, MetaException {
    boolean success = false;
    try {
        openTransaction();
        funcName = HiveStringUtils.normalizeIdentifier(funcName);
        dbName = HiveStringUtils.normalizeIdentifier(dbName);
        MFunction newf = convertToMFunction(newFunction);
        if (newf == null) {
            throw new InvalidObjectException("new function is invalid");
        }
        MFunction oldf = getMFunction(dbName, funcName);
        if (oldf == null) {
            throw new MetaException("function " + funcName + " doesn't exist");
        }
        // For now only alter name, owner, class name, type
        oldf.setFunctionName(HiveStringUtils.normalizeIdentifier(newf.getFunctionName()));
        oldf.setDatabase(newf.getDatabase());
        oldf.setOwnerName(newf.getOwnerName());
        oldf.setOwnerType(newf.getOwnerType());
        oldf.setClassName(newf.getClassName());
        oldf.setFunctionType(newf.getFunctionType());
        // commit the changes
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
}
Also used : MFunction(org.apache.hadoop.hive.metastore.model.MFunction) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 2 with MFunction

use of org.apache.hadoop.hive.metastore.model.MFunction in project hive by apache.

the class ObjectStore method getAllFunctions.

@Override
public List<Function> getAllFunctions() throws MetaException {
    boolean commited = false;
    try {
        openTransaction();
        Query query = pm.newQuery(MFunction.class);
        List<MFunction> allFunctions = (List<MFunction>) query.execute();
        pm.retrieveAll(allFunctions);
        commited = commitTransaction();
        return convertToFunctions(allFunctions);
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
}
Also used : Query(javax.jdo.Query) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MFunction(org.apache.hadoop.hive.metastore.model.MFunction)

Example 3 with MFunction

use of org.apache.hadoop.hive.metastore.model.MFunction in project hive by apache.

the class ObjectStore method convertToMFunction.

private MFunction convertToMFunction(Function func) throws InvalidObjectException {
    if (func == null) {
        return null;
    }
    MDatabase mdb = null;
    try {
        mdb = getMDatabase(func.getDbName());
    } catch (NoSuchObjectException e) {
        LOG.error(StringUtils.stringifyException(e));
        throw new InvalidObjectException("Database " + func.getDbName() + " doesn't exist.");
    }
    MFunction mfunc = new MFunction(func.getFunctionName(), mdb, func.getClassName(), func.getOwnerName(), func.getOwnerType().name(), func.getCreateTime(), func.getFunctionType().getValue(), convertToMResourceUriList(func.getResourceUris()));
    return mfunc;
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MFunction(org.apache.hadoop.hive.metastore.model.MFunction)

Example 4 with MFunction

use of org.apache.hadoop.hive.metastore.model.MFunction in project hive by apache.

the class ObjectStore method dropFunction.

@Override
public void dropFunction(String dbName, String funcName) throws MetaException, NoSuchObjectException, InvalidObjectException, InvalidInputException {
    boolean success = false;
    try {
        openTransaction();
        MFunction mfunc = getMFunction(dbName, funcName);
        pm.retrieve(mfunc);
        if (mfunc != null) {
            // TODO: When function privileges are implemented, they should be deleted here.
            pm.deletePersistentAll(mfunc);
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
}
Also used : MFunction(org.apache.hadoop.hive.metastore.model.MFunction)

Example 5 with MFunction

use of org.apache.hadoop.hive.metastore.model.MFunction in project hive by apache.

the class ObjectStore method createFunction.

@Override
public void createFunction(Function func) throws InvalidObjectException, MetaException {
    boolean committed = false;
    try {
        openTransaction();
        MFunction mfunc = convertToMFunction(func);
        pm.makePersistent(mfunc);
        committed = commitTransaction();
    } finally {
        if (!committed) {
            rollbackTransaction();
        }
    }
}
Also used : MFunction(org.apache.hadoop.hive.metastore.model.MFunction)

Aggregations

MFunction (org.apache.hadoop.hive.metastore.model.MFunction)6 Query (javax.jdo.Query)2 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 MDatabase (org.apache.hadoop.hive.metastore.model.MDatabase)1 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)1