@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 AvroConverter<String, ?> getConverterFromString(org.apache.avro.Schema.Field f) { return super.getConverter(String.class); }
@Override public ConverterT get() { return createANew(converterClass, datumClass); }
/** * 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\":[]}"; }
/** * 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; }
SerializableFunction<? super DatumT, Schema> inferrer = getFromClassRegistry(mapSchemaInferrer, datum.getClass()); AvroConverter<?, ?> converter = getConverter(datum.getClass()); if (converter != null) { inferrer = new LambdaReturnConstantSchemaFunction<>(converter.getSchema());
/** * Gets a converter for instances of the given class, capable of converting or wrapping them to Avro-compatible * instances. * * @param datumClass The class of the object that should be converted. * @return An instance that can convert to and from instances of the DatumT class to an Avro-compatible instance. * This instance can be reused. */ public <T> AvroConverter<T, ?> getConverter(Class<T> datumClass) { // If a converter exists, it is guaranteed to be correctly typed because of the register methods. // Try to get a private converter first. AvroConverter<T, ?> converter = getFromClassRegistry(mapConverter, datumClass); if (converter != null) { return converter; } // Fall-back on the shared converters. return getFromClassRegistry(mapSharedConverter, datumClass); }
/** * 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); }
/** * 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; }
match = getFromClassRegistry(map, datumClass.getSuperclass()); if (match != null) { return match; match = getFromClassRegistry(map, iClass); if (match != null) { return match;
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); }
@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; }
public AvroConverter<String, ?> getConverterFromString(org.apache.avro.Schema.Field f) { return super.getConverter(String.class); }
/** * Creates a new instance of an {@link IndexedRecordConverter} that can be used to wrap or convert objects of the * specified class into {@link IndexedRecord}. * <p> * As a general rule, when the expected output {@link Schema} of the generated {@link IndexedRecord} is the same for * all incoming data, the factory should be cached and reused to optimize its performance. * * @param datumClass The class of the object that the {@link IndexedRecordConverter} knows how to wrap. * @return A new {@link IndexedRecordConverter} that can process instances of the datumClass, or null if none * exists. */ public <DatumT> IndexedRecordConverter<? super DatumT, ?> createIndexedRecordConverter(Class<DatumT> datumClass) { // This is guaranteed to be correctly typed if it exists, because of the register methods. @SuppressWarnings({ "rawtypes", "unchecked" }) Supplier<? extends IndexedRecordConverter<DatumT, ?>> converter = (Supplier) getFromClassRegistry( mapSharedIndexedRecordConverter, datumClass); if (converter == null && IndexedRecord.class.isAssignableFrom(datumClass)) { @SuppressWarnings("unchecked") IndexedRecordConverter<DatumT, ?> unconverted = (IndexedRecordConverter<DatumT, ?>) new UnconvertedIndexedRecordConverter<>(); return unconverted; } return converter == null ? null : converter.get(); }
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); }
@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 AvroConverter<String, ?> convertToString(Schema.Field f) { Schema fieldSchema = AvroUtils.unwrapIfNullable(f.schema()); switch (fieldSchema.getType()) { case LONG: String pattern = f.getProp(SchemaConstants.TALEND_COLUMN_PATTERN); if (pattern != null && !pattern.isEmpty()) { fieldSchema.addProp(SchemaConstants.TALEND_COLUMN_PATTERN, pattern); return new DateToStringConvert(fieldSchema); } else { return super.getConverter(String.class); } default: return super.getConverter(String.class); } }
/** * 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)); }
public IndexedRecordConverter<Object, ? extends IndexedRecord> getFactory(Object datum) { if (null == factory) { factory = (IndexedRecordConverter<Object, ? extends IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); } return factory; }
public AvroConverter<String, ?> convertToString(Schema.Field f) { Schema fieldSchema = AvroUtils.unwrapIfNullable(f.schema()); switch (fieldSchema.getType()) { case LONG: String pattern = f.getProp(SchemaConstants.TALEND_COLUMN_PATTERN); if (pattern != null && !pattern.isEmpty()) { fieldSchema.addProp(SchemaConstants.TALEND_COLUMN_PATTERN, pattern); return new DateToStringConvert(fieldSchema); } else { return super.getConverter(String.class); } default: return super.getConverter(String.class); } }