那麼,你需要查詢執行的低級細節,並且事情在那裏是顛簸的。 您已收到警告:)
正如您在註釋中所述,所有執行信息均在此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