嗯,您要求的是查询执行的低级详细信息,而那里的事情却很坎坷。 您已被警告 :)
正如你在评论中提到的,所有的执行信息都在这个private[hive] HiveTableScanExec中。
了解HiveTableScanExec 物理运算符(即执行时的Hive 表)的一种方法是在org.apache.spark.sql.hive 包中创建一种不是private[hive] 的后门。
package org.apache.spark.sql.hive
import org.apache.spark.sql.hive.execution.HiveTableScanExec
object scan {
def findHiveTables(execPlan: org.apache.spark.sql.execution.SparkPlan) = execPlan.collect { case hiveTables: HiveTableScanExec => hiveTables }
}
更改代码以满足您的需要。
使用scan.findHiveTables,我通常在spark-shell 中使用:paste -raw 来潜入这些“未知领域”。
然后您可以简单地执行以下操作:
scala> spark.version
res0: String = 2.4.0-SNAPSHOT
// Create a Hive table
import org.apache.spark.sql.types.StructType
spark.catalog.createTable(
tableName = "h1",
source = "hive", // <-- that makes for a Hive table
schema = new StructType().add($"id".long),
options = Map.empty[String, String])
// select * from h1
val q = spark.table("h1")
val execPlan = q.queryExecution.executedPlan
scala> println(execPlan.numberedTreeString)
00 HiveTableScan [id#22L], HiveTableRelation `default`.`h1`, org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, [id#22L]
// Use the above code and :paste -raw in spark-shell
import org.apache.spark.sql.hive.scan
scala> scan.findHiveTables(execPlan).size
res11: Int = 1
relation 字段是使用 Spark 分析器用于解析数据源和 Hive 表的 ResolveRelations 和 FindDataSourceTable 逻辑规则解析后的 Hive 表。
您可以使用ExternalCatalog 接口从 Hive 元存储中获取 Spark 使用的几乎所有信息,该接口可用作spark.sharedState.externalCatalog。这为您提供了 Spark 用于计划对 Hive 表的查询的几乎所有元数据。