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)
相关推荐
Sui_Network9 小时前
Mysten Labs 与不丹王国政府的创新与技术部携手探索离线区块链
大数据·人工智能·web3·去中心化·区块链
互联科技报9 小时前
GEO优化工具、AI搜索引擎优化软件平台实测报告:四大平台深度体验与选型指南
大数据·人工智能·搜索引擎
‘胶己人’9 小时前
redis分布式锁
数据库·redis·分布式
递归尽头是星辰9 小时前
AI 驱动的报表系统:从传统到智能的落地与演进
大数据·人工智能·大模型应用·spring ai·ai 报表·报表智能化
山沐与山9 小时前
【MQ】Kafka与RocketMQ深度对比
分布式·kafka·rocketmq
cetcht88889 小时前
35kV-750kV 变电站集中监控系统(涵盖火灾消防、安全防卫、动环、智能锁控、智能巡视等) 设备配置与布置
大数据·运维·物联网·机器人·能源
Elastic 中国社区官方博客9 小时前
通过 Elasticsearch 中的 function score query 按利润和受欢迎程度提升电商搜索效果
大数据·数据库·elasticsearch·搜索引擎·全文检索
武子康9 小时前
Java-203 RabbitMQ 生产者/消费者工作流程拆解:Connection/Channel、默认交换器、ACK
java·分布式·消息队列·rabbitmq·erlang·ruby·java-rabbitmq
Data-Miner9 小时前
165页满分PPT | 某商贸企业数字化蓝图整体规划方案
大数据
CES_Asia9 小时前
政策x技术x市场:三位一体推动机器人产业爆发
大数据·人工智能·科技·机器人