-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[WIP] Fix KafkaAvroSource to use the latest schema #765
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package com.uber.hoodie.utilities.sources; | ||
|
|
||
| import com.uber.hoodie.common.util.TypedProperties; | ||
| import com.uber.hoodie.utilities.UtilHelpers; | ||
| import com.uber.hoodie.utilities.schema.SchemaProvider; | ||
| import io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer; | ||
| import io.confluent.kafka.serializers.KafkaAvroDeserializerConfig; | ||
| import java.io.IOException; | ||
| import java.util.Map.Entry; | ||
| import java.util.Objects; | ||
| import java.util.Properties; | ||
| import kafka.serializer.Decoder; | ||
| import kafka.utils.VerifiableProperties; | ||
| import org.apache.avro.Schema; | ||
| import org.apache.kafka.common.errors.SerializationException; | ||
|
|
||
| /** A Kafka decoder that uses the source schema for read. */ | ||
| public class SourceSchemaKafkaAvroDecoder extends AbstractKafkaAvroDeserializer | ||
| implements Decoder<Object> { | ||
|
|
||
| private static final String SCHEMA_PROVIDER_CLASS_PROP = "hoodie.deltastreamer.schemaprovider.class"; | ||
|
|
||
| private final Schema sourceSchema; | ||
|
|
||
| public SourceSchemaKafkaAvroDecoder(VerifiableProperties props) { | ||
| this.configure(new KafkaAvroDeserializerConfig(props.props())); | ||
|
|
||
| TypedProperties typedProperties = new TypedProperties(); | ||
| copyProperties(typedProperties, props.props()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we do away with this function? |
||
|
|
||
| try { | ||
| SchemaProvider schemaProvider = | ||
| UtilHelpers.createSchemaProvider( | ||
| props.getString(SCHEMA_PROVIDER_CLASS_PROP), typedProperties); | ||
| sourceSchema = Objects.requireNonNull(schemaProvider).getSourceSchema(); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Object fromBytes(byte[] bytes) { | ||
| return deserialize(bytes); | ||
| } | ||
|
|
||
| @Override | ||
| protected Object deserialize( | ||
| boolean includeSchemaAndVersion, | ||
| String topic, | ||
| Boolean isKey, | ||
| byte[] payload, | ||
| Schema readerSchema) | ||
| throws SerializationException { | ||
| if (readerSchema != null) { | ||
| return super.deserialize(includeSchemaAndVersion, topic, isKey, payload, readerSchema); | ||
| } | ||
|
|
||
| return super.deserialize(includeSchemaAndVersion, topic, isKey, payload, sourceSchema); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @haiminh87 I was thinking if we could make this configurable in sense that have a boolean like readUsingLatestSchema with a default value of true and can be overridden via TypedProperties instance. |
||
| } | ||
|
|
||
| private static void copyProperties(TypedProperties typedProperties, Properties properties) { | ||
| for (Entry<Object, Object> entry : properties.entrySet()) { | ||
| typedProperties.put(entry.getKey(), entry.getValue()); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason why you are using VerifiableProperties here and not TypedProperties?