Search in sources :

Example 6 with SetPartitionsStatsRequest

use of org.apache.hadoop.hive.metastore.api.SetPartitionsStatsRequest in project hive by apache.

the class ColumnStatsUpdateTask method persistColumnStats.

private int persistColumnStats(Hive db) throws HiveException, MetaException, IOException {
    ColumnStatistics colStats = constructColumnStatsFromInput();
    SetPartitionsStatsRequest request = new SetPartitionsStatsRequest(Collections.singletonList(colStats), Constants.HIVE_ENGINE);
    // non-null value only during replication.
    if (work.getColStats() != null) {
        String dbName = colStats.getStatsDesc().getDbName();
        String tblName = colStats.getStatsDesc().getTableName();
        Table tbl = db.getTable(dbName, tblName);
        long writeId = work.getWriteId();
        // associated with it.
        if (AcidUtils.isTransactionalTable(tbl)) {
            ValidWriteIdList writeIds;
            // We need a valid writeId list to update column statistics for a transactional table. We
            // do not have a valid writeId list which was used to update the column stats on the
            // source. But we know for sure that the writeId associated with the stats was valid then
            // (otherwise column stats update would have failed on the source). So use a valid
            // transaction list with only that writeId and use it to update the stats.
            writeIds = new ValidReaderWriteIdList(TableName.getDbTable(dbName, tblName), new long[0], new BitSet(), writeId);
            request.setValidWriteIdList(writeIds.toString());
            request.setWriteId(writeId);
        }
    }
    db.setPartitionColumnStatistics(request);
    return 0;
}
Also used : ColumnStatistics(org.apache.hadoop.hive.metastore.api.ColumnStatistics) Table(org.apache.hadoop.hive.ql.metadata.Table) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) BitSet(java.util.BitSet) SetPartitionsStatsRequest(org.apache.hadoop.hive.metastore.api.SetPartitionsStatsRequest) ValidReaderWriteIdList(org.apache.hadoop.hive.common.ValidReaderWriteIdList)

Aggregations

SetPartitionsStatsRequest (org.apache.hadoop.hive.metastore.api.SetPartitionsStatsRequest)6 ColumnStatistics (org.apache.hadoop.hive.metastore.api.ColumnStatistics)5 ArrayList (java.util.ArrayList)4 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)2 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)1 Catalog (org.apache.hadoop.hive.metastore.api.Catalog)1 ColumnStatisticsData (org.apache.hadoop.hive.metastore.api.ColumnStatisticsData)1 ColumnStatisticsDesc (org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc)1 ColumnStatisticsObj (org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj)1 Database (org.apache.hadoop.hive.metastore.api.Database)1 StringColumnStatsData (org.apache.hadoop.hive.metastore.api.StringColumnStatsData)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 CatalogBuilder (org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder)1 DatabaseBuilder (org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder)1 PartitionBuilder (org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder)1 TableBuilder (org.apache.hadoop.hive.metastore.client.builder.TableBuilder)1 CreateDatabaseEvent (org.apache.hadoop.hive.metastore.events.CreateDatabaseEvent)1