Skip to content
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 @@ -26,7 +26,6 @@
import co.cask.cdap.api.data.format.StructuredRecord;
import co.cask.cdap.api.data.schema.Schema;
import co.cask.cdap.api.dataset.lib.KeyValue;
import co.cask.cdap.api.flow.flowlet.StreamEvent;
import co.cask.cdap.common.io.ByteBuffers;
import co.cask.cdap.etl.api.Emitter;
import co.cask.cdap.etl.api.PipelineConfigurer;
Expand All @@ -50,6 +49,7 @@

import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -68,7 +68,7 @@ public class KafkaBatchSource extends BatchSource<KafkaKey, KafkaMessage, Struct
private final Kafka10BatchConfig config;
private List<KafkaRequest> kafkaRequests;
private Schema schema;
private RecordFormat<StreamEvent, StructuredRecord> recordFormat;
private RecordFormat<ByteBuffer, StructuredRecord> recordFormat;
private String messageField;
private FileContext fileContext;
private Path offsetsFile;
Expand Down Expand Up @@ -231,7 +231,7 @@ public void transform(KeyValue<KafkaKey, KafkaMessage> input, Emitter<Structured
if (config.getFormat() == null) {
builder.set(messageField, ByteBuffers.getByteArray(input.getValue().getPayload()));
} else {
StructuredRecord messageRecord = recordFormat.read(new StreamEvent(input.getValue().getPayload()));
StructuredRecord messageRecord = recordFormat.read(input.getValue().getPayload());
for (Schema.Field field : messageRecord.getSchema().getFields()) {
String fieldName = field.getName();
builder.set(fieldName, messageRecord.get(fieldName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import co.cask.cdap.api.data.format.RecordFormat;
import co.cask.cdap.api.data.format.StructuredRecord;
import co.cask.cdap.api.data.schema.Schema;
import co.cask.cdap.api.flow.flowlet.StreamEvent;
import co.cask.cdap.etl.api.PipelineConfigurer;
import co.cask.cdap.etl.api.streaming.StreamingContext;
import co.cask.cdap.etl.api.streaming.StreamingSource;
Expand Down Expand Up @@ -271,7 +270,7 @@ protected void addMessage(StructuredRecord.Builder builder, String messageField,
* Everything here should be serializable, as Spark Streaming will serialize all functions.
*/
private static class FormatFunction extends BaseFunction {
private transient RecordFormat<StreamEvent, StructuredRecord> recordFormat;
private transient RecordFormat<ByteBuffer, StructuredRecord> recordFormat;

FormatFunction(long ts, KafkaConfig conf) {
super(ts, conf);
Expand All @@ -283,11 +282,11 @@ protected void addMessage(StructuredRecord.Builder builder, String messageField,
if (recordFormat == null) {
Schema messageSchema = conf.getMessageSchema();
FormatSpecification spec =
new FormatSpecification(conf.getFormat(), messageSchema, new HashMap<String, String>());
new FormatSpecification(conf.getFormat(), messageSchema, new HashMap<>());
recordFormat = RecordFormats.createInitializedFormat(spec);
}

StructuredRecord messageRecord = recordFormat.read(new StreamEvent(ByteBuffer.wrap(message)));
StructuredRecord messageRecord = recordFormat.read(ByteBuffer.wrap(message));
for (Schema.Field field : messageRecord.getSchema().getFields()) {
String fieldName = field.getName();
builder.set(fieldName, messageRecord.get(fieldName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import co.cask.cdap.api.data.format.StructuredRecord;
import co.cask.cdap.api.data.schema.Schema;
import co.cask.cdap.api.dataset.lib.KeyValue;
import co.cask.cdap.api.flow.flowlet.StreamEvent;
import co.cask.cdap.common.io.ByteBuffers;
import co.cask.cdap.etl.api.Emitter;
import co.cask.cdap.etl.api.PipelineConfigurer;
Expand All @@ -45,6 +44,7 @@

import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -64,7 +64,7 @@ public class KafkaBatchSource extends BatchSource<KafkaKey, KafkaMessage, Struct
private Path offsetsFile;
private List<KafkaRequest> kafkaRequests;
private Schema schema;
private RecordFormat<StreamEvent, StructuredRecord> recordFormat;
private RecordFormat<ByteBuffer, StructuredRecord> recordFormat;
private String messageField;

public KafkaBatchSource(KafkaBatchConfig config) {
Expand Down Expand Up @@ -164,7 +164,7 @@ public void transform(KeyValue<KafkaKey, KafkaMessage> input, Emitter<Structured
if (config.getFormat() == null) {
builder.set(messageField, ByteBuffers.getByteArray(input.getValue().getPayload()));
} else {
StructuredRecord messageRecord = recordFormat.read(new StreamEvent(input.getValue().getPayload()));
StructuredRecord messageRecord = recordFormat.read(input.getValue().getPayload());
for (Schema.Field field : messageRecord.getSchema().getFields()) {
String fieldName = field.getName();
builder.set(fieldName, messageRecord.get(fieldName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import co.cask.cdap.api.data.format.RecordFormat;
import co.cask.cdap.api.data.format.StructuredRecord;
import co.cask.cdap.api.data.schema.Schema;
import co.cask.cdap.api.flow.flowlet.StreamEvent;
import co.cask.cdap.etl.api.PipelineConfigurer;
import co.cask.cdap.etl.api.streaming.StreamingContext;
import co.cask.cdap.etl.api.streaming.StreamingSource;
Expand Down Expand Up @@ -271,7 +270,7 @@ protected void addMessage(StructuredRecord.Builder builder, String messageField,
* Everything here should be serializable, as Spark Streaming will serialize all functions.
*/
private static class FormatFunction extends BaseFunction {
private transient RecordFormat<StreamEvent, StructuredRecord> recordFormat;
private transient RecordFormat<ByteBuffer, StructuredRecord> recordFormat;

FormatFunction(long ts, KafkaConfig conf) {
super(ts, conf);
Expand All @@ -283,11 +282,11 @@ protected void addMessage(StructuredRecord.Builder builder, String messageField,
if (recordFormat == null) {
Schema messageSchema = conf.getMessageSchema();
FormatSpecification spec =
new FormatSpecification(conf.getFormat(), messageSchema, new HashMap<String, String>());
new FormatSpecification(conf.getFormat(), messageSchema, new HashMap<>());
recordFormat = RecordFormats.createInitializedFormat(spec);
}

StructuredRecord messageRecord = recordFormat.read(new StreamEvent(ByteBuffer.wrap(message)));
StructuredRecord messageRecord = recordFormat.read(ByteBuffer.wrap(message));
for (Schema.Field field : messageRecord.getSchema().getFields()) {
String fieldName = field.getName();
builder.set(fieldName, messageRecord.get(fieldName));
Expand Down