Skip to content

Commit

Permalink
[BUG FIX] (Issue : rhive.size.table() permission error #80)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssshow16 committed Dec 11, 2014
1 parent 77a799e commit 9a73f07
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions RHive/R/rhive.R
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@

.rhive.big.query <- function(query, fetchSize=50, limit=-1, memLimit=64*1024*1024) {
table <- .HIVE_QUERY_RESULT_TABLE_NAME()
.createTableAs(table, query)
.createTableAs(table, query)
size <- .rhive.size.table(table)

if (size > memLimit) {
Expand Down Expand Up @@ -932,16 +932,46 @@
}

.rhive.size.table <- function(tableName) {

if (missing(tableName)) {
stop("missing tableName")
stop("missing tableName")
}

location <- .rhive.table.location(tableName)
dataInfo <- .rhive.hdfs.du(location, summary=TRUE)
tryCatch ( {
dataInfo <- .rhive.hdfs.du(location, summary=TRUE)
return (dataInfo$length)
}, error=function(e) {
#ignore
}
)
# get the table size from 'DESC EXTENDED {table_name}'
size = .rhive.get.table.size(tableName)

if(size != -1){
return (size)
}else{
# if there is not the size information, execute 'analyze' query and try it again.
.rhive.execute(sprintf("analyze table %s compute statistics",tableName))
size = .rhive.get.table.size(tableName)
return (size)
}
}

.rhive.get.table.size <- function(tableName){
str <- .rhive.desc.table(tableName, detail=TRUE)
i <- regexpr("totalSize\\s*=\\s*[^,]+", str)
l <- attr(i, "match.length")

return (dataInfo$length)
if(l == -1)
return (-1)

str <- substr(str, i, i + l - 1)
str <- gsub("^totalSize\\s*=\\s*", "", str)
as.numeric(str)
}


.rhive.table.location <- function(tableName) {
str <- .rhive.desc.table(tableName, detail=TRUE)
i <- regexpr("location\\s*:\\s*[^,]+", str)
Expand Down

0 comments on commit 9a73f07

Please sign in to comment.