Vignesh Venkataraman
03/28/2023, 7:04 PMUsers can now leverage the Java API from any Scala version
Im finding it a little hard to understand the above message, please let me know if its possible process using Flink through scala? And i would highly appreciate it if the community could also share some Scala-Flink tutorialsMartijn Visser
03/28/2023, 7:06 PMMartijn Visser
03/28/2023, 7:06 PMVignesh Venkataraman
03/28/2023, 7:30 PMVignesh Venkataraman
03/28/2023, 7:31 PMimport org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.api.common.functions.FilterFunction;
public class Example {
public static void main(String[] args) throws Exception {
final StreamExecutionEnvironment env =
StreamExecutionEnvironment.getExecutionEnvironment();
DataStream<Person> flintstones = env.fromElements(
new Person("Fred", 35),
new Person("Wilma", 35),
new Person("Pebbles", 2));
DataStream<Person> adults = flintstones.filter(new FilterFunction<Person>() {
@Override
public boolean filter(Person person) throws Exception {
return person.age >= 18;
}
});
adults.print();
env.execute();
}
public static class Person {
public String name;
public Integer age;
public Person() {}
public Person(String name, Integer age) {
this.name = name;
this.age = age;
}
public String toString() {
return this.name.toString() + ": age " + this.age.toString();
}
}
}Vignesh Venkataraman
03/28/2023, 7:31 PMimport org.apache.flink.streaming.api.scala._
import org.apache.flink.api.common.functions.FilterFunction
object Example {
def main(args: Array[String]) {
val env = StreamExecutionEnvironment.getExecutionEnvironment
val flintstones = env.fromElements(
new Person("Fred", 35),
new Person("Wilma", 35),
new Person("Pebbles", 2))
val adults = flintstones.filter(new FilterFunction[Person] {
override def filter(person: Person): Boolean = {
person.age >= 18
}
})
adults.print()
env.execute("Example")
}
class Person(var name: String, var age: Int) {
def this() {
this("", 0)
}
override def toString: String = {
name + ": age " + age.toString
}
}
}Vignesh Venkataraman
03/28/2023, 7:32 PMsap1ens
03/28/2023, 8:19 PMsap1ens
03/28/2023, 8:19 PMVignesh Venkataraman
03/28/2023, 10:43 PMFilterFunction method correctly used in the above scala code?
As per the Java API docs - https://nightlies.apache.org/flink/flink-docs-release-1.17/api/java/ FilterFunction is a interface with filter methodsap1ens
03/28/2023, 10:48 PM