使用spark_read_csv()从Rstudio Server中的Azure Blob存储读取CSV文件

时间:2018-11-13 06:40:07

标签: apache-spark rstudio sparklyr rstudio-server

我已经在带有Java 8 HDI 3.6的Spark 2.2上预配置了Azure HDInsight群集类型ML Services(R Server),操作系统Linux,版本ML Services 9.3。

在Rstudio Server中,我试图从blob存储中读取一个csv文件。

Sys.setenv(SPARK_HOME="/usr/hdp/current/spark-client")
Sys.setenv(YARN_CONF_DIR="/etc/hadoop/conf")
Sys.setenv(HADOOP_CONF_DIR="/etc/hadoop/conf")
Sys.setenv(SPARK_CONF_DIR="/etc/spark/conf")

options(rsparkling.sparklingwater.version = "2.2.28")

library(sparklyr)
library(dplyr)
library(h2o)
library(rsparkling)


sc <- spark_connect(master = "yarn-client",
                    version = "2.2.0")

origins <-file.path("wasb://MYDefaultContainer@MyStorageAccount.blob.core.windows.net",
                 "user/RevoShare")

df2 <- spark_read_csv(sc,
                 path = origins,
                 name = 'Nov-MD-Dan',
                 memory = FALSE)```

运行此命令时,出现以下错误

Error: java.lang.IllegalArgumentException: invalid method csv 
for object 235
at sparklyr.Invoke$.invoke(invoke.scala:122)
at sparklyr.StreamHandler$.handleMethodCall(stream.scala:97)
at sparklyr.StreamHandler$.read(stream.scala:62)
at sparklyr.BackendHandler.channelRead0(handler.scala:52)
at sparklyr.BackendHandler.channelRead0(handler.scala:14)
at 

io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleCh   annelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
    at java.lang.Thread.run(Thread.java:748)

任何帮助都会很棒!

1 个答案:

答案 0 :(得分:1)

路径origins应指向CSV文件或CSV目录。您确定origins指向文件目录还是文件?对于每个HDFS用户,/user/RevoShare/下通常至少还有一个目录,即/user/RevoShare/sshuser/

以下示例可能会有所帮助:

sample_file <- file.path("/example/data/", "yellowthings.txt")

library(sparklyr)
library(dplyr)
cc <- rxSparkConnect(interop = "sparklyr")
sc <- rxGetSparklyrConnection(cc)

fruits <- spark_read_csv(sc, path = sample_file, name = "fruits", header = FALSE)

您可以使用RxHadoopListFiles("/example/data/")或使用hdfs dfs -ls /example/data检查HDFS / Blob上的目录。

HTH!