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)
相关推荐
Elastic 中国社区官方博客2 小时前
通过自主 IT 平台和 Elastic 迈出可观测性的下一步
大数据·elasticsearch·搜索引擎·全文检索·可用性测试
一个有温度的技术博主3 小时前
Redis AOF持久化:用“记账”的方式守护数据安全
redis·分布式·缓存
成长之路5144 小时前
【数据集】A股上市公司深度合成算法业务数据(2001-2024)
大数据
GIS数据转换器7 小时前
延凡智慧水务系统:引领行业变革的智能引擎
大数据·人工智能·无人机·智慧城市
2601_949539457 小时前
家用新能源 SUV 核心技术科普:后排娱乐、空间工程与混动可靠性解析
大数据·网络·人工智能·算法·机器学习
莫叫石榴姐7 小时前
字节广告数开一面 | 实习
大数据·数据仓库·面试
2402_881319307 小时前
引入 Redis 分布式锁解决并发脏写 (Dirty Write)-AI模拟面试的构建rag部分
redis·分布式·面试
T06205148 小时前
【面板数据】地级市人力资本水平测算数据(1990-2024年)
大数据
TDengine (老段)8 小时前
TDengine IDMP 可视化 —— 饼图
大数据·数据库·人工智能·物联网·时序数据库·tdengine·涛思数据
Flying pigs~~8 小时前
从“踩坑”到“可控”:大模型 Prompt 工程实战总结与进阶方法论
大数据·人工智能·大模型·prompt·提示词工程