【问题标题】:Getting size of s3 directory in spark scala在 spark scala 中获取 s3 目录的大小
【发布时间】:2021-07-31 14:28:16
【问题描述】:

我在需要目录大小的数据框列中有一个 s3 路径。 在 spark scala 中有什么方法可以让我们在新列中获取 s3 目录的大小。

【问题讨论】:

  • 我不熟悉 spark scala,但您需要对存储在给定路径中的每个对象的大小求和。没有 S3 命令来查找“目录”的大小。

标签: scala apache-spark amazon-s3


【解决方案1】:

您可以尝试使用此 udf 来获取 s3 存储桶的大小。


    val sizeEstimator = udf { (path: String) =>
          val path1 = new Path(path)
          val hdfs = path1.getFileSystem(new Configuration())
          var length:Long =0
          if (hdfs.exists(path1)) {
            val cSummary = hdfs.getContentSummary(path1)
            length = cSummary.getLength
          }
          length
        }
    
    
val size =df.select(udfService.sizeEstimator(lit("<Path to s3>"))).first().get(0).asInstanceOf[Long]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-14
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 2010-10-03
    • 2010-11-10
    • 1970-01-01
    相关资源
    最近更新 更多