Shekhar Prasad Rajak created FLINK-39789:
--------------------------------------------
Summary: AvroSchemaConverter.convertToDataType(String) ignores
local-timestamp-* and timestamp-nanos logical types, silently maps to BIGINT
Key: FLINK-39789
URL: https://issues.apache.org/jira/browse/FLINK-39789
Project: Flink
Issue Type: Bug
Affects Versions: 2.1.0
Reporter: Shekhar Prasad Rajak
AvroSchemaConverter.convertToDataType(String avroSchemaString) is the only
public Avro→Flink type-mapping entry point. It silently drops the logical type
for several Avro long logical types and returns BIGINT, which then produces a
Flink RowType that is incompatible with TimestampData values at runtime.
The internal two-arg convertToDataType(Schema, boolean) does contain branches
for local-timestamp-millis and local-timestamp-micros, but they are reached
only when the boolean is false. The single-arg public API hard-codes the
boolean to true, so those branches are unreachable from any public API. There
are also no branches at all for timestamp-nanos or local-timestamp-nanos.
String avro =
"{ \"type\": \"record\", \"name\": \"R\", \"fields\": ["
+ "{ \"name\": \"ts\", \"type\": { \"type\": \"long\","
+ " \"logicalType\": \"local-timestamp-micros\" } } ] }";
DataType dt = AvroSchemaConverter.convertToDataType(avro);
System.out.println(dt);
// Current : ROW<`ts` BIGINT NOT NULL> NOT NULL
// Expected: ROW<`ts` TIMESTAMP(6) NOT NULL> NOT NULL
Because of that :
```
RowType row = (RowType)
AvroSchemaConverter.convertToDataType(avro).getLogicalType();
RowData.FieldGetter getter = RowData.createFieldGetter(row.getTypeAt(0), 0);
GenericRowData data = new GenericRowData(1);
data.setField(0, TimestampData.fromEpochMillis(0L)); // semantically correct
value
getter.getFieldOrNull(data);
// java.lang.ClassCastException:
// class org.apache.flink.table.data.TimestampData cannot be cast to class
java.lang.Long
```
--
This message was sent by Atlassian Jira
(v8.20.10#820010)