Structure Streaming和spark streaming原生API访问HDFS文件数据对比

本文详细介绍了如何使用Spark Streaming从HDFS中读取数据并进行处理,同时探讨了不同数据读取方式的支持情况,包括移动文件和目录到基目录的场景。通过具体示例,展示了基于代码的实现细节及遇到的问题解决方案。

此文已由作者岳猛授权网易云社区发布。

欢迎访问网易云社区,了解更多网易技术产品运营经验。

Structure Stream访问方式

code examples

import org.apache.spark.sql.streaming._
val df = spark.readStream.text("/home/testhdfs")
val ps = df.writeStream.format("console").outputMode(OutputMode.Append).start复制代码

结论

basedir = /home/testhdfs
支持:mv file to basedir(/home/testhdfs)
不支持:mv directory to basedir

如果往basedir里面添加文件夹会出现ERROR:

java.lang.AssertionError: assertion failed: Conflicting directory structures detected. Suspicious paths:
        hdfs://172.17.1.180:9000/home/testhdfs/data1
        hdfs://172.17.1.180:9000/home/testhdfsIf provided paths are partition directories, please set "basePath" in the options of the data source to specify the root directory of the table. If there are multiple root directories, please load them separately and then union them.复制代码

spark streaming 访问方式

测试textFile接口使用

import org.apache.spark.streaming._
val ssc = StreamingContext.getActiveOrCreate(() => new StreamingContext(sc,                  Seconds(120)))
val ds1 = ssc.textFileStream("/home/testhdfs2")
ds1.print
ssc.start复制代码

结论

支持:mv file to basedir(/home/testhdfs2)
支持:mv directory to basedir



链接:www.jianshu.com/p/9eb8ff8f0…


免费体验云安全(易盾)内容安全、验证码等服务

更多网易技术、产品、运营经验分享请点击




相关文章:
【推荐】 考拉Android统一弹框
【推荐】 用Go编写的本地文件服务器


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值