【发布时间】:2017-07-18 22:03:07
【问题描述】:
有没有办法在 foreachPartition 中将 Row 转换为 JSON? 我看过 How to convert Row to json in Spark 2 Scala 。 但是这种方法不起作用,因为我无法从 foreachPartition 中访问 sqlContext,而且我的数据包含嵌套类型。
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)
}
【问题讨论】:
标签: scala apache-spark dataframe apache-spark-sql