首页 > 解决方案 > 通过 spark 在 hive 中创建表

问题描述

我正在尝试使用以下代码通过 Spark 连接到 Hive,但无法这样做。代码失败,NoSuchDatabaseException Database 'raw' not found。我在 hive 中有名为“raw”的数据库。我在这里想念什么?

     val spark = SparkSession
      .builder()
      .appName("Connecting to hive")
      .config("hive.metastore.uris", "thrift://myserver.domain.local:9083") 
      .enableHiveSupport() 
      .getOrCreate()

    import spark.implicits._
    import spark.sql
    
    val frame = Seq(("one", 1), ("two", 2), ("three", 3)).toDF("word", "count")
   
    frame.show()
    frame.write.mode("overwrite").saveAsTable("raw.temp1")

spark.sql("SHOW DATABASES") 的输出

在此处输入图像描述

标签: apache-sparkspark-hive

解决方案


推荐阅读