Hi! If your custom type is a POJO then readCsvFile should work, otherwise as far as I know there is no way to let the parser directly parse a custom type for you. You can of course implement your own csv input format by extending GenericCsvInputFormat but I think it would be better to just read the data as strings and parse it with a UDF.
Mason Chan <mason...@gmail.com> 于2021年7月12日周一 上午5:36写道: > Hi, > > I am using the scala api and I want to deserialize a column in a CSV to a > custom object type. Is this possible? Here's a code snippet of something I > want to do: > > val rows = env.readCsvFile[(String, CustomType)]("./test.csv", > includedFields = Array(0, 1), ignoreFirstLine = true) > > When I do this I get this error: "The type 'org.example.CustomType' is not > supported for the CSV input format." > > I saw that readCsvFile only supports these types: > https://github.com/apache/flink/blob/e10e548feb2bedf54c3863bbd49ed4f9140546cf/flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java > > Is it possible to add custom deserializers? The only other way I thought > was to read it as a string and then map it as the custom type. I even tried > something like: env.registerTypeWithKryoSerializer(CustomType.getClass(), > new RowSer().getClass()) > > But I guess that api doesn't affect the CSV parser. > > Thanks > >