本文整理汇总了Scala中org.apache.spark.sql.sources.StreamSinkProvider类的典型用法代码示例。如果您正苦于以下问题:Scala StreamSinkProvider类的具体用法?Scala StreamSinkProvider怎么用?Scala StreamSinkProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StreamSinkProvider类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CustomSinkProvider
//设置package包名称以及导入依赖的类
package com.knockdata.spark.highcharts
import com.knockdata.spark.highcharts.model.Highcharts
import org.apache.spark.sql._
import org.apache.spark.sql.execution.streaming.Sink
import org.apache.spark.sql.sources.StreamSinkProvider
import org.apache.spark.sql.streaming.OutputMode
class CustomSinkProvider extends StreamSinkProvider {
def createSink(
sqlContext: SQLContext,
parameters: Map[String, String],
partitionColumns: Seq[String],
outputMode: OutputMode): Sink = {
new Sink {
override def addBatch(batchId: Long, data: DataFrame): Unit = {
val chartId = parameters("chartId")
val chartParagraphId = parameters("chartParagraphId")
println(s"batchId: $batchId, chartId: $chartId, chartParagraphId: $chartParagraphId")
// data.show(3)
val z = Registry.get(s"$chartId-z").asInstanceOf[ZeppelinContextHolder]
val seriesHolder = Registry.get(s"$chartId-seriesHolder").asInstanceOf[SeriesHolder]
val outputMode = Registry.get(s"$chartId-outputMode").asInstanceOf[CustomOutputMode]
seriesHolder.dataFrame = data
val result = seriesHolder.result
val (normalSeriesList, drilldownSeriesList) = outputMode.result(result._1, result._2)
val chart = new Highcharts(normalSeriesList, seriesHolder.chartId)
.drilldown(drilldownSeriesList)
val plotData = chart.plotData
// val escaped = plotData.replace("%angular", "")
// println(s" put $chartParagraphId $escaped")
z.put(chartParagraphId, plotData)
println(s"run $chartParagraphId")
z.run(chartParagraphId)
}
}
}
}
示例2: CustomSinkProvider
//设置package包名称以及导入依赖的类
package com.rockiey.kafka
import org.apache.spark.sql._
import org.apache.spark.sql.execution.streaming.Sink
import org.apache.spark.sql.sources.StreamSinkProvider
import org.apache.spark.sql.streaming.OutputMode
class CustomSinkProvider extends StreamSinkProvider {
def createSink(
sqlContext: SQLContext,
parameters: Map[String, String],
partitionColumns: Seq[String],
outputMode: OutputMode): Sink = {
new Sink {
override def addBatch(batchId: Long, data: DataFrame): Unit = {
data.printSchema()
data.show()
println(s"count ${data.count()}")
}
}
}
}
示例3: ClickHouseSinkProvider
//设置package包名称以及导入依赖的类
package io.clickhouse.ext.spark.streaming
import io.clickhouse.ext.ClickHouseUtils
import org.apache.spark.internal.Logging
import org.apache.spark.sql.{Encoders, SQLContext}
import org.apache.spark.sql.sources.StreamSinkProvider
import org.apache.spark.sql.streaming.OutputMode
import scala.reflect.{ClassTag, classTag}
import scala.reflect.runtime.universe.TypeTag
abstract class ClickHouseSinkProvider[T <: Product: ClassTag](implicit tag: TypeTag[T]) extends StreamSinkProvider with Serializable with Logging {
def clickHouseServers: Seq[(String, Int)]
def dbName: String
def tableName: Option[String] = None
def eventDateColumnName: String
def indexColumns: Seq[String]
def partitionFunc: (org.apache.spark.sql.Row) => java.sql.Date
override def createSink(
sqlContext: SQLContext,
parameters: Map[String, String],
partitionColumns: Seq[String],
outputMode: OutputMode): ClickHouseSink[T] = {
val typeEncoder = Encoders.product[T]
val schema = typeEncoder.schema
val _tableName = tableName.get //tableName.getOrElse(classOf[T].getName)
val createTableSql = ClickHouseUtils.createTableIfNotExistsSql(
schema,
dbName,
_tableName,
eventDateColumnName,
indexColumns
)
log.info("create new table sql:")
log.info(createTableSql)
val connection = ClickHouseUtils.createConnection(getConnectionString())
try{
connection.createStatement().execute(createTableSql)
}finally {
connection.close()
log.info(s"ClickHouse table ${dbName}.${_tableName} created")
}
log.info("Creating ClickHouse sink")
new ClickHouseSink[T](dbName, _tableName, eventDateColumnName)(getConnectionString)(partitionFunc)
}
def getConnectionString(): (String, Int) = clickHouseServers.head
}