Skip to content

Commit aa2ba2e

Browse files
committed
Merge branch '4.1.x' into 5.0.x
2 parents c36922b + c9b1132 commit aa2ba2e

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
@@ -201,10 +201,12 @@ private static JsonNode inferPrimitive(String type, Object defaultValue) {
201201
break;
202202
case ElasticsearchSinkConnectorConstants.STRING_TYPE:
203203
case ElasticsearchSinkConnectorConstants.TEXT_TYPE:
204-
defaultValueNode = JsonNodeFactory.instance.textNode((String) defaultValue);
205-
break;
206204
case ElasticsearchSinkConnectorConstants.BINARY_TYPE:
207-
defaultValueNode = JsonNodeFactory.instance.binaryNode(bytes(defaultValue));
205+
// IGNORE default values for text and binary types as this is not supported by ES side.
206+
// see https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html
207+
// https://www.elastic.co/guide/en/elasticsearch/reference/current/binary.html
208+
// for more details.
209+
//defaultValueNode = null;
208210
break;
209211
case ElasticsearchSinkConnectorConstants.BOOLEAN_TYPE:
210212
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
@@ -19,6 +19,7 @@
1919
import com.fasterxml.jackson.databind.node.NumericNode;
2020
import com.fasterxml.jackson.databind.node.ObjectNode;
2121
import com.fasterxml.jackson.databind.node.TextNode;
22+
import com.fasterxml.jackson.databind.JsonNode;
2223
import com.google.gson.JsonObject;
2324

2425
import org.apache.kafka.connect.data.Date;
@@ -35,7 +36,6 @@
3536
import static io.confluent.connect.elasticsearch.DataConverter.BehaviorOnNullValues;
3637
import static io.confluent.connect.elasticsearch.ElasticsearchSinkConnectorConstants.KEYWORD_TYPE;
3738
import static io.confluent.connect.elasticsearch.ElasticsearchSinkConnectorConstants.TEXT_TYPE;
38-
import static org.junit.Assert.assertEquals;
3939
import static org.mockito.Mockito.mock;
4040
import static org.mockito.Mockito.when;
4141

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

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

0 commit comments

Comments
 (0)