|
|
-
Re: Printing integers in the Hbase shellDavid Koch 2012-08-12, 11:52
Hi Anil,
Thank you for your advice. On Sat, Aug 11, 2012 at 10:12 PM, anil gupta <[EMAIL PROTECTED]> wrote: > 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: > > http://stackoverflow.com/questions/7256100/how-to-scan-hbase-from-hbase-shell-using-filter > 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 > HH:mm:ss"); > > 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. > scan.setStartRow(getReverseTimestamp(merchantId,endDate)); > scan.setStopRow(getReverseTimestamp(merchantId,startDate)); > * 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 > scan==============="); > > for (Result result : scanner) { > for (KeyValue kv : result.raw()) { > if(Bytes.toString(kv.getQualifier()).equals("amt")) > { > System.out.println("Printing the value for amt"); > System.out.println("KV: " + kv + ", Value: " + > Bytes.toDouble(kv.getValue())); > } > else > { > System.out.println("KV: " + kv + ", Value: " + > Bytes.toString(kv.getValue())); > } > } > }* > scanner.close(); > System.out.println("===============SCAN > COMPLETED==============="); > System.out.println("TIme Taken:"+ (System.currentTimeMillis() - > starttime)); > // > > System.out.println(Bytes.toString(getReverseTimestamp(merchantId,endDate))); > // > > System.out.println(Bytes.toString(getReverseTimestamp(merchantId,startDate))); > } > } > * > If you are invoking a class in HBase shell then you need to specify: > <fullclassname>.new(<Constructor args>) > * > HTH, > Anil > > 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 |