Search in sources :

Example 1 with BuiltInFieldInfo

use of org.apache.inlong.sort.protocol.BuiltInFieldInfo in project incubator-inlong by apache.

the class FieldInfoUtils method setAllMigrationBuiltInField.

/**
 * Get all migration built-in field for binlog source.
 */
public static void setAllMigrationBuiltInField(List<FieldInfo> sourceFields, List<FieldInfo> sinkFields, List<FieldMappingUnit> fieldMappingUnitList) {
    BuiltInFieldInfo dataField = new BuiltInFieldInfo("data", StringFormatInfo.INSTANCE, BuiltInField.MYSQL_METADATA_DATA);
    sourceFields.add(dataField);
    sinkFields.add(dataField);
    fieldMappingUnitList.add(new FieldMappingUnit(dataField, dataField));
    for (Map.Entry<String, BuiltInField> entry : BUILT_IN_FIELD_MAP.entrySet()) {
        if (entry.getKey().equals("data_time")) {
            continue;
        }
        BuiltInFieldInfo fieldInfo = new BuiltInFieldInfo(entry.getKey(), StringFormatInfo.INSTANCE, entry.getValue());
        sourceFields.add(fieldInfo);
        sinkFields.add(fieldInfo);
        fieldMappingUnitList.add(new FieldMappingUnit(fieldInfo, fieldInfo));
    }
}
Also used : BuiltInField(org.apache.inlong.sort.protocol.BuiltInFieldInfo.BuiltInField) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) HashMap(java.util.HashMap) Map(java.util.Map) FieldMappingUnit(org.apache.inlong.sort.protocol.transformation.FieldMappingRule.FieldMappingUnit)

Example 2 with BuiltInFieldInfo

use of org.apache.inlong.sort.protocol.BuiltInFieldInfo in project incubator-inlong by apache.

the class FieldMappingTransformer method transform.

public Record transform(Record sourceRecord) throws Exception {
    final FieldInfo[] sinkFieldInfos = sinkFieldInfoMap.get(sourceRecord.getDataflowId());
    if (sinkFieldInfos == null) {
        throw new Exception("No field info found for data flow:" + sourceRecord.getDataflowId());
    }
    final Row sourceRow = sourceRecord.getRow();
    final Row sinkRow = new Row(sinkFieldInfos.length);
    int fieldIndex = SOURCE_FIELD_SKIP_STEP;
    for (int i = 0; i < sinkFieldInfos.length; i++) {
        Object fieldValue = null;
        if (sinkFieldInfos[i] instanceof BuiltInFieldInfo) {
            BuiltInFieldInfo builtInFieldInfo = (BuiltInFieldInfo) sinkFieldInfos[i];
            fieldValue = transformBuiltInField(builtInFieldInfo, sourceRecord.getTimestampMillis());
        } else if (fieldIndex < sourceRow.getArity()) {
            fieldValue = sourceRow.getField(fieldIndex);
            fieldIndex++;
        }
        if (fieldValue == null) {
            fieldValue = getDefaultValue(sourceRecord.getDataflowId(), sinkFieldInfos[i].getFormatInfo());
        }
        sinkRow.setField(i, fieldValue);
    }
    return new Record(sourceRecord.getDataflowId(), sourceRecord.getTimestampMillis(), sinkRow);
}
Also used : BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) Record(org.apache.inlong.sort.flink.Record) Row(org.apache.flink.types.Row) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo)

Example 3 with BuiltInFieldInfo

use of org.apache.inlong.sort.protocol.BuiltInFieldInfo in project incubator-inlong by apache.

the class DebeziumDeserializationSchemaBuilder method getMetadataFieldInfos.

public static FieldInfo[] getMetadataFieldInfos(FieldInfo[] fieldInfos) {
    List<FieldInfo> metadataFieldInfos = new ArrayList<>();
    Arrays.stream(fieldInfos).filter(fieldInfo -> fieldInfo instanceof BuiltInFieldInfo).forEach(fieldInfo -> {
        BuiltInFieldInfo builtInFieldInfo = (BuiltInFieldInfo) fieldInfo;
        BuiltInField builtInField = builtInFieldInfo.getBuiltInField();
        switch(builtInField) {
            case MYSQL_METADATA_DATABASE:
                metadataFieldInfos.add(new FieldInfo(ReadableMetadata.SOURCE_DATABASE.getKey(), StringFormatInfo.INSTANCE));
                break;
            case MYSQL_METADATA_TABLE:
                metadataFieldInfos.add(new FieldInfo(ReadableMetadata.SOURCE_TABLE.getKey(), StringFormatInfo.INSTANCE));
                break;
            case MYSQL_METADATA_EVENT_TIME:
                metadataFieldInfos.add(new FieldInfo(ReadableMetadata.INGESTION_TIMESTAMP.getKey(), LongFormatInfo.INSTANCE));
                break;
            case MYSQL_METADATA_IS_DDL:
            case MYSQL_METADATA_EVENT_TYPE:
            case MYSQL_METADATA_DATA:
                break;
            default:
                throw new IllegalArgumentException("Unsupported builtin field '" + builtInField + "' in debezium deserialization");
        }
    });
    return metadataFieldInfos.toArray(new FieldInfo[0]);
}
Also used : DataType(org.apache.flink.table.types.DataType) CommonUtils.convertDateToStringFormatInfo(org.apache.inlong.sort.singletenant.flink.utils.CommonUtils.convertDateToStringFormatInfo) Arrays(java.util.Arrays) CommonUtils.convertFieldInfosToDataType(org.apache.inlong.sort.singletenant.flink.utils.CommonUtils.convertFieldInfosToDataType) ReadableMetadata(org.apache.inlong.sort.formats.json.debezium.DebeziumJsonDecodingFormat.ReadableMetadata) ArrayList(java.util.ArrayList) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) BuiltInField(org.apache.inlong.sort.protocol.BuiltInFieldInfo.BuiltInField) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) RowData(org.apache.flink.table.data.RowData) CommonUtils.checkWhetherMigrateAll(org.apache.inlong.sort.singletenant.flink.utils.CommonUtils.checkWhetherMigrateAll) CommonUtils.extractFormatInfos(org.apache.inlong.sort.singletenant.flink.utils.CommonUtils.extractFormatInfos) IOException(java.io.IOException) DebeziumDeserializationInfo(org.apache.inlong.sort.protocol.deserialization.DebeziumDeserializationInfo) TimestampFormat(org.apache.flink.formats.common.TimestampFormat) DebeziumJsonDecodingFormat(org.apache.inlong.sort.formats.json.debezium.DebeziumJsonDecodingFormat) Collectors(java.util.stream.Collectors) MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) DeserializationSchema(org.apache.flink.api.common.serialization.DeserializationSchema) CommonUtils.getTimestampFormatStandard(org.apache.inlong.sort.singletenant.flink.utils.CommonUtils.getTimestampFormatStandard) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) List(java.util.List) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) CommonUtils(org.apache.inlong.sort.singletenant.flink.utils.CommonUtils) DataTypeUtils.validateInputDataType(org.apache.flink.table.types.utils.DataTypeUtils.validateInputDataType) Row(org.apache.flink.types.Row) BuiltInField(org.apache.inlong.sort.protocol.BuiltInFieldInfo.BuiltInField) ArrayList(java.util.ArrayList) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo)

Example 4 with BuiltInFieldInfo

use of org.apache.inlong.sort.protocol.BuiltInFieldInfo in project incubator-inlong by apache.

the class FieldMappingTransformer method transform.

public Row transform(Row sourceRow, long dt) {
    final Row outputRow = new Row(outputFieldInfos.length);
    int sourceRowIndex = SOURCE_FIELD_SKIP_STEP;
    Map<String, String> attributes = (Map<String, String>) sourceRow.getField(0);
    for (int i = 0; i < outputFieldInfos.length; i++) {
        Object fieldValue = null;
        if (outputFieldInfos[i] instanceof BuiltInFieldInfo) {
            BuiltInFieldInfo builtInFieldInfo = (BuiltInFieldInfo) outputFieldInfos[i];
            fieldValue = transformBuiltInField(builtInFieldInfo, attributes, dt, sourceRow.getKind());
        } else if (sourceRowIndex < sourceRow.getArity()) {
            fieldValue = sourceRow.getField(sourceRowIndex);
            sourceRowIndex++;
        }
        if (fieldValue == null) {
            fieldValue = defaultValueStrategy.getDefaultValue(outputFieldInfos[i].getFormatInfo());
        }
        outputRow.setField(i, fieldValue);
    }
    outputRow.setKind(sourceRow.getKind());
    return outputRow;
}
Also used : BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) Row(org.apache.flink.types.Row) Map(java.util.Map)

Example 5 with BuiltInFieldInfo

use of org.apache.inlong.sort.protocol.BuiltInFieldInfo in project incubator-inlong by apache.

the class CanalSerializationSchemaBuilder method getFieldIndexToMetadata.

private static Map<Integer, ReadableMetadata> getFieldIndexToMetadata(FieldInfo[] fieldInfos) {
    Map<Integer, ReadableMetadata> fieldIndexToMetadata = new HashMap<>();
    for (int i = 0; i < fieldInfos.length; i++) {
        FieldInfo fieldInfo = fieldInfos[i];
        if (fieldInfo instanceof BuiltInFieldInfo) {
            BuiltInFieldInfo builtInFieldInfo = (BuiltInFieldInfo) fieldInfo;
            BuiltInField builtInField = builtInFieldInfo.getBuiltInField();
            switch(builtInField) {
                case MYSQL_METADATA_DATABASE:
                    fieldIndexToMetadata.put(i, ReadableMetadata.DATABASE);
                    break;
                case MYSQL_METADATA_TABLE:
                    fieldIndexToMetadata.put(i, ReadableMetadata.TABLE);
                    break;
                case MYSQL_METADATA_EVENT_TIME:
                    fieldIndexToMetadata.put(i, ReadableMetadata.EVENT_TIMESTAMP);
                    break;
                case MYSQL_METADATA_IS_DDL:
                    fieldIndexToMetadata.put(i, ReadableMetadata.IS_DDL);
                    break;
                case MYSQL_METADATA_DATA:
                case MYSQL_METADATA_EVENT_TYPE:
                    // We will always append `type` to the result
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported builtin field '" + builtInField + "' in debezium deserialization");
            }
        }
    }
    return fieldIndexToMetadata;
}
Also used : HashMap(java.util.HashMap) BuiltInField(org.apache.inlong.sort.protocol.BuiltInFieldInfo.BuiltInField) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) ReadableMetadata(org.apache.inlong.sort.formats.json.canal.CanalJsonDecodingFormat.ReadableMetadata) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo)

Aggregations

BuiltInFieldInfo (org.apache.inlong.sort.protocol.BuiltInFieldInfo)11 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)9 Row (org.apache.flink.types.Row)5 BuiltInField (org.apache.inlong.sort.protocol.BuiltInFieldInfo.BuiltInField)5 LongFormatInfo (org.apache.inlong.sort.formats.common.LongFormatInfo)4 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)4 TimestampFormatInfo (org.apache.inlong.sort.formats.common.TimestampFormatInfo)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 Timestamp (java.sql.Timestamp)2 Map (java.util.Map)2 Configuration (org.apache.inlong.sort.configuration.Configuration)2 Record (org.apache.inlong.sort.flink.Record)2 ArrayFormatInfo (org.apache.inlong.sort.formats.common.ArrayFormatInfo)2 BooleanFormatInfo (org.apache.inlong.sort.formats.common.BooleanFormatInfo)2 ByteFormatInfo (org.apache.inlong.sort.formats.common.ByteFormatInfo)2 DateFormatInfo (org.apache.inlong.sort.formats.common.DateFormatInfo)2 DecimalFormatInfo (org.apache.inlong.sort.formats.common.DecimalFormatInfo)2 DoubleFormatInfo (org.apache.inlong.sort.formats.common.DoubleFormatInfo)2 FloatFormatInfo (org.apache.inlong.sort.formats.common.FloatFormatInfo)2