Skip to content

Conversation

@DanielleSucher
Copy link
Collaborator

Add a MapAggregator to join tuples of (K, Aggregator[A, Bn, C]) pairs
into a composed Aggregator[A, TupleN[B1,...,BN], Map[K, C]].

cc @avibryant @mlmanapat

@avibryant
Copy link
Contributor

I could be wrong about this but I think it would be more usable if the apply methods took N Tuple2 parameters instead of a single TupleN[Tuple2...]. As a practical matter, that means you wouldn't need the extra set of parens and constructing a MapAggregator would look almost exactly like constructing a Map: MapAggregator("min" -> Aggregator.min, "max" -> Aggregator.max).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests would be more informative if there were different aggregators used for each key. It would also be a better test if the aggregators had different intermediate types (like, the B in the agg's A, B, C type params).

@johnynek
Copy link
Collaborator

johnynek commented Feb 7, 2015

+1 to Avi's suggestion. Also, not that it is super important: but are you planning to use this or is it just a nice generalization? The reason I ask is that I'm surprised that the result type (V is the map) is homogenous across a wide variety of aggregations. Of course, Double might be common enough.

@avibryant
Copy link
Contributor

Yeah, Double is quite common for us. Also, you can imagine using an Either type or something similar (like brushfire's 4-way Dispatched) to unify disparate aggregation results into a single V.

DanielleSucher and others added 2 commits February 12, 2015 01:16
Add a MapAggregator to join tuples of (K, Aggregator[A, Bn, C]) pairs
into a composed Aggregator[A, TupleN[B1,...,BN], Map[K, C]].
@DanielleSucher
Copy link
Collaborator Author

Totally convinced, made the suggested changes! cc @mlmanapat

johnynek added a commit that referenced this pull request Feb 17, 2015
Add MapAggregator to compose tuples of (key, agg) pairs
@johnynek johnynek merged commit a303a6a into twitter:develop Feb 17, 2015
@johnynek
Copy link
Collaborator

Thanks, @DanielleSucher!

@vidma
Copy link
Contributor

vidma commented May 21, 2015

For consistency/simplicity-of-use, we're missing the ability to generate Tuple or Map aggregator from one entry...

at the moment we'he hacked up this:

  /**
   * makes an aggregator returning a Tuple1[Metric]
   * this allows to keep aggregator definition consistent with GeneratedTupleAggregator.fromN
   */
  def tupleAggrFrom1[A, B, C](agg: Aggregator[A, B, C]): Aggregator[A, B, scala.Tuple1[C]] = {
    agg.andThenPresent(Tuple1(_))
  }

  // for the MapAggregator
  def mapAggrFrom1[A, B, C <: AnyVal](aggDef: (String, Aggregator[A, B, C])): Aggregator[A, B, Map[String, AnyVal]] = {
    val (key, agg) = aggDef
    agg.andThenPresent(value => Map(key -> value))
  }

it would be nice to have these methods in algebird too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants