spark读取多个目录下多个文件

最近项目要用准时数据,于是改用sparkSQL还对数据进行统计。kafka落到HDFS上是按照天分区,小时文件。
HDFS上的目录结构如下:
A/20190101/2019010100 A/20190101/2019010101
B/20190101/2019010100 B/20190101/2019010101
方法1:使用sparkContext.read.text(paths=[path1, path2, …])方法
val inputPath: List[String] = List(“A/20190101/2019010100”,“A/20190101/2019010101”,“B/20190101/2019010100”,“B/20190101/2019010101”)
val result=spark.sparkContext.textFile(inputpath.mkString(","))
方法2:
val A1=spark.sparkContext.textFile(“A/20190101/2019010100”)
val A2=spark.sparkContext.textFile(“A/20190101/2019010101”)
val B1=spark.sparkContext.textFile(“B/20190101/2019010100”)
val B2=spark.sparkContext.textFile(“B/20190101/2019010101”)
val result=A1.union(A2).union(B1).union(B2)

你可能感兴趣的:(Spark)