Search in sources :

Example 1 with UpdatePartitionColumnStatEvent

use of org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEvent 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)

Example 2 with UpdatePartitionColumnStatEvent

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

the class DbNotificationListener method onUpdatePartitionColumnStatInBatch.

@Override
public void onUpdatePartitionColumnStatInBatch(UpdatePartitionColumnStatEventBatch updatePartColStatEventBatch, Connection dbConn, SQLGenerator sqlGenerator) throws MetaException {
    List<NotificationEvent> eventBatch = new ArrayList<>();
    List<ListenerEvent> listenerEventBatch = new ArrayList<>();
    for (int i = 0; i < updatePartColStatEventBatch.getNumEntries(); i++) {
        UpdatePartitionColumnStatEvent updatePartColStatEvent = updatePartColStatEventBatch.getPartColStatEvent(i);
        UpdatePartitionColumnStatMessage msg = MessageBuilder.getInstance().buildUpdatePartitionColumnStatMessage(updatePartColStatEvent.getPartColStats(), updatePartColStatEvent.getPartVals(), updatePartColStatEvent.getPartParameters(), updatePartColStatEvent.getTableObj(), updatePartColStatEvent.getWriteId());
        ColumnStatisticsDesc statDesc = updatePartColStatEvent.getPartColStats().getStatsDesc();
        NotificationEvent event = new NotificationEvent(0, now(), EventType.UPDATE_PARTITION_COLUMN_STAT.toString(), msgEncoder.getSerializer().serialize(msg));
        event.setCatName(statDesc.isSetCatName() ? statDesc.getCatName() : DEFAULT_CATALOG_NAME);
        event.setDbName(statDesc.getDbName());
        event.setTableName(statDesc.getTableName());
        eventBatch.add(event);
        listenerEventBatch.add(updatePartColStatEvent);
    }
    try {
        addNotificationLogBatch(eventBatch, listenerEventBatch, dbConn, sqlGenerator);
    } catch (SQLException e) {
        throw new MetaException("Unable to execute direct SQL " + StringUtils.stringifyException(e));
    }
}
Also used : UpdatePartitionColumnStatMessage(org.apache.hadoop.hive.metastore.messaging.UpdatePartitionColumnStatMessage) UpdatePartitionColumnStatEvent(org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEvent) SQLException(java.sql.SQLException) ColumnStatisticsDesc(org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc) ArrayList(java.util.ArrayList) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) ListenerEvent(org.apache.hadoop.hive.metastore.events.ListenerEvent) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

SQLException (java.sql.SQLException)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 UpdatePartitionColumnStatEvent (org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEvent)2 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)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 ColumnStatisticsDesc (org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)1 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)1 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)1 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)1 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)1 ListenerEvent (org.apache.hadoop.hive.metastore.events.ListenerEvent)1 UpdatePartitionColumnStatEventBatch (org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEventBatch)1 UpdatePartitionColumnStatMessage (org.apache.hadoop.hive.metastore.messaging.UpdatePartitionColumnStatMessage)1 MPartitionColumnStatistics (org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics)1