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;
}
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;
}
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());
}
}
}
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;
}
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());
}
}
}
}
Aggregations