use of org.apache.kafka.connect.source.SourceRecord in project kafka by apache.
the class CastTest method castWholeRecordValueSchemalessFloat32.
@Test
public void castWholeRecordValueSchemalessFloat32() {
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "float32"));
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, null, 42));
assertNull(transformed.valueSchema());
assertEquals(42.f, transformed.value());
}
use of org.apache.kafka.connect.source.SourceRecord in project kafka by apache.
the class CastTest method castWholeRecordValueWithSchemaBooleanFalse.
@Test
public void castWholeRecordValueWithSchemaBooleanFalse() {
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "boolean"));
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, Schema.INT32_SCHEMA, 0));
assertEquals(Schema.Type.BOOLEAN, transformed.valueSchema().type());
assertEquals(false, transformed.value());
}
use of org.apache.kafka.connect.source.SourceRecord in project kafka by apache.
the class CastTest method castLogicalToString.
@Test
public void castLogicalToString() {
Date date = new Date(MILLIS_PER_DAY);
Date time = new Date(MILLIS_PER_HOUR);
Date timestamp = new Date();
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "date:string,decimal:string,time:string,timestamp:string"));
SchemaBuilder builder = SchemaBuilder.struct();
builder.field("date", org.apache.kafka.connect.data.Date.SCHEMA);
builder.field("decimal", Decimal.schema(new BigDecimal(1982).scale()));
builder.field("time", Time.SCHEMA);
builder.field("timestamp", Timestamp.SCHEMA);
Schema supportedTypesSchema = builder.build();
Struct recordValue = new Struct(supportedTypesSchema);
recordValue.put("date", date);
recordValue.put("decimal", new BigDecimal(1982));
recordValue.put("time", time);
recordValue.put("timestamp", timestamp);
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, supportedTypesSchema, recordValue));
assertEquals(Values.dateFormatFor(date).format(date), ((Struct) transformed.value()).get("date"));
assertEquals("1982", ((Struct) transformed.value()).get("decimal"));
assertEquals(Values.dateFormatFor(time).format(time), ((Struct) transformed.value()).get("time"));
assertEquals(Values.dateFormatFor(timestamp).format(timestamp), ((Struct) transformed.value()).get("timestamp"));
Schema transformedSchema = ((Struct) transformed.value()).schema();
assertEquals(Type.STRING, transformedSchema.field("date").schema().type());
assertEquals(Type.STRING, transformedSchema.field("decimal").schema().type());
assertEquals(Type.STRING, transformedSchema.field("time").schema().type());
assertEquals(Type.STRING, transformedSchema.field("timestamp").schema().type());
}
use of org.apache.kafka.connect.source.SourceRecord in project kafka by apache.
the class CastTest method castWholeRecordValueWithSchemaFloat32.
@Test
public void castWholeRecordValueWithSchemaFloat32() {
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "float32"));
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, Schema.INT32_SCHEMA, 42));
assertEquals(Schema.Type.FLOAT32, transformed.valueSchema().type());
assertEquals(42.f, transformed.value());
}
use of org.apache.kafka.connect.source.SourceRecord in project kafka by apache.
the class CastTest method castWholeRecordKeyWithSchema.
@Test
public void castWholeRecordKeyWithSchema() {
xformKey.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "int8"));
SourceRecord transformed = xformKey.apply(new SourceRecord(null, null, "topic", 0, Schema.INT32_SCHEMA, 42, Schema.STRING_SCHEMA, "bogus"));
assertEquals(Schema.Type.INT8, transformed.keySchema().type());
assertEquals((byte) 42, transformed.key());
}
Aggregations