有个需求,需要判断文件夹下是否有parquet文件,但是涉及到中间有一层/id=vin号/文件目录,无法用通配符、
由此转化为判断hdfs文件夹下文件数量来判断。
代码为
val hadoopfs: FileSystem = FileSystem.get(spark.sparkContext.hadoopConfiguration)
val file = hadoopfs.getContentSummary(new Path(inputPath)).getFileCount
if (file > 1){
val parquet_DF: DataFrame = spark.read.parquet(inputPath)
.withColumn("exception_cells",convert($"cells"))
.select("vin", "start_charge_time", "end_charge_time","anomaly_type", "cells")
.drop("cells")
writeSQL(parquet_DF,sql_url,user,password,table)
}else{
println("parquet file not exist")
}
file为该文件加下文件数量。如果大于1(不光只有_success文件)则说明跑出来数据了。