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

Jie Huang commented on HBASE-6592:
----------------------------------

Thanks Stack. 'c(CLASSNAME).METHOD' is much better. What I mean is that the 
user can define their own converter function in the CONVERTER definition.  :)

For that Exception, it is caused by the converter itself. We also met the 
similar problem while running java code. 

The current Bytes.toXXX needs to check the length of the byte array in advance. 
For example, if you want to encode *1*(Int) to a byte array, the array will 
contain 4 bytes (something like "\000\000\000\001"). And then you are able to 
convert that byte array to an Int object.  You can find the corresponding code 
in *org.apache.hadoop.hbase.util.Bytes.java*. In order to get rid of those 
'\000' in the ruby shell result, here we allow the end user to provide a 
converter to print out the proper output format as they like.
{code}
  public static int toInt(byte[] bytes, int offset, final int length) {
    if (length != SIZEOF_INT || offset + length > bytes.length) {  //check the 
length here.
      throw explainWrongLengthOrOffset(bytes, offset, length, SIZEOF_INT);
    }
    int n = 0;
    for(int i = offset; i < (offset + length); i++) {
      n <<= 8;
      n ^= bytes[i] & 0xFF;
    }
    return n;
  }
{code}
Meanwhile, we also allow the end user to provide their own converter for the 
case as you pointed out. They can define a converter as  'c(CLASSNAME).METHOD' 
as you mentioned. 
                
> [shell] Add means of custom formatting output by column
> -------------------------------------------------------
>
>                 Key: HBASE-6592
>                 URL: https://issues.apache.org/jira/browse/HBASE-6592
>             Project: HBase
>          Issue Type: New Feature
>          Components: shell
>            Reporter: stack
>            Priority: Minor
>              Labels: noob
>         Attachments: hbase-6592.patch, hbase-6592-v2.patch, 
> hbase-6952-v1.patch
>
>
> See Jacques suggestion toward end of this thread for how we should allow 
> adding a custom formatter per column to use outputting column content in 
> shell: 
> http://search-hadoop.com/m/2WxUB1fuxL11/Printing+integers+in+the+Hbase+shell&subj=Printing+integers+in+the+Hbase+shell

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to