private <T> int doCleanNotificationEvents(final int ageSec, final Optional<Integer> batchSize, Class<T> tableClass, String tableName) {
    final Transaction tx = pm.currentTransaction();
    int eventsCount = 0;

    try {
      String key = null;
      tx.begin();

      try (Query query = pm.newQuery(tableClass, "eventTime <= tooOld")) {
        query.declareParameters("java.lang.Integer tooOld");
        if (MNotificationLog.class.equals(tableClass)) {
          key = "eventId";
        } else if (MTxnWriteNotificationLog.class.equals(tableClass)) {
          key = "txnId";
        }
        query.setOrdering(key + " ascending");
        if (batchSize.isPresent()) {
          query.setRange(0, batchSize.get());
        }

        List<T> events = (List) query.execute(ageSec);
        if (CollectionUtils.isNotEmpty(events)) {
          eventsCount = events.size();
          if (LOG.isDebugEnabled()) {
            int minEventTime, maxEventTime;
            long minId, maxId;
            T firstNotification = events.get(0);
            T lastNotification = events.get(eventsCount - 1);
            if (MNotificationLog.class.equals(tableClass)) {
              minEventTime = ((MNotificationLog)firstNotification).getEventTime();
              minId = ((MNotificationLog)firstNotification).getEventId();
              maxEventTime = ((MNotificationLog)lastNotification).getEventTime();
              maxId = ((MNotificationLog)lastNotification).getEventId();
            } else if (MTxnWriteNotificationLog.class.equals(tableClass)) {
              minEventTime = ((MTxnWriteNotificationLog)firstNotification).getEventTime();
              minId = ((MTxnWriteNotificationLog)firstNotification).getTxnId();
              maxEventTime = ((MTxnWriteNotificationLog)lastNotification).getEventTime();
              maxId = ((MTxnWriteNotificationLog)lastNotification).getTxnId();
            } else {
              throw new RuntimeException("Cleaning of older " + tableName + " events failed. " +
                      "Reason: Unknown table encountered " + tableClass.getName());
            }

            LOG.debug(
                    "Remove {} batch of {} events with eventTime < {}, min {}: {}, max {}: {}, min eventTime {}, max eventTime {}",
                    tableName, eventsCount, ageSec, key, minId, key, maxId, minEventTime, maxEventTime);
          }

          pm.deletePersistentAll(events);
        }
      }

      tx.commit();
    } catch (Exception e) {
      LOG.error("Unable to delete batch of " + tableName + " events", e);
      eventsCount = 0;
    } finally {
      if (tx.isActive()) {
        tx.rollback();
      }
    }

    return eventsCount;
  }
Get partition's column stats

@return Map of column name and its stats
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java