This is an automated email from the ASF dual-hosted git repository. yong pushed a commit to branch branch-2.7 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit bb410225394a3b0a9a1e87ece8d9845ce8b3a66e Author: Vincent Royer <[email protected]> AuthorDate: Thu Apr 1 20:38:27 2021 +0200 Fix AutoConsumeSchema KeyValue encoding (#10089) ### Motivation Keep the KeyValueEncodingType when auto-consuming a KeyValue schema. ### Modifications see the single commit. ### Verifying this change Add a unit test org.apache.pulsar.client.impl.schema.KeyValueSchemaTest.testKeyValueSchemaSeparatedEncoding checking that the encoding type is preserved. (cherry picked from commit 6717974eda5192666c7769efc87c80ecff381ce1) --- .../org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java | 3 ++- .../org/apache/pulsar/client/impl/schema/KeyValueSchemaTest.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java index 442ede1..405b9cc 100644 --- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java +++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java @@ -209,7 +209,8 @@ public class AutoConsumeSchema implements Schema<GenericRecord> { KeyValueSchemaInfo.decodeKeyValueSchemaInfo(schemaInfo); Schema<?> keySchema = getSchema(kvSchemaInfo.getKey()); Schema<?> valueSchema = getSchema(kvSchemaInfo.getValue()); - return KeyValueSchema.of(keySchema, valueSchema); + return KeyValueSchema.of(keySchema, valueSchema, + KeyValueSchemaInfo.decodeKeyValueEncodingType(schemaInfo)); default: throw new IllegalArgumentException("Retrieve schema instance from schema info for type '" + schemaInfo.getType() + "' is not supported yet"); diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaTest.java b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaTest.java index 9c903fa..4692290 100644 --- a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaTest.java +++ b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaTest.java @@ -388,4 +388,13 @@ public class KeyValueSchemaTest { assertEquals(foo, fooBack); assertEquals(bar, barBack); } + + @Test + public void testKeyValueSchemaSeparatedEncoding() { + KeyValueSchema<String, String> keyValueSchema = (KeyValueSchema<String,String>) + KeyValueSchema.of(Schema.STRING, Schema.STRING, KeyValueEncodingType.SEPARATED); + KeyValueSchema<String, String> keyValueSchema2 = (KeyValueSchema<String,String>) + AutoConsumeSchema.getSchema(keyValueSchema.getSchemaInfo()); + assertEquals(keyValueSchema.getKeyValueEncodingType(), keyValueSchema2.getKeyValueEncodingType()); + } }
