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
d8ee184d
Commit
d8ee184d
authored
12 years ago
by
Nick Pentreath
Browse files
Options
Downloads
Patches
Plain Diff
Dependencies and refactoring for streaming HLL example, and using context.twitterStream method
parent
315ea069
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/pom.xml
+0
-6
0 additions, 6 deletions
examples/pom.xml
examples/src/main/scala/spark/streaming/examples/TwitterAlgebirdHLL.scala
+14
-15
14 additions, 15 deletions
...n/scala/spark/streaming/examples/TwitterAlgebirdHLL.scala
streaming/pom.xml
+10
-0
10 additions, 0 deletions
streaming/pom.xml
with
24 additions
and
21 deletions
examples/pom.xml
+
0
−
6
View file @
d8ee184d
...
...
@@ -19,17 +19,11 @@
<groupId>
org.eclipse.jetty
</groupId>
<artifactId>
jetty-server
</artifactId>
</dependency>
<dependency>
<groupId>
org.twitter4j
</groupId>
<artifactId>
twitter4j-stream
</artifactId>
<version>
3.0.3
</version>
</dependency>
<dependency>
<groupId>
com.twitter
</groupId>
<artifactId>
algebird-core_2.9.2
</artifactId>
<version>
0.1.8
</version>
</dependency>
<dependency>
<groupId>
org.scalatest
</groupId>
<artifactId>
scalatest_${scala.version}
</artifactId>
...
...
This diff is collapsed.
Click to expand it.
examples/src/main/scala/spark/streaming/examples/
t
witter
/Streaming
HLL.scala
→
examples/src/main/scala/spark/streaming/examples/
T
witter
Algebird
HLL.scala
+
14
−
15
View file @
d8ee184d
package
spark.streaming.examples
.twitter
package
spark.streaming.examples
import
spark.streaming.
{
Seconds
,
StreamingContext
}
import
spark.storage.StorageLevel
...
...
@@ -7,44 +7,43 @@ import com.twitter.algebird.HyperLogLogMonoid
import
spark.streaming.dstream.TwitterInputDStream
/**
* Example
of
using HyperLogLog monoid from Twitter's Algebird together with Spark Streaming's
* TwitterInputDStream
* Example using HyperLogLog monoid from Twitter's Algebird together with Spark Streaming's
* TwitterInputDStream
to compute approximate distinct counts of userids.
*/
object
Streaming
HLL
{
object
TwitterAlgebird
HLL
{
def
main
(
args
:
Array
[
String
])
{
if
(
args
.
length
<
3
)
{
System
.
err
.
println
(
"Usage: Twitter
Streaming
HLL <master> <twitter_username> <twitter_password>"
+
System
.
err
.
println
(
"Usage: Twitter
Algebird
HLL <master> <twitter_username> <twitter_password>"
+
" [filter1] [filter2] ... [filter n]"
)
System
.
exit
(
1
)
}
/** Bit size parameter for HyperLogLog */
val
BIT_SIZE
=
12
val
Array
(
master
,
username
,
password
)
=
args
.
slice
(
0
,
3
)
val
filters
=
args
.
slice
(
3
,
args
.
length
)
val
ssc
=
new
StreamingContext
(
master
,
"TwitterStreamingHLL"
,
Seconds
(
2
))
val
stream
=
new
TwitterInputDStream
(
ssc
,
username
,
password
,
filters
,
StorageLevel
.
MEMORY_ONLY_SER
)
ssc
.
registerInputStream
(
stream
)
val
ssc
=
new
StreamingContext
(
master
,
"TwitterAlgebirdHLL"
,
Seconds
(
5
))
val
stream
=
ssc
.
twitterStream
(
username
,
password
,
filters
,
StorageLevel
.
MEMORY_ONLY_SER
)
val
users
=
stream
.
map
(
status
=>
status
.
getUser
.
getId
)
va
l
globalHll
=
new
HyperLogLogMonoid
(
12
)
va
r
globalHll
=
new
HyperLogLogMonoid
(
BIT_SIZE
).
zero
var
userSet
:
Set
[
Long
]
=
Set
()
val
approxUsers
=
users
.
mapPartitions
(
ids
=>
{
val
hll
=
new
HyperLogLogMonoid
(
12
)
val
hll
=
new
HyperLogLogMonoid
(
BIT_SIZE
)
ids
.
map
(
id
=>
hll
(
id
))
}).
reduce
(
_
+
_
)
val
exactUsers
=
users
.
map
(
id
=>
Set
(
id
)).
reduce
(
_
++
_
)
var
h
=
globalHll
.
zero
approxUsers
.
foreach
(
rdd
=>
{
if
(
rdd
.
count
()
!=
0
)
{
val
partial
=
rdd
.
first
()
h
+=
partial
globalHll
+=
partial
println
(
"Approx distinct users this batch: %d"
.
format
(
partial
.
estimatedSize
.
toInt
))
println
(
"Approx distinct users overall: %d"
.
format
(
globalHll
.
estimateSize
(
h
)
.
toInt
))
println
(
"Approx distinct users overall: %d"
.
format
(
globalHll
.
estimate
d
Size
.
toInt
))
}
})
...
...
@@ -54,7 +53,7 @@ object StreamingHLL {
userSet
++=
partial
println
(
"Exact distinct users this batch: %d"
.
format
(
partial
.
size
))
println
(
"Exact distinct users overall: %d"
.
format
(
userSet
.
size
))
println
(
"Error rate: %2.5f%%"
.
format
(((
globalHll
.
estimateSize
(
h
)
/
userSet
.
size
.
toDouble
)
-
1
)
*
100
))
println
(
"Error rate: %2.5f%%"
.
format
(((
globalHll
.
estimate
d
Size
/
userSet
.
size
.
toDouble
)
-
1
)
*
100
))
}
})
...
...
This diff is collapsed.
Click to expand it.
streaming/pom.xml
+
10
−
0
View file @
d8ee184d
...
...
@@ -47,6 +47,16 @@
<artifactId>
zkclient
</artifactId>
<version>
0.1
</version>
</dependency>
<dependency>
<groupId>
org.twitter4j
</groupId>
<artifactId>
twitter4j-stream
</artifactId>
<version>
3.0.3
</version>
</dependency>
<dependency>
<groupId>
org.twitter4j
</groupId>
<artifactId>
twitter4j-core
</artifactId>
<version>
3.0.3
</version>
</dependency>
<dependency>
<groupId>
org.scalatest
</groupId>
...
...
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