Search in sources :

Example 1 with Query

use of javax.jdo.Query in project hive by apache.

the class ObjectStore method deletePartitionColumnStatistics.

@Override
public boolean deletePartitionColumnStatistics(String dbName, String tableName, String partName, List<String> partVals, String colName) throws NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException {
    boolean ret = false;
    Query query = null;
    if (dbName == null) {
        dbName = MetaStoreUtils.DEFAULT_DATABASE_NAME;
    }
    if (tableName == null) {
        throw new InvalidInputException("Table name is null.");
    }
    try {
        openTransaction();
        MTable mTable = getMTable(dbName, tableName);
        MPartitionColumnStatistics mStatsObj;
        List<MPartitionColumnStatistics> mStatsObjColl;
        if (mTable == null) {
            throw new NoSuchObjectException("Table " + tableName + "  for which stats deletion is requested doesn't exist");
        }
        MPartition mPartition = getMPartition(dbName, tableName, partVals);
        if (mPartition == null) {
            throw new NoSuchObjectException("Partition " + partName + " for which stats deletion is requested doesn't exist");
        }
        query = pm.newQuery(MPartitionColumnStatistics.class);
        String filter;
        String parameters;
        if (colName != null) {
            filter = "partition.partitionName == t1 && dbName == t2 && tableName == t3 && " + "colName == t4";
            parameters = "java.lang.String t1, java.lang.String t2, " + "java.lang.String t3, java.lang.String t4";
        } else {
            filter = "partition.partitionName == t1 && dbName == t2 && tableName == t3";
            parameters = "java.lang.String t1, java.lang.String t2, java.lang.String t3";
        }
        query.setFilter(filter);
        query.declareParameters(parameters);
        if (colName != null) {
            query.setUnique(true);
            mStatsObj = (MPartitionColumnStatistics) query.executeWithArray(partName.trim(), HiveStringUtils.normalizeIdentifier(dbName), HiveStringUtils.normalizeIdentifier(tableName), HiveStringUtils.normalizeIdentifier(colName));
            pm.retrieve(mStatsObj);
            if (mStatsObj != null) {
                pm.deletePersistent(mStatsObj);
            } else {
                throw new NoSuchObjectException("Column stats doesn't exist for db=" + dbName + " table=" + tableName + " partition=" + partName + " col=" + colName);
            }
        } else {
            mStatsObjColl = (List<MPartitionColumnStatistics>) query.execute(partName.trim(), HiveStringUtils.normalizeIdentifier(dbName), HiveStringUtils.normalizeIdentifier(tableName));
            pm.retrieveAll(mStatsObjColl);
            if (mStatsObjColl != null) {
                pm.deletePersistentAll(mStatsObjColl);
            } else {
                throw new NoSuchObjectException("Column stats doesn't exist for db=" + dbName + " table=" + tableName + " partition" + partName);
            }
        }
        ret = commitTransaction();
    } catch (NoSuchObjectException e) {
        rollbackTransaction();
        throw e;
    } finally {
        if (!ret) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
    return ret;
}
Also used : InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) MTable(org.apache.hadoop.hive.metastore.model.MTable) Query(javax.jdo.Query) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MPartitionColumnStatistics(org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Example 2 with Query

use of javax.jdo.Query in project hive by apache.

the class ObjectStore method constraintNameAlreadyExists.

private boolean constraintNameAlreadyExists(String name) {
    boolean commited = false;
    Query constraintExistsQuery = null;
    String constraintNameIfExists = null;
    try {
        openTransaction();
        name = HiveStringUtils.normalizeIdentifier(name);
        constraintExistsQuery = pm.newQuery(MConstraint.class, "constraintName == name");
        constraintExistsQuery.declareParameters("java.lang.String name");
        constraintExistsQuery.setUnique(true);
        constraintExistsQuery.setResult("name");
        constraintNameIfExists = (String) constraintExistsQuery.execute(name);
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
        if (constraintExistsQuery != null) {
            constraintExistsQuery.closeAll();
        }
    }
    return constraintNameIfExists != null && !constraintNameIfExists.isEmpty();
}
Also used : Query(javax.jdo.Query) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint)

Example 3 with Query

use of javax.jdo.Query in project hive by apache.

the class ObjectStore method getMSecurityUserRoleMap.

private MRoleMap getMSecurityUserRoleMap(String userName, PrincipalType principalType, String roleName) {
    MRoleMap mRoleMember = null;
    boolean commited = false;
    Query query = null;
    try {
        openTransaction();
        query = pm.newQuery(MRoleMap.class, "principalName == t1 && principalType == t2 && role.roleName == t3");
        query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
        query.setUnique(true);
        mRoleMember = (MRoleMap) query.executeWithArray(userName, principalType.toString(), roleName);
        pm.retrieve(mRoleMember);
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
    return mRoleMember;
}
Also used : Query(javax.jdo.Query) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap)

Example 4 with Query

use of javax.jdo.Query in project hive by apache.

the class ObjectStore method getCurrentNotificationEventId.

@Override
public CurrentNotificationEventId getCurrentNotificationEventId() {
    boolean commited = false;
    Query query = null;
    try {
        openTransaction();
        query = pm.newQuery(MNotificationNextId.class);
        Collection<MNotificationNextId> ids = (Collection) query.execute();
        long id = 0;
        if (ids != null && ids.size() > 0) {
            id = ids.iterator().next().getNextEventId() - 1;
        }
        commited = commitTransaction();
        return new CurrentNotificationEventId(id);
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
}
Also used : Query(javax.jdo.Query) MNotificationNextId(org.apache.hadoop.hive.metastore.model.MNotificationNextId) Collection(java.util.Collection) CurrentNotificationEventId(org.apache.hadoop.hive.metastore.api.CurrentNotificationEventId)

Example 5 with Query

use of javax.jdo.Query in project hive by apache.

the class ObjectStore method updateMStorageDescriptorTblURI.

/** The following APIs
  *
  *  - updateMStorageDescriptorTblURI
  *
  * is used by HiveMetaTool. This API **shouldn't** be exposed via Thrift.
  *
  */
public UpdateMStorageDescriptorTblURIRetVal updateMStorageDescriptorTblURI(URI oldLoc, URI newLoc, boolean isDryRun) {
    boolean committed = false;
    Query query = null;
    Map<String, String> updateLocations = new HashMap<String, String>();
    List<String> badRecords = new ArrayList<String>();
    int numNullRecords = 0;
    UpdateMStorageDescriptorTblURIRetVal retVal = null;
    try {
        openTransaction();
        query = pm.newQuery(MStorageDescriptor.class);
        List<MStorageDescriptor> mSDSs = (List<MStorageDescriptor>) query.execute();
        pm.retrieveAll(mSDSs);
        for (MStorageDescriptor mSDS : mSDSs) {
            URI locationURI = null;
            String location = mSDS.getLocation();
            if (location == null) {
                // This can happen for View or Index
                numNullRecords++;
                continue;
            }
            try {
                locationURI = new Path(location).toUri();
            } catch (IllegalArgumentException e) {
                badRecords.add(location);
            }
            if (locationURI == null) {
                badRecords.add(location);
            } else {
                if (shouldUpdateURI(locationURI, oldLoc)) {
                    String tblLoc = mSDS.getLocation().replaceAll(oldLoc.toString(), newLoc.toString());
                    updateLocations.put(locationURI.toString(), tblLoc);
                    if (!isDryRun) {
                        mSDS.setLocation(tblLoc);
                    }
                }
            }
        }
        committed = commitTransaction();
        if (committed) {
            retVal = new UpdateMStorageDescriptorTblURIRetVal(badRecords, updateLocations, numNullRecords);
        }
        return retVal;
    } finally {
        if (!committed) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Query(javax.jdo.Query) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MStorageDescriptor(org.apache.hadoop.hive.metastore.model.MStorageDescriptor)

Aggregations

Query (javax.jdo.Query)115 ArrayList (java.util.ArrayList)51 List (java.util.List)38 LinkedList (java.util.LinkedList)30 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)30 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)23 Collection (java.util.Collection)22 HashMap (java.util.HashMap)18 MTable (org.apache.hadoop.hive.metastore.model.MTable)12 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)11 Iterator (java.util.Iterator)9 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)8 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)8 Map (java.util.Map)7 MRoleMap (org.apache.hadoop.hive.metastore.model.MRoleMap)7 MDatabase (org.apache.hadoop.hive.metastore.model.MDatabase)6 MPartition (org.apache.hadoop.hive.metastore.model.MPartition)6 MPartitionColumnPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)5 MPartitionPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionPrivilege)5 MTableColumnPrivilege (org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)5