use of org.talend.components.splunk.objects.SplunkJSONEventField in project components by Talend.
the class TSplunkEventCollectorTestIT method testDefaultSchema.
@Test
public void testDefaultSchema() {
TSplunkEventCollectorProperties props = (TSplunkEventCollectorProperties) new TSplunkEventCollectorDefinition().createProperties();
Schema s = props.getSchema();
List<Field> fields = s.getFields();
List<SplunkJSONEventField> schemaEventFields = new ArrayList<>();
for (Field f : fields) {
schemaEventFields.add(SplunkJSONEventField.getByName(f.name()));
}
assertTrue("Default schema is wrong.", schemaEventFields.size() == SplunkJSONEventField.getMetadataFields().size());
assertTrue("Default schema doesn't contain all metadata fields.", schemaEventFields.containsAll(SplunkJSONEventField.getMetadataFields()));
}
use of org.talend.components.splunk.objects.SplunkJSONEventField 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.components.splunk.objects.SplunkJSONEventField 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);
}
Aggregations