Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Spark Sample Code
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CSN21 DSP
Spark Sample Code
Commits
e79e9da0
Commit
e79e9da0
authored
3 years ago
by
Fellner, Sebastian
Browse files
Options
Downloads
Patches
Plain Diff
Small tweaks
parent
175c4eab
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
average.py
+4
-2
4 additions, 2 deletions
average.py
wordcount.py
+1
-1
1 addition, 1 deletion
wordcount.py
with
5 additions
and
3 deletions
average.py
+
4
−
2
View file @
e79e9da0
...
...
@@ -9,17 +9,18 @@ Example: Calculates running averages of raw numerical data.
"""
def
main
():
sc
=
SparkContext
(
MASTER
,
"
spark-dsp-wordcount
"
)
# Use
"
batches
"
of 2 seconds each
# Use batches of 2 seconds each
ssc
=
StreamingContext
(
sc
,
2
)
# This directory will be used to store checkpoints
# Allows recovery from errors without data loss
ssc
.
checkpoint
(
"
checkpoint/average
"
)
# Create a stream based on raw data
lines
=
ssc
.
textFileStream
(
"
numeric-data
"
)
results
=
(
lines
.
map
(
lambda
line
:
float
(
line
))
# Filtering operation: Only keep non-negative values
.
filter
(
lambda
x
:
x
>=
0
)
# Enhancement operation: Pair each value with "1" (necessary
by
aggregation below)
# Enhancement operation: Pair each value with "1" (necessary
for
aggregation below)
.
map
(
lambda
x
:
(
x
,
1
))
# Aggregation operation: Calculate sums and counts per window
# Uses a sliding window, i.e., values can be part of multiple windows
...
...
@@ -29,6 +30,7 @@ def main():
# Calculate the average per sliding window
.
map
(
lambda
aggr
:
aggr
[
0
]
/
aggr
[
1
])
)
# Continuously print the resulting stream
results
.
pprint
()
ssc
.
start
()
...
...
This diff is collapsed.
Click to expand it.
wordcount.py
+
1
−
1
View file @
e79e9da0
...
...
@@ -5,7 +5,7 @@ from pyspark.streaming import StreamingContext
MASTER
=
"
local[*]
"
"""
Example: Counts the number of
word
occurrences of a text input stream.
Example: Counts the number of occurrences
for each word
of a text input stream.
"""
def
main
():
sc
=
SparkContext
(
MASTER
,
"
spark-dsp-wordcount
"
)
...
...
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