pysparkDataframe到配置单元表

kokeuurv  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(298)

如何将pysparkDataframe对象存储到配置单元表,“primary12345”是配置单元表?我使用下面的代码 masterDataDf 是Dataframe对象

masterDataDf.write.saveAsTable("default.primary12345")

低于错误
:java.lang.runtimeexception:使用sqlcontext创建的表必须是临时的。改用hivecontext。

ndasle7k

ndasle7k1#

可以创建一个临时表。

masterDataDf.createOrReplaceTempView("mytempTable")

然后可以使用简单的hive语句来创建表并从temp表中转储数据。

sqlContext.sql("create table primary12345 as select * from mytempTable");


如果要使用hivecontext,则需要拥有/创建hivecontext

import org.apache.spark.sql.hive.HiveContext;

HiveContext sqlContext = new org.apache.spark.sql.hive.HiveContext(sc.sc());

然后直接保存dataframe或选择要存储为配置单元表的列

masterDataDf.write().mode("overwrite").saveAsTable("default.primary12345 ");

相关问题