Skip to content

Commit

Permalink
Fix AutoConsumeSchema KeyValue encoding (apache#10089)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
Vincent Royer authored Apr 1, 2021
1 parent 4128151 commit 6717974
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ public static Schema<?> getSchema(SchemaInfo schemaInfo) {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,13 @@ public void testNotAllowNullBytesSchemaEncodeAndDecode() {
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());
}
}

0 comments on commit 6717974

Please sign in to comment.