Class RowDataUtils
- java.lang.Object
-
- org.apache.flink.cdc.connectors.hudi.sink.util.RowDataUtils
-
public class RowDataUtils extends Object
Utils for convertingRowDataandDataChangeEvent.
-
-
Constructor Summary
Constructors Constructor Description RowDataUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.apache.hudi.client.model.HoodieFlinkInternalRowconvertDataChangeEventToHoodieFlinkInternalRow(DataChangeEvent dataChangeEvent, Schema schema, java.time.ZoneId zoneId, org.apache.hudi.sink.bulk.RowDataKeyGen keyGen, String fileId, String instantTime)Convert a DataChangeEvent to a HoodieFlinkInternalRow with automatic record key and partition path extraction using Hudi's RowDataKeyGen.static org.apache.flink.table.data.RowDataconvertDataChangeEventToRowData(ChangeEvent changeEvent, List<RecordData.FieldGetter> fieldGetters)ConvertDataChangeEventtoRowData.static RecordData.FieldGettercreateFieldGetter(DataType fieldType, int fieldPos, java.time.ZoneId zoneId)Create aRecordData.FieldGetterfor the givenDataType.static List<RecordData.FieldGetter>createFieldGetters(Schema schema, java.time.ZoneId zoneId)static org.apache.hudi.sink.bulk.RowDataKeyGencreateKeyGen(Schema schema)Create a RowDataKeyGen for a table based on its schema.static StringextractPartitionPathFromDataChangeEvent(DataChangeEvent dataChangeEvent, Schema schema)Extract partition path from DataChangeEvent based on partition key fields in schema.static StringextractRecordKeyFromDataChangeEvent(DataChangeEvent dataChangeEvent, Schema schema)Extract record key from DataChangeEvent based on primary key fields in schema.static org.apache.flink.table.types.logical.LogicalTypetoLogicalType(DataType cdcType)Maps a Flink CDC DataType to a Flink Table LogicalType.static org.apache.flink.table.types.logical.RowTypetoRowType(Schema schema)Converts a Flink CDC Schema to a Flink Table RowType.
-
-
-
Method Detail
-
convertDataChangeEventToRowData
public static org.apache.flink.table.data.RowData convertDataChangeEventToRowData(ChangeEvent changeEvent, List<RecordData.FieldGetter> fieldGetters)
ConvertDataChangeEventtoRowData.
-
createFieldGetters
public static List<RecordData.FieldGetter> createFieldGetters(Schema schema, java.time.ZoneId zoneId)
-
createFieldGetter
public static RecordData.FieldGetter createFieldGetter(DataType fieldType, int fieldPos, java.time.ZoneId zoneId)
Create aRecordData.FieldGetterfor the givenDataType.
-
convertDataChangeEventToHoodieFlinkInternalRow
public static org.apache.hudi.client.model.HoodieFlinkInternalRow convertDataChangeEventToHoodieFlinkInternalRow(DataChangeEvent dataChangeEvent, Schema schema, java.time.ZoneId zoneId, org.apache.hudi.sink.bulk.RowDataKeyGen keyGen, String fileId, String instantTime)
Convert a DataChangeEvent to a HoodieFlinkInternalRow with automatic record key and partition path extraction using Hudi's RowDataKeyGen. This is the preferred method as it uses Hudi's built-in key generation logic.- Parameters:
dataChangeEvent- The DataChangeEvent to convertschema- Schema for the tablezoneId- Time zone for timestamp conversionkeyGen- Hudi's RowDataKeyGen for extracting record keys and partition pathsfileId- The file ID for the recordinstantTime- The instant time for the record- Returns:
- HoodieFlinkInternalRow containing the converted data
-
extractRecordKeyFromDataChangeEvent
public static String extractRecordKeyFromDataChangeEvent(DataChangeEvent dataChangeEvent, Schema schema)
Extract record key from DataChangeEvent based on primary key fields in schema. Public utility method for use by operators that need to calculate record keys.- Parameters:
dataChangeEvent- The DataChangeEvent to extract record key fromschema- The table schema containing primary key definitions- Returns:
- The record key string in format "field1:value1,field2:value2"
-
extractPartitionPathFromDataChangeEvent
public static String extractPartitionPathFromDataChangeEvent(DataChangeEvent dataChangeEvent, Schema schema)
Extract partition path from DataChangeEvent based on partition key fields in schema. Public utility method for use by operators that need to calculate partition paths.If the schema has partition keys defined:
- Extracts partition field values from the record data
- Formats them as "field1=value1/field2=value2" (Hive-style partitioning)
If no partition keys are defined, returns empty string (for unpartitioned tables).
- Parameters:
dataChangeEvent- The DataChangeEvent to extract partition fromschema- The table schema containing partition key definitions- Returns:
- The partition path string (empty string for unpartitioned tables)
-
toRowType
public static org.apache.flink.table.types.logical.RowType toRowType(Schema schema)
Converts a Flink CDC Schema to a Flink Table RowType.- Parameters:
schema- The input org.apache.flink.cdc.common.schema.Schema- Returns:
- The corresponding org.apache.flink.table.types.logical.RowType
-
toLogicalType
public static org.apache.flink.table.types.logical.LogicalType toLogicalType(DataType cdcType)
Maps a Flink CDC DataType to a Flink Table LogicalType. This method covers a wide range of common types.- Parameters:
cdcType- The CDC data type- Returns:
- The corresponding LogicalType
-
createKeyGen
public static org.apache.hudi.sink.bulk.RowDataKeyGen createKeyGen(Schema schema)
Create a RowDataKeyGen for a table based on its schema.- Parameters:
schema- The table schema- Returns:
- RowDataKeyGen configured with record key and partition fields from schema
-
-