-
Notifications
You must be signed in to change notification settings - Fork 347
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
Refactor MapAggregator #462
Conversation
- 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
P.S. we found it quite weird that currently having an aggregator created by 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 |
|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(", ")} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
+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]
} |
much cleaner code-gen! Thanks. |
prepare
,present
,semigroup
@johnynek