sijie commented on a change in pull request #4211:
[issue#4155][pulsar-clients]Support key value schema versioning
URL: https://github.com/apache/pulsar/pull/4211#discussion_r281064238
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/KeyValueSchema.java
##########
@@ -154,14 +205,52 @@ private KeyValueSchema(Schema<K> keySchema,
byte[] valueBytes = new byte[valueLength];
byteBuffer.get(valueBytes);
- return decode(keyBytes, valueBytes);
+ return decode(keyBytes, valueBytes, schemaVersion);
}
- public KeyValue<K, V> decode(byte[] keyBytes, byte[] valueBytes) {
- return new KeyValue<>(keySchema.decode(keyBytes),
valueSchema.decode(valueBytes));
+ public KeyValue<K, V> decode(byte[] keyBytes, byte[] valueBytes, byte[]
schemaVersion) {
+ K k;
+ if (keySchema.supportSchemaVersioning() && schemaVersion != null) {
+ k = keySchema.decode(keyBytes, schemaVersion);
+ } else {
+ k = keySchema.decode(keyBytes);
+ }
+ V v;
+ if (valueSchema.supportSchemaVersioning() && schemaVersion != null) {
+ v = valueSchema.decode(valueBytes, schemaVersion);
+ } else {
+ v = valueSchema.decode(valueBytes);
+ }
+ return new KeyValue<>(k, v);
}
public SchemaInfo getSchemaInfo() {
return this.schemaInfo;
}
+
+ public void setSchemaInfoProvider(SchemaInfoProvider schemaInfoProvider) {
+ this.schemaInfoProvider = schemaInfoProvider;
+ }
+
+ private Map<String, SchemaInfo> decodeKeyValueSchemaInfo(SchemaInfo
schemaInfo) {
Review comment:
why not just use `Pair<SchemaInfo, SchemaInfo>` or `KeyValue<SchemaInfo,
SchemaInfo>`? hen you can use getKey or getValue. It would be much clearer than
using a map.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services