|
16 | 16 |
|
17 | 17 | package io.confluent.connect.elasticsearch; |
18 | 18 |
|
| 19 | +import com.fasterxml.jackson.databind.JsonNode; |
19 | 20 | import com.google.gson.JsonObject; |
20 | 21 |
|
21 | 22 | import org.apache.kafka.connect.data.Date; |
@@ -51,6 +52,29 @@ public void testMapping() throws Exception { |
51 | 52 | verifyMapping(schema, mapping); |
52 | 53 | } |
53 | 54 |
|
| 55 | + @Test |
| 56 | + public void testInferMapping() throws Exception { |
| 57 | + |
| 58 | + Schema stringSchema = SchemaBuilder |
| 59 | + .struct() |
| 60 | + .name("record") |
| 61 | + .field("foo", SchemaBuilder.string().defaultValue("0").build()) |
| 62 | + .build(); |
| 63 | + JsonNode stringMapping = Mapping.inferMapping(client, stringSchema); |
| 64 | + |
| 65 | + assertNull(stringMapping.get("properties").get("foo").get("null_value")); |
| 66 | + |
| 67 | + Schema intSchema =SchemaBuilder |
| 68 | + .struct() |
| 69 | + .name("record") |
| 70 | + .field("foo", SchemaBuilder.int32().defaultValue(0).build()) |
| 71 | + .build(); |
| 72 | + |
| 73 | + JsonNode intMapping = Mapping.inferMapping(client, intSchema); |
| 74 | + assertNotNull(intMapping.get("properties").get("foo").get("null_value")); |
| 75 | + assertEquals(0, intMapping.get("properties").get("foo").get("null_value").asInt()); |
| 76 | + } |
| 77 | + |
54 | 78 | protected Schema createSchema() { |
55 | 79 | Schema structSchema = createInnerSchema(); |
56 | 80 | return SchemaBuilder.struct().name("record") |
@@ -96,7 +120,6 @@ private Schema createInnerSchema() { |
96 | 120 | @SuppressWarnings("unchecked") |
97 | 121 | private void verifyMapping(Schema schema, JsonObject mapping) throws Exception { |
98 | 122 | String schemaName = schema.name(); |
99 | | - |
100 | 123 | Object type = mapping.get("type"); |
101 | 124 | if (schemaName != null) { |
102 | 125 | switch (schemaName) { |
|
0 commit comments