use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class CastTest method castWholeRecordValueSchemalessBooleanFalse.
@Test
public void castWholeRecordValueSchemalessBooleanFalse() {
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "boolean"));
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, null, 0));
assertNull(transformed.valueSchema());
assertEquals(false, transformed.value());
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class CastTest method castWholeRecordValueWithSchemaInt8.
@Test
public void castWholeRecordValueWithSchemaInt8() {
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "int8"));
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, Schema.INT32_SCHEMA, 42));
assertEquals(Schema.Type.INT8, transformed.valueSchema().type());
assertEquals((byte) 42, transformed.value());
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class CastTest method castWholeRecordValueSchemalessInt32.
@Test
public void castWholeRecordValueSchemalessInt32() {
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "int32"));
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, null, 42));
assertNull(transformed.valueSchema());
assertEquals(42, transformed.value());
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class CastTest method castWholeRecordValueWithSchemaInt32.
@Test
public void castWholeRecordValueWithSchemaInt32() {
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "int32"));
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, Schema.INT32_SCHEMA, 42));
assertEquals(Schema.Type.INT32, transformed.valueSchema().type());
assertEquals(42, transformed.value());
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class FlattenTest method testOptionalAndDefaultValuesNested.
@Test
public void testOptionalAndDefaultValuesNested() {
// If we have a nested structure where an entire sub-Struct is optional, all flattened fields generated from its
// children should also be optional. Similarly, if the parent Struct has a default value, the default value for
// the flattened field
xformValue.configure(Collections.<String, String>emptyMap());
SchemaBuilder builder = SchemaBuilder.struct().optional();
builder.field("req_field", Schema.STRING_SCHEMA);
builder.field("opt_field", SchemaBuilder.string().optional().defaultValue("child_default").build());
Struct childDefaultValue = new Struct(builder);
childDefaultValue.put("req_field", "req_default");
builder.defaultValue(childDefaultValue);
Schema schema = builder.build();
// Intentionally leave this entire value empty since it is optional
Struct value = new Struct(schema);
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, schema, value));
assertNotNull(transformed);
Schema transformedSchema = transformed.valueSchema();
assertEquals(Schema.Type.STRUCT, transformedSchema.type());
assertEquals(2, transformedSchema.fields().size());
// Required field should pick up both being optional and the default value from the parent
Schema transformedReqFieldSchema = SchemaBuilder.string().optional().defaultValue("req_default").build();
assertEquals(transformedReqFieldSchema, transformedSchema.field("req_field").schema());
// The optional field should still be optional but should have picked up the default value. However, since
// the parent didn't specify the default explicitly, we should still be using the field's normal default
Schema transformedOptFieldSchema = SchemaBuilder.string().optional().defaultValue("child_default").build();
assertEquals(transformedOptFieldSchema, transformedSchema.field("opt_field").schema());
}
Aggregations