首页 > 解决方案 > 使用databricks中的pyspark将多个json文件从blob存储读取到数据帧

问题描述

我正在尝试将所有 json 文件存储在 blob 存储的子文件夹中的单个容器中。我已经在数据块中设置了环境并链接了连接。目前我正在使用此代码

df = spark.read.json("wasbs://container_name@blob_storage_account.blob.core.windows.net/sub_folder/*.json")

但我得到的只是第一个文件,而不是子文件夹中存在的所有 json 文件,即使在包含通配符之后也是如此/*.json

我正在尝试从单个数据框中的子文件夹中获取所有文件,并将其作为表存储在 sql 数据库中。

有人可以帮助解决我所缺少的。

标签: pythonpysparkazure-blob-storagedatabricks

解决方案


I have tested in my environment.

I have 3 json blob files inside the subfolder of my container in storage account. I am able to read all the blob json files in a single data frame

enter image description here

You can use the below code to display all json the files from the subfolder in a single data frame

df = spark.read.json("wasbs://container_name@blob_storage_account.blob.core.windows.net/sub_folder/*.json")
df.show()

enter image description here


推荐阅读