Search in sources :

Example 6 with PrincipalType

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

the class ObjectStore method convertGlobal.

private List<HiveObjectPrivilege> convertGlobal(List<MGlobalPrivilege> privs) {
    List<HiveObjectPrivilege> result = new ArrayList<>();
    for (MGlobalPrivilege priv : privs) {
        String pname = priv.getPrincipalName();
        String authorizer = priv.getAuthorizer();
        PrincipalType ptype = PrincipalType.valueOf(priv.getPrincipalType());
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.GLOBAL, null, null, null, null);
        PrivilegeGrantInfo grantor = new PrivilegeGrantInfo(priv.getPrivilege(), priv.getCreateTime(), priv.getGrantor(), PrincipalType.valueOf(priv.getGrantorType()), priv.getGrantOption());
        result.add(new HiveObjectPrivilege(objectRef, pname, ptype, grantor, authorizer));
    }
    return result;
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) MGlobalPrivilege(org.apache.hadoop.hive.metastore.model.MGlobalPrivilege) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Example 7 with PrincipalType

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

the class ObjectStore method getJDODatabase.

public Database getJDODatabase(String catName, String name) throws NoSuchObjectException {
    MDatabase mdb = null;
    boolean commited = false;
    try {
        openTransaction();
        mdb = getMDatabase(catName, name);
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
    Database db = new Database();
    db.setName(mdb.getName());
    db.setDescription(mdb.getDescription());
    db.setParameters(convertMap(mdb.getParameters()));
    db.setOwnerName(mdb.getOwnerName());
    String type = org.apache.commons.lang3.StringUtils.defaultIfBlank(mdb.getOwnerType(), null);
    PrincipalType principalType = (type == null) ? null : PrincipalType.valueOf(type);
    db.setOwnerType(principalType);
    if (mdb.getType().equalsIgnoreCase(DatabaseType.NATIVE.name())) {
        db.setType(DatabaseType.NATIVE);
        db.setLocationUri(mdb.getLocationUri());
        db.setManagedLocationUri(org.apache.commons.lang3.StringUtils.defaultIfBlank(mdb.getManagedLocationUri(), null));
    } else {
        db.setType(DatabaseType.REMOTE);
        db.setConnector_name(org.apache.commons.lang3.StringUtils.defaultIfBlank(mdb.getDataConnectorName(), null));
        db.setRemote_dbname(org.apache.commons.lang3.StringUtils.defaultIfBlank(mdb.getRemoteDatabaseName(), null));
    }
    db.setCatalogName(catName);
    db.setCreateTime(mdb.getCreateTime());
    return db;
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) Database(org.apache.hadoop.hive.metastore.api.Database) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Example 8 with PrincipalType

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

the class TestHiveMetaStore method testFunctionWithResources.

@Test
public void testFunctionWithResources() throws Exception {
    String dbName = "test_db2";
    String funcName = "test_func";
    String className = "org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper";
    String owner = "test_owner";
    PrincipalType ownerType = PrincipalType.USER;
    int createTime = (int) (System.currentTimeMillis() / 1000);
    FunctionType funcType = FunctionType.JAVA;
    List<ResourceUri> resList = new ArrayList<>();
    resList.add(new ResourceUri(ResourceType.JAR, "hdfs:///tmp/jar1.jar"));
    resList.add(new ResourceUri(ResourceType.FILE, "hdfs:///tmp/file1.txt"));
    resList.add(new ResourceUri(ResourceType.ARCHIVE, "hdfs:///tmp/archive1.tgz"));
    try {
        cleanUp(dbName, null, null);
        createDb(dbName);
        createFunction(dbName, funcName, className, owner, ownerType, createTime, funcType, resList);
        // Try the different getters
        // getFunction()
        Function func = client.getFunction(dbName, funcName);
        assertEquals("function db name", dbName, func.getDbName());
        assertEquals("function name", funcName, func.getFunctionName());
        assertEquals("function class name", className, func.getClassName());
        assertEquals("function owner name", owner, func.getOwnerName());
        assertEquals("function owner type", PrincipalType.USER, func.getOwnerType());
        assertEquals("function type", funcType, func.getFunctionType());
        List<ResourceUri> resources = func.getResourceUris();
        assertEquals("Resource list size", resList.size(), resources.size());
        for (ResourceUri res : resources) {
            assertTrue("Matching resource " + res.getResourceType() + " " + res.getUri(), resList.indexOf(res) >= 0);
        }
        client.dropFunction(dbName, funcName);
    } catch (Exception e) {
        System.err.println(StringUtils.stringifyException(e));
        System.err.println("testConcurrentMetastores() failed.");
        throw e;
    } finally {
        silentDropDatabase(dbName);
    }
}
Also used : ResourceUri(org.apache.hadoop.hive.metastore.api.ResourceUri) Function(org.apache.hadoop.hive.metastore.api.Function) FunctionType(org.apache.hadoop.hive.metastore.api.FunctionType) ArrayList(java.util.ArrayList) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) 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) IOException(java.io.IOException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Test(org.junit.Test)

Example 9 with PrincipalType

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

the class ObjectStore method convertToMTable.

private MTable convertToMTable(Table tbl) throws InvalidObjectException, MetaException {
    // existing write ID against the caller's valid list.
    if (tbl == null) {
        return null;
    }
    MDatabase mdb = null;
    String catName = tbl.isSetCatName() ? tbl.getCatName() : getDefaultCatalog(conf);
    try {
        mdb = getMDatabase(catName, tbl.getDbName());
    } catch (NoSuchObjectException e) {
        LOG.error("Could not convert to MTable", e);
        throw new InvalidObjectException("Database " + DatabaseName.getQualified(catName, tbl.getDbName()) + " doesn't exist.");
    }
    // If the table has property EXTERNAL set, update table type
    // accordingly
    String tableType = tbl.getTableType();
    boolean isExternal = Boolean.parseBoolean(tbl.getParameters().get("EXTERNAL"));
    if (TableType.MANAGED_TABLE.toString().equals(tableType)) {
        if (isExternal) {
            tableType = TableType.EXTERNAL_TABLE.toString();
        }
    }
    if (TableType.EXTERNAL_TABLE.toString().equals(tableType)) {
        if (!isExternal) {
            tableType = TableType.MANAGED_TABLE.toString();
        }
    }
    PrincipalType ownerPrincipalType = tbl.getOwnerType();
    String ownerType = (ownerPrincipalType == null) ? PrincipalType.USER.name() : ownerPrincipalType.name();
    // A new table is always created with a new column descriptor
    return new MTable(normalizeIdentifier(tbl.getTableName()), mdb, convertToMStorageDescriptor(tbl.getSd()), tbl.getOwner(), ownerType, tbl.getCreateTime(), tbl.getLastAccessTime(), tbl.getRetention(), convertToMFieldSchemas(tbl.getPartitionKeys()), tbl.getParameters(), tbl.getViewOriginalText(), tbl.getViewExpandedText(), tbl.isRewriteEnabled(), tableType);
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) MTable(org.apache.hadoop.hive.metastore.model.MTable) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Example 10 with PrincipalType

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

the class ObjectStore method createDataConnector.

@Override
public void createDataConnector(DataConnector connector) throws InvalidObjectException, MetaException {
    boolean commited = false;
    MDataConnector mDataConnector = new MDataConnector();
    mDataConnector.setName(connector.getName().toLowerCase());
    mDataConnector.setType(connector.getType());
    mDataConnector.setUrl(connector.getUrl());
    mDataConnector.setDescription(connector.getDescription());
    mDataConnector.setParameters(connector.getParameters());
    mDataConnector.setOwnerName(connector.getOwnerName());
    PrincipalType ownerType = connector.getOwnerType();
    mDataConnector.setOwnerType((null == ownerType ? PrincipalType.USER.name() : ownerType.name()));
    mDataConnector.setCreateTime(connector.getCreateTime());
    try {
        openTransaction();
        pm.makePersistent(mDataConnector);
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
}
Also used : MDataConnector(org.apache.hadoop.hive.metastore.model.MDataConnector) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType)

Aggregations

PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)29 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)15 ArrayList (java.util.ArrayList)14 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)13 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)11 MDatabase (org.apache.hadoop.hive.metastore.model.MDatabase)8 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)6 MTable (org.apache.hadoop.hive.metastore.model.MTable)6 Hive (org.apache.hadoop.hive.ql.metadata.Hive)6 Database (org.apache.hadoop.hive.metastore.api.Database)5 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)5 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)5 MDataConnector (org.apache.hadoop.hive.metastore.model.MDataConnector)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)4 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 List (java.util.List)3 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)3 MDBPrivilege (org.apache.hadoop.hive.metastore.model.MDBPrivilege)3 MDCPrivilege (org.apache.hadoop.hive.metastore.model.MDCPrivilege)3