Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-20378][CORE][SQL][SS] StreamSinkProvider should provide schema in createSink #17689

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private[kafka010] class KafkaSourceProvider extends DataSourceRegister
}

override def createSink(
schema: StructType,
sqlContext: SQLContext,
parameters: Map[String, String],
partitionColumns: Seq[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@ case class DataSource(
}

/** Returns a sink that can be used to continually write data. */
def createSink(outputMode: OutputMode): Sink = {
def createSink(schema: StructType, outputMode: OutputMode): Sink = {
providingClass.newInstance() match {
case s: StreamSinkProvider =>
s.createSink(sparkSession.sqlContext, caseInsensitiveOptions, partitionColumns, outputMode)
s.createSink(schema, sparkSession.sqlContext,
caseInsensitiveOptions, partitionColumns, outputMode)

case fileFormat: FileFormat =>
val path = caseInsensitiveOptions.getOrElse("path", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.apache.spark.internal.Logging
import org.apache.spark.sql.{DataFrame, SQLContext}
import org.apache.spark.sql.sources.{DataSourceRegister, StreamSinkProvider}
import org.apache.spark.sql.streaming.OutputMode
import org.apache.spark.sql.types.StructType

class ConsoleSink(options: Map[String, String]) extends Sink with Logging {
// Number of rows to display, by default 20 rows
Expand Down Expand Up @@ -53,6 +54,7 @@ class ConsoleSink(options: Map[String, String]) extends Sink with Logging {

class ConsoleSinkProvider extends StreamSinkProvider with DataSourceRegister {
def createSink(
schema: StructType,
sqlContext: SQLContext,
parameters: Map[String, String],
partitionColumns: Seq[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ trait StreamSourceProvider {
@InterfaceStability.Unstable
trait StreamSinkProvider {
def createSink(
schema: StructType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface can't just be changed like this. This breaks backwards compatibility ...

sqlContext: SQLContext,
parameters: Map[String, String],
partitionColumns: Seq[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ final class DataStreamWriter[T] private[sql](ds: Dataset[T]) {
extraOptions.get("queryName"),
extraOptions.get("checkpointLocation"),
df,
dataSource.createSink(outputMode),
dataSource.createSink(df.schema, outputMode),
outputMode,
useTempCheckpointLocation = useTempCheckpointLocation,
recoverFromCheckpointLocation = recoverFromCheckpointLocation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class DefaultSource extends StreamSourceProvider with StreamSinkProvider {
}

override def createSink(
schema: StructType,
spark: SQLContext,
parameters: Map[String, String],
partitionColumns: Seq[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class BlockingSource extends StreamSourceProvider with StreamSinkProvider {
}

override def createSink(
schema: StructType,
spark: SQLContext,
parameters: Map[String, String],
partitionColumns: Seq[String],
Expand Down