Search in sources :

Example 1 with MIndex

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;
}
Also used : MTable(org.apache.hadoop.hive.metastore.model.MTable) Query(javax.jdo.Query) MIndex(org.apache.hadoop.hive.metastore.model.MIndex)

Example 2 with MIndex

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;
}
Also used : MIndex(org.apache.hadoop.hive.metastore.model.MIndex)

Example 3 with MIndex

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;
}
Also used : MIndex(org.apache.hadoop.hive.metastore.model.MIndex) MIndex(org.apache.hadoop.hive.metastore.model.MIndex) Index(org.apache.hadoop.hive.metastore.api.Index)

Example 4 with MIndex

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;
        }
    }
}
Also used : MIndex(org.apache.hadoop.hive.metastore.model.MIndex)

Example 5 with MIndex

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());
}
Also used : MTable(org.apache.hadoop.hive.metastore.model.MTable) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) MStorageDescriptor(org.apache.hadoop.hive.metastore.model.MStorageDescriptor) MIndex(org.apache.hadoop.hive.metastore.model.MIndex) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MStorageDescriptor(org.apache.hadoop.hive.metastore.model.MStorageDescriptor)

Aggregations

MIndex (org.apache.hadoop.hive.metastore.model.MIndex)8 Index (org.apache.hadoop.hive.metastore.api.Index)3 MTable (org.apache.hadoop.hive.metastore.model.MTable)3 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 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)1 MStorageDescriptor (org.apache.hadoop.hive.metastore.model.MStorageDescriptor)1 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)1