use of org.talend.daikon.avro.AvroRegistry in project components by Talend.
the class PythonRowPropertiesTest method testSetupSchema.
/**
* Checks {@link PythonRowProperties} update correctly * schema property
*/
@Test
public void testSetupSchema() {
PythonRowProperties properties = new PythonRowProperties("test");
properties.init();
AvroRegistry registry = new AvroRegistry();
Schema stringSchema = registry.getConverter(String.class).getSchema();
Schema.Field inputValue1Field = new Schema.Field("inputValue1", stringSchema, null, null, Order.ASCENDING);
Schema.Field inputValue2Field = new Schema.Field("inputValue2", stringSchema, null, null, Order.ASCENDING);
Schema inputSchema = Schema.createRecord("inputSchema", null, null, false, Arrays.asList(inputValue1Field, inputValue2Field));
properties.main.schema.setValue(inputSchema);
assertThat(inputSchema, equalTo(properties.main.schema.getValue()));
}
use of org.talend.daikon.avro.AvroRegistry in project components by Talend.
the class TSplunkEventCollectorWriter method initDefaultSchema.
private Schema initDefaultSchema(Schema designSchema) {
AvroRegistry avroReg = new AvroRegistry();
FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields();
for (SplunkJSONEventField metadataField : SplunkJSONEventField.getMetadataFields()) {
Schema base = avroReg.getConverter(metadataField.getDataType()).getSchema();
FieldBuilder<Schema> fieldBuilder = record.name(metadataField.getName());
if (metadataField.getName().equals(SplunkJSONEventField.TIME.getName())) {
String datePattern;
Field designField = designSchema.getField(metadataField.getName());
if (designField != null) {
datePattern = designField.getProp(SchemaConstants.TALEND_COLUMN_PATTERN);
} else {
datePattern = designSchema.getProp(SchemaConstants.TALEND_COLUMN_PATTERN);
}
if (datePattern == null || datePattern.isEmpty()) {
datePattern = "dd-MM-yyyy";
}
fieldBuilder.prop(SchemaConstants.TALEND_COLUMN_PATTERN, datePattern);
}
fieldBuilder.type(AvroUtils.wrapAsNullable(base)).noDefault();
}
Schema defaultSchema = record.endRecord();
return defaultSchema;
}
use of org.talend.daikon.avro.AvroRegistry in project components by Talend.
the class TSplunkEventCollectorProperties method setupDefaultSchema.
private void setupDefaultSchema() {
AvroRegistry avroReg = new AvroRegistry();
FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields();
for (SplunkJSONEventField metadataField : SplunkJSONEventField.getMetadataFields()) {
Schema base = avroReg.getConverter(metadataField.getDataType()).getSchema();
FieldBuilder<Schema> fieldBuilder = record.name(metadataField.getName());
if (metadataField.getName().equals(SplunkJSONEventField.TIME.getName())) {
fieldBuilder.prop(SchemaConstants.TALEND_COLUMN_PATTERN, "dd-MM-yyyy");
}
fieldBuilder.type(AvroUtils.wrapAsNullable(base)).noDefault();
}
Schema defaultSchema = record.endRecord();
schema.schema.setValue(defaultSchema);
}
use of org.talend.daikon.avro.AvroRegistry in project components by Talend.
the class AssertResultWriter method write.
@Override
public void write(Object object) throws IOException {
if (null == object) {
return;
}
if (null == converter) {
converter = (IndexedRecordConverter<Object, ? extends IndexedRecord>) new AvroRegistry().createIndexedRecordConverter(object.getClass());
}
IndexedRecord record = converter.convertToAvro(object);
actualResult.add(record.get(0).toString());
total++;
if (expectedResult.contains(record.get(0).toString())) {
success++;
} else {
failed++;
}
}
use of org.talend.daikon.avro.AvroRegistry in project components by Talend.
the class TSplunkEventCollectorWriterTestIT method createSchemaWithTimeAsString.
/**
* create schema for indexed record with Date presented as String.
*/
private Schema createSchemaWithTimeAsString() {
AvroRegistry avroReg = new AvroRegistry();
FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields();
addField(record, "FieldString", String.class, avroReg);
addField(record, "FieldInt", Integer.class, avroReg);
addField(record, "Description", String.class, avroReg);
addField(record, "time", String.class, avroReg);
Schema defaultSchema = record.endRecord();
return defaultSchema;
}
Aggregations