Is there a way to convert Row to JSON inside foreachPartition? I have looked at How to convert Row to json in Spark 2 Scala . However this approach won't work as I can't access sqlContext from within foreachPartition and also my data contains nested type.
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)
}