【发布时间】:2020-05-17 14:31:00
【问题描述】:
我有一个数据框,我正试图将其保存为我的配置单元表。我已经尝试了所有可能的方法,但无法将其保存为 HDP 3.0 中的表。我正在使用下面的代码。
var sparksession = SparkSession.builder()
.appName("appname")
.config("hive.exec.dynamic.partition", "true")
.config("hive.exec.dynamic.partition.mode", "nonstrict")
.config("spark.sql.sources.maxConcurrentWrites","1")
.config("hive.support.concurrency", "true")
.config("parquet.compression", "SNAPPY")
.config("parquet.enable.dictionary", "false")
.config("spark.sql.parquet.compression.codec", "snappy")
.config("hive.mapred.mode", "nonstrict")
.config("spark.sql.hive.hiveserver2.jdbc.url","url")
.enableHiveSupport()
.getOrCreate()
val hive = com.hortonworks.spark.sql.hive.llap.HiveWarehouseBuilder.session(sparksession).build()
hive.setDatabase("testdb")
val d1="select id,name,salary,city from testdb.test";
val d2=hive.executeQuery(d1)
d2.show //showing hive table's data.
d2.write.format("orc").mode("append").saveAsTable("testdb.test_2")
//test_2 table is already created in testdb database.
//but here getting error 'testdb' not found
d2.write.format("orc").mode("append").saveAsTable("default.test_2")
//if am using default then its not giving any error but saving data in
spark metadata not as a hive table.
//same code is working fine in cloudera and am am getting data
in hive table but in hdp it's giving error.
我已经尝试过 save() 方法,它也适用于分区表,但我无法在使用 save 方法时使用存储桶。 谁能建议我如何将这个数据框直接保存到 HDP 3.0 中的配置单元表中。(表被分桶,所以不能使用保存方法)
【问题讨论】:
-
错误是什么?
-
@QuickSilver 数据库未找到。
标签: scala apache-spark apache-spark-sql hdp