Structure Streaming和spark streaming原生API访问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/testhdfs
If 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容