Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,27 @@ object Scalding {
*/
def pipeFactory[T](factory: (DateRange) => Mappable[T])
(implicit timeOf: TimeExtractor[T]): PipeFactory[T] =
StateWithError[(Interval[Timestamp], Mode), List[FailureReason], FlowToPipe[T]]{
optionMappedPipeFactory(factory)(t => Some(t))

/**
* Like pipeFactory, but allows the output of the factory to be mapped.
*
* Useful when using TextLine, for example, where the lines need to be
* parsed before you can extract the timestamps.
*/
def mappedPipeFactory[T,U](factory: (DateRange) => Mappable[T])(fn: T => U)
(implicit timeOf: TimeExtractor[U]): PipeFactory[U] =
optionMappedPipeFactory(factory)(t => Some(fn(t)))

/**
* Like pipeFactory, but allows the output of the factory to be mapped to an optional value.
*
* Useful when using TextLine, for example, where the lines need to be
* parsed before you can extract the timestamps.
*/
def optionMappedPipeFactory[T,U](factory: (DateRange) => Mappable[T])(fn: T => Option[U])
(implicit timeOf: TimeExtractor[U]): PipeFactory[U] =
StateWithError[(Interval[Timestamp], Mode), List[FailureReason], FlowToPipe[U]]{
(timeMode: (Interval[Timestamp], Mode)) => {
val (timeSpan, mode) = timeMode

Expand All @@ -173,8 +193,10 @@ object Scalding {
((newIntr, mode), Reader { (fdM: (FlowDef, Mode)) =>
TypedPipe.from(mappable)(fdM._1, fdM._2)
.flatMap { t =>
val time = Timestamp(timeOf(t))
if(newIntr(time)) Some((time, t)) else None
fn(t).flatMap { mapped =>
val time = Timestamp(timeOf(mapped))
if(newIntr(time)) Some((time, mapped)) else None
}
}
})
}
Expand Down