Search in sources :

Example 11 with MPartitionColumnStatistics

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

the class ObjectStore method updatePartitionColumnStatistics.

@Override
public boolean updatePartitionColumnStatistics(ColumnStatistics colStats, List<String> partVals) throws NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException {
    boolean committed = false;
    try {
        openTransaction();
        List<ColumnStatisticsObj> statsObjs = colStats.getStatsObj();
        ColumnStatisticsDesc statsDesc = colStats.getStatsDesc();
        Table table = ensureGetTable(statsDesc.getDbName(), statsDesc.getTableName());
        Partition partition = convertToPart(getMPartition(statsDesc.getDbName(), statsDesc.getTableName(), partVals));
        List<String> colNames = new ArrayList<>();
        for (ColumnStatisticsObj statsObj : statsObjs) {
            colNames.add(statsObj.getColName());
        }
        Map<String, MPartitionColumnStatistics> oldStats = getPartitionColStats(table, statsDesc.getPartName(), colNames);
        MPartition mPartition = getMPartition(statsDesc.getDbName(), statsDesc.getTableName(), partVals);
        if (partition == null) {
            throw new NoSuchObjectException("Partition for which stats is gathered doesn't exist.");
        }
        for (ColumnStatisticsObj statsObj : statsObjs) {
            MPartitionColumnStatistics mStatsObj = StatObjectConverter.convertToMPartitionColumnStatistics(mPartition, statsDesc, statsObj);
            writeMPartitionColumnStatistics(table, partition, mStatsObj, oldStats.get(statsObj.getColName()));
        }
        Map<String, String> parameters = mPartition.getParameters();
        StatsSetupConst.setColumnStatsState(parameters, colNames);
        mPartition.setParameters(parameters);
        committed = commitTransaction();
        return committed;
    } finally {
        if (!committed) {
            rollbackTransaction();
        }
    }
}
Also used : MPartition(org.apache.hadoop.hive.metastore.model.MPartition) Partition(org.apache.hadoop.hive.metastore.api.Partition) MVersionTable(org.apache.hadoop.hive.metastore.model.MVersionTable) Table(org.apache.hadoop.hive.metastore.api.Table) MTable(org.apache.hadoop.hive.metastore.model.MTable) ArrayList(java.util.ArrayList) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) ColumnStatisticsDesc(org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MPartitionColumnStatistics(org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Aggregations

MPartitionColumnStatistics (org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics)11 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)7 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)6 HashMap (java.util.HashMap)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 PreparedStatement (java.sql.PreparedStatement)3 Query (javax.jdo.Query)3 ColumnStatisticsDesc (org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc)3 ColumnStatisticsObj (org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj)3 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)3 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)2 List (java.util.List)2 JDODataStoreException (javax.jdo.JDODataStoreException)2 JDOException (javax.jdo.JDOException)2 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)2 JDOConnection (javax.jdo.datastore.JDOConnection)2