[英]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
文件夾。
我四處搜索,找到的解決方案沒有幫助 - 其中大部分都不適用於嵌入式模式。
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.