diff --git a/protobuf-converter/src/main/java/io/confluent/connect/protobuf/ProtobufData.java b/protobuf-converter/src/main/java/io/confluent/connect/protobuf/ProtobufData.java index c54f5f13518..d98b7485acc 100644 --- a/protobuf-converter/src/main/java/io/confluent/connect/protobuf/ProtobufData.java +++ b/protobuf-converter/src/main/java/io/confluent/connect/protobuf/ProtobufData.java @@ -1062,7 +1062,8 @@ private static boolean isMapDescriptor( private SchemaBuilder toMapSchema(ToConnectContext ctx, Descriptor descriptor) { List fieldDescriptors = descriptor.getFields(); - String name = ProtobufSchema.toMapField(descriptor.getName()); + String name = ProtobufSchema.toMapField( + enhancedSchemaSupport ? descriptor.getFullName() : descriptor.getName()); return SchemaBuilder.map(toConnectSchema(ctx, fieldDescriptors.get(0)), toConnectSchema(ctx, fieldDescriptors.get(1)) ).name(name); diff --git a/protobuf-converter/src/test/java/io/confluent/connect/protobuf/ProtobufDataTest.java b/protobuf-converter/src/test/java/io/confluent/connect/protobuf/ProtobufDataTest.java index 02c13fe9b94..303a26a4b24 100644 --- a/protobuf-converter/src/test/java/io/confluent/connect/protobuf/ProtobufDataTest.java +++ b/protobuf-converter/src/test/java/io/confluent/connect/protobuf/ProtobufDataTest.java @@ -1273,6 +1273,36 @@ public void testToConnectFullyQualifiedSchema() { assertEquals("foo.Event.Action", actual.field("action").schema().name()); } + @Test + public void testToConnectFullyQualifiedMapSchema() { + String schema = "syntax = \"proto3\";\n" + + "\n" + + "option java_package = \"io.confluent.connect.protobuf.test\";\n" + + "\n" + + "message Customer {\n" + + " map tags = 1;\n" + + " Meta meta = 2;\n" + + "}\n" + + "\n" + + "message Meta {\n" + + " map tags = 2;\n" + + "}\n" + + "\n" + + "message Value{\n" + + " float a=1;\n" + + " float b=2;\n" + + "}\n"; + + ProtobufSchema protobufSchema = new ProtobufSchema(schema); + Map configs = new HashMap<>(); + configs.put(ProtobufDataConfig.ENHANCED_PROTOBUF_SCHEMA_SUPPORT_CONFIG, true); + ProtobufData protobufData = new ProtobufData(new ProtobufDataConfig(configs)); + Schema actual = protobufData.toConnectSchema(protobufSchema); + assertEquals("Customer.tags", + actual.field("tags").schema().name()); + assertEquals("Meta.tags", actual.field("meta").schema().field("tags").schema().name()); + } + @Test public void testToConnectMultipleMapReferences() throws Exception { AttributeFieldEntry entry1 = AttributeFieldEntry.newBuilder() diff --git a/protobuf-provider/src/main/java/io/confluent/kafka/schemaregistry/protobuf/ProtobufSchema.java b/protobuf-provider/src/main/java/io/confluent/kafka/schemaregistry/protobuf/ProtobufSchema.java index c431cef2d78..85a4277d714 100644 --- a/protobuf-provider/src/main/java/io/confluent/kafka/schemaregistry/protobuf/ProtobufSchema.java +++ b/protobuf-provider/src/main/java/io/confluent/kafka/schemaregistry/protobuf/ProtobufSchema.java @@ -954,10 +954,13 @@ public static String toMapEntry(String s) { } public static String toMapField(String s) { - if (s.endsWith(MAP_ENTRY_SUFFIX)) { - s = s.substring(0, s.length() - MAP_ENTRY_SUFFIX.length()); - s = UPPER_CAMEL.to(LOWER_UNDERSCORE, s); - } - return s; + String[] parts = s.split("\\."); + String lastPart = parts[parts.length - 1]; + if (lastPart.endsWith(MAP_ENTRY_SUFFIX)) { + lastPart = lastPart.substring(0, lastPart.length() - MAP_ENTRY_SUFFIX.length()); + lastPart = UPPER_CAMEL.to(LOWER_UNDERSCORE, lastPart); + parts[parts.length - 1] = lastPart; + } + return String.join(".", parts); } }