为SaveAsTable插入计数并插入INTO

时间:2018-05-24 15:16:34

标签: scala apache-spark dataframe hive hiveql

我有一个Scala代码,我在spark-shell中运行以从json文件中提取数据并首先在HIVE临时表中加载,然后从分段中提取数据并加载到HIVE中的最终主表中。

我使用以下命令:

//read json to DF
  val df = hiveContext.read.schema(schema1).json(file)
//DF to Staging
  df.write.mode("append").saveAsTable("stg")
//Staging to Final
  hiveContext.sql("insert into final select distinct columns from stg left outer join final on stg.id = final.id where stg.id is not null and final.id is null")

我希望能够理解每个阶段读/写的记录数。 对于json到DF,我知道我可以做 df.count(),但剩下的两个阶段呢。如何获取saveAsTable和Insert到语句的计数?

0 个答案:

没有答案
相关问题