Database Reference
In-Depth Information
while (( res = scanner . next ()) != null && count ++ < maxCount ) {
byte [] row = res . getRow ();
byte [] value = res . getValue ( DATA_COLUMNFAMILY ,
AIRTEMP_QUALIFIER );
Long stamp = Long . MAX_VALUE -
Bytes . toLong ( row , row . length - Bytes . SIZEOF_LONG ,
Bytes . SIZEOF_LONG );
Integer temp = Bytes . toInt ( value );
resultMap . put ( stamp , temp );
}
} finally {
scanner . close ();
}
return resultMap ;
}
public int run ( String [] args ) throws IOException {
if ( args . length != 1 ) {
System . err . println ( "Usage: HBaseTemperatureQuery <station_id>" );
return - 1 ;
}
HTable table = new HTable ( HBaseConfiguration . create ( getConf ()),
"observations" );
try {
NavigableMap < Long , Integer > observations =
getStationObservations ( table , args [ 0 ], Long . MAX_VALUE ,
10 ). descendingMap ();
for ( Map . Entry < Long , Integer > observation :
observations . entrySet ()) {
// Print the date, time, and temperature
System . out . printf ( "%1$tF %1$tR\t%2$s\n" , observation . getKey (),
observation . getValue ());
}
return 0 ;
} finally {
table . close ();
}
}
public static void main ( String [] args ) throws Exception {
int exitCode = ToolRunner . run ( HBaseConfiguration . create (),
new HBaseTemperatureQuery (), args );
System . exit ( exitCode );
}
}
Search WWH ::




Custom Search