Skip to content
Open
Changes from 2 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 @@ -19,7 +19,7 @@ package com.twitter.scalding.commons.source
import scala.reflect.ClassTag

import com.backtype.cascading.tap.PailTap
import com.backtype.hadoop.pail.PailStructure
import com.backtype.hadoop.pail.{ PailStructure, PailSpec }
import cascading.tap.Tap
import com.twitter.bijection.Injection
import com.twitter.scalding._
Expand Down Expand Up @@ -79,9 +79,16 @@ object PailSource {

/**
* Generic version of Pail sink accepts a PailStructure.
* Prefer the override taking a PailSpec as it gives you finer control over pail configuration (compression for ex)
*/
def sink[T](rootPath: String, structure: PailStructure[T]): PailSource[T] =
new PailSource(rootPath, structure)
sink(rootPath, PailTap.makeSpec(null, structure))

/**
* Generic version of Pail sink accepts a PailSpec.
*/
def sink[T](rootPath: String, spec: PailSpec): PailSource[T] =
new PailSource[T](rootPath, spec)

/**
* A Pail sink can also build its structure on the fly from a
Expand Down Expand Up @@ -113,10 +120,19 @@ object PailSource {

/**
* Generic version of Pail source accepts a PailStructure.
* Prefer the override taking a PailSpec as it gives you finer control over pail configuration (compression for ex)
*/
def source[T](rootPath: String, structure: PailStructure[T], subPaths: Array[List[String]]): PailSource[T] = {
assert(subPaths != null && subPaths.size > 0)
new PailSource(rootPath, structure, subPaths)
new PailSource[T](rootPath, PailTap.makeSpec(null, structure), subPaths)
}

/**
* Generic version of Pail source accepts a PailSpec.
*/
def source[T](rootPath: String, spec: PailSpec, subPaths: Array[List[String]]): PailSource[T] = {
assert(subPaths != null && subPaths.size > 0)
new PailSource[T](rootPath, spec, subPaths)
}

/**
Expand Down Expand Up @@ -145,15 +161,14 @@ object PailSource {
}
}

class PailSource[T] private (rootPath: String, structure: PailStructure[T], subPaths: Array[List[String]] = null)(implicit conv: TupleConverter[T])
class PailSource[T] private (rootPath: String, spec: PailSpec, subPaths: Array[List[String]] = null)(implicit conv: TupleConverter[T])
extends Source with Mappable[T] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add with TypedSink[T]? Is there any reason why you can't write to this?

import Dsl._

override def converter[U >: T] = TupleConverter.asSuperConverter[T, U](conv)
val fieldName = "pailItem"

lazy val getTap = {
val spec = PailTap.makeSpec(null, structure)
val javaSubPath = if ((subPaths == null) || (subPaths.size == 0)) null else subPaths map { _.asJava }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the constructor setting up the null for the list is private, and we only seem to care if the path is empty or not. Can we just default subPaths to an empty list and not need to do null checking?

val opts = new PailTap.PailTapOptions(spec, fieldName, javaSubPath, null)
new PailTap(rootPath, opts)
Expand Down