1

Converting java to scala code I face a strange Problem An example can be found here https://gist.github.com/geoHeil/895260a04d3673b9848b345edf388a2d The error is

[error] src/main/scala/myOrg/CustomInputMapperWKT.scala:17: overriding method call in trait FlatMapFunction of type (x$1: String)java.util.Iterator[Any];
[error]  method call has incompatible type
[error]   override def call(line: String): Iterator[_] = {

When trying to convert spark java to spark scala API I am struggling to port this java class https://github.com/DataSystemsLab/GeoSpark/blob/master/src/main/java/org/datasyslab/geospark/showcase/UserSuppliedPolygonMapper.java#L59-L81 to scala.

Where

class CustomInputMapperWKT extends FlatMapFunction[String, Any] {
....
override def call(line: String): Iterator[_] = {
val result: collection.Seq[Polygon] with Growable[Polygon] = mutable.Buffer[Polygon]()
result.iterator
  }
}

is the minimal sample describing the problem.

edit

Trying to fix a possible typing problem I substituted Any with its respective type of polygon. But that doesn't help to Fox the problem.

1 Answer 1

2

Have you tried this signature?

override def call(t: String): java.util.Iterator[Any] = {
...

Because this code example is compiled successfully:

import org.apache.spark.api.java.function.FlatMapFunction
import collection.JavaConverters._

class CustomInputMapperWKT extends FlatMapFunction[String, Any] {
  override def call(t: String): java.util.Iterator[Any] = {
    ...
    result.iterator.asJava
  }
}
Sign up to request clarification or add additional context in comments.

5 Comments

This is partly on the right track. the new Problem now is that val result: collection.Seq[Polygon] with Growable[Polygon] = mutable.Buffer[Polygon]() when called as result.iterator will not produce a java.util.iterator but rather type mismatch; [error] found : Iterator[com.vividsolutions.jts.geom.Polygon] [error] required: java.util.Iterator[com.vividsolutions.jts.geom.Polygon]
can you use JavaConverters as I did? docs.scala-lang.org/overviews/collections/…
When using val javaList: java.util.List[Polygon] = scala.collection.JavaConversions.seqAsJavaList(result) javaList.iterator() it will compile but that is not clean scala code. Do you see an alternative? Strangely the implicit mapper will not work.
if return of result.iterator.asJava doesn't work, it will be hard to say right now
looks like that. strange.

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.