src/main/java/org/apache/hadoop/hdfs/server/namenode/queries/Histograms.java
public static String toCsv(Map<String, Long> histogram, String find, boolean rawTimestamp) {
    long s1 = System.currentTimeMillis();

    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, Long> entry : histogram.entrySet()) {
      if (rawTimestamp || find == null || find.length() == 0) {
        sb.append(entry.getKey()).append(',').append(entry.getValue().toString()).append('\n');
      } else {
        String[] finds = find.split(":");
        String findField = finds[1];
        switch (findField) {
          case "accessTime":
          case "modTime":
            sb.append(entry.getKey()).append(',').append(new Date(entry.getValue())).append('\n');
            break;
          default:
            sb.append(entry.getKey()).append(',').append(entry.getValue().toString()).append('\n');
            break;
        }
      }
    }

    long e1 = System.currentTimeMillis();
    String csv = sb.toString();
    LOG.info(
        "Time to dump histogram to CSV String of {} chars took: {} ms.", csv.length(), (e1 - s1));
    return csv;
  }
/**
   * Converts given histogram data points to CSV String.
   *
   * @param histogram data points of histogram
   * @param find specifies field to be included as date (accessTime or modTime)
   * @return csv string of histogram
   */
Converts given histogram data points to CSV String.
@param histogram data points of histogram
@param find specifies field to be included as date (accessTime or modTime)
@return csv string of histogram
Converts given histogram data points to CSV String . @param histogram data points of histogram @param find specifies field to be included as date ( accessTime or modTime ) @return csv string of histogram
public static String toCsv(Map<String, Long> histogram, String find, boolean rawTimestamp) {
    long s1 = System.currentTimeMillis();
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, Long> entry : histogram.entrySet()) {
      if (rawTimestamp || find == null || find.length() == 0) {
        sb.append(entry.getKey()).append(',').append(entry.getValue().toString()).append('\n');
      } else {
        String[] finds = find.split(":");
        String findField = finds[1];
        switch (findField) {
          case "accessTime":
          case "modTime":
            sb.append(entry.getKey()).append(',').append(new Date(entry.getValue())).append('\n');
            break;
          default:
            sb.append(entry.getKey()).append(',').append(entry.getValue().toString()).append('\n');
            break;
        }
      }
    }
    long e1 = System.currentTimeMillis();
    String csv = sb.toString();
    LOG.info(
        "Time to dump histogram to CSV String of {} chars took: {} ms.", csv.length(), (e1 - s1));
    return csv;
  }
public static String toCsv ( Map < String , Long > histogram , String find , boolean rawTimestamp ) { long s1 = System . currentTimeMillis ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( Map . Entry < String , Long > entry : histogram . entrySet ( ) ) { if ( rawTimestamp || find == null || find . length ( ) == 0 ) { sb . append ( entry . getKey ( ) ) . append ( ',' ) . append ( entry . getValue ( ) . toString ( ) ) . append ( '\n' ) ; } else { String [ ] finds = find . split ( ":" ) ; String findField = finds [ 1 ] ; switch ( findField ) { case "accessTime" : case "modTime" : sb . append ( entry . getKey ( ) ) . append ( ',' ) . append ( new Date ( entry . getValue ( ) ) ) . append ( '\n' ) ; break ; default : sb . append ( entry . getKey ( ) ) . append ( ',' ) . append ( entry . getValue ( ) . toString ( ) ) . append ( '\n' ) ; break ; } } } long e1 = System . currentTimeMillis ( ) ; String csv = sb . toString ( ) ; LOG . info ( "Time to dump histogram to CSV String of {} chars took: {} ms." , csv . length ( ) , ( e1 - s1 ) ) ; return csv ; }
Converts given histogram data points to CSV String.
Converts given histogram data points to CSV String .