Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
15a2ab5f
Commit
15a2ab5f
authored
10 years ago
by
Sean Owen
Browse files
Options
Downloads
Patches
Plain Diff
Revise formatting of previous commit
f80e2629
parent
f80e2629
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/src/main/java/org/apache/spark/examples/streaming/JavaStatefulNetworkWordCount.java
+18
-18
18 additions, 18 deletions
...park/examples/streaming/JavaStatefulNetworkWordCount.java
with
18 additions
and
18 deletions
examples/src/main/java/org/apache/spark/examples/streaming/JavaStatefulNetworkWordCount.java
+
18
−
18
View file @
15a2ab5f
...
...
@@ -39,7 +39,6 @@ import org.apache.spark.streaming.api.java.JavaPairDStream;
import
org.apache.spark.streaming.api.java.JavaReceiverInputDStream
;
import
org.apache.spark.streaming.api.java.JavaStreamingContext
;
/**
* Counts words cumulatively in UTF8 encoded, '\n' delimited text received from the network every
* second starting with initial value of word count.
...
...
@@ -65,17 +64,17 @@ public class JavaStatefulNetworkWordCount {
StreamingExamples
.
setStreamingLogLevels
();
// Update the cumulative count function
final
Function2
<
List
<
Integer
>,
Optional
<
Integer
>,
Optional
<
Integer
>>
updateFunction
=
new
Function2
<
List
<
Integer
>,
Optional
<
Integer
>,
Optional
<
Integer
>>()
{
@Override
public
Optional
<
Integer
>
call
(
List
<
Integer
>
values
,
Optional
<
Integer
>
state
)
{
Integer
newSum
=
state
.
or
(
0
);
for
(
Integer
value
:
values
)
{
newSum
+=
value
;
}
return
Optional
.
of
(
newSum
);
}
};
final
Function2
<
List
<
Integer
>,
Optional
<
Integer
>,
Optional
<
Integer
>>
updateFunction
=
new
Function2
<
List
<
Integer
>,
Optional
<
Integer
>,
Optional
<
Integer
>>()
{
@Override
public
Optional
<
Integer
>
call
(
List
<
Integer
>
values
,
Optional
<
Integer
>
state
)
{
Integer
newSum
=
state
.
or
(
0
);
for
(
Integer
value
:
values
)
{
newSum
+=
value
;
}
return
Optional
.
of
(
newSum
);
}
};
// Create the context with a 1 second batch size
SparkConf
sparkConf
=
new
SparkConf
().
setAppName
(
"JavaStatefulNetworkWordCount"
);
...
...
@@ -97,12 +96,13 @@ public class JavaStatefulNetworkWordCount {
}
});
JavaPairDStream
<
String
,
Integer
>
wordsDstream
=
words
.
mapToPair
(
new
PairFunction
<
String
,
String
,
Integer
>()
{
@Override
public
Tuple2
<
String
,
Integer
>
call
(
String
s
)
{
return
new
Tuple2
<
String
,
Integer
>(
s
,
1
);
}
});
JavaPairDStream
<
String
,
Integer
>
wordsDstream
=
words
.
mapToPair
(
new
PairFunction
<
String
,
String
,
Integer
>()
{
@Override
public
Tuple2
<
String
,
Integer
>
call
(
String
s
)
{
return
new
Tuple2
<
String
,
Integer
>(
s
,
1
);
}
});
// This will give a Dstream made of state (which is the cumulative count of the words)
JavaPairDStream
<
String
,
Integer
>
stateDstream
=
wordsDstream
.
updateStateByKey
(
updateFunction
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment