@SuppressWarnings("unchecked") private IndexedRecordConverter<Object, ? extends IndexedRecord> getFactory(Object datum) { if (null == factory) { factory = (IndexedRecordConverter<Object, ? extends IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); } return factory; } }
public IndexedRecordConverter<Object, ? extends IndexedRecord> getFactory(Object datum) { if (null == factory) { factory = (IndexedRecordConverter<Object, ? extends IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); } return factory; }
@SuppressWarnings("unchecked") public IndexedRecordConverter<Object, ? extends IndexedRecord> getFactory(Object datum) { if (null == factory) { factory = (IndexedRecordConverter<Object, ? extends IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); } return factory; }
public IndexedRecordConverter<Object, ? extends IndexedRecord> getFactory(Object datum) { if (null == factory) { factory = (IndexedRecordConverter<Object, ? extends IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); } return factory; }
@SuppressWarnings("unchecked") private IndexedRecordConverter<Object, ? extends IndexedRecord> getFactory(Object datum) { if (null == converter) { converter = (IndexedRecordConverter<Object, ? extends IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); } return converter; }
@SuppressWarnings("unchecked") private IndexedRecordConverter<Object, ? extends IndexedRecord> getFactory(Object datum) { if (null == converter) { converter = (IndexedRecordConverter<Object, ? extends IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); } return converter; }
/** * Returns IndexedRecord converter * * @param datum data object * @return IndexedRecord converter */ protected IndexedRecordConverter<Object, ? extends IndexedRecord> getFactory(Object datum) { if (null == factory) { factory = (IndexedRecordConverter<Object, ? extends IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); } return factory; }
/** * Returns IndexedRecord converter * * @param datum data object * @return IndexedRecord converter */ protected IndexedRecordConverter<Object, ? extends IndexedRecord> getFactory(Object datum) { if (null == factory) { factory = (IndexedRecordConverter<Object, ? extends IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); } return factory; }
public IndexedRecord getCurrent() throws NoSuchElementException { T current = reader.getCurrent(); if (current == null) { return null; } if (current instanceof IndexedRecord) { return (IndexedRecord) current; } if (indexedRecordConverter == null) { indexedRecordConverter = (IndexedRecordConverter<T, ?>) (new AvroRegistry()) .createIndexedRecordConverter(current.getClass()); } return indexedRecordConverter.convertToAvro(current); }
/** * Return a converter that can any datum to an {@link IndexedRecord} representation as if it were passed in the * transformation. This might be an expensive call, so the converter should be cached if possible. * * @param datum the datum to convert. * @return a converter that can turn it into an Avro {@link IndexedRecord}. */ public static <DatumT> IndexedRecordConverter<DatumT, IndexedRecord> getConverter(DatumT datum) { @SuppressWarnings("unchecked") IndexedRecordConverter<DatumT, IndexedRecord> converter = (IndexedRecordConverter<DatumT, IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); if (datum instanceof IndexedRecord) { converter.setSchema(((IndexedRecord) datum).getSchema()); } if (converter == null) { throw new Pipeline.PipelineExecutionException( new RuntimeException("Cannot convert " + datum.getClass() + " to IndexedRecord.")); } return converter; }
public IndexedRecord getCurrent() throws NoSuchElementException { T current = reader.getCurrent(); if (current == null) { return null; } if (current instanceof IndexedRecord) { return (IndexedRecord) current; } if (indexedRecordConverter == null) { indexedRecordConverter = (IndexedRecordConverter<T, ?>) (new AvroRegistry()) .createIndexedRecordConverter(current.getClass()); } return indexedRecordConverter.convertToAvro(current); }
@DoFn.ProcessElement public void processElement(ProcessContext c) throws Exception { if (c.element() == null) { return; } if (converter == null) { converter = new AvroRegistry().createIndexedRecordConverter(c.element().getClass()); } c.output((IndexedRecord) converter.convertToAvro(c.element())); } }));
/** * Initializes test arguments before tests */ @BeforeClass public static void setUp() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); testSchema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); testSchema.addProp(TALEND_IS_LOCKED, "true"); testJson = "{\"startAt\":0,\"maxResults\":2,\"total\":1,\"issues\":[]}"; }
/** * Checks {@link TJiraInputProperties#setupSchema()} sets correct initial schema property */ @Test public void testSetupSchema() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); Schema expectedSchema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); expectedSchema.addProp(TALEND_IS_LOCKED, "true"); TJiraInputProperties properties = new TJiraInputProperties("root"); properties.setupSchema(); Schema schema = properties.schema.schema.getValue(); assertThat(schema, equalTo(expectedSchema)); }
/** * Create default static schema for indexed record. */ private Schema createSchema() { AvroRegistry avroReg = new AvroRegistry(); FieldAssembler<Schema> record = SchemaBuilder.record("Main").fields(); addField(record, "FieldString", String.class, avroReg); addField(record, "FieldInt", Integer.class, avroReg); Schema defaultSchema = record.endRecord(); return defaultSchema; }
/** * Initializes test arguments before tests */ @BeforeClass public static void setUp() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); testSchema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); testSchema.addProp(TALEND_IS_LOCKED, "true"); issueIndexedRecord = new IssueIndexedRecord(testJson, testSchema); }
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); }
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); }
/** * 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; }
/** * Prepares required instances for tests */ @Before public void setUp() { AvroRegistry registry = new AvroRegistry(); Schema stringSchema = registry.getConverter(String.class).getSchema(); Schema.Field jsonField = new Schema.Field("json", stringSchema, null, null, Order.ASCENDING); schema = Schema.createRecord("jira", null, null, false, Collections.singletonList(jsonField)); schema.addProp(TALEND_IS_LOCKED, "true"); outputProperties = new TJiraOutputProperties("root"); outputProperties.connection.hostUrl.setValue("hostValue"); outputProperties.connection.basicAuthentication.userId.setValue("userIdValue"); outputProperties.connection.basicAuthentication.password.setValue("passwordValue"); outputProperties.resource.setValue(Resource.ISSUE); outputProperties.schema.schema.setValue(schema); outputProperties.action.setValue(Action.INSERT); outputProperties.deleteSubtasks.setValue(true); }