Skip to content

Commit b64a11b

Browse files
committed
Support dotted field names in avro
KAFKA-137
1 parent 1a52acd commit b64a11b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/main/java/com/mongodb/kafka/connect/source/schema/AvroSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static Schema fromJson(final String jsonSchema) {
113113

114114
static org.apache.avro.Schema parseSchema(final String jsonSchema) {
115115
try {
116-
return new Parser().parse(jsonSchema);
116+
return new Parser().setValidate(false).parse(jsonSchema);
117117
} catch (Exception e) {
118118
throw new ConnectException(format("Invalid Avro schema. %s\n%s", e.getMessage(), jsonSchema));
119119
}

src/test/java/com/mongodb/kafka/connect/source/schema/AvroSchemaTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,27 @@ void testUnsupportedAvroSchema() {
198198
});
199199
}
200200

201+
@Test
202+
@DisplayName("test nested field support")
203+
void testNestedFieldSupport() {
204+
Schema actual =
205+
AvroSchema.fromJson(
206+
"{\n"
207+
+ " \"type\": \"record\",\n"
208+
+ " \"name\": \"keySchema\",\n"
209+
+ " \"fields\" : [{\"name\": \"fullDocument.documentKey\", \"type\": \"string\", \"default\": \"MISSING\"}]\n"
210+
+ "}");
211+
212+
Schema expected =
213+
SchemaBuilder.struct()
214+
.name("keySchema")
215+
.field(
216+
"fullDocument.documentKey", SchemaBuilder.string().defaultValue("MISSING").build())
217+
.build();
218+
219+
SchemaUtils.assertSchemaEquals(expected, actual);
220+
}
221+
201222
@Test
202223
@DisplayName("test invalid avro schema definitions")
203224
void testInvalidAvroSchema() {

0 commit comments

Comments
 (0)