private static void appendKllSketch(StringBuilder rewrittenQueryBuilder, HiveConf conf, String columnName,
      ColumnStatsType columnStatsType) throws SemanticException {
    int k;
    try {
      k = HiveStatsUtils.getKParamForKllSketch(conf);
    } catch (Exception e) {
      throw new SemanticException(e.getMessage());
    }

    boolean isDateFamily = columnStatsType.equals(ColumnStatsType.DATE) ||
        columnStatsType.equals(ColumnStatsType.TIMESTAMP);

    if (isDateFamily) {
      rewrittenQueryBuilder.append("ds_kll_sketch(cast(unix_timestamp(")
          .append(columnName)
          .append(") as float)");
    } else {
      // add cast to float to make sure it works for other numeric types
      rewrittenQueryBuilder.append("ds_kll_sketch(cast(")
          .append(columnName)
          .append(" as float)");
    }
    rewrittenQueryBuilder.append(", ")
        .append(k)
        .append(")");
  }
Generates a SQL statement that will compute the stats for all columns
included in the input table.
ql/src/java/org/apache/hadoop/hive/ql/parse/ColumnStatsSemanticAnalyzer.java