Package org.apache.hadoop.hive.metastore.api

Examples of org.apache.hadoop.hive.metastore.api.ColumnStatistics$ColumnStatisticsTupleSchemeFactory


    + "\"BIG_DECIMAL_HIGH_VALUE\", \"NUM_NULLS\", \"NUM_DISTINCTS\", \"AVG_COL_LEN\", "
    + "\"MAX_COL_LEN\", \"NUM_TRUES\", \"NUM_FALSES\", \"LAST_ANALYZED\" ";

  private ColumnStatistics makeColumnStats(
      List<Object[]> list, ColumnStatisticsDesc csd, int offset) throws MetaException {
    ColumnStatistics result = new ColumnStatistics();
    result.setStatsDesc(csd);
    List<ColumnStatisticsObj> csos = new ArrayList<ColumnStatisticsObj>(list.size());
    for (Object[] row : list) {
      // LastAnalyzed is stored per column but thrift has it per several;
      // get the lowest for now as nobody actually uses this field.
      Object laObj = row[offset + 14];
      if (laObj != null && (!csd.isSetLastAnalyzed() || csd.getLastAnalyzed() > extractSqlLong(laObj))) {
        csd.setLastAnalyzed(extractSqlLong(laObj));
      }
      ColumnStatisticsData data = new ColumnStatisticsData();
      // see STATS_COLLIST
      int i = offset;
      ColumnStatisticsObj cso = new ColumnStatisticsObj((String)row[i++], (String)row[i++], data);
      Object llow = row[i++], lhigh = row[i++], dlow = row[i++], dhigh = row[i++],
          declow = row[i++], dechigh = row[i++], nulls = row[i++], dist = row[i++],
          avglen = row[i++], maxlen = row[i++], trues = row[i++], falses = row[i++];
      StatObjectConverter.fillColumnStatisticsData(cso.getColType(), data,
          llow, lhigh, dlow, dhigh, declow, dechigh, nulls, dist, avglen, maxlen, trues, falses);
      csos.add(cso);
    }
    result.setStatsObj(csos);
    return result;
  }
View Full Code Here


      statsData.getStringStats().setNumNulls(numNulls);

      statsObj.setStatsData(statsData);
      statsObjs.add(statsObj);

      ColumnStatistics colStats = new ColumnStatistics();
      colStats.setStatsDesc(statsDesc);
      colStats.setStatsObj(statsObjs);

      // write stats objs persistently
      client.updateTableColumnStatistics(colStats);

      // retrieve the stats obj that was just written
      ColumnStatistics colStats2 = client.getTableColumnStatistics(dbName, tblName, colName[0]);

     // compare stats obj to ensure what we get is what we wrote
      assertNotNull(colStats2);
      assertEquals(colStats2.getStatsDesc().getDbName(), dbName);
      assertEquals(colStats2.getStatsDesc().getTableName(), tblName);
      assertEquals(colStats2.getStatsObj().get(0).getColName(), colName[0]);
      assertEquals(colStats2.getStatsObj().get(0).getStatsData().getDoubleStats().getLowValue(),
        lowValue);
      assertEquals(colStats2.getStatsObj().get(0).getStatsData().getDoubleStats().getHighValue(),
        highValue);
      assertEquals(colStats2.getStatsObj().get(0).getStatsData().getDoubleStats().getNumNulls(),
        numNulls);
      assertEquals(colStats2.getStatsObj().get(0).getStatsData().getDoubleStats().getNumDVs(),
        numDVs);
      assertEquals(colStats2.getStatsDesc().isIsTblLevel(), isTblLevel);

      // test delete column stats; if no col name is passed all column stats associated with the
      // table is deleted
      boolean status = client.deleteTableColumnStatistics(dbName, tblName, null);
      assertTrue(status);
      // try to query stats for a column for which stats doesn't exist
      try {
        colStats2 = client.getTableColumnStatistics(dbName, tblName, colName[1]);
        assertTrue(true);
      } catch (NoSuchObjectException e) {
        System.out.println("Statistics for column=" + colName[1] + " not found");
      }

      colStats.setStatsDesc(statsDesc);
      colStats.setStatsObj(statsObjs);

      // update table level column stats
      client.updateTableColumnStatistics(colStats);

      // query column stats for column whose stats were updated in the previous call
      colStats2 = client.getTableColumnStatistics(dbName, tblName, colName[0]);

      // partition level column statistics test
      // create a table with multiple partitions
      cleanUp(dbName, tblName, typeName);

      List<List<String>> values = new ArrayList<List<String>>();
      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> partitions = client.listPartitionNames(dbName, tblName, (short)-1);

      partName = partitions.get(0);
      isTblLevel = false;

      // create a new columnstatistics desc to represent partition level column stats
      statsDesc = new ColumnStatisticsDesc();
      statsDesc.setDbName(dbName);
      statsDesc.setTableName(tblName);
      statsDesc.setPartName(partName);
      statsDesc.setIsTblLevel(isTblLevel);

      colStats = new ColumnStatistics();
      colStats.setStatsDesc(statsDesc);
      colStats.setStatsObj(statsObjs);

     client.updatePartitionColumnStatistics(colStats);

     colStats2 = client.getPartitionColumnStatistics(dbName, tblName, partName, colName[1]);

     // compare stats obj to ensure what we get is what we wrote
     assertNotNull(colStats2);
     assertEquals(colStats2.getStatsDesc().getDbName(), dbName);
     assertEquals(colStats2.getStatsDesc().getTableName(), tblName);
     assertEquals(colStats.getStatsDesc().getPartName(), partName);
     assertEquals(colStats2.getStatsObj().get(0).getColName(), colName[1]);
     assertEquals(colStats2.getStatsObj().get(0).getStatsData().getStringStats().getMaxColLen(),
       maxColLen);
     assertEquals(colStats2.getStatsObj().get(0).getStatsData().getStringStats().getAvgColLen(),
       avgColLen);
     assertEquals(colStats2.getStatsObj().get(0).getStatsData().getStringStats().getNumNulls(),
       numNulls);
     assertEquals(colStats2.getStatsObj().get(0).getStatsData().getStringStats().getNumDVs(),
       numDVs);
     assertEquals(colStats2.getStatsDesc().isIsTblLevel(), isTblLevel);

     // test stats deletion at partition level
     client.deletePartitionColumnStatistics(dbName, tblName, partName, colName[1]);

     colStats2 = client.getPartitionColumnStatistics(dbName, tblName, partName, colName[0]);
View Full Code Here

      dbName = dbName.toLowerCase();
      tableName = tableName.toLowerCase();
      colName = colName.toLowerCase();
      startFunction("get_column_statistics_by_table: db=" + dbName + " table=" + tableName +
                    " column=" + colName);
      ColumnStatistics statsObj = null;
      try {
        statsObj = getMS().getTableColumnStatistics(dbName, tableName, colName);
      } finally {
        endFunction("get_column_statistics_by_table: ", statsObj != null, null, tableName);
      }
View Full Code Here

      tableName = tableName.toLowerCase();
      colName = colName.toLowerCase();
      String convertedPartName = lowerCaseConvertPartName(partName);
      startFunction("get_column_statistics_by_partition: db=" + dbName + " table=" + tableName +
          " partition=" + convertedPartName + " column=" + colName);
      ColumnStatistics statsObj = null;

      try {
        List<String> partVals = getPartValsFromName(getMS(), dbName, tableName, partName);
        statsObj = getMS().getPartitionColumnStatistics(dbName, tableName, convertedPartName,
                                                            partVals, colName);
View Full Code Here

    ColumnStatisticsDesc statsDesc = getTableColumnStatisticsDesc(mStatsObj);
    ColumnStatisticsObj statsObj = getTableColumnStatisticsObj(mStatsObj);
    List<ColumnStatisticsObj> statsObjs = new ArrayList<ColumnStatisticsObj>();
    statsObjs.add(statsObj);

    ColumnStatistics colStats = new ColumnStatistics();
    colStats.setStatsDesc(statsDesc);
    colStats.setStatsObj(statsObjs);
    return colStats;
  }
View Full Code Here

  }

public ColumnStatistics getTableColumnStatistics(String dbName, String tableName, String colName)
   throws MetaException, NoSuchObjectException, InvalidInputException
  {
    ColumnStatistics statsObj;
    MTableColumnStatistics mStatsObj = getMTableColumnStatistics(dbName, tableName, colName);

    if (mStatsObj == null) {
      throw new NoSuchObjectException("Statistics for dbName=" + dbName + " tableName=" + tableName
        + " columnName=" + colName + " doesn't exist.");
View Full Code Here

  public ColumnStatistics getPartitionColumnStatistics(String dbName, String tableName,
    String partName, List<String> partVal, String colName)
    throws MetaException, NoSuchObjectException, InvalidInputException
  {
    ColumnStatistics statsObj;
    MPartitionColumnStatistics mStatsObj =
          getMPartitionColumnStatistics(dbName, tableName, partName, partVal, colName);

    if (mStatsObj == null) {
      throw new NoSuchObjectException("Statistics for dbName=" + dbName + " tableName=" + tableName
View Full Code Here

    ColumnStatisticsDesc statsDesc = getPartitionColumnStatisticsDesc(mStatsObj);
    ColumnStatisticsObj statsObj = getPartitionColumnStatisticsObj(mStatsObj);
    List<ColumnStatisticsObj> statsObjs = new ArrayList<ColumnStatisticsObj>();
    statsObjs.add(statsObj);

    ColumnStatistics colStats = new ColumnStatistics();
    colStats.setStatsDesc(statsDesc);
    colStats.setStatsObj(statsObjs);
    return colStats;
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.metastore.api.ColumnStatistics$ColumnStatisticsTupleSchemeFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.