Martin Egri
07/02/2025, 3:57 PMjava.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:
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:
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)Martin Egri
07/02/2025, 4:06 PMMartin Egri
07/02/2025, 7:28 PMTableSchema.fromTypeInfo . It is deprecated but I didn't realise it caused everything to break if decimal types were present in the RowTypeInfo.. Kinda crazy.