lig*_*ght 3 hadoop apache-spark
我正在尝试在spark中加载一个镶木地板文件目录,但似乎无法让它工作......这似乎有效:
val df = sqlContext.load("hdfs://nameservice1/data/rtl/events/stream/loaddate=20151102")
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
val df = sqlContext.load("hdfs://nameservice1/data/rtl/events/stream/loaddate=201511*")
Run Code Online (Sandbox Code Playgroud)
它让我回到了这个错误:
java.io.FileNotFoundException: File does not exist: hdfs://nameservice1/data/rtl/events/stream/loaddate=201511*
Run Code Online (Sandbox Code Playgroud)
我如何使用外卡?
您可以使用文件系统列表状态读取文件或文件夹列表.然后查看要阅读的文件/文件夹.使用reduce with union将所有文件缩减为一个rdd.
获取文件/文件夹:
val fs = FileSystem.get(new Configuration())
val status = fs.listStatus(new Path(YOUR_HDFS_PATH))
Run Code Online (Sandbox Code Playgroud)
读入数据:
val parquetFiles= status .map(folder => {
sqlContext.read.parquet(folder.getPath.toString)
})
Run Code Online (Sandbox Code Playgroud)
将数据合并为单个rdd:
val mergedFile= parquetFiles.reduce((x, y) => x.unionAll(y))
Run Code Online (Sandbox Code Playgroud)
您还可以查看我过去关于同一主题的帖子.
Spark/Scala flatten和flatMap无法在DataFrame上运行
归档时间: |
|
查看次数: |
6964 次 |
最近记录: |