val TimeFormat = new SimpleDateFormat("yyyyMMdd")//设定日期的格式
val year = "2016"
val month = "01,02,03,04,05,06,07,08,09,10,11,12".split(",")
val testpath = "E:\Portable\sibat\spark\testdata"
val calender = Calendar.getInstance()
for(i <- month){
for(j <- 0 until 6) { //递增一周
try {
calender.setTime(TimeFormat.parse(year + i + "28"))
calender.add(Calendar.DATE, j) //日期递增j天
}catch {
case e: Exception =>
e.printStackTrace()
}
val date = TimeFormat.format(calender.getTime) //规定格式输出递增的日期
CalStationIO(sparkSession,path+date).saveAsTextFile(outpath+date)
}
}
def CalStationIO(sparkSession: SparkSession,path:String):RDD[String]={
sparkSession.sparkContext.textFile(path+"/*").map(_.split(",")).filter(_.length>=6).map(s => szt(s(0),s(1),s(2),s(3),s(4),s(5),s(6)))}
通过calender来循环得到日期递增的字符串
最后
以上就是冷静音响最近收集整理的关于spark循环读取日期文件数据的全部内容,更多相关spark循环读取日期文件数据内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复