hbase-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Purtell (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HBASE-4116) [stargate] StringIndexOutOfBoundsException in row spec parse
Date Mon, 18 Jul 2011 23:32:57 GMT
[stargate] StringIndexOutOfBoundsException in row spec parse
------------------------------------------------------------

                 Key: HBASE-4116
                 URL: https://issues.apache.org/jira/browse/HBASE-4116
             Project: HBase
          Issue Type: Bug
            Reporter: Andrew Purtell
            Assignee: Andrew Purtell
             Fix For: 0.90.4, 0.92.0


>From user@hbase, Allan Yan writes:

There might be a bug for REST web service to get rows with given startRow and endRow.

For example, to get a list of rows with startRow=testrow1, endRow=testrow2, I send GET request:

curl http://localhost:8123/TestRowResource/testrow1,testrow2/a:1

And got StringIndexOutOfBoundsException.

This was because in the RowSpec.java, parseRowKeys method, startRow value was changed:

{code}

       startRow = sb.toString();
       int idx = startRow.indexOf(',');
       if (idx != -1) {
         startRow = URLDecoder.decode(startRow.substring(0, idx),
           HConstants.UTF8_ENCODING);
         endRow = URLDecoder.decode(startRow.substring(idx + 1),
           HConstants.UTF8_ENCODING);
       } else {
         startRow = URLDecoder.decode(startRow, HConstants.UTF8_ENCODING);
       }
{code}

 After change to this, it works:

{code}
       String row = sb.toString();
       int idx = row.indexOf(',');
       if (idx != -1) {
         startRow = URLDecoder.decode(row.substring(0, idx),
           HConstants.UTF8_ENCODING);
         endRow = URLDecoder.decode(row.substring(idx + 1),
           HConstants.UTF8_ENCODING);
       } else {
         startRow = URLDecoder.decode(row, HConstants.UTF8_ENCODING);
       }
{code}

I've also created a unit test method in TestRowResource.java,

{code}

   @Test
   public void testStartEndRowGetPutXML() throws IOException, JAXBException {
     String[] rows = {ROW_1,ROW_2,ROW_3};
     String[] values = {VALUE_1,VALUE_2,VALUE_3}; 
     Response response = null;
     for(int i=0; i<rows.length; i++){
         response = putValueXML(TABLE, rows[i], COLUMN_1, values[i]);
         assertEquals(200, response.getCode());
         checkValueXML(TABLE, rows[i], COLUMN_1, values[i]);
     }

     response = getValueXML(TABLE, rows[0], rows[2], COLUMN_1);
     assertEquals(200, response.getCode());
     CellSetModel cellSet = (CellSetModel)
       unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
     assertEquals(2, cellSet.getRows().size());
     for(int i=0; i<cellSet.getRows().size()-1; i++){
         RowModel rowModel = cellSet.getRows().get(i);
         for(CellModel cell : rowModel.getCells()){
             assertEquals(COLUMN_1, Bytes.toString(cell.getColumn()));
             assertEquals(values[i], Bytes.toString(cell.getValue()));
         }   
     }
    
     for(String row : rows){
         response = deleteRow(TABLE, row);
         assertEquals(200, response.getCode());
     }
   }

   private static Response getValueXML(String table, String startRow, String
 endRow, String column)
           throws IOException {
         StringBuilder path = new StringBuilder();
         path.append('/');
         path.append(table);
         path.append('/');
         path.append(startRow);
         path.append(",");
         path.append(endRow);
         path.append('/');
         path.append(column);
         return getValueXML(path.toString());
   }
{code}


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message