0

I new to Scala (2.10) and currently working on a POC to store some data inside HBase. To store the data I'm trying to use the scala pickling library to serialise my case classes into a binary format

"org.scala-lang.modules" %% "scala-pickling" % "0.10.1"

I have these two simple classes:

case class Location(source: Source,
                    country: String,
                    region: String,
                    metro: String,
                    postalcode: String) {
}

And

case class Source(name: String,
                  trust: Float,
                  created: String) {

  /** compares this Source with the other source and returns the difference in their trust levels */
  def compare(other: Source): Float = {
    trust - other.trust
  }

  /** returns whether you should prefer this source (true) or the other source (false) */
  def prefer(other: Source): Boolean = {
    trust >= other.trust
  }
}

object Source {
  def apply(name: String, trust: Float) = new Source(name, trust, DateTime.now.toString)

  def apply(row: Row) = {
    val name = row.getAs[String](0)
    val trust = row.getAs[Float](1)
    val created = row.getAs[String](2)

    new Source(name, trust, created)
  }
}

And I'm testing out the serialisation using ScalaTest class

import scala.pickling._
import binary._

class DebuggingSpec extends UnitSpec {
  "debugging" should "Allow the serialisation and deserialisation of a Link class" in {
    val loc = new Location(Source("Source1", 1), "UK", "Wales", "Cardiff", "CF99 1PP")
    val bytes = loc.pickle

    bytes.value.length should not be(0)
  }

  it should "Allow the serialisation and deserialisation of a Location class" in {
    val link = Link(Source("Source1", 1), "MyId1", 3)
    val bytes = link.pickle

    bytes.value.length should not be(0)
  }
}

But when I compile this inside IntelliJ or on the command line via sbt package I get the following error message

Error:(12, 9) macro implementation not found: pickle (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)
    val bytes = loc.pickle
        ^

EDIT: I've run this code successfully in the spark-shell (1.3.1) and it will happily pickle and unpickle these classes... but identical code and import produce and error when compiling

Andy Long
  • 706
  • 5
  • 15
  • i guess this module uses macros ([Macros in Scala](http://docs.scala-lang.org/overviews/macros/overview.html)) to make serialization effective. you can dig in this direction. – pyanzin Oct 08 '15 at 14:12
  • @kedkod: I think I'll be looking for a different serialiser if i need to start looking at how its implementing macros... ;) – Andy Long Oct 08 '15 at 15:28

0 Answers0