NICTA / scoobi

A Scala productivity framework for Hadoop.
http://nicta.github.com/scoobi/
482 stars 97 forks source link

ClassCastException at runtime #319

Closed etorreborre closed 1 year ago

etorreborre commented 10 years ago

The following exception fails at runtime with a ClassCastException:

import org.specs2._
import com.nicta.scoobi.Scoobi._
import com.nicta.scoobi.testing.mutable._
import com.nicta.scoobi.testing.SimpleJobs
import com.nicta.scoobi.testing.TestFiles._
import com.nicta.scoobi.testing.TempFiles
import scalaz.{DList => _, _}, Scalaz._

object ScalazWireFormats {
  import java.io._
  implicit def DisjunctionFmt[A, B](implicit wf: WireFormat[Either[A, B]]) = new WireFormat[A \/ B] {
    def toWire(v: A \/ B, out: DataOutput) = wf.toWire(v.toEither, out)
    def fromWire(in: DataInput): A \/ B = wf.fromWire(in).disjunction
    override def toString = "DisjunctionFmt["+wf.toString+"]"
    def show(v: A \/ B): String = v.toString
  }
}

class BugSpec extends HadoopSpecification with SimpleJobs {
  import ScalazWireFormats._

  "Should not get class cast exception" >> { implicit sc: ScoobiConfiguration =>

    val dlist: DList[String \/ Int] = DList("test".left, 1.right)

    val lefts: DList[String] = dlist.collect { case -\/(l) => l+"2" }
    val rights: DList[Int] = dlist.collect { case \/-(r) => r+1 }

    val other: DList[String \/ Int] = rights.map(r => (r.toString+"3").left[Int])
    val otherLefts = other.collect { case -\/(l) => l+"last" }

    val all = (lefts ++ otherLefts)

    val len = all.length
    persist(len, all.toTextFile("target/test", overwrite = true))
    len.run must be_==(2)
  }
}