You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If on every reduce operation or join we counted the number of values for the key (say N_v), and then incremented a counter by N_v^2, then since map-reduce gives the number of groups, and the number of input and output records, we could compute the standard deviation of the (values per key). If we compare that to the mean of (values per key) we get some idea of the skew. I don't think we would overflow a long counter with this, in most cases, but it is possible (probably we can't directly compute the third standard moment, which is more directly skew), but I think the stdev might be enough in most cases.
We probably want the incoming skew and the outgoing skew. For standard sums/reduces/folds, the outgoing stdev should be 0 since each key has one value.
where is the "reduce operation or join" you mentioned located in the code? (I guess it's scalding/scalding-core/src/main/scala/com/twitter/scalding/ReduceOperations.scala) but not 100% sure
why we want to add N_v^2? Is it for the convenience to do sqrt(E[x^2] - E[x]^2) and get std?
where (in the code) can I get the number of input and output records? is the number of output records equal to number of keys, and thus we could get the mean?
Hadoop already keeps the number of key groups and the total number of pairs, so this gives you values/key. What we need to get (as you point out) is the \sum_k v_k^2 where v_k is the number of values for key k. With that, we can compute the Var[V] where V is the random variable of the number of values for a randomly selected key.
Have been thinking about this a bit for today (and also read a bit more related part by searching "Counter" in the core-package), and I'm wondering where shall I put this counter class?
i.e. I'm not sure how to expose it for others to use. Seems like the only other counter in core is Stat. Shall I put this
class KeyValueCounter(val nKey: Long, val valuesSquaredSum: Double, val valuesSum: Double) {
The cascading flowProcess gives access to the counter mechanism, so you should be able to increment that directly in the places where we put this statistic.
Activity
oeddyo commentedon May 6, 2015
Taking a look.
May I have a bit more hints here?
where is the "reduce operation or join" you mentioned located in the code? (I guess it's scalding/scalding-core/src/main/scala/com/twitter/scalding/ReduceOperations.scala) but not 100% sure
why we want to add N_v^2? Is it for the convenience to do sqrt(E[x^2] - E[x]^2) and get std?
where (in the code) can I get the number of input and output records? is the number of output records equal to number of keys, and thus we could get the mean?
johnynek commentedon May 6, 2015
Hadoop already keeps the number of key groups and the total number of pairs, so this gives you values/key. What we need to get (as you point out) is the
\sum_k v_k^2wherev_kis the number of values for keyk. With that, we can compute theVar[V]whereVis the random variable of the number of values for a randomly selected key.To get the number of values for a key, we need to look at https://github.com/twitter/scalding/blob/develop/scalding-core/src/main/scala/com/twitter/scalding/Operations.scala#L480 TypedBufferOp. Not on 496, we iterate through the iterator, so we could increment a counter at the end with the size squared.
For the case of joins, it is more complex (and probably should use a different stat key). That code is here: https://github.com/twitter/scalding/blob/develop/scalding-core/src/main/scala/com/twitter/scalding/typed/CoGrouped.scala#L306 - we might want a key for each of the join inputs, or maybe just the output. It's not clear. We can take it in two PRs.
oeddyo commentedon May 7, 2015
Thanks @johnynek for the help.
Currently I have the "proof of concept" PR.
Basically what I'm doing is:
Create a simple test, to do a reduce. The data I'm using is
TypedPipe.from(List((1, 2), (1, 3), (2, 3), (2, 5), (3, 1000)))
then I did: test-only com.twitter.scalding.ExperimentTest
And I'm doing a print in
However, the variable printed for t2 is unexpected.
The output for above is:
t2 = 5
t2 = 8
t2 = 1000
RES = ArrayBuffer((1,5), (2,8), (3,1000))
But I was expecting
t2 = Iteraor[Int](2, 3) // For key 1
t2 = Iterator[Int](3, 5) // For key 2
It seems to be the case that "+" is associative and then reduce somehow combined them before going to the while loop?
Because of this, the size of values (i.e. values.size) is always one. Is there any way I could get around this?
oeddyo commentedon May 12, 2015
It seems to prove my theory that simply doing reduce on Int would trigger some sort of mechanism without calling the reduce function?
Since if I do:
TypedPipe.from(List((1, (1, 1)), (2, (2, 2)), (1, (3, 3)), (3, (3, 3))))
.group
.foldLeft((0, 0)){ (a, b) => (a._1 + b._1, a._2 + b._2) }
.toTypedPipe
.map{
case (a: Int, (b: Int, c: Int)) =>
(a, b, c)
}
.write(TypedTsv(Int, Int, Int))
}
I was able to get the size of the values
oeddyo commentedon May 12, 2015
Have been thinking about this a bit for today (and also read a bit more related part by searching "Counter" in the core-package), and I'm wondering where shall I put this counter class?
i.e. I'm not sure how to expose it for others to use. Seems like the only other counter in core is Stat. Shall I put this
class KeyValueCounter(val nKey: Long, val valuesSquaredSum: Double, val valuesSum: Double) {
into a Stat instead?
johnynek commentedon May 14, 2015
The cascading flowProcess gives access to the counter mechanism, so you should be able to increment that directly in the places where we put this statistic.