0

I have the below piece of code in my scala program that uses Flink's Table API.

val custTS = new CsvTableSource("D:\\input\\customerinfo.csv", 
                               Array("customerId","name","address","zip"),
                               Array(String,String,String,Long))

The editor is displaying error at the third line for the three 'String's with the error message "Object java.lang.String not a value". 'String' is used in many other places in the rest of the code. But it doesn't throw error anywhere else. I saw a couple of Stackoverflow questions with similar issues mentioned, but I couldn't fix this based on the solutions mentioned. The imports in the program are given below.

import org.apache.flink.api.scala._
import org.apache.flink.table.api.TableEnvironment
import org.apache.flink.table.api.scala._
import org.apache.flink.table.sinks.CsvTableSink
import org.apache.flink.table.sources.CsvTableSource

I have used 'String' in many other scala programs for Flink. But I haven't encountered such an error in any of those programs.

1 Answer 1

2

First of all you can't use types (in this case String) as a value in Array. Collections stores objects. You should pass array of type Array[TypeInformation[_]].

So it should look like:

import org.apache.flink.table.api.Types

val custTS = new CsvTableSource(
  "D:\\input\\customerinfo.csv",
  Array("customerId", "name", "address", "zip"),
  Array[TypeInformation[_]](Types.STRING, Types.STRING, Types.STRING, Types.LONG)
  )

Unfortunately right now you have to explicitly provide type for the Array. For reasons why, you can have a look at this discussion.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Dawid. That solved the problem. In the previous code, I had used the code snippet from the link "slideshare.net/fhueske/…" as my reference. But I guess they were supposed to be guidelines and not to be used directly in the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.