Class SchemaMergingUtils

    • Constructor Detail

      • SchemaMergingUtils

        public SchemaMergingUtils()
    • Method Detail

      • isSchemaCompatible

        public static boolean isSchemaCompatible​(@Nullable
                                                 Schema currentSchema,
                                                 Schema upcomingSchema)
        Checking if given upcomingSchema could be fit into currently known currentSchema. Current schema could be null (as the cold opening state, and in this case it always returns false) 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 merge upcomingSchema into currentSchema by 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 compatible beforeSchema to afterSchema.
      • coerceRow

        public static Object[] coerceRow​(String timezone,
                                         Schema currentSchema,
                                         Schema upcomingSchema,
                                         List<Object> upcomingRow)
        Coercing upcomingRow with upcomingTypes schema into currentTypes schema. Invoking this method implicitly assumes that isSchemaCompatible(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)
        Coercing upcomingRow with upcomingTypes schema into currentTypes schema. Invoking this method implicitly assumes that isSchemaCompatible(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.