Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor MapAggregator #462

Merged
merged 4 commits into from
Jul 15, 2015

Conversation

vidma
Copy link
Contributor

@vidma vidma commented Jul 11, 2015

  • use string interpolation instead of .format()
  • inline prepare, present, semigroup
  • use more clear variable names:
    • rename i to aggrCount
    • rename nums to aggrNums
    • rename semiType to semigroup (it refers to field name, not type), add semigroupType which actually refers to type

@johnynek

- use string interpolation instead of .format()
- inline prepare, present, semigroup methods
- use more clear variable names:
  - rename i to aggrCount
  - rename nums to aggrNums
  - rename semiType to semigroup (it refers to field name, not type), add semigroupType which actually refers to type
@vidma
Copy link
Contributor Author

vidma commented Jul 11, 2015

P.S. we found it quite weird that currently having an aggregator created by MapAggregator one can't get the keys out of it:

val aggr = MapAggregator(
  "sum" -> Aggregator.sum,
  "min" -> Aggregator.min
)
// can't do this yet
val keys = aggr.keys

Looks like this would need to introduce a class MapAggregator extends Aggregator , and then define a keys method (separate PR).

|def apply[K, A, $bs, C]($inputAggs): ${aggType}Aggregator[A, $tupleBs, Map[K, C]] = {
| new ${aggType}Aggregator[A, $tupleBs, Map[K, C]] {
| def prepare(a: A) = (
| ${aggrNums.map(i => s"agg$i._2.prepare(a)").mkString(", ")}
Copy link
Collaborator

Choose a reason for hiding this comment

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

$i._2 is ambigious... well its not, but it doesn't operate like it reads. can we use ${i} here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@johnynek
Copy link
Collaborator

+1 to Ian's suggestion.

Also I like the idea of:

trait MapAggregator[A, B, K, C] extends Aggregator[A, B, Map[K, C]] {
  def keys: Set[K]
}

trait MapMonoidAggregator[A, B, K, C] extends MonoidAggregator[A, B, Map[K, C]] {
  def keys: Set[K]
}

@johnynek
Copy link
Collaborator

much cleaner code-gen! Thanks.

johnynek added a commit that referenced this pull request Jul 15, 2015
@johnynek johnynek merged commit 2bdab21 into twitter:develop Jul 15, 2015
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.

3 participants