![](/img/trans.png)
[英]NULL values when trying to import CSV in Azure Databricks DBFS
[英]mount error when trying to access the Azure DBFS file system in Azure Databricks
我能夠建立與我的 Databricks FileStore DBFS
的連接並訪問文件存儲。
可以使用 Pyspark 讀取、寫入和轉換數據,但是當我嘗試使用本地 Python API(例如pathlib
或OS
模塊文件系統)時,我無法通過第一級 DBFS 文件系統
我可以使用一個魔術命令:
%fs ls dbfs:\mnt\my_fs\...
完美運行並列出所有子目錄?
但是如果我執行os.listdir('\dbfs\mnt\my_fs\')
它會返回['mount.err']
作為返回值
我已經在一個新集群上測試過了,結果是一樣的
我在帶有 Apache Spark 2.4.4 的 Databricks Runtine 版本 6.1 上使用 Python
有沒有人可以提供建議。
連接腳本:
我使用 Databricks CLI 庫來存儲我的憑據,這些憑據根據 databricks 文檔進行格式化:
def initialise_connection(secrets_func):
configs = secrets_func()
# Check if the mount exists
bMountExists = False
for item in dbutils.fs.ls("/mnt/"):
if str(item.name) == r"WFM/":
bMountExists = True
# drop if exists to refresh credentials
if bMountExists:
dbutils.fs.unmount("/mnt/WFM")
bMountExists = False
# Mount a drive
if not (bMountExists):
dbutils.fs.mount(
source="adl://test.azuredatalakestore.net/WFM",
mount_point="/mnt/WFM",
extra_configs=configs
)
print("Drive mounted")
else:
print("Drive already mounted")
當同一個容器安裝到工作區中的兩個不同路徑時,我們遇到了這個問題。 卸載所有並重新安裝解決了我們的問題。 我們使用的是 Databricks 6.2 版(Spark 2.4.4、Scala 2.11)。 我們的 blob 存儲容器配置:
運行筆記本腳本以卸載/mnt
中的所有掛載:
# Iterate through all mounts and unmount
print('Unmounting all mounts beginning with /mnt/')
dbutils.fs.mounts()
for mount in dbutils.fs.mounts():
if mount.mountPoint.startswith('/mnt/'):
dbutils.fs.unmount(mount.mountPoint)
# Re-list all mount points
print('Re-listing all mounts')
dbutils.fs.mounts()
假設您有一個單獨的過程來創建安裝。 創建作業定義( job.json
)以在自動化集群上運行 Python 腳本:
{
"name": "Minimal Job",
"new_cluster": {
"spark_version": "6.2.x-scala2.11",
"spark_conf": {},
"node_type_id": "Standard_F8s",
"driver_node_type_id": "Standard_F8s",
"num_workers": 2,
"enable_elastic_disk": true,
"spark_env_vars": {
"PYSPARK_PYTHON": "/databricks/python3/bin/python3"
}
},
"timeout_seconds": 14400,
"max_retries": 0,
"spark_python_task": {
"python_file": "dbfs:/minimal/job.py"
}
}
Python 文件 ( job.py
) 打印出掛載:
import os
path_mounts = '/dbfs/mnt/'
print(f"Listing contents of {path_mounts}:")
print(os.listdir(path_mounts))
path_mount = path_mounts + 'YOURCONTAINERNAME'
print(f"Listing contents of {path_mount }:")
print(os.listdir(path_mount))
運行 databricks CLI 命令來運行作業。 查看 output 的 Spark 驅動程序日志,確認mount.err
不存在。
databricks fs mkdirs dbfs:/minimal
databricks fs cp job.py dbfs:/minimal/job.py --overwrite
databricks jobs create --json-file job.json
databricks jobs run-now --job-id <JOBID FROM LAST COMMAND>
在連接到 Azure Generation2 存儲帳戶(沒有分層名稱空間)時,我們遇到了同樣的問題。
將 Databricks 運行時環境從 5.5 切換到 6.x 時似乎會發生該錯誤。 但是,我們無法查明造成這種情況的確切原因。 我們假設某些功能可能已被棄用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.