1
有沒有辦法將行轉換爲JSON在foreachPartition中? 我查看過How to convert Row to json in Spark 2 Scala。 但是,這種方法不會工作,因爲我不能從foreachPartition中訪問sqlContext,而且我的數據也包含嵌套類型。如何將行轉換爲foreachPartition中的JSON?
dataframe.foreachPartition { partitionOfRecords =>
..
val connectionString: ConnectionStringBuilder = new ConnectionStringBuilder(
eventHubsNamespace,
eventHubName,
policyName,
policyKey)
val eventHubsClient: EventHubClient = EventHubClient.createFromConnectionString(connectionString.toString()).get()
val json = /* CONVERT partitionOfRecords to JSON */
val bytes = json.getBytes()
val eventData = new EventData(bytes)
eventHubsClient.send(eventData)
}