This is an automated email from the ASF dual-hosted git repository.
tison pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new a22700df665 [fix][client] SchemaDefinition handle
JSR310_CONVERSION_ENABLED property (#20201)
a22700df665 is described below
commit a22700df665a9ea0a8db98334b6d4337e5e490f3
Author: tison <[email protected]>
AuthorDate: Mon May 1 16:47:36 2023 +0800
[fix][client] SchemaDefinition handle JSR310_CONVERSION_ENABLED property
(#20201)
Signed-off-by: tison <[email protected]>
---
.../impl/schema/SchemaDefinitionBuilderImpl.java | 2 +-
.../client/impl/schema/KeyValueSchemaTest.java | 34 ++++++++++++++++++++--
.../pulsar/functions/source/TopicSchema.java | 2 --
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/SchemaDefinitionBuilderImpl.java
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/SchemaDefinitionBuilderImpl.java
index c50aac5c398..93869a3bb9e 100644
---
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/SchemaDefinitionBuilderImpl.java
+++
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/SchemaDefinitionBuilderImpl.java
@@ -129,7 +129,7 @@ public class SchemaDefinitionBuilderImpl<T> implements
SchemaDefinitionBuilder<T
if (properties.containsKey(ALWAYS_ALLOW_NULL)) {
alwaysAllowNull =
Boolean.parseBoolean(properties.get(ALWAYS_ALLOW_NULL));
}
- if (properties.containsKey(ALWAYS_ALLOW_NULL)) {
+ if (properties.containsKey(JSR310_CONVERSION_ENABLED)) {
jsr310ConversionEnabled =
Boolean.parseBoolean(properties.get(JSR310_CONVERSION_ENABLED));
}
return this;
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 b40fa86e8bf..078c52c5f2e 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
@@ -69,7 +69,7 @@ public class KeyValueSchemaTest {
}
@Test
- public void testFillParametersToSchemainfo() {
+ public void testFillParametersToSchemaInfo() {
Map<String, String> keyProperties = new TreeMap<>();
keyProperties.put("foo.key1", "value");
keyProperties.put("foo.key2", "value");
@@ -89,7 +89,6 @@ public class KeyValueSchemaTest {
.build());
Schema<KeyValue<Foo, Bar>> keyValueSchema1 =
Schema.KeyValue(fooSchema, barSchema);
-
assertEquals(keyValueSchema1.getSchemaInfo().getProperties().get("key.schema.type"),
String.valueOf(SchemaType.AVRO));
assertEquals(keyValueSchema1.getSchemaInfo().getProperties().get("key.schema.properties"),
"{\"__alwaysAllowNull\":\"true\",\"__jsr310ConversionEnabled\":\"false\",\"foo.key1\":\"value\",\"foo.key2\":\"value\"}");
@@ -98,6 +97,37 @@ public class KeyValueSchemaTest {
"{\"__alwaysAllowNull\":\"true\",\"__jsr310ConversionEnabled\":\"false\",\"bar.key\":\"key\"}");
}
+ @Test
+ public void testOverwriteSchemaDefaultProperties() {
+ Map<String, String> keyProperties = new TreeMap<>();
+ keyProperties.put("foo.key1", "value");
+ keyProperties.put("foo.key2", "value");
+ keyProperties.put(SchemaDefinitionBuilderImpl.ALWAYS_ALLOW_NULL,
"false");
+
keyProperties.put(SchemaDefinitionBuilderImpl.JSR310_CONVERSION_ENABLED,
"true");
+
+ Map<String, String> valueProperties = new TreeMap<>();
+ valueProperties.put("bar.key", "key");
+
+ AvroSchema<Foo> fooSchema = AvroSchema.of(
+ SchemaDefinition.<Foo>builder()
+ .withPojo(Foo.class)
+ .withProperties(keyProperties)
+ .build());
+ AvroSchema<Bar> barSchema = AvroSchema.of(
+ SchemaDefinition.<Bar>builder()
+ .withPojo(Bar.class)
+ .withProperties(valueProperties)
+ .build());
+
+ Schema<KeyValue<Foo, Bar>> keyValueSchema1 =
Schema.KeyValue(fooSchema, barSchema);
+
assertEquals(keyValueSchema1.getSchemaInfo().getProperties().get("key.schema.type"),
String.valueOf(SchemaType.AVRO));
+
assertEquals(keyValueSchema1.getSchemaInfo().getProperties().get("key.schema.properties"),
+
"{\"__alwaysAllowNull\":\"false\",\"__jsr310ConversionEnabled\":\"true\",\"foo.key1\":\"value\",\"foo.key2\":\"value\"}");
+
assertEquals(keyValueSchema1.getSchemaInfo().getProperties().get("value.schema.type"),
String.valueOf(SchemaType.AVRO));
+
assertEquals(keyValueSchema1.getSchemaInfo().getProperties().get("value.schema.properties"),
+
"{\"__alwaysAllowNull\":\"true\",\"__jsr310ConversionEnabled\":\"false\",\"bar.key\":\"key\"}");
+ }
+
@Test
public void testNotAllowNullAvroSchemaCreate() {
AvroSchema<Foo> fooSchema =
AvroSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).withAlwaysAllowNull(false).build());
diff --git
a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/source/TopicSchema.java
b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/source/TopicSchema.java
index 57f49fed0ca..8ed177cba3b 100644
---
a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/source/TopicSchema.java
+++
b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/source/TopicSchema.java
@@ -44,8 +44,6 @@ import org.apache.pulsar.functions.instance.InstanceUtils;
@Slf4j
public class TopicSchema {
- public static final String JSR_310_CONVERSION_ENABLED =
"jsr310ConversionEnabled";
- public static final String ALWAYS_ALLOW_NULL = "alwaysAllowNull";
private final Map<String, Schema<?>> cachedSchemas = new HashMap<>();
private final PulsarClient client;