Repository navigation
Publish AnalyzedItems to Cassandra - #28
Conversation
We can only have a single Spark Context running per JVM so splitting the tests out over multiple specs is more hassle than it's worth spending time to figure out right now.
Smarker
left a comment
There was a problem hiding this comment.
Everything else looks good.
|
|
||
| object Utils { | ||
| def mean(items: List[Double]): Double = { | ||
| items.sum / items.length |
There was a problem hiding this comment.
What if the length of items is 0? Wouldn't this cause an error?
| def rescale(items: List[Double], min_new: Double, max_new: Double): List[Double] = { | ||
| val min_old = items.min | ||
| val max_old = items.max | ||
| val coef = (max_new - min_new) / (max_old - min_old) |
There was a problem hiding this comment.
If max_old == min_old, the denominator would be 0. Maybe put a check for this?
e13eef1 to
f34f55a
Compare
| @@ -0,0 +1,6 @@ | |||
| package com.microsoft.partnercatalyst.fortis.spark.transforms.gender | |||
|
|
|||
| object GenderDetector { | |||
There was a problem hiding this comment.
May I suggest adding extends Enumeration here?
jcjimenez
left a comment
There was a problem hiding this comment.
LGTM with the division by zero check
erikschlegel
left a comment
There was a problem hiding this comment.
Looks great. Nice work. Left some comments around offloading the uuid() call to cassandra.
Starting next week, I'll add the pieces to aggregate the results by place, tile and topic and make the saveToCassnadra call for each.
| import transformContext._ | ||
|
|
||
| stream.map(tada => AnalyzedItem( | ||
| id = randomUUID(), |
There was a problem hiding this comment.
This should be called via the uuid() function in cassandra.
There was a problem hiding this comment.
The advantage of creating the id early is that we have a way to track every event through the pipeline (e.g. useful when logging). Is this benefit worth explicitly creating the UUID?
|
|
||
| private def convertToSchema(stream: DStream[RadioTranscription], transformContext: TransformContext): DStream[AnalyzedItem] = { | ||
| stream.map(transcription => AnalyzedItem( | ||
| id = randomUUID(), |
There was a problem hiding this comment.
This should be called via the uuid() function in cassandra.
| // do computer vision analysis | ||
| val analysis = imageAnalyzer.analyze(instagram.images.standard_resolution.url) | ||
| AnalyzedItem( | ||
| id = randomUUID(), |
There was a problem hiding this comment.
This should be called via the uuid() function in cassandra.
| import scala.collection.mutable | ||
|
|
||
| class StreamProviderSpec extends FlatSpec with BeforeAndAfter { | ||
| class SparkSpec extends FlatSpec with BeforeAndAfter { |
There was a problem hiding this comment.
I would ideally like to keep the StreamProviderSpec separate since the StreamProvider package is an isolated component that could be moved out to a library at any time (and it'd be nice to take the test spec with it).
There was a problem hiding this comment.
As per the comment on 629e5d3, we can only have a single Spark Context running per JVM so I merged all the tests for now (they were previously split but it's non-trivial to get that to work). If this becomes an issue, we can spend the time to figure out how to split the tests.
There was a problem hiding this comment.
I briefly looked into using the spark-testing-base package but they don't have anything built-in for Spark Streaming. I started working on a streaming extension but got some odd errors so preferred to just push this for now. I'll look more into this when I get a free minute.
For now, using a test keyspace and table on the cluster that Erik set up:
There will be some follow-up work required to adapt the
CassandraSchemaclass once our events schema is finalized.Resolves #14