This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package au.com.cba.omnia.eventually.ops | |
import au.com.cba.omnia.eventually.schema.{Entity, EntityAware} | |
import SelectEntitySyntax._ | |
import com.twitter.scalding.typed.{ TypedPipe, Grouped } | |
import scala.reflect.ClassTag | |
trait GroupByEntity[C] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The lag function is an analytic function that lets | |
* you query more than one event at a time. | |
* | |
* Finds events associated with previous events of the same type. | |
* For each item in the `events` pipe, find all `events` which occurred `offset` time steps | |
* in the past | |
* | |
* @param events Input data | |
* @param offset Time lag | |
* @return TypedPipe of Tupels (E[t-offset],E[t]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lag[A: Ordering : Timestamped : EntityAware] | |
(events: TypedPipe[A], | |
offset: Int): TypedPipe[(A, A)] = { | |
events | |
.groupByEntity | |
.sortBy(_.timestamp) | |
.mapValueStream { | |
events => { | |
events.sliding(2,offset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These are my two event classes... | |
case class Event1(id: Int, eventStartTime: DateTime, entityRoles: EntityRoles) | |
object Event1 { | |
override def toString = "ev1" | |
implicit val isTimeStamped: Timestamped[Event1] = | |
Timestamped.from(_.eventStartTime) | |
implicit val isEntityRoleAware: EntityRoleAware[Event1] = | |
EntityRoleAware.from(_.entityRoles.roles) | |
implicit val hasOrdering: Ordering[Event1] = | |
Ordering.by(e => (e.eventStartTime, e.entityRoles)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait LeftFolder[C <: Coproduct, In, F] extends Serializable { | |
def apply(c: C, in: In): In | |
} | |
object LeftFolder { | |
def apply[C <: Coproduct, In, F](implicit folder: LeftFolder[C, In, F]) = folder | |
implicit def hdLeftFolder[H, T <: Coproduct, In, F] | |
(implicit f: Case2.Aux[F, In, H, In]): LeftFolder[H :+: T, In, F] = new LeftFolder[H :+: T, In, F] { | |
def apply(c: H :+: T, in: In): In = c match { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless._ | |
import syntax._ | |
import poly._ | |
object LeftFolderOps { | |
trait LeftFolder[C <: Coproduct, In, F] extends Serializable { | |
def apply(c: C, in: In): In | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless._ | |
trait Test { | |
def ex[InL <: HList, H, T <: HList](in : InL)(implicit isHCons: IsHCons1.Aux[InL, List[H], T]) | |
val ii: List[Int]::List[Int]::HNil | |
ex(ii) | |
} | |
trait IsHCons1[L] { type H; type T <: HList} | |
object IsHCons1 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Abc { | |
import shapeless.{ =:!=, Nat, Succ } | |
import shapeless.nat.{ _0 => D0, _1 => D1, _2 => D2, _3 => D3 } | |
import shapeless.ops.nat.{ Diff, GT, LTEq, ToInt } | |
import shapeless.ops.hlist._ | |
trait Value { | |
def toShortString = ??? | |
} | |
object Value { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Def { | |
import shapeless.{ =:!=, HNil, HList, Nat, Poly1, Succ, Witness } | |
import shapeless.nat.{ _0 => D0, _1 => D1, _2 => D2, _3 => D3 } | |
import shapeless.ops.nat.{ Diff, GT, LTEq, ToInt } | |
import shapeless.ops.hlist.{ Mapper, ToTraversable, ZipConst } | |
trait Value { | |
def toShortString = ??? | |
} | |
object Value { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Def { | |
import shapeless.{ =:!=, HNil, HList, Nat, Poly1, Succ, Witness } | |
import shapeless.nat.{ _0 => D0, _1 => D1, _2 => D2, _3 => D3 } | |
import shapeless.ops.nat.{ Diff, GT, LTEq, ToInt } | |
import shapeless.ops.hlist.{ Mapper, ToTraversable, ZipConst } | |
trait Value { | |
def toShortString = ??? | |
} | |
object Value { |
OlderNewer