java-20079: upgrade apache-spark module libraries (#14087)
This commit is contained in:
+5
-1
@@ -16,8 +16,11 @@ import org.apache.log4j.Logger;
|
||||
import org.apache.spark.SparkConf;
|
||||
import org.apache.spark.api.java.JavaRDD;
|
||||
import org.apache.spark.api.java.JavaSparkContext;
|
||||
import org.apache.spark.api.java.Optional;
|
||||
import org.apache.spark.api.java.function.Function2;
|
||||
import org.apache.spark.api.java.function.Function3;
|
||||
import org.apache.spark.streaming.Durations;
|
||||
import org.apache.spark.streaming.State;
|
||||
import org.apache.spark.streaming.StateSpec;
|
||||
import org.apache.spark.streaming.api.java.JavaDStream;
|
||||
import org.apache.spark.streaming.api.java.JavaInputDStream;
|
||||
@@ -74,7 +77,8 @@ public class WordCountingAppWithCheckpoint {
|
||||
JavaPairDStream<String, Integer> wordCounts = words.mapToPair(s -> new Tuple2<>(s, 1))
|
||||
.reduceByKey((Function2<Integer, Integer, Integer>) (i1, i2) -> i1 + i2);
|
||||
|
||||
JavaMapWithStateDStream<String, Integer, Integer, Tuple2<String, Integer>> cumulativeWordCounts = wordCounts.mapWithState(StateSpec.function((word, one, state) -> {
|
||||
JavaMapWithStateDStream<String, Integer, Integer, Tuple2<String, Integer>> cumulativeWordCounts =
|
||||
wordCounts.mapWithState(StateSpec.function((Function3<String, Optional<Integer>, State<Integer>, Tuple2<String, Integer>>) (word, one, state) -> {
|
||||
int sum = one.orElse(0) + (state.exists() ? state.get() : 0);
|
||||
Tuple2<String, Integer> output = new Tuple2<>(word, sum);
|
||||
state.update(sum);
|
||||
|
||||
@@ -9,6 +9,7 @@ public class SparkDriver implements Serializable {
|
||||
public static SparkSession getSparkSession() {
|
||||
return SparkSession.builder()
|
||||
.appName("Customer Aggregation pipeline")
|
||||
.config("spark.sql.legacy.timeParserPolicy", "LEGACY")
|
||||
.master("local")
|
||||
.getOrCreate();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user