1 获取目录或路径大小
/**
* 获取某个目录的大小(单位b字节),注意:只能在driver端使用,可以多线程来提速。
*/
def get_path_size(spark: SparkSession, path: String): Long = {
//取文件系统
val filePath = new org.apache.hadoop.fs.Path( path )
val fileSystem = filePath.getFileSystem( spark.sparkContext.hadoopConfiguration )
// 获取该目录的大小,单位是字节
if (fileSystem.exists( filePath )) {
fileSystem.getContentSummary( filePath ).getLength
} else {
0
}
}