首页 > 解决方案 > 如何使用文件存储架构反序列化来自事件中心的 Avro 消息并存储在 Azure Databricks 的数据框中

问题描述

来自事件中心的数据采用 Avro 格式,二进制/不可读。需要在特定模式中转换为可读格式。

以下是尝试的代码:

%scala

// Configuration parameters for connecting to Event Hubs.
// Build connection string with the above information 

val connectionString =  ConnectionStringBuilder("our connection string).setEventHubName(EventHubName).build

val customEventhubParameters = 
  EventHubsConf(connectionString)
  .setMaxEventsPerTrigger(1)

val incomingStream = spark.readStream.format("eventhubs").options(customEventhubParameters.toMap).load()

val messages = incomingStream.withColumn("Body", $"body".cast(StringType)).select("Body")

需要读取用户定义的 .avsc 模式并将其存储在 Dataframe 中以供以后处理

标签: scalaapache-sparkavrodatabricksazure-databricks

解决方案


推荐阅读