use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class FlattenTest method testNestedStruct.
@Test
public void testNestedStruct() {
xformValue.configure(Collections.<String, String>emptyMap());
SchemaBuilder builder = SchemaBuilder.struct();
builder.field("int8", Schema.INT8_SCHEMA);
builder.field("int16", Schema.INT16_SCHEMA);
builder.field("int32", Schema.INT32_SCHEMA);
builder.field("int64", Schema.INT64_SCHEMA);
builder.field("float32", Schema.FLOAT32_SCHEMA);
builder.field("float64", Schema.FLOAT64_SCHEMA);
builder.field("boolean", Schema.BOOLEAN_SCHEMA);
builder.field("string", Schema.STRING_SCHEMA);
builder.field("bytes", Schema.BYTES_SCHEMA);
Schema supportedTypesSchema = builder.build();
builder = SchemaBuilder.struct();
builder.field("B", supportedTypesSchema);
Schema oneLevelNestedSchema = builder.build();
builder = SchemaBuilder.struct();
builder.field("A", oneLevelNestedSchema);
Schema twoLevelNestedSchema = builder.build();
Struct supportedTypes = new Struct(supportedTypesSchema);
supportedTypes.put("int8", (byte) 8);
supportedTypes.put("int16", (short) 16);
supportedTypes.put("int32", 32);
supportedTypes.put("int64", (long) 64);
supportedTypes.put("float32", 32.f);
supportedTypes.put("float64", 64.);
supportedTypes.put("boolean", true);
supportedTypes.put("string", "stringy");
supportedTypes.put("bytes", "bytes".getBytes());
Struct oneLevelNestedStruct = new Struct(oneLevelNestedSchema);
oneLevelNestedStruct.put("B", supportedTypes);
Struct twoLevelNestedStruct = new Struct(twoLevelNestedSchema);
twoLevelNestedStruct.put("A", oneLevelNestedStruct);
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, twoLevelNestedSchema, twoLevelNestedStruct));
assertEquals(Schema.Type.STRUCT, transformed.valueSchema().type());
Struct transformedStruct = (Struct) transformed.value();
assertEquals(9, transformedStruct.schema().fields().size());
assertEquals(8, (byte) transformedStruct.getInt8("A.B.int8"));
assertEquals(16, (short) transformedStruct.getInt16("A.B.int16"));
assertEquals(32, (int) transformedStruct.getInt32("A.B.int32"));
assertEquals(64L, (long) transformedStruct.getInt64("A.B.int64"));
assertEquals(32.f, transformedStruct.getFloat32("A.B.float32"), 0.f);
assertEquals(64., transformedStruct.getFloat64("A.B.float64"), 0.);
assertEquals(true, transformedStruct.getBoolean("A.B.boolean"));
assertEquals("stringy", transformedStruct.getString("A.B.string"));
assertArrayEquals("bytes".getBytes(), transformedStruct.getBytes("A.B.bytes"));
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class FlattenTest method testOptionalFieldStruct.
@Test
public void testOptionalFieldStruct() {
xformValue.configure(Collections.<String, String>emptyMap());
SchemaBuilder builder = SchemaBuilder.struct();
builder.field("opt_int32", Schema.OPTIONAL_INT32_SCHEMA);
Schema supportedTypesSchema = builder.build();
builder = SchemaBuilder.struct();
builder.field("B", supportedTypesSchema);
Schema oneLevelNestedSchema = builder.build();
Struct supportedTypes = new Struct(supportedTypesSchema);
supportedTypes.put("opt_int32", null);
Struct oneLevelNestedStruct = new Struct(oneLevelNestedSchema);
oneLevelNestedStruct.put("B", supportedTypes);
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, oneLevelNestedSchema, oneLevelNestedStruct));
assertEquals(Schema.Type.STRUCT, transformed.valueSchema().type());
Struct transformedStruct = (Struct) transformed.value();
assertNull(transformedStruct.get("B.opt_int32"));
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class FlattenTest method testUnsupportedTypeInMap.
@Test(expected = DataException.class)
public void testUnsupportedTypeInMap() {
xformValue.configure(Collections.<String, String>emptyMap());
Object value = Collections.singletonMap("foo", Arrays.asList("bar", "baz"));
xformValue.apply(new SourceRecord(null, null, "topic", 0, null, value));
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class InsertFieldTest method topLevelStructRequired.
@Test(expected = DataException.class)
public void topLevelStructRequired() {
xform.configure(Collections.singletonMap("topic.field", "topic_field"));
xform.apply(new SourceRecord(null, null, "", 0, Schema.INT32_SCHEMA, 42));
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class TimestampConverterTest method testWithSchemaTimeToTimestamp.
@Test
public void testWithSchemaTimeToTimestamp() {
xformValue.configure(Collections.singletonMap(TimestampConverter.TARGET_TYPE_CONFIG, "Timestamp"));
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, Time.SCHEMA, TIME.getTime()));
assertEquals(Timestamp.SCHEMA, transformed.valueSchema());
// No change expected since the source type is coarser-grained
assertEquals(TIME.getTime(), transformed.value());
}
Aggregations