Search in sources :

Example 41 with AggrStats

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

the class TestHiveMetaStore method testStatsFastTrivial.

// Tests that in the absence of stats for partitions, and/or absence of columns
// to get stats for, the metastore does not break. See HIVE-12083 for motivation.
@Test
public void testStatsFastTrivial() throws Throwable {
    String dbName = "tstatsfast";
    String tblName = "t1";
    String tblOwner = "statstester";
    String typeName = "Person";
    int lastAccessed = 12083;
    cleanUp(dbName, tblName, typeName);
    List<List<String>> values = new ArrayList<>();
    values.add(makeVals("2008-07-01 14:13:12", "14"));
    values.add(makeVals("2008-07-01 14:13:12", "15"));
    values.add(makeVals("2008-07-02 14:13:12", "15"));
    values.add(makeVals("2008-07-03 14:13:12", "151"));
    createMultiPartitionTableSchema(dbName, tblName, typeName, values);
    List<String> emptyColNames = new ArrayList<>();
    List<String> emptyPartNames = new ArrayList<>();
    List<String> colNames = new ArrayList<>();
    colNames.add("name");
    colNames.add("income");
    List<String> partNames = client.listPartitionNames(dbName, tblName, (short) -1);
    assertEquals(0, emptyColNames.size());
    assertEquals(0, emptyPartNames.size());
    assertEquals(2, colNames.size());
    assertEquals(4, partNames.size());
    // Test for both colNames and partNames being empty:
    AggrStats aggrStatsEmpty = client.getAggrColStatsFor(dbName, tblName, emptyColNames, emptyPartNames, ENGINE);
    // short-circuited on client-side, verifying that it's an empty object, not null
    assertNotNull(aggrStatsEmpty);
    assertEquals(0, aggrStatsEmpty.getPartsFound());
    assertNotNull(aggrStatsEmpty.getColStats());
    assert (aggrStatsEmpty.getColStats().isEmpty());
    // Test for only colNames being empty
    AggrStats aggrStatsOnlyParts = client.getAggrColStatsFor(dbName, tblName, emptyColNames, partNames, ENGINE);
    // short-circuited on client-side, verifying that it's an empty object, not null
    assertNotNull(aggrStatsOnlyParts);
    assertEquals(0, aggrStatsOnlyParts.getPartsFound());
    assertNotNull(aggrStatsOnlyParts.getColStats());
    assert (aggrStatsOnlyParts.getColStats().isEmpty());
    // Test for only partNames being empty
    AggrStats aggrStatsOnlyCols = client.getAggrColStatsFor(dbName, tblName, colNames, emptyPartNames, ENGINE);
    // short-circuited on client-side, verifying that it's an empty object, not null
    assertNotNull(aggrStatsOnlyCols);
    assertEquals(0, aggrStatsOnlyCols.getPartsFound());
    assertNotNull(aggrStatsOnlyCols.getColStats());
    assert (aggrStatsOnlyCols.getColStats().isEmpty());
    // Test for valid values for both.
    AggrStats aggrStatsFull = client.getAggrColStatsFor(dbName, tblName, colNames, partNames, ENGINE);
    assertNotNull(aggrStatsFull);
    // would still be empty, because no stats are actually populated.
    assertEquals(0, aggrStatsFull.getPartsFound());
    assertNotNull(aggrStatsFull.getColStats());
    assert (aggrStatsFull.getColStats().isEmpty());
}
Also used : AggrStats(org.apache.hadoop.hive.metastore.api.AggrStats) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 42 with AggrStats

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

the class ObjectStore method get_aggr_stats_for.

@Override
public AggrStats get_aggr_stats_for(String catName, String dbName, String tblName, final List<String> partNames, final List<String> colNames, String engine) throws MetaException, NoSuchObjectException {
    final boolean useDensityFunctionForNDVEstimation = MetastoreConf.getBoolVar(getConf(), ConfVars.STATS_NDV_DENSITY_FUNCTION);
    final double ndvTuner = MetastoreConf.getDoubleVar(getConf(), ConfVars.STATS_NDV_TUNER);
    final boolean enableBitVector = MetastoreConf.getBoolVar(getConf(), ConfVars.STATS_FETCH_BITVECTOR);
    return new GetHelper<AggrStats>(catName, dbName, tblName, true, false) {

        @Override
        protected AggrStats getSqlResult(GetHelper<AggrStats> ctx) throws MetaException {
            return directSql.aggrColStatsForPartitions(catName, dbName, tblName, partNames, colNames, engine, useDensityFunctionForNDVEstimation, ndvTuner, enableBitVector);
        }

        @Override
        protected AggrStats getJdoResult(GetHelper<AggrStats> ctx) throws MetaException, NoSuchObjectException {
            // directSql, do it. No point in failing back to slow path here.
            throw new MetaException("Jdo path is not implemented for stats aggr.");
        }

        @Override
        protected String describeResult() {
            return null;
        }
    }.run(true);
}
Also used : AggrStats(org.apache.hadoop.hive.metastore.api.AggrStats) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

AggrStats (org.apache.hadoop.hive.metastore.api.AggrStats)42 ArrayList (java.util.ArrayList)37 ColumnStatisticsObj (org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj)29 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)29 Partition (org.apache.hadoop.hive.metastore.api.Partition)28 Table (org.apache.hadoop.hive.metastore.api.Table)28 Test (org.junit.Test)28 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)27 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)27 ColumnStatistics (org.apache.hadoop.hive.metastore.api.ColumnStatistics)26 ColumnStatisticsData (org.apache.hadoop.hive.metastore.api.ColumnStatisticsData)26 ColumnStatisticsDesc (org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc)25 List (java.util.List)21 LongColumnStatsData (org.apache.hadoop.hive.metastore.api.LongColumnStatsData)12 BooleanColumnStatsData (org.apache.hadoop.hive.metastore.api.BooleanColumnStatsData)5 DoubleColumnStatsData (org.apache.hadoop.hive.metastore.api.DoubleColumnStatsData)5 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)4 IOException (java.io.IOException)3 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)3 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)3