Class SchemaMergingUtils
- java.lang.Object
-
- org.apache.flink.cdc.common.utils.SchemaMergingUtils
-
@PublicEvolving public class SchemaMergingUtils extends Object
Utils for mergingSchemas andDataTypes. Prefer using this overSchemaUtilsto get consistent schema merging behaviors.
-
-
Constructor Summary
Constructors Constructor Description SchemaMergingUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectcoerceObject(String timezone, Object originalField, DataType originalType, DataType destinationType)static Object[]coerceRow(String timezone, Schema currentSchema, Schema upcomingSchema, List<Object> upcomingRow)CoercingupcomingRowwithupcomingTypesschema intocurrentTypesschema.static Object[]coerceRow(String timezone, Schema currentSchema, Schema upcomingSchema, List<Object> upcomingRow, boolean toleranceMode)CoercingupcomingRowwithupcomingTypesschema intocurrentTypesschema.static SchemagetCommonSchema(List<Schema> schemas)Merge compatible schemas.static SchemagetLeastCommonSchema(Schema currentSchema, Schema upcomingSchema)Try to mergeupcomingSchemaintocurrentSchemaby performing lenient schema changes.static intgetNumericPrecision(DataType dataType)static List<SchemaChangeEvent>getSchemaDifference(TableId tableId, Schema beforeSchema, Schema afterSchema)Generating what schema change events we need to do by converting compatiblebeforeSchematoafterSchema.static booleanisDataTypeCompatible(DataType currentType, DataType upcomingType)Checks whether the upcoming data type can fit into the current data type.static booleanisSchemaCompatible(Schema currentSchema, Schema upcomingSchema)Checking if givenupcomingSchemacould be fit into currently knowncurrentSchema.
-
-
-
Method Detail
-
isSchemaCompatible
public static boolean isSchemaCompatible(@Nullable Schema currentSchema, Schema upcomingSchema)
Checking if givenupcomingSchemacould be fit into currently knowncurrentSchema. Current schema could be null (as the cold opening state, and in this case it always returnsfalse) but the upcoming schema should never be null.
This method only checks columns' type compatibility, but ignores metadata fields like primaryKeys, partitionKeys, options.
-
getLeastCommonSchema
public static Schema getLeastCommonSchema(@Nullable Schema currentSchema, Schema upcomingSchema)
Try to mergeupcomingSchemaintocurrentSchemaby performing lenient schema changes. Returns a wider schema that could both of them.
-
getCommonSchema
public static Schema getCommonSchema(List<Schema> schemas)
Merge compatible schemas.
-
getSchemaDifference
public static List<SchemaChangeEvent> getSchemaDifference(TableId tableId, @Nullable Schema beforeSchema, Schema afterSchema)
Generating what schema change events we need to do by converting compatiblebeforeSchematoafterSchema.
-
coerceRow
public static Object[] coerceRow(String timezone, Schema currentSchema, Schema upcomingSchema, List<Object> upcomingRow)
CoercingupcomingRowwithupcomingTypesschema intocurrentTypesschema. Invoking this method implicitly assumes thatisSchemaCompatible(currentSchema, upcomingSchema)returns true. Otherwise, some upstream records might be lost.
-
coerceRow
public static Object[] coerceRow(String timezone, Schema currentSchema, Schema upcomingSchema, List<Object> upcomingRow, boolean toleranceMode)
CoercingupcomingRowwithupcomingTypesschema intocurrentTypesschema. Invoking this method implicitly assumes thatisSchemaCompatible(currentSchema, upcomingSchema)returns true. Otherwise, some upstream records might be lost.
-
isDataTypeCompatible
public static boolean isDataTypeCompatible(@Nullable DataType currentType, DataType upcomingType)
Checks whether the upcoming data type can fit into the current data type. A missing current type is treated as incompatible.
-
getNumericPrecision
@VisibleForTesting public static int getNumericPrecision(DataType dataType)
-
-