-
Notifications
You must be signed in to change notification settings - Fork 266
Pass the semigroup to create Mergeable online #687
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
package com.twitter.summingbird.online | ||
|
||
import com.twitter.algebird.Semigroup | ||
import com.twitter.storehaus.algebra.{ MergeableStore, Mergeable, StoreAlgebra } | ||
import com.twitter.summingbird.batch.{ Batcher, BatchID } | ||
|
||
|
@@ -26,23 +27,28 @@ import com.twitter.summingbird.batch.{ Batcher, BatchID } | |
*/ | ||
object MergeableStoreFactory { | ||
|
||
def apply[K, V](store: () => Mergeable[K, V], batcher: Batcher) = { | ||
def apply[K, V](store: () => Mergeable[K, V], batcher: Batcher) = | ||
fromWithSemigroup { _: Semigroup[V] => store() }(batcher) | ||
|
||
def from[K, V](store: => Mergeable[(K, BatchID), V])(implicit batcher: Batcher): MergeableStoreFactory[(K, BatchID), V] = | ||
fromWithSemigroup(_ => store) | ||
|
||
def fromWithSemigroup[K, V](fn: Semigroup[V] => Mergeable[K, V])(implicit batcher: Batcher): MergeableStoreFactory[K, V] = | ||
new MergeableStoreFactory[K, V] { | ||
def mergeableStore = store | ||
def mergeableStore = fn | ||
def mergeableBatcher = batcher | ||
} | ||
} | ||
|
||
def from[K, V](store: => Mergeable[(K, BatchID), V])(implicit batcher: Batcher): MergeableStoreFactory[(K, BatchID), V] = | ||
apply({ () => store }, batcher) | ||
|
||
def fromOnlineOnly[K, V](store: => MergeableStore[K, V]): MergeableStoreFactory[(K, BatchID), V] = { | ||
implicit val batcher = Batcher.unit | ||
from(store.convert { k: (K, BatchID) => k._1 }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. good call. |
||
} | ||
|
||
def fromOnlineOnlyWithSemigroup[K, V](fn: Semigroup[V] => MergeableStore[K, V]): MergeableStoreFactory[(K, BatchID), V] = | ||
fromWithSemigroup(fn.andThen(_.convert { k: (K, BatchID) => k._1 }))(Batcher.unit) | ||
} | ||
|
||
trait MergeableStoreFactory[-K, V] extends java.io.Serializable { | ||
def mergeableStore: () => Mergeable[K, V] | ||
def mergeableStore: Semigroup[V] => Mergeable[K, V] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point it seems like this method should be named like a function and not a property. Earlier it was in the spirit of lazily created mergeable store so the name was ok. Should we call it createMergeableStore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I'm a little nervous about that because it lead to a lot of serialization problems before (which is why we did this). Calling a method is still lazy, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't mean to suggest we change the structure, just the name. MergeableStoreFactory.mergeableStore reads like a property which would provide a mergeable store but it is a function that takes an input to provide a mergeable store. e.g. when I read factory.mergeableStore I would think that this is a mergeable store object, finding out that it is a function that needs a semigroup as input to produce a mergeable store would be a surprise. |
||
def mergeableBatcher: Batcher | ||
} |
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.
Inconsistency between
_
and()
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.
what do you mean? They mean different things.
_: Semigroup[V]
is being ignored here.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.
Ah, of course