Skip to content

Instantly share code, notes, and snippets.

@emaxerrno
Created August 21, 2013 18:52
Show Gist options
  • Select an option

  • Save emaxerrno/6298625 to your computer and use it in GitHub Desktop.

Select an option

Save emaxerrno/6298625 to your computer and use it in GitHub Desktop.
deletedtt.java
def tupleListForPageView(pvld: PageViewLogData): TupleList = {
import com.yieldmo.hadoop.scalding.DiscreteVariableStates._
val isCell = (Option(pvld.getCellular()) getOrElse false).asInstanceOf[Boolean]
val location = Option(pvld.getLocation()) getOrElse { new Location }
var metro = "other"
var country = "other"
Option(location).foreach { loc: Location =>
if (loc.getMetroCode != 0) metro = "" + loc.getMetroCode
Option(loc.getCountryCode) foreach { x: String => country = getCountry(x) }
}
def tupleListForResult(list: Iterable[ResultImpression]): TupleList = list match {
case head :: tail =>
def creativeListToLabelList(creativeList: Iterable[ResultCreative]): TupleList = creativeList match{
case creativeHead::creativeTail =>
def randomVariableAssignment(l:String, assign: String):(Long,Long,String,String) =
(head.getPlacementId().toLong,creativeHead.getAdvertiserId.getValue,l,assign)
List(randomVariableAssignment("metro", metro),
randomVariableAssignment("country", country)) ++
creativeListToLabelList(creativeTail)
case Nil => List()
}
creativeListToLabelList(scala.collection.JavaConversions.asScalaIterable(head.getCreatives()))
case Nil => List()
}
tupleListForResult(scala.collection.JavaConversions.asScalaIterable(pvld.getResults()))
}
@fanatoly
Copy link
Copy Markdown

def creativeListToLabelList(creativeList: Iterable[ResultCreative]): TupleList = creativeList match{
          case creativeHead::creativeTail =>
            def randomVariableAssignment(l:String, assign: String):(Long,Long,String,String) =
              (head.getPlacementId().toLong,creativeHead.getAdvertiserId.getValue,l,assign)

            List(randomVariableAssignment("metro", metro),
              randomVariableAssignment("country", country)) ++
            creativeListToLabelList(creativeTail)
          case Nil => List()
        }

is the same as

def creativeListToLabelList(creativeList: Iterable[ResultCreative]): TupleList = creativeList flatMap{ creativeHead =>
            def randomVariableAssignment(l:String, assign: String):(Long,Long,String,String) =
              (head.getPlacementId().toLong,creativeHead.getAdvertiserId.getValue,l,assign)

            List(randomVariableAssignment("metro", metro),
              randomVariableAssignment("country", country))

        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment