Search in sources :

Example 16 with AvroRegistry

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()));
}
Also used : AvroRegistry(org.talend.daikon.avro.AvroRegistry) Schema(org.apache.avro.Schema) Test(org.junit.Test)

Example 17 with AvroRegistry

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;
}
Also used : SplunkJSONEventField(org.talend.components.splunk.objects.SplunkJSONEventField) Field(org.apache.avro.Schema.Field) GenericAvroRegistry(org.talend.components.common.runtime.GenericAvroRegistry) AvroRegistry(org.talend.daikon.avro.AvroRegistry) Schema(org.apache.avro.Schema) SplunkJSONEventField(org.talend.components.splunk.objects.SplunkJSONEventField)

Example 18 with AvroRegistry

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);
}
Also used : AvroRegistry(org.talend.daikon.avro.AvroRegistry) Schema(org.apache.avro.Schema) SplunkJSONEventField(org.talend.components.splunk.objects.SplunkJSONEventField)

Example 19 with AvroRegistry

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++;
    }
}
Also used : AvroRegistry(org.talend.daikon.avro.AvroRegistry) IndexedRecord(org.apache.avro.generic.IndexedRecord)

Example 20 with AvroRegistry

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;
}
Also used : AvroRegistry(org.talend.daikon.avro.AvroRegistry) Schema(org.apache.avro.Schema)

Aggregations

AvroRegistry (org.talend.daikon.avro.AvroRegistry)31 Schema (org.apache.avro.Schema)29 Test (org.junit.Test)19 Ignore (org.junit.Ignore)11 Before (org.junit.Before)4 TJiraOutputProperties (org.talend.components.jira.tjiraoutput.TJiraOutputProperties)3 IndexedRecord (org.apache.avro.generic.IndexedRecord)2 BeforeClass (org.junit.BeforeClass)2 SplunkJSONEventField (org.talend.components.splunk.objects.SplunkJSONEventField)2 Field (org.apache.avro.Schema.Field)1 DoFn (org.apache.beam.sdk.transforms.DoFn)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 GenericAvroRegistry (org.talend.components.common.runtime.GenericAvroRegistry)1 Action (org.talend.components.jira.Action)1 Mode (org.talend.components.jira.Mode)1 Resource (org.talend.components.jira.Resource)1 TJiraInputProperties (org.talend.components.jira.tjirainput.TJiraInputProperties)1 IndexedRecordConverter (org.talend.daikon.avro.converter.IndexedRecordConverter)1 TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)1