为什么 pyspark 只能从根目录中找到本地配置单元元存储?

why pyspark find local hive metastore only from root directory?

我对 delta lake 的 hive metastore 支持有疑问, 我已经在具有以下配置的独立 spark 会话上定义了一个 Metastore

pyspark --conf "spark.sql.catalog.spark_catalog=org.apache.spark.sql.delta.catalog.DeltaCatalog" --conf "spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension"
spark = SparkSession \
    .builder \
    .appName("Python Spark SQL Hive integration example") \
    .config("spark.sql.warehouse.dir", '/mnt/data/db/medilake/') \
    .config("spark.hadoop.datanucleus.autoCreateSchema", 'true') \
    .enableHiveSupport() \
    .getOrCreate()
and it all worked while i was in the session according to the doc https://docs.delta.io/latest/delta-batch.html#-control-data-location&language-python
then when i opened a new session i got this error
>>> spark.sql("SELECT * FROM BRONZE.user").show()
20/09/04 20:30:27 WARN ObjectStore: Failed to get database bronze, returning NoSuchObjectException
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/spark-3.0.0-bin-hadoop3.2/python/pyspark/sql/session.py", line 646, in sql
    return DataFrame(self._jsparkSession.sql(sqlQuery), self._wrapped)
  File "/opt/spark-3.0.0-bin-hadoop3.2/python/lib/py4j-0.10.9-src.zip/py4j/java_gateway.py", line 1305, in __call__
  File "/opt/spark-3.0.0-bin-hadoop3.2/python/pyspark/sql/utils.py", line 137, in deco
    raise_from(converted)
  File "<string>", line 3, in raise_from
pyspark.sql.utils.AnalysisException: Table or view not found: BRONZE.user; line 1 pos 14;
'Project [*]
+- 'UnresolvedRelation [BRONZE, user]

我仍然可以看到文件夹中排列的数据,但现在数据库是空的(以前是 bronze/silver/gold)

>>> spark.catalog.listDatabases()
[Database(name='default', description='Default Hive database', locationUri='file:/mnt/data/db/medilake/spark-warehouse')]

文件夹:

root@m:/mnt/data/db/medilake# ll
total 16
drwxr-xr-x 9 root root 4096 Sep  4 19:05 bronze.db
-rw-r--r-- 1 root root  708 Sep  4 19:45 derby.log
drwxr-xr-x 4 root root 4096 Sep  4 19:36 gold.db
drwxr-xr-x 5 root root 4096 Sep  4 19:45 metastore_db

配置文件:

>>> spark.conf.get("spark.sql.warehouse.dir")
'/mnt/data/db/medilake/'

如何设置 属性 从任何工作目录工作?

.config("spark.sql.warehouse.dir", '/mnt/data/db/medilake/')

Barak,也许我可以通过以下方式帮助您添加 spark sql 语法

spark.sql("CREATE TABLE BRONZE.user USING DELTA LOCATION '/mnt/data/db/medilake/spark-warehouse'")

我记得要读取增量 table 它必须从 parquet 或 csv 文件中保存,有关更多详细信息,请参阅文档

Delta Lake

只需按照说明进行操作即可。 在 spark-default.conf 上设置 spark.sql.warehouse.dir 就成功了