Search in sources :

Example 1 with MCreationMetadata

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

the class ObjectStore method dropCreationMetadata.

private boolean dropCreationMetadata(String dbName, String tableName) throws MetaException, NoSuchObjectException, InvalidObjectException, InvalidInputException {
    boolean success = false;
    try {
        openTransaction();
        MCreationMetadata mcm = getCreationMetadata(dbName, tableName);
        pm.retrieve(mcm);
        if (mcm != null) {
            pm.deletePersistentAll(mcm);
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
    return success;
}
Also used : MCreationMetadata(org.apache.hadoop.hive.metastore.model.MCreationMetadata)

Example 2 with MCreationMetadata

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

the class ObjectStore method getCreationMetadata.

private MCreationMetadata getCreationMetadata(String dbName, String tblName) {
    boolean commited = false;
    MCreationMetadata mcm = null;
    Query query = null;
    try {
        openTransaction();
        query = pm.newQuery(MCreationMetadata.class, "tblName == table && dbName == db");
        query.declareParameters("java.lang.String table, java.lang.String db");
        query.setUnique(true);
        mcm = (MCreationMetadata) query.execute(tblName, dbName);
        pm.retrieve(mcm);
        commited = commitTransaction();
    } finally {
        rollbackAndCleanup(commited, query);
    }
    return mcm;
}
Also used : Query(javax.jdo.Query) MCreationMetadata(org.apache.hadoop.hive.metastore.model.MCreationMetadata)

Example 3 with MCreationMetadata

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

the class ObjectStore method updateCreationMetadata.

@Override
public void updateCreationMetadata(String dbname, String tablename, CreationMetadata cm) throws MetaException {
    boolean success = false;
    try {
        openTransaction();
        dbname = normalizeIdentifier(dbname);
        tablename = normalizeIdentifier(tablename);
        // Update creation metadata
        MCreationMetadata newMcm = convertToMCreationMetadata(cm);
        MCreationMetadata mcm = getCreationMetadata(dbname, tablename);
        mcm.setTables(newMcm.getTables());
        mcm.setTxnList(newMcm.getTxnList());
        // commit the changes
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        } else {
            // Add to the invalidation cache if the creation signature has changed
            MaterializationsInvalidationCache.get().alterMaterializedView(dbname, tablename, cm.getTablesUsed(), cm.getValidTxnList());
        }
    }
}
Also used : MCreationMetadata(org.apache.hadoop.hive.metastore.model.MCreationMetadata)

Example 4 with MCreationMetadata

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

the class ObjectStore method convertToCreationMetadata.

private CreationMetadata convertToCreationMetadata(MCreationMetadata s) throws MetaException {
    if (s == null) {
        return null;
    }
    Set<String> tablesUsed = new HashSet<>();
    for (MTable mtbl : s.getTables()) {
        tablesUsed.add(Warehouse.getQualifiedName(mtbl.getDatabase().getName(), mtbl.getTableName()));
    }
    CreationMetadata r = new CreationMetadata(s.getDbName(), s.getTblName(), tablesUsed);
    if (s.getTxnList() != null) {
        r.setValidTxnList(s.getTxnList());
    }
    return r;
}
Also used : MCreationMetadata(org.apache.hadoop.hive.metastore.model.MCreationMetadata) CreationMetadata(org.apache.hadoop.hive.metastore.api.CreationMetadata) MTable(org.apache.hadoop.hive.metastore.model.MTable) HashSet(java.util.HashSet)

Example 5 with MCreationMetadata

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

the class ObjectStore method createTable.

@Override
public void createTable(Table tbl) throws InvalidObjectException, MetaException {
    boolean commited = false;
    try {
        openTransaction();
        MTable mtbl = convertToMTable(tbl);
        pm.makePersistent(mtbl);
        if (tbl.getCreationMetadata() != null) {
            MCreationMetadata mcm = convertToMCreationMetadata(tbl.getCreationMetadata());
            pm.makePersistent(mcm);
        }
        PrincipalPrivilegeSet principalPrivs = tbl.getPrivileges();
        List<Object> toPersistPrivObjs = new ArrayList<>();
        if (principalPrivs != null) {
            int now = (int) (System.currentTimeMillis() / 1000);
            Map<String, List<PrivilegeGrantInfo>> userPrivs = principalPrivs.getUserPrivileges();
            putPersistentPrivObjects(mtbl, toPersistPrivObjs, now, userPrivs, PrincipalType.USER);
            Map<String, List<PrivilegeGrantInfo>> groupPrivs = principalPrivs.getGroupPrivileges();
            putPersistentPrivObjects(mtbl, toPersistPrivObjs, now, groupPrivs, PrincipalType.GROUP);
            Map<String, List<PrivilegeGrantInfo>> rolePrivs = principalPrivs.getRolePrivileges();
            putPersistentPrivObjects(mtbl, toPersistPrivObjs, now, rolePrivs, PrincipalType.ROLE);
        }
        pm.makePersistentAll(toPersistPrivObjs);
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        } else {
            if (MetaStoreUtils.isMaterializedViewTable(tbl)) {
                // Add to the invalidation cache
                MaterializationsInvalidationCache.get().createMaterializedView(tbl.getDbName(), tbl.getTableName(), tbl.getCreationMetadata().getTablesUsed(), tbl.getCreationMetadata().getValidTxnList());
            }
        }
    }
}
Also used : MTable(org.apache.hadoop.hive.metastore.model.MTable) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) MCreationMetadata(org.apache.hadoop.hive.metastore.model.MCreationMetadata)

Aggregations

MCreationMetadata (org.apache.hadoop.hive.metastore.model.MCreationMetadata)5 MTable (org.apache.hadoop.hive.metastore.model.MTable)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Query (javax.jdo.Query)1 CreationMetadata (org.apache.hadoop.hive.metastore.api.CreationMetadata)1 PrincipalPrivilegeSet (org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet)1 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)1 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)1 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)1 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)1 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)1 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)1