use of org.apache.inlong.sort.formats.common.TimestampFormatInfo in project incubator-inlong by apache.
the class FieldInfoUtils method createFieldInfo.
/**
* Get field info list.
* TODO 1. Support partition field, 2. Add is_metadata field in StreamSinkFieldEntity
*/
public static FieldMappingRule createFieldInfo(boolean isAllMigration, List<SinkFieldResponse> fieldList, List<FieldInfo> sourceFields, List<FieldInfo> sinkFields, String partitionField) {
List<FieldMappingUnit> fieldMappingUnitList = new ArrayList<>();
if (isAllMigration) {
setAllMigrationBuiltInField(sourceFields, sinkFields, fieldMappingUnitList);
} else {
boolean duplicate = false;
for (SinkFieldResponse field : fieldList) {
// If the field name equals to build-in field, new a build-in field info
FieldInfo sourceFieldInfo = getFieldInfo(field.getSourceFieldName(), field.getSourceFieldType(), field.getIsSourceMetaField() == 1);
sourceFields.add(sourceFieldInfo);
// Get sink field info
String sinkFieldName = field.getFieldName();
if (sinkFieldName.equals(partitionField)) {
duplicate = true;
}
FieldInfo sinkFieldInfo = getSinkFieldInfo(field.getFieldName(), field.getFieldType(), field.getSourceFieldName(), field.getIsSourceMetaField() == 1);
sinkFields.add(sinkFieldInfo);
fieldMappingUnitList.add(new FieldMappingUnit(sourceFieldInfo, sinkFieldInfo));
}
// If no partition field in the ordinary fields, add the partition field to the first position
if (!duplicate && StringUtils.isNotEmpty(partitionField)) {
FieldInfo fieldInfo = new FieldInfo(partitionField, new TimestampFormatInfo("MILLIS"));
sourceFields.add(0, fieldInfo);
}
}
return new FieldMappingRule(fieldMappingUnitList.toArray(new FieldMappingUnit[0]));
}
Aggregations