Thanks for the feedback .. here are the details ..
Just to give u some background the original API is a Scala API as follows ..
final def readStream[In: TypeInformation: DeserializationSchema](inlet: CodecInlet[In]): DataStream[In] =
context.readStream(inlet)
and the
Scala version of the code runs fine .. Here's the Java API (also written in Scala though but passing type information and deserialization schema explicitly and using the DataStream class from Flink Java) ..
final def readStream[In](inlet: CodecInlet[In], clazz: Class[In], deserializationSchema: DeserializationSchema[In]): JDataStream[In] =
context.readStream(inlet)(TypeInformation.of[In](clazz), deserializationSchema)
.javaStream
Here's the Java code for transformation where I get the error ..
DataStream<Data> ins =
this.<Data>readStream(in, Data.class, serdeData)
.map((Data d) -> d)
.returns(new TypeHint<Data>(){}.getTypeInfo());
DataStream<Simple> simples = ins.map((Data d) -> new Simple(d.getName())); // .returns(new TypeHint<Simple>(){}.getTypeInfo());
DataStreamSink<Simple> sink = writeStream(out, simples, Simple.class, serdeSimple);
Here's the corresponding Scala code that runs fine ..
val ins: DataStream[Data] = readStream(in)
val simples: DataStream[Simple] = ins.map(r ⇒ new Simple(r.getName()))
writeStream(out, simples)
Here's the custom source that's also referred in the exception .. the case class is directly used in Scala while I use the Java API that uses that case class from Java ..
object FlinkSource {
case class CollectionSourceFunction[T](data: Seq[T]) extends SourceFunction[T] {
def cancel(): Unit = {}
def run(ctx: SourceContext[T]): Unit = {
data.foreach(d ⇒ ctx.collect(d))
}
}
/**
* Java API
*/
def collectionSourceFunction[T](data: java.util.List[T]) =
CollectionSourceFunction(data.asScala.toSeq)
}
Here's how I use the custom source from Java .. (which gives exception) .. here data is a java.util.List<Data>
env.<Data>addSource(
FlinkSource.<Data>collectionSourceFunction(data)
)
and here's the Scala version, which runs fine .. here data is a scala.Seq[Data]
env.addSource(FlinkSource.CollectionSourceFunction(data))
Here's the complete exception ..
[info] org.apache.flink.api.common.functions.InvalidTypesException: The return type of function 'Custom Source' could not be determined automatically, due to type erasure. You can give type information hints by using the returns(...) method on the result of the transformation call, or by letting your function implement the 'ResultTypeQueryable' interface.
[info] at org.apache.flink.streaming.api.transformations.StreamTransformation.getOutputType(StreamTransformation.java:420)
[info] at org.apache.flink.streaming.api.datastream.DataStream.getType(DataStream.java:175)
[info] at org.apache.flink.streaming.api.datastream.DataStream.map(DataStream.java:587)
[info] at pipelines.flink.FlinkStreamletLogic.readStream(FlinkStreamlet.scala:237)
[info] at pipelines.flink.javadsl.FlinkProcessorJ$1.buildExecutionGraph(FlinkProcessorJ.java:38)
[info] at pipelines.flink.FlinkStreamletLogic.executeStreamingQueries(FlinkStreamlet.scala:282)
[info] at pipelines.flink.FlinkStreamlet.run(FlinkStreamlet.scala:151)
[info] at pipelines.flink.testkit.FlinkTestkit.doRun(FlinkTestkit.scala:146)
[info] at pipelines.flink.testkit.FlinkTestkit.run(FlinkTestkit.scala:138)
[info] at pipelines.flink.javadsl.FlinkStreamletTest.shouldProcessDataWhenItIsRun(FlinkStreamletTest.java:46)
[info] ...
[info] Cause: org.apache.flink.api.common.functions.InvalidTypesException: Type of TypeVariable 'T' in 'class pipelines.flink.testkit.FlinkSource$CollectionSourceFunction' could not be determined. This is most likely a type erasure problem. The type extraction currently supports types with generic variables only in cases where all variables in the return type can be deduced from the input type(s). Otherwise the type has to be specified explicitly using type information.
[info] at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfoWithTypeHierarchy(TypeExtractor.java:882)
[info] at org.apache.flink.api.java.typeutils.TypeExtractor.privateCreateTypeInfo(TypeExtractor.java:803)
[info] at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfo(TypeExtractor.java:769)
[info] at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1459)
[info] at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1414)
[info] at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1396)
[info] at pipelines.flink.javadsl.FlinkStreamletTest.shouldProcessDataWhenItIsRun(FlinkStreamletTest.java:34)
[info] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[info] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[info] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[info] ...
regards.