Spark 之 HiveStrategies

HiveTableRelation 相关代码

HiveStrategies.scala

当 relation.tableMeta.stats.isEmpty 是, 即调用 hiveTableWithStats

class DetermineTableStats(session: SparkSession) extends Rule[LogicalPlan] {
  private def hiveTableWithStats(relation: HiveTableRelation): HiveTableRelation = {
    val table = relation.tableMeta
    val partitionCols = relation.partitionCols
    // For partitioned tables, the partition directory may be outside of the table directory.
    // Which is expensive to get table size. Please see how we implemented it in the AnalyzeTable.
    val sizeInBytes = if (conf.fallBackToHdfsForStatsEnabled && partitionCols.isEmpty) {
      try {
        val hadoopConf = session.sessionState.newHadoopConf()
        val tablePath = new Path(table.location)
        val fs: FileSystem = tablePath.getFileSystem(hadoopConf)
        fs.getContentSummary(tablePath).getLength
      } catch {
        case e: IOException =>
          logWarning("Failed to get table size from HDFS.", e)
          conf.defaultSizeInBytes
      }
    } else {
      conf.defaultSizeInBytes
    }

    val stats = Some(Statistics(sizeInBytes = BigInt(sizeInBytes)))
    relation.copy(tableStats = stats)
  }

  override def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
    case relation: HiveTableRelation
      if DDLUtils.isHiveTable(relation.tableMeta) && relation.tableMeta.stats.isEmpty =>
      hiveTableWithStats(relation)

    // handles InsertIntoStatement specially as the table in InsertIntoStatement is not added in its
    // children, hence not matched directly by previous HiveTableRelation case.
    case i @ InsertIntoStatement(relation: HiveTableRelation, _, _, _, _, _)
      if DDLUtils.isHiveTable(relation.tableMeta) && relation.tableMeta.stats.isEmpty =>
      i.copy(table = hiveTableWithStats(relation))
  }
}
  • HiveTableRelation

    /**

    • A LogicalPlan that represents a hive table.
    • TODO: remove this after we completely make hive as a data source.
      */
      case class HiveTableRelation(
      tableMeta: CatalogTable,
      dataCols: Seq[AttributeReference],
      partitionCols: Seq[AttributeReference],
      tableStats: Option[Statistics] = None,
      @transient prunedPartitions: Option[Seq[CatalogTablePartition]] = None)
相关推荐
HaoHao_0101 小时前
AWS Outposts
大数据·服务器·数据库·aws·云服务器
HaoHao_0101 小时前
VMware 的 AWS
大数据·服务器·数据库·云计算·aws·云服务器
Elastic 中国社区官方博客4 小时前
将 OneLake 数据索引到 Elasticsearch - 第二部分
大数据·数据库·elasticsearch·搜索引擎·信息可视化·全文检索
庄小焱4 小时前
Elasticsearch——Elasticsearch查询实战
大数据·elasticsearch·搜索引擎
金融OG4 小时前
99.17 金融难点通俗解释:归母净利润
大数据·数据库·python·机器学习·金融
豪越大豪5 小时前
智慧消防营区一体化安全管控 2024 年度深度剖析与展望
大数据·运维
weixin_307779136 小时前
性能优化案例:通过合理设置spark.storage.memoryFraction参数的值来优化PySpark程序的性能
大数据·python·spark
重生之Java再爱我一次8 小时前
Redisson分布式限流的使用及原理
分布式·redisson·分布式限流
007php00713 小时前
在系统重构中的工作计划与总结
大数据·开发语言·人工智能·后端·重构·aigc·php