HADOOP-1800 [hbaseshell] output should default utf8 encoding
M src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java Make a PrintStream that outputs utf8. Have all printing use it. M src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java Fix few places where we make Strings w/o stipulating UTF-8 encoding. git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@571317 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
463f847bd4
commit
7d48b5f7d5
|
@ -26,6 +26,7 @@ Trunk (unreleased changes)
|
|||
HADOOP-1805 Region server hang on exit
|
||||
HADOOP-1785 TableInputFormat.TableRecordReader.next has a bug
|
||||
(Ning Li via Stack)
|
||||
HADOOP-1800 output should default utf8 encoding
|
||||
|
||||
IMPROVEMENTS
|
||||
HADOOP-1737 Make HColumnDescriptor data publically members settable
|
||||
|
|
|
@ -19,157 +19,168 @@
|
|||
*/
|
||||
package org.apache.hadoop.hbase.shell;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* Manufactures console table, but stupid.
|
||||
*/
|
||||
public class ConsoleTable {
|
||||
private static PrintStream out;
|
||||
static {
|
||||
try {
|
||||
out = new PrintStream(System.out, true, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void printHead(String name) {
|
||||
System.out.println("+------+----------------------+");
|
||||
System.out.print("| No. | ");
|
||||
System.out.printf("%-20s", name);
|
||||
System.out.println(" |");
|
||||
out.println("+------+----------------------+");
|
||||
out.print("| No. | ");
|
||||
out.printf("%-20s", name);
|
||||
out.println(" |");
|
||||
}
|
||||
|
||||
public static void printFoot() {
|
||||
System.out.println("+------+----------------------+");
|
||||
System.out.println();
|
||||
out.println("+------+----------------------+");
|
||||
out.println();
|
||||
}
|
||||
|
||||
public static void printTable(int count, String name) {
|
||||
System.out.println("+------+----------------------+");
|
||||
out.println("+------+----------------------+");
|
||||
|
||||
if (name.length() > 20) {
|
||||
int interval = 20;
|
||||
|
||||
System.out.print("| ");
|
||||
System.out.printf("%-4s", count + 1);
|
||||
System.out.print(" | ");
|
||||
System.out.printf("%-20s", name.substring(0, interval));
|
||||
System.out.println(" |");
|
||||
out.print("| ");
|
||||
out.printf("%-4s", count + 1);
|
||||
out.print(" | ");
|
||||
out.printf("%-20s", name.substring(0, interval));
|
||||
out.println(" |");
|
||||
|
||||
for (int i = 0; i < name.length() / interval; i++) {
|
||||
System.out.print("| ");
|
||||
System.out.printf("%-4s", "");
|
||||
System.out.print(" | ");
|
||||
out.print("| ");
|
||||
out.printf("%-4s", "");
|
||||
out.print(" | ");
|
||||
|
||||
int end = ((interval * i) + interval + interval);
|
||||
if (end > name.length()) {
|
||||
System.out.printf("%-20s", name.substring(end - interval,
|
||||
out.printf("%-20s", name.substring(end - interval,
|
||||
name.length()));
|
||||
} else {
|
||||
System.out.printf("%-20s", name.substring(end - interval, end));
|
||||
out.printf("%-20s", name.substring(end - interval, end));
|
||||
}
|
||||
System.out.println(" |");
|
||||
out.println(" |");
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.print("| ");
|
||||
System.out.printf("%-4s", count + 1);
|
||||
System.out.print(" | ");
|
||||
System.out.printf("%-20s", name);
|
||||
System.out.println(" |");
|
||||
out.print("| ");
|
||||
out.printf("%-4s", count + 1);
|
||||
out.print(" | ");
|
||||
out.printf("%-20s", name);
|
||||
out.println(" |");
|
||||
}
|
||||
}
|
||||
|
||||
public static void selectHead() {
|
||||
System.out.println("+------+----------------------+" +
|
||||
out.println("+------+----------------------+" +
|
||||
"----------------------+----------------------+");
|
||||
System.out.print("| No. | ");
|
||||
System.out.printf("%-20s", "Row");
|
||||
System.out.printf(" | ");
|
||||
System.out.printf("%-20s", "Column");
|
||||
System.out.printf(" | ");
|
||||
System.out.printf("%-20s", "Cell");
|
||||
System.out.println(" | ");
|
||||
out.print("| No. | ");
|
||||
out.printf("%-20s", "Row");
|
||||
out.printf(" | ");
|
||||
out.printf("%-20s", "Column");
|
||||
out.printf(" | ");
|
||||
out.printf("%-20s", "Cell");
|
||||
out.println(" | ");
|
||||
}
|
||||
|
||||
public static void printLine(int count, String key, String column,
|
||||
String cellData) {
|
||||
System.out.println("+------+----------------------+" +
|
||||
out.println("+------+----------------------+" +
|
||||
"----------------------+----------------------+");
|
||||
|
||||
if (key.length() > 20 || column.length() > 20 || cellData.length() > 20) {
|
||||
int interval = 20;
|
||||
System.out.print("| ");
|
||||
System.out.printf("%-4s", count + 1);
|
||||
System.out.print(" | ");
|
||||
out.print("| ");
|
||||
out.printf("%-4s", count + 1);
|
||||
out.print(" | ");
|
||||
if (key.length() > 20)
|
||||
System.out.printf("%-20s", key.substring(0, interval));
|
||||
out.printf("%-20s", key.substring(0, interval));
|
||||
else
|
||||
System.out.printf("%-20s", key);
|
||||
System.out.print(" | ");
|
||||
out.printf("%-20s", key);
|
||||
out.print(" | ");
|
||||
if (column.length() > 20)
|
||||
System.out.printf("%-20s", column.substring(0, interval));
|
||||
out.printf("%-20s", column.substring(0, interval));
|
||||
else
|
||||
System.out.printf("%-20s", column);
|
||||
System.out.print(" | ");
|
||||
out.printf("%-20s", column);
|
||||
out.print(" | ");
|
||||
if (cellData.length() > 20)
|
||||
System.out.printf("%-20s", cellData.substring(0, interval));
|
||||
out.printf("%-20s", cellData.substring(0, interval));
|
||||
else
|
||||
System.out.printf("%-20s", cellData);
|
||||
System.out.println(" |");
|
||||
out.printf("%-20s", cellData);
|
||||
out.println(" |");
|
||||
|
||||
// System.out.println(getBiggerInt(new int[]{ 3, 1, 9}));
|
||||
// out.println(getBiggerInt(new int[]{ 3, 1, 9}));
|
||||
int biggerStrLength = getBiggerInt(new int[] { key.length(),
|
||||
column.length(), cellData.length() });
|
||||
|
||||
for (int i = 0; i < (biggerStrLength / interval); i++) {
|
||||
System.out.print("| ");
|
||||
System.out.printf("%-4s", "");
|
||||
System.out.print(" | ");
|
||||
out.print("| ");
|
||||
out.printf("%-4s", "");
|
||||
out.print(" | ");
|
||||
|
||||
int end = ((interval * i) + interval + interval);
|
||||
|
||||
if (end > key.length()) {
|
||||
if (key.length() > interval && end - interval < key.length()) {
|
||||
System.out.printf("%-20s", key.substring(end - interval,
|
||||
out.printf("%-20s", key.substring(end - interval,
|
||||
key.length()));
|
||||
} else {
|
||||
System.out.printf("%-20s", "");
|
||||
out.printf("%-20s", "");
|
||||
}
|
||||
} else {
|
||||
System.out.printf("%-20s", key.substring(end - interval, end));
|
||||
out.printf("%-20s", key.substring(end - interval, end));
|
||||
}
|
||||
|
||||
System.out.print(" | ");
|
||||
out.print(" | ");
|
||||
|
||||
if (end > column.length()) {
|
||||
if (column.length() > interval && end - interval < column.length()) {
|
||||
System.out.printf("%-20s", column.substring(end - interval,
|
||||
out.printf("%-20s", column.substring(end - interval,
|
||||
column.length()));
|
||||
} else {
|
||||
System.out.printf("%-20s", "");
|
||||
out.printf("%-20s", "");
|
||||
}
|
||||
} else {
|
||||
System.out.printf("%-20s", column.substring(end - interval, end));
|
||||
out.printf("%-20s", column.substring(end - interval, end));
|
||||
}
|
||||
|
||||
System.out.print(" | ");
|
||||
out.print(" | ");
|
||||
if (end > cellData.length()) {
|
||||
if (cellData.length() > interval &&
|
||||
end - interval < cellData.length()) {
|
||||
System.out.printf("%-20s",
|
||||
out.printf("%-20s",
|
||||
cellData.substring(end - interval, cellData.length()));
|
||||
} else {
|
||||
System.out.printf("%-20s", "");
|
||||
out.printf("%-20s", "");
|
||||
}
|
||||
} else {
|
||||
System.out.printf("%-20s", cellData.substring(end - interval, end));
|
||||
out.printf("%-20s", cellData.substring(end - interval, end));
|
||||
}
|
||||
System.out.println(" |");
|
||||
out.println(" |");
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.print("| ");
|
||||
System.out.printf("%-4s", count + 1);
|
||||
System.out.print(" | ");
|
||||
System.out.printf("%-20s", key);
|
||||
System.out.print(" | ");
|
||||
System.out.printf("%-20s", column);
|
||||
System.out.print(" | ");
|
||||
System.out.printf("%-20s", cellData);
|
||||
System.out.println(" |");
|
||||
out.print("| ");
|
||||
out.printf("%-4s", count + 1);
|
||||
out.print(" | ");
|
||||
out.printf("%-20s", key);
|
||||
out.print(" | ");
|
||||
out.printf("%-20s", column);
|
||||
out.print(" | ");
|
||||
out.printf("%-20s", cellData);
|
||||
out.println(" |");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,9 +195,9 @@ public class ConsoleTable {
|
|||
}
|
||||
|
||||
public static void selectFoot() {
|
||||
System.out.println("+------+----------------------+" +
|
||||
out.println("+------+----------------------+" +
|
||||
"----------------------+----------------------+");
|
||||
System.out.println();
|
||||
out.println();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class SelectCommand extends BasicCommand {
|
|||
|
||||
for (Text columnKey : results.keySet()) {
|
||||
byte[] value = results.get(columnKey);
|
||||
String cellData = new String(value);
|
||||
String cellData = new String(value, HConstants.UTF8_ENCODING);
|
||||
|
||||
if (columnKey.equals(HConstants.COL_REGIONINFO)) {
|
||||
DataInputBuffer inbuf = new DataInputBuffer();
|
||||
|
@ -105,7 +105,7 @@ public class SelectCommand extends BasicCommand {
|
|||
for (Map.Entry<Text, byte[]> entry : table.getRow(new Text(getRow())).entrySet()) {
|
||||
|
||||
byte[] value = entry.getValue();
|
||||
String cellData = new String(value);
|
||||
String cellData = new String(value, HConstants.UTF8_ENCODING);
|
||||
|
||||
if (entry.getKey().equals(HConstants.COL_REGIONINFO)) {
|
||||
DataInputBuffer inbuf = new DataInputBuffer();
|
||||
|
@ -138,7 +138,7 @@ public class SelectCommand extends BasicCommand {
|
|||
|
||||
for (Text columnKey : r.keySet()) {
|
||||
byte[] value = r.get(columnKey);
|
||||
String cellData = new String(value);
|
||||
String cellData = new String(value, HConstants.UTF8_ENCODING);
|
||||
ConsoleTable.printLine(count, rowKey.toString(), columnKey.toString(),
|
||||
cellData);
|
||||
count++;
|
||||
|
@ -180,7 +180,7 @@ public class SelectCommand extends BasicCommand {
|
|||
|
||||
ConsoleTable.selectHead();
|
||||
for (int i = 0; i < rs3.length; i++) {
|
||||
ConsoleTable.printLine(i, getRow(), getColumn(), new String(rs3[i]));
|
||||
ConsoleTable.printLine(i, getRow(), getColumn(), new String(rs3[i], HConstants.UTF8_ENCODING));
|
||||
}
|
||||
ConsoleTable.selectFoot();
|
||||
|
||||
|
|
Loading…
Reference in New Issue