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来循环得到日期递增的字符串