I'm currently reading a book about hbase (hbase in action by manning).
In this book it is explained how to perform a scan if the rowkey is
made out of a md5 hash (page 45 in the book). My rowkey design (and
table filling method) looks like this:

SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss");
Date date = dateFormatter.parse("2013-01-01");

for( int i = 0; i < 31; ++i ) {
        for( int k = 0; k < 24; ++k ) {
                for( int j = 0; j < 1; ++j ) {
                        //md5() is a custom method that transforms a
string into a md5 hash
                        byte[] ts = md5( dateFormatter.format(date) );
                        byte[] tm = md5( timeFormatter.format(date) );
                        byte[] ip = md5( generateRandomIPAddress() /* toy 
method that
generates ip addresses */ );
                        byte[] rowkey = new byte[ ts.length + tm.length + 
ip.length ];
                        System.arraycopy( ts, 0, rowkey, 0, ts.length );
                        System.arraycopy( tm, 0, rowkey, ts.length, tm.length );
                        System.arraycopy( ip, 0, rowkey, ts.length+tm.length, 
ip.length );
                        Put p = new Put( rowkey );

                        p.add( Bytes.toBytes("CF"), Bytes.toBytes("SampleCol"),
Bytes.toBytes( "Value_" + (i+1) + " = " + dateFormatter.format(date) +
" " + timeFormatter.format(date) ) );
                        toyDataTable.put( p );
                }
        
                //custom method that adds an hour to the current date object
                date = addHours( date, 1 );
        }
        
}

Now I'd like to do the following scan (I more or less took the same
code from the example in the book):

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date refDate = formatter.parse("2013-01-15");

HTableInterface toyDataTable = pool.getTable("ToyDataTable");

byte[] md5Key = md5( refDate.getTime() +"" );
int md5Length = 16;
int longLength = 8;
byte[] startRow = Bytes.padTail( md5Key, longLength );
byte[] endRow = Bytes.padTail( md5Key, longLength );
endRow[md5Length-1]++;

Scan scan = new Scan( startRow, endRow );
ResultScanner rs = toyDataTable.getScanner( scan );
for( Result r : rs ) {
        String value =  Bytes.toString( r.getValue( Bytes.toBytes("CF"),
Bytes.toBytes("SampleCol")) );
        System.out.println( value );
}

The result is empty. How is that possible?

Reply via email to