diff --git a/pkg/R/hbase.r b/pkg/R/hbase.r index 05ecd8b..0b9dffc 100644 --- a/pkg/R/hbase.r +++ b/pkg/R/hbase.r @@ -269,3 +269,52 @@ hb.get.data.frame <- function(tablename, start,end=NULL,columns=NULL){ } } +.hb.as.data.frame <- function( scan, colspec ) +{ + raw_result <- scan$get() + # interpret column specification + if( length( colspec ) == 1 ) { + cols <- raw_result[[ 1 ]][[ 2 ]] + } else { + cols <- colspec + } + # define column vectors + get_column_index_values <- function( column_index ) + { + get_value <- function( row, column_name ) + { + indices <- which( row[[ 2 ]] == column_name ) + index <- ifelse( length( indices ) == 1, indices[[ 1 ]], 0 ) + ifelse( index == 0, NA, row[[ 3 ]][[ index ]] ) + } + column_name <- cols[[ column_index ]] + unlist( lapply( raw_result, get_value, column_name ) ) + } + # define resulting data frame + df <- as.data.frame( lapply( 1:length( cols ), get_column_index_values ) ) + rownames( df ) <- unlist( lapply( raw_result, "[[", 1 ) ) + colnames( df ) <- cols + df +} + +hb.scan.data.frame <- function( tablename, startrow, end=NULL, colspec, + sz=hb.defaults("sz"), + usz=hb.defaults("usz"), + hbc=hb.defaults("hbc") ) +{ + scn <- hb.scan( tablename, startrow, end, colspec, sz, usz, hbc ) + .hb.as.data.frame( scn, colspec ) +} + +hb.scan.ex.data.frame <- function( tablename, startrow='', end='', + colspec, timestamp=0, caching=0, + filterstring=character(0), + sz=hb.defaults("sz"), + usz=hb.defaults("usz"), + hbc=hb.defaults("hbc") ) +{ + scn <- + hb.scan.ex( tablename, startrow, end, colspec, timestamp, caching, + filterstring, sz, usz, hbc ) + .hb.as.data.frame( scn, colspec ) +}