簡體   English   中英

嵌入模式下的Spark - 找不到用戶/配置單元/倉庫

[英]Spark on embedded mode - user/hive/warehouse not found

我在嵌入式本地模式下使用Apache Spark。 我的所有依賴項都包含在我的pom.xml和相同的版本中(spark-core_2.10,spark-sql_2.10和spark-hive_2.10)。

我只想運行一個HiveQL查詢來創建一個表(存儲為Parquet)。

運行以下(相當簡單的)代碼:

public class App {
    public static void main(String[] args) throws IOException, ClassNotFoundException {

        SparkConf sparkConf = new SparkConf().setAppName("JavaSparkSQL").setMaster("local[2]").set("spark.executor.memory", "1g");
        JavaSparkContext ctx = new JavaSparkContext(sparkConf);
        HiveContext sqlContext = new org.apache.spark.sql.hive.HiveContext(ctx.sc());

        String createQuery = "CREATE TABLE IF NOT EXISTS Test (id int, name string) STORED AS PARQUET";
        sqlContext.sql(createQuery);
    }
}

...正在返回以下異常:

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:file:/user/hive/warehouse/test is not a directory or unable to create one)

我可以看到在項目的根目錄中創建的metastore_db文件夾。

我四處搜索,找到的解決方案沒有幫助 - 其中大部分都不適用於嵌入式模式。

  • 一種解決方案是檢查權限,我使用相同的用戶。
  • 另一個解決方案是在HDFS中手動創建文件夾,我做了,我可以導航到/ user / hive / warehouse / test。
  • 一種解決方案是通過添加以下sqlContext.sql("SET hive.metastore.warehouse.dir=hdfs://localhost:9000/user/hive/warehouse");手動設置Metastore: sqlContext.sql("SET hive.metastore.warehouse.dir=hdfs://localhost:9000/user/hive/warehouse");

我現在用完了想法,有人可以提供任何其他建議嗎?

為了防止將來有人幫助其他人,我正在嘗試針對使用HiveContext的Spark代碼編寫一些單元測試。 我發現為了更改為測試編寫文件的路徑,我需要調用hiveContext.setConf。 我也嘗試了與OP相同的方法,執行SET查詢,但這不起作用。 以下似乎工作!

hive.setConf("hive.metastore.warehouse.dir", 
  "file:///custom/path/to/hive/warehouse")

為了使這更有用,我特意將此路徑設置為我的代碼可以訪問的位置:

hive.setConf("hive.metastore.warehouse.dir", 
  getClass.getResource(".").toString)

有了這個,我已經能夠使用hive查詢和Spark API編寫針對我的代碼的單元測試。

由於您在本地嵌入模式下運行,因此不考慮HDFS。 這就是錯誤說file:/user/hive/warehouse/test而不是hdfs://localhost:9000/user/hive/warehouse/test 它希望/user/hive/warehouse/test存在於本地計算機上。 嘗試在本地創建它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM