@Override
    public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx procCtx,
        Object... nodeOutputs) throws SemanticException {
      TableScanOperator tsop = (TableScanOperator) nd;
      AnnotateStatsProcCtx aspCtx = (AnnotateStatsProcCtx) procCtx;
      PrunedPartitionList partList = aspCtx.getParseContext().getPrunedPartitions(tsop);
      ColumnStatsList colStatsCached = aspCtx.getParseContext().getColStatsCached(partList);
      Table table = tsop.getConf().getTableMetadata();

      try {
        Statistics stats;
        if (table.isMaterializedTable()) {
          stats = tsop.getStatistics();
        } else {
          // gather statistics for the first time and attach it to table scan operator
          stats = StatsUtils.collectStatistics(aspCtx.getConf(), partList, colStatsCached, table, tsop);
        }

        stats = applyRuntimeStats(aspCtx.getParseContext().getContext(), stats, tsop);
        tsop.setStatistics(stats);

        if (LOG.isDebugEnabled()) {
          LOG.debug("[0] STATS-" + tsop.toString() + " (" + table.getTableName() + "): " +
              stats.extendedToString());
        }
      } catch (HiveException e) {
        LOG.debug("Failed to retrieve stats ", e);
        throw new SemanticException(e);
      }
      return null;
    }
Collect basic statistics like number of rows, data size and column level statistics from the
table. Also sets the state of the available statistics. Basic and column statistics can have
one of the following states COMPLETE, PARTIAL, NONE. In case of partitioned table, the basic
and column stats are aggregated together to table level statistics. Column statistics will not
be collected if hive.stats.fetch.column.stats is set to false. If basic statistics is not
available then number of rows will be estimated from file size and average row size (computed
from schema).
ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java