public static List<ColStatistics> getTableColumnStats(
      Table table, List<String> neededColumns, ColumnStatsList colStatsCache, boolean fetchColStats) {
    List<ColStatistics> stats = new ArrayList<>();
    if (table.isMaterializedTable()) {
      LOG.debug("Materialized table does not contain table statistics");
      return stats;
    }
    // We will retrieve stats from the metastore only for columns that are not cached
    List<String> colStatsToRetrieve;
    if (colStatsCache != null) {
      colStatsToRetrieve = new ArrayList<>(neededColumns.size());
      for (String colName : neededColumns) {
        if (!colStatsCache.getColStats().containsKey(colName)) {
          colStatsToRetrieve.add(colName);
        }
      }
    } else {
      colStatsToRetrieve = neededColumns;
    }
    // Retrieve stats from metastore
    String dbName = table.getDbName();
    String tabName = table.getTableName();
    if (SemanticAnalyzer.DUMMY_DATABASE.equals(dbName) &&
        SemanticAnalyzer.DUMMY_TABLE.equals(tabName)) {
      // insert into values gets written into insert from select dummy_table
      // This table is dummy and has no stats
      return stats;
    }
    if (fetchColStats && !colStatsToRetrieve.isEmpty()) {
      try {
        List<ColumnStatisticsObj> colStat = Hive.get().getTableColumnStatistics(
            table, colStatsToRetrieve, false);
        stats = convertColStats(colStat);
      } catch (HiveException e) {
        LOG.error("Failed to retrieve table statistics: ", e);
      }
    }
    // Merge stats from cache with metastore cache
    if (colStatsCache != null) {
      for(String col:neededColumns) {
        ColStatistics cs = colStatsCache.getColStats().get(col);
        if (cs != null) {
          stats.add(cs);
          if (LOG.isDebugEnabled()) {
            LOG.debug("Stats for column " + cs.getColumnName() +
                " in table " + table.getCompleteName() + " retrieved from cache");
          }
        }
      }
    }
    return stats;
  }
Get table level column statistics for needed columns
@param table
         - table
@param neededColumns
         - list of needed columns
@return column statistics
ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java