Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-764

The name of column request has padding zero using REST interface

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.2.0
    • 0.2.0
    • REST
    • None
    • Debian GNU/Linux, Java5

    Description

      Today when i play with the REST interface and found the column POST/PUT/GET has a problem.
      When i use the hbase shell to check the data, i found the row name has the padding zero.

      The cause is that TableHandler use Text class to encode the string to the UTF-8. But CharSetEncoder
      will pre-allocate more spaces then the length of String for performance. So we get the padding zero
      when inserting the value to the table. The fix is to get the String instead of the byte[] for the BatchUpdate.

      Below is the patch. Also, the patch includes fixing the wrong use of (bytes[]).toString() using Bytes.toString(byte[])

      Index: src/java/org/apache/hadoop/hbase/rest/TableHandler.java
      ===================================================================
      — src/java/org/apache/hadoop/hbase/rest/TableHandler.java (revision 678664)
      +++ src/java/org/apache/hadoop/hbase/rest/TableHandler.java (working copy)
      @@ -174,7 +174,7 @@

      // copy over those cells with requested column names
      for(byte [] current_column: columns_retrieved) {

      • if(requested_columns_set.contains(current_column.toString()))
        Unknown macro: {+ if(requested_columns_set.contains(Bytes.toString(current_column))){ m.put(current_column, prefiltered_result.get(current_column)); } }

        @@ -295,7 +295,7 @@

      try{
      // start an update

      • Text key = new Text(row);
        + String key = new Text(row).toString();
        batchUpdate = timestamp == null ?
        new BatchUpdate(key) : new BatchUpdate(key, Long.parseLong(timestamp));

      @@ -308,7 +308,7 @@

      // extract the name and value children
      Node name_node = column.getElementsByTagName("name").item(0);

      • Text name = new Text(name_node.getFirstChild().getNodeValue());
        + String name = new Text(name_node.getFirstChild().getNodeValue()).toString();

      Node value_node = column.getElementsByTagName("value").item(0);

      @@ -356,7 +356,7 @@
      XMLOutputter outputter = getXMLOutputter(response.getWriter());
      outputter.startTag("regions");
      for (int i = 0; i < startKeys.length; i++)

      { - doElement(outputter, "region", startKeys[i].toString()); + doElement(outputter, "region", Bytes.toString(startKeys[i])); }

      outputter.endTag();
      outputter.endDocument();
      @@ -368,7 +368,7 @@
      PrintWriter out = response.getWriter();
      for (int i = 0; i < startKeys.length; i++)

      { // TODO: Add in the server location. Is it needed? - out.print(startKeys[i].toString()); + out.print(Bytes.toString(startKeys[i])); }

      out.close();
      break;
      @@ -454,7 +454,7 @@
      // pull the row key out of the path
      String row = URLDecoder.decode(pathSegments[2], HConstants.UTF8_ENCODING);

      • Text key = new Text(row);
        + String key = new Text(row).toString();

      String[] columns = request.getParameterValues(COLUMN);

      @@ -472,7 +472,7 @@
      } else{
      // delete each column in turn
      for(int i = 0; i < columns.length; i++)

      { - table.deleteAll(key, new Text(columns[i])); + table.deleteAll(key, new Text(columns[i]).toString()); }

      }
      response.setStatus(202);

      Attachments

        1. rest_column.patch
          3 kB
          sishen.freecity
        2. rest_column-v2.patch
          3 kB
          Michael Stack

        Activity

          People

            Unassigned Unassigned
            sishen sishen.freecity
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 0.5h
                0.5h
                Remaining:
                Remaining Estimate - 0.5h
                0.5h
                Logged:
                Time Spent - Not Specified
                Not Specified