use of org.apache.hadoop.hive.metastore.model.MIndex in project hive by apache.
the class ObjectStore method getMIndex.
private MIndex getMIndex(String dbName, String originalTblName, String indexName) throws MetaException {
MIndex midx = null;
boolean commited = false;
Query query = null;
try {
openTransaction();
dbName = HiveStringUtils.normalizeIdentifier(dbName);
originalTblName = HiveStringUtils.normalizeIdentifier(originalTblName);
MTable mtbl = getMTable(dbName, originalTblName);
if (mtbl == null) {
commited = commitTransaction();
return null;
}
query = pm.newQuery(MIndex.class, "origTable.tableName == t1 && origTable.database.name == t2 && indexName == t3");
query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
query.setUnique(true);
midx = (MIndex) query.execute(originalTblName, dbName, HiveStringUtils.normalizeIdentifier(indexName));
pm.retrieve(midx);
commited = commitTransaction();
} finally {
if (!commited) {
rollbackTransaction();
}
if (query != null) {
query.closeAll();
}
}
return midx;
}
use of org.apache.hadoop.hive.metastore.model.MIndex in project hive by apache.
the class ObjectStore method dropIndex.
@Override
public boolean dropIndex(String dbName, String origTableName, String indexName) throws MetaException {
boolean success = false;
try {
openTransaction();
MIndex index = getMIndex(dbName, origTableName, indexName);
if (index != null) {
pm.deletePersistent(index);
}
success = commitTransaction();
} finally {
if (!success) {
rollbackTransaction();
}
}
return success;
}
use of org.apache.hadoop.hive.metastore.model.MIndex in project hive by apache.
the class ObjectStore method getIndex.
@Override
public Index getIndex(String dbName, String origTableName, String indexName) throws MetaException {
openTransaction();
MIndex mIndex = this.getMIndex(dbName, origTableName, indexName);
Index ret = convertToIndex(mIndex);
commitTransaction();
return ret;
}
use of org.apache.hadoop.hive.metastore.model.MIndex in project hive by apache.
the class ObjectStore method addIndex.
@Override
public boolean addIndex(Index index) throws InvalidObjectException, MetaException {
boolean commited = false;
try {
openTransaction();
MIndex idx = convertToMIndex(index);
pm.makePersistent(idx);
commited = commitTransaction();
return true;
} finally {
if (!commited) {
rollbackTransaction();
return false;
}
}
}
use of org.apache.hadoop.hive.metastore.model.MIndex in project hive by apache.
the class ObjectStore method convertToMIndex.
private MIndex convertToMIndex(Index index) throws InvalidObjectException, MetaException {
StorageDescriptor sd = index.getSd();
if (sd == null) {
throw new InvalidObjectException("Storage descriptor is not defined for index.");
}
MStorageDescriptor msd = this.convertToMStorageDescriptor(sd);
MTable origTable = getMTable(index.getDbName(), index.getOrigTableName());
if (origTable == null) {
throw new InvalidObjectException("Original table does not exist for the given index.");
}
String[] qualified = MetaStoreUtils.getQualifiedName(index.getDbName(), index.getIndexTableName());
MTable indexTable = getMTable(qualified[0], qualified[1]);
if (indexTable == null) {
throw new InvalidObjectException("Underlying index table does not exist for the given index.");
}
return new MIndex(HiveStringUtils.normalizeIdentifier(index.getIndexName()), origTable, index.getCreateTime(), index.getLastAccessTime(), index.getParameters(), indexTable, msd, index.getIndexHandlerClass(), index.isDeferredRebuild());
}
Aggregations