public static Map getDisplayWidth()

in odps-console-basic/src/main/java/com/aliyun/openservices/odps/console/utils/ODPSConsoleUtils.java [480:531]


  public static Map<String, Integer> getDisplayWidth(List<Column> columns,
                                                     List<Column> partitionsColumns,
                                                     List<String> selectColumns) {
    if (columns == null || columns.isEmpty()) {
      return null;
    }

    Map<String, Integer> displayWith = new LinkedHashMap<>();
    Map<String, OdpsType> fieldTypeMap = new LinkedHashMap<>();
    // Get Column Info from Table Meta
    for (Column column : columns) {
      fieldTypeMap.put(column.getName(), column.getTypeInfo().getOdpsType());
    }

    // Get Partition Info from Table Meta
    if (partitionsColumns != null) {
      for (Column column : partitionsColumns) {
        fieldTypeMap.put(column.getName(), column.getTypeInfo().getOdpsType());
      }
    }

    // delete the column which is not in columns
    if (selectColumns != null && !selectColumns.isEmpty()) {
      Set<String> set = fieldTypeMap.keySet();
      List<String> remainList = new ArrayList<String>(set);
      Iterator<String> it = set.iterator();
      while (it.hasNext()) {
        Object o = it.next();
        if (selectColumns.contains(o)) {
          remainList.remove(o);
        }
      }

      for (Object o : remainList) {
        fieldTypeMap.remove(o);
      }
    }
    // According the fieldType to calculate the display width
    for (Map.Entry entry : fieldTypeMap.entrySet()) {
      if ("BOOLEAN".equalsIgnoreCase(entry.getValue().toString())) {
        displayWith.put(
            entry.getKey().toString(),
            entry.getKey().toString().length() > 4 ? entry.getKey().toString().length() : 4);
      } else {
        displayWith.put(
            entry.getKey().toString(),
            entry.getKey().toString().length() > 10 ? entry.getKey().toString().length() : 10);
      }
    }

    return displayWith;
  }