nicoloboschi commented on code in PR #15845:
URL: https://github.com/apache/pulsar/pull/15845#discussion_r885399546
##########
pulsar-io/jdbc/core/src/main/java/org/apache/pulsar/io/jdbc/BaseJdbcAutoSchemaSink.java:
##########
@@ -185,5 +187,36 @@ private void
fillKeyValueSchemaData(org.apache.pulsar.client.api.Schema<GenericO
+ " with KeyValueSchema");
}
}
+
+ private static Object convertAvroField(Object avroValue, Schema schema) {
+ switch (schema.getType()) {
+ case NULL:
+ case INT:
+ case LONG:
+ case DOUBLE:
+ case FLOAT:
+ case BOOLEAN:
+ return avroValue;
+ case ENUM:
+ case STRING:
+ return avroValue.toString(); // can be a String or
org.apache.avro.util.Utf8
+ case UNION:
+ for (Schema s : schema.getTypes()) {
+ if (s.getType() == Schema.Type.NULL) {
+ continue;
+ }
+ return convertAvroField(avroValue, s);
+ }
+ throw new IllegalArgumentException("Found UNION schema but it
doesn't contain any type");
+ case ARRAY:
+ case BYTES:
+ case FIXED:
+ case RECORD:
+ case MAP:
Review Comment:
I added test coverage for the avro conversion, PTAL again @shibd
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]