Search in sources :

Example 1 with UpdatePartitionColumnStatEventBatch

use of org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEventBatch in project hive by apache.

the class DirectSqlUpdateStat method updatePartitionColumnStatistics.

/**
 * Update the statistics for the given partitions. Add the notification logs also.
 * @return map of partition key to column stats if successful, null otherwise.
 */
public Map<String, Map<String, String>> updatePartitionColumnStatistics(Map<String, ColumnStatistics> partColStatsMap, Table tbl, long csId, String validWriteIds, long writeId, List<TransactionalMetaStoreEventListener> transactionalListeners) throws MetaException {
    JDOConnection jdoConn = null;
    Connection dbConn = null;
    boolean committed = false;
    try {
        lockInternal();
        jdoConn = pm.getDataStoreConnection();
        dbConn = (Connection) (jdoConn.getNativeConnection());
        setAnsiQuotes(dbConn);
        Map<PartitionInfo, ColumnStatistics> partitionInfoMap = getPartitionInfo(dbConn, tbl.getId(), partColStatsMap);
        Map<String, Map<String, String>> result = updatePartitionParamTable(dbConn, partitionInfoMap, validWriteIds, writeId, TxnUtils.isAcidTable(tbl));
        Map<PartColNameInfo, MPartitionColumnStatistics> insertMap = new HashMap<>();
        Map<PartColNameInfo, MPartitionColumnStatistics> updateMap = new HashMap<>();
        populateInsertUpdateMap(partitionInfoMap, updateMap, insertMap, dbConn);
        LOG.info("Number of stats to insert  " + insertMap.size() + " update " + updateMap.size());
        if (insertMap.size() != 0) {
            insertIntoPartColStatTable(insertMap, csId, dbConn);
        }
        if (updateMap.size() != 0) {
            updatePartColStatTable(updateMap, dbConn);
        }
        if (transactionalListeners != null) {
            UpdatePartitionColumnStatEventBatch eventBatch = new UpdatePartitionColumnStatEventBatch(null);
            for (Map.Entry entry : result.entrySet()) {
                Map<String, String> parameters = (Map<String, String>) entry.getValue();
                ColumnStatistics colStats = partColStatsMap.get(entry.getKey());
                List<String> partVals = getPartValsFromName(tbl, colStats.getStatsDesc().getPartName());
                UpdatePartitionColumnStatEvent event = new UpdatePartitionColumnStatEvent(colStats, partVals, parameters, tbl, writeId, null);
                eventBatch.addPartColStatEvent(event);
            }
            MetaStoreListenerNotifier.notifyEventWithDirectSql(transactionalListeners, EventMessage.EventType.UPDATE_PARTITION_COLUMN_STAT_BATCH, eventBatch, dbConn, sqlGenerator);
        }
        dbConn.commit();
        committed = true;
        return result;
    } catch (Exception e) {
        LOG.error("Unable to update Column stats for  " + tbl.getTableName(), e);
        throw new MetaException("Unable to update Column stats for  " + tbl.getTableName() + " due to: " + e.getMessage());
    } finally {
        if (!committed) {
            rollbackDBConn(dbConn);
        }
        closeDbConn(jdoConn);
        unlockInternal();
    }
}
Also used : MPartitionColumnStatistics(org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics) ColumnStatistics(org.apache.hadoop.hive.metastore.api.ColumnStatistics) HashMap(java.util.HashMap) Connection(java.sql.Connection) JDOConnection(javax.jdo.datastore.JDOConnection) JDOConnection(javax.jdo.datastore.JDOConnection) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) SQLException(java.sql.SQLException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) UpdatePartitionColumnStatEvent(org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEvent) HashMap(java.util.HashMap) Map(java.util.Map) UpdatePartitionColumnStatEventBatch(org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEventBatch) MPartitionColumnStatistics(org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JDOConnection (javax.jdo.datastore.JDOConnection)1 ColumnStatistics (org.apache.hadoop.hive.metastore.api.ColumnStatistics)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 UpdatePartitionColumnStatEvent (org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEvent)1 UpdatePartitionColumnStatEventBatch (org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEventBatch)1 MPartitionColumnStatistics (org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics)1