How to use Column.isin in Java?

2020-01-29 16:53发布

问题:

I'm trying to filter a Spark DataFrame using a list in Java.

java.util.List<Long> selected = ....;
DataFrame result = df.filter(df.col("something").isin(????));

The problem is that isin(...) method accepts Scala Seq or varargs.

Passing in JavaConversions.asScalaBuffer(selected) doesn't work either.

Any ideas?

回答1:

Use stream method as follows:

df.filter(col("something").isin(selected.stream().toArray(String[]::new))))


回答2:

A bit shorter version would be:

df.filter(col("something").isin(selected.toArray()));