【问题标题】:Not able to Save Spark Dataframe as Table In HDP 3.0无法在 HDP 3.0 中将 Spark Dataframe 保存为表
【发布时间】: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


【解决方案1】:

如果您将 hive 连接的默认数据库设置为testdb via hive.setDatabase("testdb") 那么您应该直接访问其中的所有表而不使用数据库 例如test_2 而不是 testdb.test_2

【讨论】:

  • 也试过了......但是在写作时遇到了这个问题,我可以读取没有数据库名称的表。当我默认使用 saveAsTable 方法时,它会使用 spark 元数据。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-16
  • 1970-01-01
  • 2016-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多