hbase-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ted Yu (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HBASE-2432) enhance hbase.util.Bytes.toBytes() with length limit
Date Sat, 10 Apr 2010 12:52:51 GMT

    [ https://issues.apache.org/jira/browse/HBASE-2432?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12855551#action_12855551
] 

Ted Yu commented on HBASE-2432:
-------------------------------

Here is one implementation:

  /**
   * Converts a string to a UTF-8 byte array with limited length.
   * @param s the string
   * @param len the length limit
   * @return the byte array
   */
  public static byte[] toBytes(String s, int len) {
    if (s == null) {
      throw new IllegalArgumentException("string cannot be null");
    }
    if (len <= 0) {
      throw new IllegalArgumentException("string length should be positive");
    }
    byte [] result = null;
	byte [] ary = null;
    try {
      ary = s.getBytes(HConstants.UTF8_ENCODING);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
	if (ary.length > len)
	{
	  result = new byte[len];
	  System.arraycopy(ary, 0, result, 0, len);
	}
	else result = ary;

    return result;
  }


> enhance hbase.util.Bytes.toBytes() with length limit
> ----------------------------------------------------
>
>                 Key: HBASE-2432
>                 URL: https://issues.apache.org/jira/browse/HBASE-2432
>             Project: Hadoop HBase
>          Issue Type: Improvement
>          Components: util
>    Affects Versions: 0.20.1
>            Reporter: Ted Yu
>
> The following stack trace is seen in our hadoop log:
> java.lang.IllegalArgumentException: Row > 32767
> 	at org.apache.hadoop.hbase.KeyValue.createByteArray(KeyValue.java:437)
> 	at org.apache.hadoop.hbase.KeyValue.(KeyValue.java:405)
> 	at org.apache.hadoop.hbase.KeyValue.(KeyValue.java:374)
> 	at org.apache.hadoop.hbase.KeyValue.(KeyValue.java:353)
> 	at org.apache.hadoop.hbase.client.Put.add(Put.java:137)
> 	at org.apache.hadoop.hbase.client.Put.add(Put.java:108)
> 	at org.apache.nutch.scoring.webgraph.ScoreUpdater$ScoreUpdaterReducer.reduce(ScoreUpdater.java:170)
> 	at org.apache.nutch.scoring.webgraph.ScoreUpdater$ScoreUpdaterReducer.reduce(ScoreUpdater.java:127)
> 	at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:174)
> 	at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:563)
> 	at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:408)
> 	at org.apache.hadoop.mapred.Child.main(Child.java:170)
> Bytes.toBytes(Float.valueOf(score).toString()) may return an array longer than 32767
bytes.
> We should enhance Bytes.toBytes() to include length limit:
>   public static byte[] toBytes(String s, int length) 
> String.getBytes() doesn't have length limit

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message