3

Does anybody knows who to read data from hive into R and then back to Hive?
I can do it easily with Python like this:

for line in sys.stdin:

  Some code ...

  sys.stdout.write(Output + '\n') 

Is there a similar way in R?

Thanks Tomer

Ofir Luzon
  • 10,635
  • 3
  • 41
  • 52
  • You may be interested in the answers and comments on this q:http://stackoverflow.com/questions/9871307/r-reading-stdin-line-by-line – agstudy Dec 02 '12 at 12:42
  • I am just curious why the title is "execute ...". What is being executed? I tried to change this to "Read data in Windows hive", but the change was rejected. – Dieter Menne Dec 02 '12 at 18:29
  • I'd guess it was rejected for the "Windows" part. This has nothing to do with Windows. – Ken Williams Feb 18 '14 at 18:31

2 Answers2

0

if you set up Rstudio on you hive server you can easily access it via R script. You would need the Rhive package. http://cran.r-project.org/web/packages/RHive/

All you need to do after that is set your paths for hadoop and hive home in your R profile and use

library(Rhive)
rhive.init()
rhcon<-rhive.connect(address,port=)

hope that helps!

Roshini
  • 703
  • 2
  • 8
  • 21
0

Ofir, I guess you can write your code in the some way in R. Precisely:

conn <- file("stdin", open="r")
while (length(next.line <- readLines(conn, n=1, warn=FALSE)) > 0) { 
    # processing
    cat(output)
}