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

[Api-draft] Fix Spark Sink Can't support batch mode. #1868

Merged
merged 16 commits into from
May 13, 2022
Merged
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 @@ -17,18 +17,20 @@

package org.apache.seatunnel.api.serialization;

import org.apache.seatunnel.common.utils.SerializationUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.io.Serializable;

public class DefaultSerializer implements Serializer<String> {
public class DefaultSerializer<T extends Serializable> implements Serializer<T> {

@Override
public byte[] serialize(String obj) throws IOException {
return obj.getBytes(StandardCharsets.UTF_8);
public byte[] serialize(T obj) throws IOException {
return SerializationUtils.serialize(obj);
}

@Override
public String deserialize(byte[] serialized) throws IOException {
return new String(serialized);
public T deserialize(byte[] serialized) throws IOException {
return SerializationUtils.deserialize(serialized);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@ public static <T extends Serializable> T stringToObject(String str) {
}
return null;
}

public static <T extends Serializable> byte[] serialize(T obj) {
return org.apache.commons.lang3.SerializationUtils.serialize(obj);
}

public static <T extends Serializable> T deserialize(byte[] bytes) {
return org.apache.commons.lang3.SerializationUtils.deserialize(bytes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.seatunnel.api.sink.SeaTunnelSink;
import org.apache.seatunnel.common.utils.SerializationUtils;

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.DataFrameWriter;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.streaming.DataStreamWriter;
import org.apache.spark.sql.streaming.OutputMode;
Expand All @@ -31,9 +31,16 @@ public class SparkSinkInjector {

private static final String SPARK_SINK_CLASS_NAME = "org.apache.seatunnel.translation.spark.sink.SparkSink";

public static DataStreamWriter<Row> inject(Dataset<Row> dataset, SeaTunnelSink<?, ?, ?, ?> sink,
public static DataStreamWriter<Row> inject(DataStreamWriter<Row> dataset, SeaTunnelSink<?, ?, ?, ?> sink,
HashMap<String, String> configuration) {
return dataset.writeStream().format(SPARK_SINK_CLASS_NAME).outputMode(OutputMode.Append())
return dataset.format(SPARK_SINK_CLASS_NAME).outputMode(OutputMode.Append())
.option("configuration", SerializationUtils.objectToString(configuration)).option("sink",
SerializationUtils.objectToString(sink));
}

public static DataFrameWriter<Row> inject(DataFrameWriter<Row> dataset, SeaTunnelSink<?, ?, ?, ?> sink,
HashMap<String, String> configuration) {
return dataset.format(SPARK_SINK_CLASS_NAME)
.option("configuration", SerializationUtils.objectToString(configuration)).option("sink",
SerializationUtils.objectToString(sink));
}
Expand Down