那么,你需要查询执行的低级细节,并且事情在那里是颠簸的。 您已收到警告:)
正如您在注释中所述,所有执行信息均在此private[hive] HiveTableScanExec
中。得到一些洞察HiveTableScanExec
物理运算符(即在执行时蜂房表)
一种方法是在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
,我通常使用:paste -raw
而在spark-shell
潜入这样的“未知领域”。
你可以那么只需做到以下几点:
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
场是巢表后,它一直使用星火分析仪使用,以解决数据源和蜂巢表ResolveRelations
和FindDataSourceTable
逻辑规则解决。
通过使用ExternalCatalog
接口,您可以获得几乎所有Spark使用的来自Hive Metastore的所有信息,该接口可用作spark.sharedState.externalCatalog
。这使您几乎可以使用Spark用于规划Hive表上的查询的所有元数据。
谢谢!我能够使用返回的'relation'上的'getHiveQlPartitions'获取相关信息,并提供'partitionPruningPred'作为参数: 'scan.findHiveTables(execPlan).flatMap(e => e.relation.getHiveQlPartitions(e。partitionPruningPred))' 这包含我需要的所有数据,包括所有输入文件的路径,正确分区修剪。 不幸的是,低级别的包私人访问是必需的,标准的'inputFiles'本身并不这样做。我认为这是出于性能原因? – binarek