Handling Deprecated Flink API: Converting Legacy TypeInformation to DataTypes
After Flink 1.9 deprecated the legacy Type API in favor of DataTypes, users encounter missing schema TypeInformation methods, and this article explains the root cause and provides a code solution to convert legacy types using TypeConversions and register a TableSink.
By 大数据技术与架构 – Scenario: After Flink 1.9 the Type API was deprecated and replaced by DataTypes, but the legacy Type methods that provide schema TypeInformation no longer have a corresponding API.
Problem: Users cannot obtain the required TypeInformation for existing Type definitions, leading to failures when registering TableSinks.
Root cause: The registration method for a TableSink that relied on the old Type API was removed.
Solution: Convert the new DataTypes to legacy TypeInformation using TypeConversions.fromDataTypeToLegacyInfo (or LegacyTypeInfoDataTypeConverter) and then register the TableSink with the converted types.
Example code:
TableSink csvSink = new CsvTableSink("/path/to/file", "|"); String[] fieldNames = {"product", "amount"}; TypeInformation[] fieldTypes = {Types.STRING, Types.INT}; DataType[] newFieldType = {DataTypes.STRING(), DataTypes.INT()}; TypeInformation<?>[] newtypeInformations = TypeConversions.fromDataTypeToLegacyInfo(newFieldType); // alternative using LegacyTypeInfoDataTypeConverter // TypeInformation<?> str = LegacyTypeInfoDataTypeConverter.toLegacyTypeInfo(DataTypes.STRING()); // TypeInformation<?> integ = LegacyTypeInfoDataTypeConverter.toLegacyTypeInfo(DataTypes.INT()); // TypeInformation[] newTypInfo = {str, integ}; tableEnv.registerTableSink("RubberOrders", fieldNames, newtypeInformations, csvSink);The article also includes several screenshots illustrating the issue and the steps taken.
Finally, the author invites readers to share their experiences with Flink upgrades.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Big Data Technology & Architecture
Wang Zhiwu, a big data expert, dedicated to sharing big data technology.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
