Skip to content

Commit 9acb27f

Browse files
committed
Merge branch '5.0.x' into 5.1.x
2 parents 46c4863 + aa2ba2e commit 9acb27f

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/main/java/io/confluent/connect/elasticsearch/Mapping.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,12 @@ private static JsonNode inferPrimitive(String type, Object defaultValue) {
200200
break;
201201
case ElasticsearchSinkConnectorConstants.STRING_TYPE:
202202
case ElasticsearchSinkConnectorConstants.TEXT_TYPE:
203-
defaultValueNode = JsonNodeFactory.instance.textNode((String) defaultValue);
204-
break;
205203
case ElasticsearchSinkConnectorConstants.BINARY_TYPE:
206-
defaultValueNode = JsonNodeFactory.instance.binaryNode(bytes(defaultValue));
204+
// IGNORE default values for text and binary types as this is not supported by ES side.
205+
// see https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html
206+
// https://www.elastic.co/guide/en/elasticsearch/reference/current/binary.html
207+
// for more details.
208+
//defaultValueNode = null;
207209
break;
208210
case ElasticsearchSinkConnectorConstants.BOOLEAN_TYPE:
209211
defaultValueNode = JsonNodeFactory.instance.booleanNode((boolean) defaultValue);

src/test/java/io/confluent/connect/elasticsearch/MappingTest.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.fasterxml.jackson.databind.node.NumericNode;
1919
import com.fasterxml.jackson.databind.node.ObjectNode;
2020
import com.fasterxml.jackson.databind.node.TextNode;
21+
import com.fasterxml.jackson.databind.JsonNode;
2122
import com.google.gson.JsonObject;
2223

2324
import org.apache.kafka.connect.data.Date;
@@ -34,7 +35,6 @@
3435
import static io.confluent.connect.elasticsearch.DataConverter.BehaviorOnNullValues;
3536
import static io.confluent.connect.elasticsearch.ElasticsearchSinkConnectorConstants.KEYWORD_TYPE;
3637
import static io.confluent.connect.elasticsearch.ElasticsearchSinkConnectorConstants.TEXT_TYPE;
37-
import static org.junit.Assert.assertEquals;
3838
import static org.mockito.Mockito.mock;
3939
import static org.mockito.Mockito.when;
4040

@@ -81,6 +81,29 @@ public void testStringMappingForES6() throws Exception {
8181
assertEquals(256, ignoreAbove.asInt());
8282
}
8383

84+
@Test
85+
public void testInferMapping() throws Exception {
86+
87+
Schema stringSchema = SchemaBuilder
88+
.struct()
89+
.name("record")
90+
.field("foo", SchemaBuilder.string().defaultValue("0").build())
91+
.build();
92+
JsonNode stringMapping = Mapping.inferMapping(client, stringSchema);
93+
94+
assertNull(stringMapping.get("properties").get("foo").get("null_value"));
95+
96+
Schema intSchema =SchemaBuilder
97+
.struct()
98+
.name("record")
99+
.field("foo", SchemaBuilder.int32().defaultValue(0).build())
100+
.build();
101+
102+
JsonNode intMapping = Mapping.inferMapping(client, intSchema);
103+
assertNotNull(intMapping.get("properties").get("foo").get("null_value"));
104+
assertEquals(0, intMapping.get("properties").get("foo").get("null_value").asInt());
105+
}
106+
84107
protected Schema createSchema() {
85108
Schema structSchema = createInnerSchema();
86109
return SchemaBuilder.struct().name("record")
@@ -126,7 +149,6 @@ private Schema createInnerSchema() {
126149
@SuppressWarnings("unchecked")
127150
private void verifyMapping(Schema schema, JsonObject mapping) throws Exception {
128151
String schemaName = schema.name();
129-
130152
Object type = mapping.get("type");
131153
if (schemaName != null) {
132154
switch (schemaName) {

0 commit comments

Comments
 (0)