Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
From Sishen:
Hi, guys. I think i have met the problem of table query. When playing with the REST interface, the result is all the table name are un-readable format and i can't get the table metadata. After some debug, i found that if use table.getName().toString() to construct the table name string. However, getName() return a byte array. So toString() method jsut return the string representation of the array object. The correct way should be new String(table.getName()). I have tested it and all work well now. Below are patches: Index: org/apache/hadoop/hbase/rest/MetaHandler.java =================================================================== --- org/apache/hadoop/hbase/rest/MetaHandler.java (revision 678344) +++ org/apache/hadoop/hbase/rest/MetaHandler.java (working copy) @@ -85,7 +85,7 @@ XMLOutputter outputter = getXMLOutputter(response.getWriter()); outputter.startTag("tables"); for (int i = 0; i < tables.length; i++) { - doElement(outputter, "table", tables[i].getName().toString()); + doElement(outputter, "table", new String(tables[i].getName())); } outputter.endTag(); outputter.endDocument(); @@ -96,7 +96,7 @@ ContentType.PLAIN.toString()); PrintWriter out = response.getWriter(); for (int i = 0; i < tables.length; i++) { - out.println(tables[i].getName().toString()); + out.println(new String(tables[i].getName())); } out.close(); break; Index: org/apache/hadoop/hbase/rest/TableHandler.java =================================================================== --- org/apache/hadoop/hbase/rest/TableHandler.java (revision 678344) +++ org/apache/hadoop/hbase/rest/TableHandler.java (working copy) @@ -391,7 +391,7 @@ HTableDescriptor [] tables = this.admin.listTables(); HTableDescriptor descriptor = null; for (int i = 0; i < tables.length; i++) { - if (tables[i].getName().toString().equals(tableName)) { + if (new String(tables[i].getName()).equals(tableName)) { descriptor = tables[i]; break; } @@ -406,7 +406,7 @@ setResponseHeader(response, 200, ContentType.XML.toString()); XMLOutputter outputter = getXMLOutputter(response.getWriter()); outputter.startTag("table"); - doElement(outputter, "name", descriptor.getName().toString()); + doElement(outputter, "name", new String(descriptor.getName())); outputter.startTag("columnfamilies"); for (HColumnDescriptor e: descriptor.getFamilies()) { outputter.startTag("columnfamily"); Best regards. sishen Index: org/apache/hadoop/hbase/rest/MetaHandler.java =================================================================== --- org/apache/hadoop/hbase/rest/MetaHandler.java (revision 678344) +++ org/apache/hadoop/hbase/rest/MetaHandler.java (working copy) @@ -85,7 +85,7 @@ XMLOutputter outputter = getXMLOutputter(response.getWriter()); outputter.startTag("tables"); for (int i = 0; i < tables.length; i++) { - doElement(outputter, "table", tables[i].getName().toString()); + doElement(outputter, "table", new String(tables[i].getName())); } outputter.endTag(); outputter.endDocument(); @@ -96,7 +96,7 @@ ContentType.PLAIN.toString()); PrintWriter out = response.getWriter(); for (int i = 0; i < tables.length; i++) { - out.println(tables[i].getName().toString()); + out.println(new String(tables[i].getName())); } out.close(); break; Index: org/apache/hadoop/hbase/rest/TableHandler.java =================================================================== --- org/apache/hadoop/hbase/rest/TableHandler.java (revision 678344) +++ org/apache/hadoop/hbase/rest/TableHandler.java (working copy) @@ -391,7 +391,7 @@ HTableDescriptor [] tables = this.admin.listTables(); HTableDescriptor descriptor = null; for (int i = 0; i < tables.length; i++) { - if (tables[i].getName().toString().equals(tableName)) { + if (new String(tables[i].getName()).equals(tableName)) { descriptor = tables[i]; break; } @@ -406,7 +406,7 @@ setResponseHeader(response, 200, ContentType.XML.toString()); XMLOutputter outputter = getXMLOutputter(response.getWriter()); outputter.startTag("table"); - doElement(outputter, "name", descriptor.getName().toString()); + doElement(outputter, "name", new String(descriptor.getName())); outputter.startTag("columnfamilies"); for (HColumnDescriptor e: descriptor.getFamilies()) { outputter.startTag("columnfamily");