From 2a3e967bbfe415aec91fd49cb017fae3554baf13 Mon Sep 17 00:00:00 2001 From: Ian O Connell Date: Mon, 16 Dec 2013 10:19:20 -0800 Subject: [PATCH 1/2] Adds the ability to add an Optional component onto any strategy --- .../twitter/storehaus/algebra/query/QueryStrategy.scala | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/storehaus-algebra/src/main/scala/com/twitter/storehaus/algebra/query/QueryStrategy.scala b/storehaus-algebra/src/main/scala/com/twitter/storehaus/algebra/query/QueryStrategy.scala index 151a6937..700b8d47 100644 --- a/storehaus-algebra/src/main/scala/com/twitter/storehaus/algebra/query/QueryStrategy.scala +++ b/storehaus-algebra/src/main/scala/com/twitter/storehaus/algebra/query/QueryStrategy.scala @@ -37,6 +37,15 @@ trait QueryStrategy[-Q,-L,X] extends Serializable { self => /** Used in your summingbird job to flatmap your keys, increment all these X with the value */ def index(key: L): Set[X] + def withOptionalStrategy: QueryStrategy[Option[Q],L,Option[X]] = new AbstractQueryStrategy[Option[Q], L, Option[X]] { + def query(q: Option[Q]) = q match { + case Some(innerQ) => self.query(innerQ).map(Some(_)) + case None => Set(None) + } + + def index(key: L) = self.index(key).map(Some(_)).toSet + None + } + /** Create new strategy on a this and a second query strategy */ def cross[Q2,L2,X2](qs2: QueryStrategy[Q2,L2,X2]): QueryStrategy[(Q,Q2),(L,L2),(X,X2)] = new AbstractQueryStrategy[(Q,Q2),(L,L2),(X,X2)] { From 3b21811b5250cc362adbc2d17a13e33e577353d4 Mon Sep 17 00:00:00 2001 From: Ian O Connell Date: Mon, 16 Dec 2013 13:48:41 -0800 Subject: [PATCH 2/2] Rename --- .../com/twitter/storehaus/algebra/query/QueryStrategy.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storehaus-algebra/src/main/scala/com/twitter/storehaus/algebra/query/QueryStrategy.scala b/storehaus-algebra/src/main/scala/com/twitter/storehaus/algebra/query/QueryStrategy.scala index 700b8d47..2602c272 100644 --- a/storehaus-algebra/src/main/scala/com/twitter/storehaus/algebra/query/QueryStrategy.scala +++ b/storehaus-algebra/src/main/scala/com/twitter/storehaus/algebra/query/QueryStrategy.scala @@ -37,7 +37,7 @@ trait QueryStrategy[-Q,-L,X] extends Serializable { self => /** Used in your summingbird job to flatmap your keys, increment all these X with the value */ def index(key: L): Set[X] - def withOptionalStrategy: QueryStrategy[Option[Q],L,Option[X]] = new AbstractQueryStrategy[Option[Q], L, Option[X]] { + def withOption: QueryStrategy[Option[Q],L,Option[X]] = new AbstractQueryStrategy[Option[Q], L, Option[X]] { def query(q: Option[Q]) = q match { case Some(innerQ) => self.query(innerQ).map(Some(_)) case None => Set(None)