Search code examples
apache-flinkflink-streaming

How to get value by FieldName in a Flink Row?


I have a method def process(row: org.apache.flink.types.Row, fieldName: String) : Unit = ???

And the processing I want to do requires me to extract a field by the name of fieldName. I can see that the Row api allows you to extract by order, but not by name.

I guess the users will have to pass me schema information, so the method will look like def process(row: org.apache.flink.types.Row, rowSchema: ???, fieldName: String) : Unit = ???.

I've looked into org.apache.flink.table.types.logical.RowType and TypeInformation for the schema information but neither of them seem right. What's the best way to go here?


Solution

  • Looks like I need org.apache.flink.api.java.typeutils.RowTypeInfo. It has method getFieldIndex(String fieldName)