I'm getting the error `java.lang.ClassCastExceptio...
# troubleshooting
m
I'm getting the error
java.lang.ClassCastException: class org.apache.flink.table.types.logical.LegacyTypeInformationType cannot be cast to class org.apache.flink.table.types.logical.DecimalType
during runtime using a homebrew KafkaSource that deserialises Avro data. I'm not sure where the LegacyTypeInformationType comes from; I've googled but the only thing that looks similar is this: https://github.com/apache/flink/pull/11874#discussion_r414251140 I'm doing the conversion like this:
Copy code
case byteBuffer: ByteBuffer =>
    logicalType match
        case decimal: LogicalTypes.Decimal =>
            val precision = decimal.getPrecision
            val scale     = decimal.getScale
            DecimalConversion().fromBytes(byteBuffer, schema, LogicalTypes.decimal(precision, scale))
        case _: LogicalTypes.BigDecimal =>
            BigDecimalConversion().fromBytes(byteBuffer, schema, LogicalTypes.bigDecimal)
        case _ =>
            val bytes = Array.ofDim[Byte](byteBuffer.remaining)
            byteBuffer.get(bytes)
            bytes
case genericFixed: GenericFixed =>
    logicalType match
        case decimal: LogicalTypes.Decimal =>
            val precision = decimal.getPrecision
            val scale     = decimal.getScale
            DecimalConversion().fromFixed(genericFixed, schema, LogicalTypes.decimal(precision, scale))
        case _ => genericFixed.bytes
… and for the `TypeInformation`s I return the corresponding:
Copy code
case Schema.Type.BYTES =>
    avroSchema.getLogicalType match
        case _: LogicalTypes.Decimal    => Types.BIG_DEC
        case _: LogicalTypes.BigDecimal => Types.BIG_DEC
        case _                          => Types.PRIMITIVE_ARRAY(Types.BYTE)

case Schema.Type.FIXED =>
    avroSchema.getLogicalType match
        case _: LogicalTypes.Decimal => Types.BIG_DEC
        case _                       => Types.PRIMITIVE_ARRAY(Types.BYTE)
To my knowledge I'm not returning a LegacyTypeInformationType anywhere.
The problem seems to stem from the method
TableSchema.fromTypeInfo
. It is deprecated but I didn't realise it caused everything to break if decimal types were present in the RowTypeInfo.. Kinda crazy.