Search in sources :

Example 16 with TimestampFormatInfo

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]));
}
Also used : FieldMappingRule(org.apache.inlong.sort.protocol.transformation.FieldMappingRule) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) ArrayList(java.util.ArrayList) SinkFieldResponse(org.apache.inlong.manager.common.pojo.sink.SinkFieldResponse) FieldMappingUnit(org.apache.inlong.sort.protocol.transformation.FieldMappingRule.FieldMappingUnit) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo)

Aggregations

TimestampFormatInfo (org.apache.inlong.sort.formats.common.TimestampFormatInfo)16 Row (org.apache.flink.types.Row)12 DateFormatInfo (org.apache.inlong.sort.formats.common.DateFormatInfo)12 TimeFormatInfo (org.apache.inlong.sort.formats.common.TimeFormatInfo)12 Test (org.junit.Test)12 Timestamp (java.sql.Timestamp)11 LongFormatInfo (org.apache.inlong.sort.formats.common.LongFormatInfo)11 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)11 BasicFormatInfo (org.apache.inlong.sort.formats.common.BasicFormatInfo)10 BooleanFormatInfo (org.apache.inlong.sort.formats.common.BooleanFormatInfo)10 ByteFormatInfo (org.apache.inlong.sort.formats.common.ByteFormatInfo)10 DecimalFormatInfo (org.apache.inlong.sort.formats.common.DecimalFormatInfo)10 DoubleFormatInfo (org.apache.inlong.sort.formats.common.DoubleFormatInfo)10 FloatFormatInfo (org.apache.inlong.sort.formats.common.FloatFormatInfo)10 FormatInfo (org.apache.inlong.sort.formats.common.FormatInfo)10 IntFormatInfo (org.apache.inlong.sort.formats.common.IntFormatInfo)10 RowFormatInfo (org.apache.inlong.sort.formats.common.RowFormatInfo)10 ShortFormatInfo (org.apache.inlong.sort.formats.common.ShortFormatInfo)10 Date (java.sql.Date)9 Time (java.sql.Time)9