IllegalArgumentException:u'错误的 FS:file://spark-warehouse,预期:file:///'

Posted

技术标签:

【中文标题】IllegalArgumentException:u\'错误的 FS:file://spark-warehouse,预期:file:///\'【英文标题】:IllegalArgumentException: u'Wrong FS: file://spark-warehouse, expected: file:///'IllegalArgumentException:u'错误的 FS:file://spark-warehouse,预期:file:///' 【发布时间】:2017-01-23 21:43:39 【问题描述】:

我正在尝试使用 PySpark 将我的 Postgres 数据库加载到 Spark:

from pyspark import SparkContext
from pyspark import SparkConf
from random import random

#spark conf
conf = SparkConf()
conf.setMaster("spark://spark-master:7077")
conf.setAppName('pyspark')

sc = SparkContext(conf=conf)

from pyspark.sql import SQLContext
sqlContext = SQLContext(sc)
properties = 
    "user": "postgres",
    "password": "password123",
    "driver": "org.postgresql.Driver"

url = "jdbc.postgresql://<POSTGRES_IP>/DB_NAME"
df = sqlContext.read.jdbc(url=url, table='myTable', properties=properties)

我收到以下错误,我不知道这是什么意思。

/opt/spark/python/pyspark/sql/readwriter.pyc in jdbc(self, url, table, column, lowerBound, upperBound, numPartitions, predicates, properties)
    420             jpredicates = utils.toJArray(gateway, gateway.jvm.java.lang.String, predicates)
    421             return self._df(self._jreader.jdbc(url, table, jpredicates, jprop))
--> 422         return self._df(self._jreader.jdbc(url, table, jprop))
    423 
    424 

/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.pyc in __call__(self, *args)
   1131         answer = self.gateway_client.send_command(command)
   1132         return_value = get_return_value(
-> 1133             answer, self.gateway_client, self.target_id, self.name)
   1134 
   1135         for temp_arg in temp_args:

/opt/spark/python/pyspark/sql/utils.pyc in deco(*a, **kw)
     77                 raise QueryExecutionException(s.split(': ', 1)[1], stackTrace)
     78             if s.startswith('java.lang.IllegalArgumentException: '):
---> 79                 raise IllegalArgumentException(s.split(': ', 1)[1], stackTrace)
     80             raise
     81     return deco

IllegalArgumentException: u'Wrong FS: file://spark-warehouse, expected: file:///'

【问题讨论】:

【参考方案1】:

为 sql 仓库目录设置指定一个现有目录应该可以解决您的问题。例如在作业启动时:

./bin/spark-submit --conf spark.sql.warehouse.dir=/tmp/ \
... # other options
your_file.py \
[application-arguments]

【讨论】:

以上是关于IllegalArgumentException:u'错误的 FS:file://spark-warehouse,预期:file:///'的主要内容,如果未能解决你的问题,请参考以下文章

IllegalArgumentException:无效的列纬度

Retrofit-IllegalArgumentException:意外的 url

引起:java.lang.IllegalArgumentException:属性'driverClassName'不能为空

IllegalArgumentException:接收方未注册

IllegalArgumentException 介绍

java.lang.IllegalArgumentException:基本 URI 不能为空