Azure Databricks Autoloader从队列存储加载失败:eventType键不存在
问题原因
cloudfiles的useNotifications模式是为了处理Azure Blob Storage的Event Grid事件通知(这类通知会包含eventType字段),但你当前尝试读取的是Azure Queue Storage中的自定义消息,并非标准的Event Grid事件结构,因此抛出找不到eventType的错误。
解决方案
如果需要直接读取Azure Queue Storage中的自定义消息,请改用azure-queue数据源格式,代码调整如下:
- 确保集群安装依赖(若未预装):
%pip install azure-storage-queue
- 重构读取流逻辑:
from pyspark.sql.types import StructType, StringType # 自定义消息结构schema,按需调整 schema = StructType().add("message", StringType(), nullable=True) df = (spark.readStream .format("azure-queue") .option("queueName", "queue-dev") .option("connectionString", "替换为你的Azure Queue存储连接字符串") .schema(schema) .load() ) streamQuery = (df.writeStream .format("delta") .outputMode("append") .option("ignoreDeletes", "true") .option("checkpointLocation", "/mnt/datalake/Streaming-test/checkpoint/") .start("/mnt/datalake/Streaming-test/data/") )
额外说明
cloudfiles+useNotifications的正确场景是:Blob存储有新文件上传时,Event Grid将事件推送到Queue,cloudfiles读取Queue中的事件通知后,自动去Blob存储拉取对应文件内容,并非直接读取Queue内的自定义消息。- 若你原本的需求是监听Blob存储的文件变化,请确保Queue中的消息是Event Grid推送的标准事件格式,而非自定义消息。
内容的提问来源于stack exchange,提问作者John K
相关产品推荐
相关产品推荐

