Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
HBase, mail # user - Printing integers in the Hbase shell

Copy link to this message
Re: Printing integers in the Hbase shell
anil gupta 2012-08-11, 20:12
Hi David,

As i understand that you want to print the Integer values as Strings in
HBase shell. There are two ways to do it:
1. You can write a ruby script to interpret the value as bytes. This might
give you some pointers to do stuff in Hbase shell:
I dont know anything about Ruby.

2. You can write a java program to interpret the row/columns as you want.
If you write your java program then you will need to put the jar in
classpath of HBase, invoke HBase shell and then use the class to scan the
table. Here is a sample snippet from a  class i use myself: Here i am
trying to print as Double as a String in HBase shell :--

package com.intuit.ihub.hbase.poc.filters;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class MyRowKeyRangeFilter1 {

    static final long  TIME_MAX= 4102473600000L; // Epoch time at
"01/01/2100 00:00:00"
    private static SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd

    public MyRowKeyRangeFilter1(String tableName, String merchantId, String
startDate, String endDate) throws IOException
         Configuration conf = HBaseConfiguration.create();
         HTable table = new HTable(conf, tableName);
         scanTable(table, merchantId, startDate, endDate);

    private void scanTable(HTable table, String merchantId, String endDate,
String startDate) {
         long starttime = System.currentTimeMillis();
            Scan scan = new Scan();
            // endDate is the startRow because the data is stored in
reverse chronological order.
*            ResultScanner scanner = null;
            try {
                scanner = table.getScanner(scan);
            } catch (IOException e) {
                System.out.println("Unable to get the scanner for filter.");
            System.out.println("===============Results of

            for (Result result : scanner) {
              for (KeyValue kv : result.raw()) {
                      System.out.println("Printing the value for amt");
                      System.out.println("KV: " + kv + ", Value: " +
                  System.out.println("KV: " + kv + ", Value: " +
            System.out.println("TIme Taken:"+ (System.currentTimeMillis() -
If you are invoking a class in HBase shell then you need to specify:
<fullclassname>.new(<Constructor args>)

On Sat, Aug 11, 2012 at 9:30 AM, Ioakim Perros <[EMAIL PROTECTED]> wrote:

> I see your point - but I thought it was necessary only for debugging
> purposes - I use this conversion for this reason. If anyone else is aware
> of a more efficient way, please answer.
> Regards,
> Ioakim
> On 08/11/2012 07:26 PM, David Koch wrote:
>> Hello Ioakim,
>> Yes, that would work but sacrificing performance by doing int/String/int
>> conversions and also space just to be able to inspect the odd row from
>> shell is not worth it :-/
>> /David
>> On Sat, Aug 11, 2012 at 5:41 PM, Ioakim Perros <[EMAIL PROTECTED]>
>> wrote:
>>  On 08/11/2012 06:38 PM, David Koch wrote:
>>>  Hello,
>>>> I have a table whose qualifiers are always integer values. They are show
Thanks & Regards,
Anil Gupta