15 package com.cloudera.impala.common;
17 import static com.cloudera.impala.common.ByteUnits.GIGABYTE;
18 import static com.cloudera.impala.common.ByteUnits.KILOBYTE;
19 import static com.cloudera.impala.common.ByteUnits.MEGABYTE;
20 import static com.cloudera.impala.common.ByteUnits.PETABYTE;
21 import static com.cloudera.impala.common.ByteUnits.TERABYTE;
23 import java.text.DecimalFormat;
34 double result = bytes;
36 if (bytes >= PETABYTE)
return new DecimalFormat(
".00PB").format(result / PETABYTE);
37 if (bytes >= TERABYTE)
return new DecimalFormat(
".00TB").format(result / TERABYTE);
38 if (bytes >= GIGABYTE)
return new DecimalFormat(
".00GB").format(result / GIGABYTE);
39 if (bytes >= MEGABYTE)
return new DecimalFormat(
".00MB").format(result / MEGABYTE);
40 if (bytes >= KILOBYTE)
return new DecimalFormat(
".00KB").format(result / KILOBYTE);
45 return prefix +
"cardinality=" +
46 ((cardinality != -1) ? String.valueOf(cardinality) :
"unavailable");
49 public static String
printHosts(String prefix,
long numHosts) {
50 return prefix +
"hosts=" + ((numHosts != -1) ? numHosts :
"unavailable");
53 public static String
printMemCost(String prefix,
long perHostMemCost) {
54 return prefix +
"per-host-mem=" +
55 ((perHostMemCost != -1) ?
printBytes(perHostMemCost) :
"unavailable");
61 public static void printMatrix(
boolean[][] matrix,
int cellSpacing,
62 StringBuilder matrixStr) {
64 for (
int i = 0; i < cellSpacing; ++i) {
65 matrixStr.append(
" ");
67 String formatStr =
"%Xd".replace(
"X", String.valueOf(cellSpacing));
68 for (
int i = 0; i < matrix.length; ++i) {
69 matrixStr.append(String.format(formatStr, i));
71 matrixStr.append(
"\n");
74 for (
int i = 0; i < matrix.length; ++i) {
75 matrixStr.append(String.format(formatStr, i));
76 for (
int j = 0; j < matrix.length; ++j) {
77 int cell = (matrix[i][j]) ? 1 : 0;
78 matrixStr.append(String.format(formatStr, cell));
80 matrixStr.append(
"\n");
static void printMatrix(boolean[][] matrix, int cellSpacing, StringBuilder matrixStr)
static String printBytes(long bytes)
static String printMemCost(String prefix, long perHostMemCost)
static String printHosts(String prefix, long numHosts)
static String printCardinality(String prefix, long cardinality)