From cece2431bd5f29449101a645132ffe7459ae0632 Mon Sep 17 00:00:00 2001 From: EeshanChatterjee Date: Thu, 12 Sep 2013 17:06:56 +0530 Subject: [PATCH] Update hbase.r Edited hb.get.data.frame to create the dataframe by calling scn$get recursively and return it. --- pkg/R/hbase.r | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/pkg/R/hbase.r b/pkg/R/hbase.r index 05ecd8b..981f102 100644 --- a/pkg/R/hbase.r +++ b/pkg/R/hbase.r @@ -249,23 +249,32 @@ hb.insert.data.frame <- function(tablename, df,sz=hb.defaults("sz"),hbc=hb.defau TRUE } -hb.get.data.frame <- function(tablename, start,end=NULL,columns=NULL){ - if(is.null(columns)) +hb.get.data.frame <- function (tablename, start, end = NULL, columns = NULL) +{ + if (is.null(columns)) columns <- rownames(hb.describe.table(tablename)) - if(is.null(end)) - scn <- hb.scan(tablename, startrow=start, colspec=columns) - else - scn <- hb.scan(tablename, startrow=start,end=end,colspec=columns) ## filter is not included - function(batchsize=100){ + if (is.null(end)) + scn <- hb.scan(tablename, startrow = start, colspec = columns) + else scn <- hb.scan(tablename, startrow = start, end = end, + colspec = columns) + dataframe<-data.frame() + df.full = 0 + getdf <- function(batchsize = 100) { f <- scn$get(batchsize) - if(length(f)==0) { + if (length(f) == 0) { scn$close() - return(NULL) + return(1) } - g <- as.data.frame( lapply(1:length(columns),function(cc) unlist(lapply( lapply(f,"[[",3),"[[",cc))) ) - rownames(g) <- unlist(lapply(f,"[[",1)) + g <- as.data.frame(lapply(1:length(columns), function(cc) unlist(lapply(lapply(f, + "[[", 3), "[[", cc)))) + rownames(g) <- unlist(lapply(f, "[[", 1)) colnames(g) <- columns - g + dataframe <<- rbind(dataframe,g) + return(0) } + while(df.full == 0){ + df.full = getdf() + } + return(dataframe) }