/** * Initialize converters per each schema field * * @param schema design schema * @review */ protected void initConverters(Schema schema) { schemaFields = schema.getFields(); avroConverters = new AvroConverter[schemaFields.size()]; for (int i = 0; i < schemaFields.size(); i++) { Schema.Field field = schemaFields.get(i); Schema fieldSchema = AvroUtils.unwrapIfNullable(field.schema()); if (LogicalTypeUtils.isLogicalTimestampMillis(fieldSchema)) { String datePattern = field.getProp( SchemaConstants.TALEND_COLUMN_PATTERN); avroConverters[i] = new StringTimestampConverter(datePattern); } else { Schema.Type type = fieldSchema.getType(); avroConverters[i] = _converterRegistry.get(type); } } }
/** * Converts Avro type to Talend type * Conversion strategy is following: * 1. check Avro logical type * 2. check java-class property * 3. if above things are null, convert it according schema type * Avro type doesn't uniquely identify Talend type. Several Talend types may correspond to the same Avro type. * Thus, logical type and java-class are checked first as they uniquely identify DI type * * @param avroType Avro field schema * @return corresponding Talend type */ public static TalendType convertFromAvro(Schema avroType) { Schema type = AvroUtils.unwrapIfNullable(avroType); String logicalType = LogicalTypeUtils.getLogicalTypeName(type); if (logicalType != null) { return getTalendByLogicalType(logicalType); } String javaClass = type.getProp(SchemaConstants.JAVA_CLASS_FLAG); if (javaClass != null) { return getTalendByJavaClass(javaClass); } return getTalendByAvroType(type.getType()); }
Schema fieldSchema = LogicalTypeUtils.getSchemaByLogicalType(logicalType); if (fieldSchema != null) { return fieldSchema;
/** * Converts Avro type to Talend type * Conversion strategy is following: * 1. check Avro logical type * 2. check java-class property * 3. if above things are null, convert it according schema type * Avro type doesn't uniquely identify Talend type. Several Talend types may correspond to the same Avro type. * Thus, logical type and java-class are checked first as they uniquely identify DI type * * @param avroType Avro field schema * @return corresponding Talend type */ public static TalendType convertFromAvro(Schema avroType) { Schema type = AvroUtils.unwrapIfNullable(avroType); String logicalType = LogicalTypeUtils.getLogicalTypeName(type); if (logicalType != null) { return getTalendByLogicalType(logicalType); } String javaClass = type.getProp(SchemaConstants.JAVA_CLASS_FLAG); if (javaClass != null) { return getTalendByJavaClass(javaClass); } return getTalendByAvroType(type.getType()); }
Schema fieldSchema = LogicalTypeUtils.getSchemaByLogicalType(logicalType); if (fieldSchema != null) { return fieldSchema;