scala - Access key from mapValues or flatMapValues? -
in spark 1.3, there way access key mapvalues?
specifically, if have
val y = x.groupby(somekey) val z = y.mapvalues(somefun) can somefun know key of y operating on?
or have do
val y = x.map(r => (somekey(r), r)).groupby(_._1) val z = y.mapvalues{ case (k, r) => somefun(r, k) } note: reason want use mapvalues rather map preserve partitioning.
you can't use key mapvalues. can preserve partitioning mappartitions.
val pairs: rdd[(int, int)] = ??? pairs.mappartitions({ => it.map { case (k, v) => // code } }, preservespartitioning = true) be careful preserve partitioning, compiler not able check it.
Comments
Post a Comment